Welcome! |
| | custom chat lua preview and help section | |
| | Author | Message |
---|
Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: custom chat lua preview and help section Wed Aug 25, 2010 4:36 am | |
| This is mostly for mun to look at and offer insight, because suggestions are always good. Taken from player_util.lua and placed it in chat.lua. If you decide to test this on your own, make sure you block out the original player_util.lua - Code:
-
-- this takes all 'say' inputs and sends them to client -- pl stands for the target player(s), ply is the speaker, -- cmd is the type of chat cmd, msg is the message itself
function CAKE.SendChat( pl, ply, cmd, msg ) umsg.Start( "chatupdate", pl ); umsg.String(pl); umsg.String(ply); umsg.String(cmd); umsg.String(msg); umsg.End( ); end
Now, this is all from cl_chatframe.lua - Code:
-
------------------------------- -- Olden's chatframe -- Author: Kain -- -- cl_chatframe.lua -- This shit is the chatframe, yo. -------------------------------
--Make note, this file is presently shared by the server and client. Will make it more independant and seperate the server/client parts later on.
-- this is our test font. Note the font size is scaled to screen. surface.CreateFont ("Arial", ScreenScale(20), 400, true, false, "Standard")
-- THE ALMIGHTY CHATLOG... IS CLIENTSIDE. Also a table. -- Yes, all chat lines eventually end up in a table named LOG, -- and each player gets one unique to the messages he/she -- will send and recieve.
pl.LOG = {}
-- Defining some colors to divide up message types when displaying them. -- These aren't all the types, just a few I've done so far.
say.color = 80, 165, 255, 100 me.color = 0, 190, 255, 100 yell.color = 240, 80, 45, 100 w.color = 85, 180, 90, 100
-- This function grabs the usermessage and formats it into our clientside chatlog.
function CAKE.ChatUpdate(entry) local pl = entry:ReadString(); local ply = entry:ReadString(); local cmd = entry:ReadString(); local msg = entry:ReadString(); cmd = string.sub(cmd, "/", "" ) local message = tostring(ply .. "^" .. cmd .. "^" .. text) table.insert( pl.LOG, message ) ChatRefresh(); end usermessage.Hook("chatupdate", ChatUpdate);
-- This function feels a little messy, but what it does is it -- formats our message table, line by line, to divide each -- line into 4 readable strings: line number, speaker, the -- chat command used, and the message itself.
function CAKE.ChatFormat( line, message )
local frmtmsg = string.Explode( ^ , message ) line.ply = frmtmsg[1] line.cmd = frmtmsg[2] line.msg = frmtmsg[3] return line, line.ply, line.cmd, line.msg end
-- And this is where the magic happens. Presently in alpha phase, -- the command is neither finished nor tested, but it should work -- fine once all the code is put together. This reads the cmd type of -- each line, picks out its color and formats the message accordingly.
function ChatRefresh();
for line , message in pairs( pl.LOG ) do CAKE.ChatFormat( line , message) if( line.cmd == say) then draw.DrawText( line.ply:Nick() .. ": " .. line.msg , "Standard", ScrW()/2, ScrH() - 300 - line*25, cmd.color, 0) elseif( line.cmd == yell) then draw.DrawText( line.ply:Nick() .. ": " .. line.msg , "Standard", ScrW()/2, ScrH() - 300 - line*25, cmd.color, 0) elseif( line.cmd == whisper) then draw.DrawText( line.ply:Nick() .. ": " .. line.msg , "Standard", ScrW()/2, ScrH() - 300 - line*25, cmd.color, 0) elseif( line.cmd == event) then elseif( line.cmd == report) then elseif( line.cmd == ooc) then elseif( line.cmd == broadcast) then elseif( line.cmd == me) then draw.DrawText( line.ply:Nick() .. ": " .. line.msg , "Standard", ScrW()/2, ScrH() - 300 - line*25, cmd.color, 0) elseif( line.cmd == pm) then
elseif( line.cmd == emote) then end
draw.DrawText( text , "Standard", screenpos.x, screenpos.y, line.cmd.color, 0)
end end
-- This little array will contain the info of our moighty chatframe. chatframe = {}
-- WITH THIS, WE SET OUR CHATBAUX IN MOSHUN -- This means, when you press enter, the real chat box -- opens up, but is hidden, but can still be 'used.' Handy, -- but this is only temporary until I get an independent -- system going (just need to find the entry for the key -- input that causes chat (like +forward for walking).
local function StartChat(TeamSay) OpenChat(); return true end hook.Add("StartChat", "HideMyChatBox", StartChat)
-- WITH THIS, WE MAKE IT SO WE CAN SEE WTF WE'RE TYPING. -- It has the text in the real chatbox show up in textentry.
function chatTextChangedHook( text ) textentry:SetValue( text ); end hook.Add( "ChatTextChanged", "ChatTextChangedHook", chatTextChangedHook );
-- This makes our chat both visible and usable.
function OpenChat() if( chatready == true) then chatframe:SetVisible( true ); chatframe:SetKeyboardInputEnabled( true ); chatframe:SetMouseInputEnabled( true ); chatform:SetVisible( true ); chatform:SetKeyboardInputEnabled( true ); chatform:SetMouseInputEnabled( true ); chatmenu:SetVisible( true ) chatmenu:SetKeyboardInputEnabled( true ) chatmenu:SetMouseInputEnabled( true ) textentry:SetVisible( true ); textentry:SetKeyboardInputEnabled( true ); textentry:SetMouseInputEnabled( true ); textentry:SetEnabled( true );
end
end
-- This hides our chat and makes it unusable
function CloseChat() if( chatready == true) then chatframe:SetVisible( false ); chatframe:SetKeyboardInputEnabled( false ); chatframe:SetMouseInputEnabled( false );
chatmenu:SetVisible( false ) chatmenu:SetKeyboardInputEnabled( false ) chatmenu:SetMouseInputEnabled( false ) chatform:SetVisible( false ); chatform:SetKeyboardInputEnabled( false ); chatform:SetMouseInputEnabled( false ); textentry:SetVisible( false ); textentry:SetKeyboardInputEnabled( false ); textentry:SetMouseInputEnabled( false ); textentry:SetEnabled( false ); textentry:SetValue( "" ); end end
-- This draws our derma chatbox. Even now, -- it's not working perfectly, because I broke it -- a little and forgot how it was when I had it -- working right. Main problems come from -- the textentry being misplaced. Make note, we -- don't remove this; it's hidden when not in use.
function DrawChat()
if(CLIENT) then
chatframe = vgui.Create( "DFrame" ) chatframe:SetSize( ScrW()/2 - ScrW()/8 + 6, ScrH()/2 - ScrH()/8 + 6) chatframe:SetPos( ScrW()/36, ScrH() - (ScrH()*13/32) ) chatframe:SetVisible( false ) chatframe:SetKeyboardInputEnabled( false ) chatframe:SetMouseInputEnabled( false ) chatframe:SetTitle( "Chatbox" ) chatframe:SetSizable(true) chatframe:SetDraggable(true) chatframe:ShowCloseButton( false )
chatform = vgui.Create("DForm"); chatform:SetSize( ScrW()/2 - ScrW()/8, ScrH()/2 - ScrH()/8) ; chatform:SetPos( ScrW()/36, ScrH() - (ScrH()*28/32) ); --actually 13/32 chatform:SetVisible( false ); chatform:SetKeyboardInputEnabled( false ); chatform:SetMouseInputEnabled( false ); chatform:SetParent( chatframe ); chatmenu = vgui.Create( "DPropertySheet" ); chatmenu:SetParent(chatframe); chatmenu:SetPos( 3, 30 ); chatmenu:SetSize( ScrW()/2 - ScrW()/8 - 6, ScrH()/2 - ScrH()/8 - 66 ); textentry = vgui.Create("DTextEntry"); chatform:AddItem(textentry); textentry:SetPos( 3, ScrH()*7/8 ); textentry:SetSize( ScrW()/2 - ScrW()/8 - 6, 25 ); textentry:SetValue(""); textentry:SetKeyboardInputEnabled( false ); textentry:SetMouseInputEnabled( false ); textentry.OnKeyCodePressed = function ( keycode ) if( keycode == KEY_ESCAPE ) then GM:FinishChat(); end end textentry.OnEnter = function() local say = textentry:GetValue(); GM:PlayerSay( say ) textentry:SetValue(""); GM:FinishChat(); end AllChat = vgui.Create("DPanelList"); AllChat:SetAutoSize(true); AllChat:SetPadding( 3, 3) AllBox = vgui.Create("DPanelList"); AllBox:SetSize( ScrW()/2 - ScrW()/8 - 12, ScrH()/2 - ScrH()/8 - 102 ); AllChat:AddItem(AllBox); ICChat = vgui.Create("DPanelList"); ICChat:SetAutoSize(true); ICChat:SetPadding( 3, 3) ICBox = vgui.Create("DPanelList"); ICBox:SetSize( ScrW()/2 - ScrW()/8 - 12, ScrH()/2 - ScrH()/8 - 102 ); ICChat:AddItem(ICBox); OOCChat = vgui.Create("DPanelList"); OOCChat:SetAutoSize(true); OOCChat:SetPadding( 3, 3) OOCBox = vgui.Create("DPanelList"); OOCBox:SetSize( ScrW()/2 - ScrW()/8 - 12, ScrH()/2 - ScrH()/8 - 102 ); OOCChat:AddItem(OOCBox); PMChat = vgui.Create("DPanelList"); PMChat:SetAutoSize(true); PMChat:SetPadding( 3, 3) PMBox = vgui.Create("DPanelList"); PMBox:SetSize( ScrW()/2 - ScrW()/8 - 12, ScrH()/2 - ScrH()/8 - 102 ); PMChat:AddItem(PMBox); chatmenu:AddSheet( "All", AllChat, nil, false, false, nil ); chatmenu:AddSheet( "In-Character", ICChat, nil, false, false, nil ); chatmenu:AddSheet( "Out-of-Character", OOCChat, nil, false, false, nil ); chatmenu:AddSheet( "Private Messages", PMChat, nil, false, false, nil ); end chatready = true end DrawChat()
Some thoughts: The whole system still feels a little messy, hasn't been fine tuned to get rid of the unnecessary parts and unnecessary steps (oh which, I'm sure some exists.) So, if any of you go through this and see obvious errors, please pas them my way, help is appreciated. Regular comments or suggestions are cool too. I dunno if I left out anything, but if you have any questions, feel free to ask.
Last edited by Kain on Thu Aug 26, 2010 3:38 pm; edited 1 time in total | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Wed Aug 25, 2010 4:42 am | |
| After I posted this, I realized the level of silliness to ChatRefresh, and I can do it with just one draw.DrawText if I remember to just format the messages beforehand, as they already are, and then, cmd.color takes care of the coloring after that... yeah, need sleep. But yeah, if you spot anything else I should fix, just lemme know. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Wed Aug 25, 2010 5:29 pm | |
| Update to ChatRefresh, removed silliness. Not sure if linecount will work with pl.LOG, though once the system is purely clientside, it should. The concept is right, though. - Code:
-
function ChatRefresh()
for line , message in pairs( pl.LOG ) do local linecount = table.getn( pl.LOG ) CAKE.ChatFormat( line , message) draw.DrawText( line.msg , "Standard", ScrW()/2, ScrH() - 300 - (linecount - line)*25, cmd.color, 0) end
end
Also, messed up on the colors, they are now fixed: - Code:
-
say.color = Color( 80, 165, 255, 100 ) me.color = Color( 0, 190, 255, 100 ) yell.color = Color( 240, 80, 45, 100 ) w.color = Color( 85, 180, 90, 100 )
There we go. Simpler is better. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Thu Aug 26, 2010 2:50 pm | |
| Completed and further improved color list. - Code:
-
color = {}
color[0] = Color( 255, 0, 0, 100 ) -- error color[1] = Color( 220, 195 , 57, 100 ) -- server message color[2] = Color( 80, 165, 255, 100 ) -- say color[3] = Color( 0, 190, 255, 100 ) -- me color[4] = Color( 230, 80, 45, 100 ) -- yell color[5] = Color( 85, 180, 90, 100 ) -- whisper color[6] = Color( 10, 115, 225, 100 ) -- anon or /? color[7] = Color( 100, 200, 255, 100 ) -- event color[8] = Color( 200, 210, 180, 100 ) -- broadcast color[9] = Color( 110, 70, 155, 100 ) -- report color[10] = Color( 190, 150, 235, 100 ) -- pm color[11] = Color( 255, 235, 225, 100 ) -- radio color[12] = Color( 180, 210, 180, 100 ) -- adverts color[13] = Color( 255, 255, 255, 100 ) -- ooc color[14] = Color( 150, 150, 150, 100 ) -- local ooc Had to revamp CAKE.SimpleChatCommand() function along with some playersay bits to have it coincide with new system. I don't even want to mention the 90+ CAKE.SendChat 's I had to edit... We're sloooowly getting there. Not entirely sure how I'm gonna hide parts of chat when we scroll up and down yet, but I'll get to that. Might end up changing how chat is drawn... we'll see. | |
| | | Munroe DEAR GOD DON'T LOOK IN HIS EYES
Posts : 1392 Join date : 2009-02-24 Location : Fortress of Ultimate Darkness
Character sheet Name: Age: Race:
| Subject: Re: custom chat lua preview and help section Thu Aug 26, 2010 4:18 pm | |
| I'm assuming you mean making it so the text is slowly occluded by the menu as you scroll rather than going line by line. If that's the case, then the best idea I have so far would be if you drew a rectangle or something towards the bottom; the rectangle would hide the text and not the menu itself, and if positioned properly, it would look like just a part of the chatframe. Otherwise, well, there's scripts out there (tacoscript?) that manage the same effect, including Robo's if I'm not mistaken. Give those a look. I don't think those used Derma, so you may be right about having to change the way text is drawn. I wouldn't worry too much about it; it seems like a lot of work for just a minor aesthetic.
Anyways, looks good so far. There aren't any errors jumping out at me, but if it's not working in-game I can give it a closer look. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Fri Aug 27, 2010 1:48 am | |
| You'd be surprised, there are a few errors in that first run.
I fixed those, but eh, we'll see. There are still more. It's a complicated thing.
As for making the text disappear, my first thought was having the alpha hit 0 once it reached a certain position (like say you scroll down and a line goes up, once it gets behind part of the chatframe, the alpha is set to 0 and it's still there, but invisible.
My only concern is how much strain having all these draw.DrawText's is going to have on the client... Kama's script already puts so much stress on the client that it's not even funny.
I'll post something more recent once I have it working. Maybe even a screenshot. | |
| | | Munroe DEAR GOD DON'T LOOK IN HIS EYES
Posts : 1392 Join date : 2009-02-24 Location : Fortress of Ultimate Darkness
Character sheet Name: Age: Race:
| Subject: Re: custom chat lua preview and help section Fri Aug 27, 2010 5:00 pm | |
| Ah, so what you meant was, the text isn't disappearing at all.
...Hm. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Sat Aug 28, 2010 11:44 am | |
| About the errors I had before: I tested the script again at my own computer, and I didn't get those errors, I got a completely different one. Guess it means that the errors were caused by the computer at the shop, though I dunno why that could be. Btw: It seems listen servers don't really come with usermessage.lua, as far as I can tell. Didn't for me. If that's the case, you'll have to use the server FTP, go to the garrysmod/lua/includes/modules/ and get usermessage.lua from there. EDIT: Scratch that, the function I called in the hook was ChatUpdate when it should have been CAKE.ChatUpdate (thus i was calling a nil function) ugggh so many errors but we're gettin der EDIT2: So here's where we are now: - Code:
-
count = 0
-- This function grabs the usermessage and formats it into our clientside chatlog. function CAKE.ChatUpdate( entry ) -- local pl = entry:ReadEntity(); local ply = entry:ReadEntity(); local clr = entry:ReadLong(); local msg = entry:ReadString(); local message = tostring( count .. "^" .. ply:Name() .. "^" .. clr .. "^" .. msg ) table.insert( LOG, message ) ChatRefresh(); count = count + 1 end usermessage.Hook( "chatupdate", CAKE.ChatUpdate );
Counting by table lines didn't work for some reason, so I've created our own counter. It should work fine. I've added the count to the string, 'cause, again, checking for lines by the table number doesn't seem to work. - Code:
-
function CAKE.ChatFormat( message )
local frmtmsg = string.Explode( "^" , message ) local row = tonumber(frmtmsg[1]) local ply = tostring(frmtmsg[2]) local clr = tonumber(frmtmsg[3]) local msg = tostring(frmtmsg[4]) return row, ply, clr, msg end
^^^ This thing up here pisssses me off. The reason is down below. - Code:
-
function ChatRefresh()
for line , message in pairs( LOG ) do local chat = CAKE.ChatFormat( message ) draw.DrawText( chat[4] , "Standard", ScrW()/2, ScrH() - 300 - (count - chat[1] )*25, chat[3], 0 ) end
end
In order to get row, ply, clr, and msg into the function, you gotta set it to some kind of global value. The only problem is it's only reading the first value (row) and I'm not sure how to make it distinguish between all 3. I'm gonna take a break and see if something comes to me. In the meantime, see if you can think of anything I missed. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Sat Aug 28, 2010 11:38 pm | |
| SO: Good times. Gonna have to incorporate it into the chatframe itself, and the colors are gonna need adjustment, too, but I hope you gaiz are happy. credit goes to Munroe, too, for helping me out here and der. | |
| | | Guest Guest
| Subject: Re: custom chat lua preview and help section Sun Aug 29, 2010 12:10 am | |
| It sucks.
No, just kidding. It's huge though, and I'd prefer it if you could see names. |
| | | Munroe DEAR GOD DON'T LOOK IN HIS EYES
Posts : 1392 Join date : 2009-02-24 Location : Fortress of Ultimate Darkness
Character sheet Name: Age: Race:
| Subject: Re: custom chat lua preview and help section Sun Aug 29, 2010 12:19 am | |
| You didn't read all the stuff in the image, xeno.
And good job, Kain. | |
| | | Guest Guest
| Subject: Re: custom chat lua preview and help section Sun Aug 29, 2010 12:25 am | |
| It should be bigger. BIGGER. |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Sun Aug 29, 2010 1:59 pm | |
| | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Thu Oct 14, 2010 2:29 pm | |
| Work on the chatframe has started up.
I've learned a bit more about derma, so I'm finally making progress on that end. If I can keep getting time to work on this, I might actually finish it within the week. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Wed Oct 20, 2010 3:35 am | |
| Just a bit of an update: The chatframe has made a looot of progress. It's now re-sizable, movable, and you can change the font size in realtime without any consequences (we switched from the old draw.DrawText method to using Derma). There are a set number of fonts you can use, but the range is wide enough that they'll get the job done. Furthermore, chat lines organize themselves into the chatbox, in multiple lines. I'll be finishing it with these features: - preset and custom filters ( presets being IC, OOC, PM's, etc)
- customizable color scheme for each message type
- the ability to give each set of filters a different color scheme
- pming a player by clicking on their name in the chatbox (WoW inspired)
- the abilty to make chat 'channels' of both OOC and IC types
- having all these things save on the client's comp and be loaded up later on.
- client-side logs for convenience of record keeping.
If there's anything you'd like to see added, tell me and I'll see what more I can do At this point, I'm not sure if the chat's gonna be too bulky/slow or if it'll run perfectly fine. Gonna have to actually test it on the server at some point. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Sat Nov 06, 2010 5:44 am | |
| Alright, so the chatframe script is ready for launch. There is one bug remaining that I need to fix, and it will be fixed shortly, pending some rest. Below are the features I stated were last left. Anything striked out is complete. Anything wtih ~ ~ on its sides means the basis of it is set up, but its on hold. (X) means I'm canceling that feature. - Quote :
-
preset and custom filters ( presets being IC, OOC, PM's, etc)
-
customizable color scheme for each message type
- (X) the ability to give each set of filters a different color scheme (X)
-
pming a player by clicking on their name in the chatbox (WoW inspired)
- ~the abilty to make chat 'channels' of both OOC and IC types~
-
having all these things save on the client's comp and be loaded up later on.
-
client-side logs for convenience of record keeping.
So far, so good. If there aren't any objections, I'd like to do a dry-run tomorrow to see how well it works and what people think. | |
| | | Kain
Posts : 1427 Join date : 2009-03-24 Location : Somewhere Pat doesn't want me to be
Character sheet Name: Kain Redwell Age: ??? Race: Human (?)
| Subject: Re: custom chat lua preview and help section Sat Nov 06, 2010 10:10 pm | |
| | |
| | | Sponsored content
| Subject: Re: custom chat lua preview and help section | |
| |
| | | | custom chat lua preview and help section | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |
|