---------------------------- -- Phoenix Script -- by Robo -- -- Clientside drawing and umsg receiving for chat frame. ---------------------------- -- Chat sizes: -- 480-599 = 12 -- 600-767 = 13 -- 768-1023 = 14 -- 1024-1199 = 20 -- 1200-10000 = 24 /* local ChatOffset = 12; if( ScrH() > 1199 ) then ChatOffset = 24; elseif( ScrH() > 1023 ) then ChatOffset = 20; elseif( ScrH() > 767 ) then ChatOffset = 14; elseif( ScrH() > 599 ) then ChatOffset = 13; end */ -- Makes sure no left over GUI elements from last load. if( ChatFrame ) then if( ChatPropertySheet ) then ChatPropertySheet:Remove(); ChatPropertySheet = nil; end if( ChatText ) then ChatText:Remove(); ChatText = nil; end if( AllChat ) then AllChat:Remove(); AllChat = nil; end if( OOCChat ) then OOCChat:Remove(); OOCChat = nil; end if( ICChat ) then ICChat:Remove(); ICChat = nil; end if( PMChat ) then PMChat:Remove(); PMChat = nil; end ChatFrame:Remove(); ChatFrame = nil; end function drawFadedChatFrame() if( LocalPlayer():GetNWInt("chatopen") == 1 ) then return; end if ( !ChatFrame ) then DrawNewChat(); end -- read derma internals to do this new trick, since hacking the derma to do this stopped working after some background update :( local ActiveTab = ChatPropertySheet:GetActiveTab() local ActivePanel = ActiveTab:GetPanel(); -- ActivePanel is now one of our DPanelLists -- we draw stright to screen to give the illusion of faded derma now, rather than hacking the derma to do it. -- we use the scroll bar value it holds to determine which to draw -- number of elements it has also is of importance local count = math.floor( ActivePanel.VBar.Scroll / 14 ) + 1; for i = count, count + 7 do local tempValue = ActivePanel.Items[i]; --AllChat:SetPos( 30 + 5 + 5 + 5, ScrH() - 340 +30 + 5 + 30 ); draw.SimpleTextOutlined( tempValue:GetText(), "NewChatFont", 45 , ScrH() - 285 + 14 * (i - count), tempValue:GetColor(), 0, 0, 1, Color(0,0,0,255) ); end end surface.CreateFont( "ChatFont", 14, 800, true, false, "NewChatFont" ); -- 1st line from TS --surface.CreateFont( "ChatFont", 14, 800, true, false, "NewChatFont" ); --surface.CreateFont( "DefaultBold", 14, 800, true, false, "NewDefaultBold" ); -- Overriding on the fly doesn't replace the old font unfortunately -- Used just to define the font we're using on client connect /* function ChatOverrideFont() if( string.match( clientSettings["chatframefont"], "ChatFont" ) ) then --RunConsoleCommand("gm_clearfonts", "\n"); BAD DO NOT RUN elseif( string.match( clientSettings["chatframefont"], "DefaultBold" ) ) then --RunConsoleCommand("gm_clearfonts", "\n"); BAD DO NOT RUN surface.CreateFont( "DefaultBold", tonumber( clientSettings["fontsize"] ), 800, true, false, "NewDefaultBold" ); end end -- was used to help hack derma to do a more panel like usage with derma easy of coding local function OverrideRebuild( inPanel ) --------------------------------------------------------- -- Name: Rebuild --------------------------------------------------------- inPanel.Rebuild = function() local Offset = 0 -- 30 + 5 + 5, ScrH() - 340 +30 + 30 inPanel:SetPos( 40, ScrH() - 283 ); for k, panel in pairs( inPanel.Items ) do panel:SetSize( inPanel:GetCanvas():GetWide() - inPanel.Padding * 2, panel:GetTall() ) panel:SetPos( inPanel.Padding, inPanel.Padding + Offset ) // Changing the width might ultimately change the height // So give the panel a chance to change its height now, // so when we call GetTall below the height will be correct. // True means layout now. panel:InvalidateLayout( true ) Offset = Offset + panel:GetTall() + inPanel.Spacing end inPanel:GetCanvas():SetTall( Offset + (inPanel.Padding) - inPanel.Spacing ) end end */ -- this will draw the chat frame. Called from GM:HUDPaint() in cl_hud.lua function DrawNewChat() -- If it already exists, return, don't want multiples or to reset it. if( ChatFrame ) then return; end ChatFrame = vgui.Create("DFrame"); ChatFrame:SetSizable(false); -- not resizeable. ChatFrame:SetScreenLock(true); -- locks it on screen, cannot be dragged off screen. ChatFrame:SetVisible(false); -- make sure we can see it ChatFrame:SetDraggable(false); -- cannot be moved ChatFrame:ShowCloseButton(true); -- can be closed ChatFrame:SetDeleteOnClose(false); -- do NOT delete on close ChatFrame:SetTitle(""); ChatFrame.btnClose.DoClick = function ( button ) CloseChat(); end --ChatFrame:EnableTitle(false); -- lets see if this works -- doesn't work for derma --ChatFrame:MakePopup(); -- make sure its not hidden -- dun need input, or it up right away. no. ChatFrame:SetPos( 30, ScrH() - 340 ); -- 39, ScrH() - 335 ChatFrame:SetSize( ScrW() * .5 - 19, 180); --ChatFrame:SetSize( ScrW() * .5 - 19, 200); ChatPropertySheet = vgui.Create("DPropertySheet", ChatFrame); --ChatPropertySheet:SetPos( 30 + 5, ScrH() - 340 + 30 ); ChatPropertySheet:SetPos( 5, 30 ); ChatPropertySheet:SetSize( ScrW() * .5 - 19 - 10, 145 ); -- height must not go beyond 175 to have 5 buffer to text entry ChatText = vgui.Create( "DTextEntry" ); --ChatText:SetPos( 5, 180 ); ChatText:SetPos( 30 + 5, ScrH() - 340 + 180 ); ChatText:SetSize( ScrW() * .5 - 19 - 10, 15 ); --ChatText:SetVisible( false ); ChatText:SetEnabled( true ); ChatText:SetKeyboardInputEnabled( true ); ChatText:SetMouseInputEnabled( true ); ChatText.OnKeyCodePressed = function ( keycode ) if( keycode == KEY_ESCAPE ) then CloseChat(); else if( string.len( ChatText:GetValue() ) >= 110 ) then LocalPlayer():EmitSound( "select_node_backward.wav" ); end if( string.len( ChatText:GetValue() ) >= 120 ) then --LocalPlayer():EmitSound( "select_node_backward.wav" ); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "TextEntry length: " .. string.len(ChatText:GetValue() )); local firstWord = ""; -- only want the first word. filter = anything but space -- capital is complement of the set for word in string.gmatch( ChatText:GetValue(), "%S+" ) do firstWord = word; break; end --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "firstWord is: " .. firstWord .. "\n"); -- see if they used a / command, if so copy it. if( string.find( firstWord, "/" ) == nil ) then firstWord = ""; else firstWord = firstWord .. " "; end --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "firstWord is now: " .. firstWord .. "\n"); RunConsoleCommand( "say", ChatText:GetValue() .. "\n" ); ChatText:SetText( firstWord ); ChatText:SetCaretPos( string.len(firstWord) ); --ChatText:UpdateConvarValue(); -- not the cursor --ChatText:SetValue( firstWord ); return; --ChatText:SetText( string.sub( ChatText:GetValue(), 1, 254 ) ); end end end -- Concommand max length is 255 -- breakup the string clientside to avoid problems in translation. -- Estimate the first line uses their "Name: " to adjust 1st line length -- Fix bad words: known "exec", "bind", "bindall" ChatText.OnEnter = function() if( string.gsub( ChatText:GetValue(), " ", "" ) == "" ) then CloseChat(); return; end --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "ChatValue is: " .. ChatText:GetValue() .. "\n"); RunConsoleCommand( "say", ChatText:GetValue() .. "\n" ); ChatText:SetText(""); CloseChat(); end AllChat = vgui.Create( "DPanelList" ); AllChat:EnableHorizontal(false); AllChat:EnableVerticalScrollbar(true); AllChat:SetPadding(5); --AllChat:SetDrawBackground( false ); OOCChat = vgui.Create( "DPanelList" ); OOCChat:EnableHorizontal(false); OOCChat:EnableVerticalScrollbar(true); OOCChat:SetPadding(5); --OOCChat:SetDrawBackground( false ); ICChat = vgui.Create( "DPanelList" ); ICChat:EnableHorizontal(false); ICChat:EnableVerticalScrollbar(true); ICChat:SetPadding(5); --ICChat:SetDrawBackground( false ); PMChat = vgui.Create( "DPanelList" ); PMChat:EnableHorizontal(false); PMChat:EnableVerticalScrollbar(true); PMChat:SetPadding(5); --PMChat:SetDrawBackground( false ); -- Keeps track of # of lines to check if should add scroll automatically. AllChat.Count = 0; OOCChat.Count = 0; ICChat.Count = 0; PMChat.Count = 0; -- Sheet one. -- All chat icon horiz vert tooltip ChatPropertySheet:AddSheet( " All ", AllChat, false, false, false, false ); -- Sheet two. -- OOC Chat ChatPropertySheet:AddSheet( " OOC ", OOCChat, false, false, false, false ); -- Sheet three. -- IC Chat ChatPropertySheet:AddSheet( " IC ", ICChat, false, false, false, false ); -- Sheet four. -- PM ChatPropertySheet:AddSheet( " PM ", PMChat, false, false, false, false ); -- THIS WAS PART OF DERMA HACK MODDING --AllChat:SetParent( nil ); --OverrideRebuild( AllChat ); --AllChat:SetPos( 30 + 5 + 5 + 5, ScrH() - 340 +30 + 5 + 30 ); -- X: +30 (chatframe) +5 (property) +5 (padding) +5 (property position) --AllChat.X = 30 + 5 + 5 + 5; --AllChat.Y = ScrH() - 340 +30 + 5 + 30; --OOCChat:SetParent( nil ); --OverrideRebuild( OOCChat ); --OOCChat:SetPos( 30 + 5 + 5 + 5, ScrH() - 340 +30 + 5 + 30 ); -- Y: +scrh()-340 (chatframe) +30 (property) +5 (padding) +30 (property position) --OOCChat.X = 30 + 5 + 5 + 5; --OOCChat.Y = ScrH() - 340 +30 + 5 + 30; --ICChat:SetParent( nil ); --OverrideRebuild( ICChat ); --ICChat:SetPos( 30 + 5 + 5 + 5, ScrH() - 340 +30 + 5 + 30 ); --ICChat.X = 30 + 5 + 5 + 5; --ICChat.Y = ScrH() - 340 +30 + 5 + 30; --PMChat:SetParent( nil ); --OverrideRebuild( PMChat ); --PMChat:SetPos( 30 + 5 + 5 + 5, ScrH() - 340 +30 + 5 + 30 ); --PMChat.X = 30 + 5 + 5 + 5; --PMChat.Y = ScrH() - 340 +30 + 5 + 30; end -- Call this to add chat to a player's frame. -- Text is the string to send them. -- Channel #'s are: -- 1 - IC -- 2 - OOC -- 3 - PM -- Vector for the color of the text. -- Message format: -- Text String of what you want added, no supplementing is done in this function (yet?). ---- could allow longer msgs, but at this point would just add more work with little returns -- Integer for the channel to add it to, saves thinking about string dissemination. -- Vector for color of the text. function AddChat(data) if( AllChat == nil ) then return; end local text = data:ReadString(); local textTwo = data:ReadString2(); local channel = data:ReadShort(); local vector = data:ReadVector(); local color = Color( vector.x, vector.y, vector.z, 255 ); local outputText = ""; local referText = ""; local offset = 0; -- seems umsg string length is about 130-140, split up to allow the max length of concmds to be used. text = text .. textTwo; -- Fail cases: -- thats actually pretty handy in a legit rp environment -- figure out why sending a string will do -- Wait 1 seconds --PrintTable( string.Explode(" ", text ) ); -- needed for font width checking surface.SetFont( "NewChatFont" ); -- explode the string into a table with numerical indices. for u, w in ipairs ( string.Explode(" ", text ) ) do -- if output is empty, doing first word of the line. if ( string.len( outputText ) == 0 ) then outputText = w; -- items in the output else -- if adding the next word would exceed the chat screen size, lock offset to block any -- smaller words from being added, put all the rest of the words in referText. local wW, hW = surface.GetTextSize( w ); local wOut, hOut = surface.GetTextSize( outputText ); if( wW + wOut + offset >= (ScrW() * .5 - 19 - 10 - 10 - 40) ) then offset = ScrW(); referText = referText .. w .. " "; -- add next word to output and reloop. else outputText = outputText .. " " .. w; end end end --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Output : " .. outputText .. " || Refer: " .. referText .."\n"); local notUsed, ChatOffset = surface.GetTextSize( outputText ); local label = vgui.Create("DLabel"); label:SetFont( "NewChatFont" ); label:SetText( outputText ); label:SizeToContents(); label:SetTextColor( color ); label.GetText = function() return outputText; end; label.GetColor = function() return color; end; --label.SetVisible = function () end; -- Add a line of text to the appropriate tabs. -- Scroll them down by 1 line of text which translates to a value of 13 internally -- Increment the scroll first, AllChat:AddItem(label); AllChat.Count = AllChat.Count + 1; -- make it only remember 50 items if( AllChat.Count > 50 ) then local tempPanel = table.remove( AllChat.Items, 1 ); tempPanel:SetParent( tempPanel ); tempPanel:SetVisible( false ); tempPanel:Remove(); AllChat:InvalidateLayout(); elseif ( AllChat.Count * ChatOffset >= 104 ) then AllChat.VBar.Scroll = ChatOffset * AllChat.Count - 104 ; -- adjust the scroll bar. end -- Create a second duplicate label to get around the issue of each vgui can only have 1 parent. local label2 = vgui.Create("DLabel"); label2:SetFont( "NewChatFont" ); label2:SetText( outputText ); label2:SizeToContents(); label2:SetTextColor( color ); label2.GetText = function() return outputText; end; label2.GetColor = function() return color; end; --label2.SetVisible = function () end; if ( channel == 1 ) then -- make it only remember 50 items if( ICChat.Count > 50 ) then local tempPanel = table.remove( ICChat.Items, 1 ); tempPanel:SetParent( tempPanel ); tempPanel:SetVisible( false ); tempPanel:Remove(); ICChat:InvalidateLayout(); elseif ( ICChat.Count * ChatOffset >= 104 ) then ICChat.VBar.Scroll = ChatOffset * ICChat.Count - 104; end ICChat:AddItem(label2); ICChat.Count = ICChat.Count + 1; elseif ( channel == 2 ) then -- make it only remember 50 items if( OOCChat.Count > 50 ) then local tempPanel = table.remove( OOCChat.Items, 1 ); tempPanel:SetParent( tempPanel ); tempPanel:SetVisible( false ); tempPanel:Remove(); OOCChat:InvalidateLayout(); elseif ( OOCChat.Count * ChatOffset >= 104 ) then OOCChat.VBar.Scroll = ChatOffset * OOCChat.Count - 104; end OOCChat:AddItem(label2); OOCChat.Count = OOCChat.Count + 1; elseif ( channel == 3 ) then -- make it only remember 50 items if( PMChat.Count > 50 ) then local tempPanel = table.remove( PMChat.Items, 1 ); tempPanel:SetParent( tempPanel ); tempPanel:SetVisible( false ); tempPanel:Remove(); PMChat:InvalidateLayout(); elseif ( PMChat.Count * ChatOffset >= 104 ) then PMChat.VBar.Scroll = ChatOffset * PMChat.Count - 104; end PMChat:AddItem(label2); PMChat.Count = PMChat.Count + 1; end -- Handling message breakup on client send to make sending it easier serverside. if ( string.gsub(referText, " ", "") != "" ) then local sendData = {}; sendData.ReadString = function() return referText end; sendData.ReadString2 = function() return "" end; sendData.ReadShort = function() return channel end; sendData.ReadVector = function() return vector end; AddChat(sendData); end end -- Should catch anything sent to the chat frame and put a copy of it in console. -- Also, refers it to the client to be put in the chat frame. function AddConsole(data) local text = data:ReadString(); local text2 = data:ReadString(); local channel = data:ReadShort(); local vector = data:ReadVector(); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "text: " .. text .. "\n"); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "text2: " .. text2 .. "\n"); local data2 = {}; data2.ReadString = function() return text; end; data2.ReadString2 = function() return text2; end; data2.ReadShort = function() return channel; end; data2.ReadVector = function() return vector; end; AddChat(data2); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, text .. text2 .. "\n"); Msg( text .. text2 .. "\n"); end usermessage.Hook("AddChat", AddConsole); -- 8 lines needed before compensating -- 100 chars per line or .. occurs and text lost -- Delta per line is 13 function TestDelta() --surface.SetFont( "NewChatFont" ); --local notUsed, ChatOffset = surface.GetTextSize( "this is a test" ); for u, v in pairs( AllChat.Items ) do LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Type is: " .. type(u) .. "\n" ); LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Values: " .. u .. " and: " .. v:GetText() .. "\n" ); local tryBracket = AllChat.Items[ u ]; if( tryBracket == nil ) then LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Bracket nil\n" ); end local tryPeriod = AllChat.Items.u; if( tryPeriod == nil ) then LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Period nil\n" ); end end --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Divider value is: " .. AllChat.VBar.Scroll / 14 .. "\n" ); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Height is: " .. ChatOffset .. "\n"); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "AllChat Offset: " .. AllChat.VBar:GetScroll() .. "\n" ); --LocalPlayer():ChatPrint( "ICChat: " .. ICChat.VBar:GetScroll() ); --LocalPlayer():ChatPrint( "AC X: " .. AllChat.pnlCanvas.X .. " Y: " .. AllChat.pnlCanvas.Y ); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "Property X: " .. AllChat.X .. " Y: " .. AllChat.Y ); --LocalPlayer():PrintMessage( HUD_PRINTCONSOLE, "X wide: " .. AllChat:GetCanvas():GetWide() .. " Y wide: " .. AllChat:GetTall() ); end usermessage.Hook("TestDelta", TestDelta); -- Can be called clientside anywhere. -- Sets all chat components visible. -- Activates the Text entry. function OpenChat() --ChatFrame:SetPaintBackgroundEnabled( true ); --ChatPropertySheet:SetPaintBackgroundEnabled( true ); --ChatPropertySheet:SetPaintBorderEnabled( true ); --ChatPropertySheet:SetAlpha( 255 ); --ChatPropertySheet.Items[1].Tab:SetVisible( true ); --ChatPropertySheet.Items[2].Tab:SetVisible( true ); --ChatPropertySheet.Items[3].Tab:SetVisible( true ); --ChatPropertySheet.Items[4].Tab:SetVisible( true ); --ChatPropertySheet.Items[1].Panel:SetPaintBorderEnabled( true ); --ChatPropertySheet.Items[2].Panel:SetPaintBorderEnabled( true ); --ChatPropertySheet.Items[3].Panel:SetPaintBorderEnabled( true ); --ChatPropertySheet.Items[4].Panel:SetPaintBorderEnabled( true ); RunConsoleCommand("rp_openedchat", "\n"); ChatFrame:SetVisible( true ); ChatFrame:MakePopup(); gui.EnableScreenClicker( true ); ChatText:MakePopup(); ChatText:SetVisible( true ); /* ChatFrame:SetAlpha( 200 ); PMChat:SetDrawBackground( true ); ICChat:SetDrawBackground( true ); OOCChat:SetDrawBackground( true ); AllChat:SetDrawBackground( true ); ChatPropertySheet:SetAlpha( 200 ); --AllChat:SetAlpha( 200 ); -- makes the text stay partial, looks smokey --OOCChat:SetAlpha( 200 ); --ICChat:SetAlpha( 200 ); --PMChat:SetAlpha( 200 ); AllChat.VBar:SetAlpha( 255 ); OOCChat.VBar:SetAlpha( 255 ); ICChat.VBar:SetAlpha( 255 ); PMChat.VBar:SetAlpha( 255 ); */ end -- Can be called clientside anywhere. -- Attempts to set all but the tabs to invisible. -- Disables the text entry. function CloseChat() if ( !ChatFrame ) then DrawNewChat(); end RunConsoleCommand("rp_closedchat", "\n"); --ChatFrame:SetPaintBackgroundEnabled( false ); --ChatPropertySheet:SetPaintBackgroundEnabled( false ); --ChatPropertySheet:SetPaintBorderEnabled( false ); --ChatPropertySheet:SetAlpha( 0 ); --( ChatPropertySheet:GetActiveTab() ):SetAlpha( 255 ); --ChatPropertySheet.Items[1].Tab:SetVisible( false ); --ChatPropertySheet.Items[2].Tab:SetVisible( false ); --ChatPropertySheet.Items[3].Tab:SetVisible( false ); --ChatPropertySheet.Items[4].Tab:SetVisible( false ); --ChatPropertySheet.Items[1].Panel:SetPaintBorderEnabled( false ); --ChatPropertySheet.Items[2].Panel:SetPaintBorderEnabled( false ); --ChatPropertySheet.Items[3].Panel:SetPaintBorderEnabled( false ); --ChatPropertySheet.Items[4].Panel:SetPaintBorderEnabled( false ); ChatFrame:SetVisible(false); gui.EnableScreenClicker( false ); ChatText:SetText(""); ChatText:SetVisible(false); /* PMChat:SetDrawBackground( false ); ICChat:SetDrawBackground( false ); OOCChat:SetDrawBackground( false ); AllChat:SetDrawBackground( false ); AllChat.VBar:SetAlpha( 0 ); OOCChat.VBar:SetAlpha( 0 ); ICChat.VBar:SetAlpha( 0 ); PMChat.VBar:SetAlpha( 0 ); */ end ------------------ ------------------ --- MOVED CODE STUFFZ ------------------ ------------------ /* sendText = ChatText:GetValue(); outputText = ""; offset = string.len( LocalPlayer():Nick() .. ": " ) + 10 -- +10 for compensation on whisper/pm (worst case) -- filter ".^%s" means all characters not space -- for w in string.gmatch( sendText, "[.^%s]" ) do RunConsoleCommand( "say", "TEST " .. ChatText:GetValue() .. "\n" ); RunConsoleCommand( "say", "SIZE: " .. table.Count( string.Explode(" ", sendText) ) .. "\n" ); for u, w in ipairs ( string.Explode(" ", sendText ) ) do -- if output is empty, doing first word of the line. if ( string.len( outputText ) == 0 ) then outputText = w; -- items in the output else -- if adding the next word would exceed the line + offset, say it to the server. -- set the offset to 0, for all future lines which have nothing added to them. -- After sending the output text, set the output to be the current word. if( string.len(outputText) + string.len(w) + offset > 100 ) then RunConsoleCommand( "say", outputText .. "\n" ); offset = 0; outputText = w; -- add next word to output and reloop. else outputText = outputText .. " " .. w; end end end -- make sure we don't miss the last line. if ( string.len( outputText ) > 0 ) then RunConsoleCommand( "say", outputText .. "\n" ); end ChatText:SetText(""); CloseChat(); */