diff --git a/emojichat/lua/emojichat/cl_chat-overrides.lua b/emojichat/lua/emojichat/cl_chat-overrides.lua index 78c6765..6978d36 100644 --- a/emojichat/lua/emojichat/cl_chat-overrides.lua +++ b/emojichat/lua/emojichat/cl_chat-overrides.lua @@ -1,7 +1,7 @@ local oldAddText = chat.AddText function chat.AddText(...) - eChat.AddLine(TextComponentBuilder.Build(...)) - oldAddText(...) + eChat.AddLine(TextComponentBuilder.Build(...)) + oldAddText(...) end chat.Open = eChat.showBox diff --git a/emojichat/lua/emojichat/cl_echat.lua b/emojichat/lua/emojichat/cl_echat.lua index 1f5cdbc..46f35df 100644 --- a/emojichat/lua/emojichat/cl_echat.lua +++ b/emojichat/lua/emojichat/cl_echat.lua @@ -2,19 +2,19 @@ CHATMODE_GLOBAL = 1 CHATMODE_TEAM = 2 eChat = { - Ready = false, - Active = false, - ChatMode = CHATMODE_GLOBAL, - ExistingMessages = { }, - HTMLOutput = nil + Ready = false, + Active = false, + ChatMode = CHATMODE_GLOBAL, + ExistingMessages = { }, + HTMLOutput = nil } eChat.config = { - html = table.concat(emojichatHTML), - timestamps = true, - position = 1, - fadeTime = 12, - defaultChatColour = Color(255, 255, 255, 255), - timestampColour = Color(255, 255, 255, 255), - serverMessageColour = Color(151, 211, 255, 255) + html = table.concat(emojichatHTML), + timestamps = true, + position = 1, + fadeTime = 12, + defaultChatColour = Color(255, 255, 255, 255), + timestampColour = Color(255, 255, 255, 255), + serverMessageColour = Color(151, 211, 255, 255) } diff --git a/emojichat/lua/emojichat/cl_hooks.lua b/emojichat/lua/emojichat/cl_hooks.lua index 5d2a3ec..ad62c7d 100644 --- a/emojichat/lua/emojichat/cl_hooks.lua +++ b/emojichat/lua/emojichat/cl_hooks.lua @@ -1,34 +1,34 @@ hook.Remove("Initialize", "emojichat_init") hook.Add("Initialize", "emojichat_init", function() -- TODO: Can this get called too early? - eChat.AddServerMessage("EmojiChat by Badger") + eChat.AddServerMessage("EmojiChat by Badger") eChat.buildBox() end) hook.Remove("ChatText", "emojichat_joinleave") hook.Add("ChatText", "emojichat_joinleave", function( index, name, text, type ) - if type != "chat" then - eChat.AddServerMessage(text) - return true - end + if type != "chat" then + eChat.AddServerMessage(text) + return true + end end) hook.Remove("PlayerBindPress", "emojichat_hijackbind") hook.Add("PlayerBindPress", "emojichat_hijackbind", function(ply, bind, pressed) - if string.sub( bind, 1, 11 ) == "messagemode" then - local chatMode = CHATMODE_GLOBAL - if bind == "messagemode2" then - chatMode = CHATMODE_TEAM - end + if string.sub( bind, 1, 11 ) == "messagemode" then + local chatMode = CHATMODE_GLOBAL + if bind == "messagemode2" then + chatMode = CHATMODE_TEAM + end - eChat.showBox(chatMode) - return true - end + eChat.showBox(chatMode) + return true + end end) hook.Remove("HUDShouldDraw", "emojichat_hidedefault") hook.Add("HUDShouldDraw", "emojichat_hidedefault", function( name ) - if name == "CHudChat" then - return false - end + if name == "CHudChat" then + return false + end end) diff --git a/emojichat/lua/emojichat/cl_html-chat-callbacks.lua b/emojichat/lua/emojichat/cl_html-chat-callbacks.lua index bf01dc9..d9f72ac 100644 --- a/emojichat/lua/emojichat/cl_html-chat-callbacks.lua +++ b/emojichat/lua/emojichat/cl_html-chat-callbacks.lua @@ -1,35 +1,35 @@ HTMLChatCallbacks = {} function HTMLChatCallbacks.SendMessage(message, destination) - if string.Trim( message ) != "" then + if string.Trim( message ) != "" then - if destination == DESTINATION_TEAM then - LocalPlayer():ConCommand("say_team \"" .. (message or "") .. "\"") + if destination == DESTINATION_TEAM then + LocalPlayer():ConCommand("say_team \"" .. (message or "") .. "\"") - elseif destination == DESTINATION_CONSOLE then - LocalPlayer():ConCommand(message or "") + elseif destination == DESTINATION_CONSOLE then + LocalPlayer():ConCommand(message or "") - else - LocalPlayer():ConCommand("say \"" .. message .. "\"") + else + LocalPlayer():ConCommand("say \"" .. message .. "\"") - end - end + end + end - eChat.hideBox() - HTMLChatCallbacks.InputChange("") + eChat.hideBox() + HTMLChatCallbacks.InputChange("") end function HTMLChatCallbacks.InputChange(newValue) - hook.Run("ChatTextChanged", newValue) + hook.Run("ChatTextChanged", newValue) end function HTMLChatCallbacks.CloseChat() eChat.hideBox() - gui.HideGameUI() + gui.HideGameUI() end function HTMLChatCallbacks.PlayWarningSound() - surface.PlaySound("resource/warning.wav") + surface.PlaySound("resource/warning.wav") end function HTMLChatCallbacks.HideMenu() @@ -37,6 +37,6 @@ function HTMLChatCallbacks.HideMenu() end function HTMLChatCallbacks.OpenURL(url) - gui.OpenURL(url) - HTMLChatCallbacks.CloseChat() + gui.OpenURL(url) + HTMLChatCallbacks.CloseChat() end diff --git a/emojichat/lua/emojichat/cl_html-chat-component.lua b/emojichat/lua/emojichat/cl_html-chat-component.lua index ba75cf9..82fa6fb 100644 --- a/emojichat/lua/emojichat/cl_html-chat-component.lua +++ b/emojichat/lua/emojichat/cl_html-chat-component.lua @@ -7,53 +7,53 @@ HTMLChatComponent = { } HTMLChatComponent.__index = HTMLChatComponent function HTMLChatComponent.New(htmlVGUIElement) - local self = setmetatable({}, HTMLChatComponent) - self.htmlElement = htmlVGUIElement - return self + local self = setmetatable({}, HTMLChatComponent) + self.htmlElement = htmlVGUIElement + return self end function HTMLChatComponent.RenderTextLine(self, textComponents) - local json = string.JavascriptSafe(util.TableToJSON(textComponents)) - self.htmlElement:QueueJavascript("emojiChat.addOutput('" .. json .. "')") + local json = string.JavascriptSafe(util.TableToJSON(textComponents)) + self.htmlElement:QueueJavascript("emojiChat.addOutput('" .. json .. "')") end function HTMLChatComponent.SetActive(self, chatMode) - local desination = DESTINATION_GLOBAL - if(chatMode == CHATMODE_TEAM) then - desination = DESTINATION_TEAM - end + local desination = DESTINATION_GLOBAL + if(chatMode == CHATMODE_TEAM) then + desination = DESTINATION_TEAM + end - local playerList = {} - for k, ply in pairs(player.GetAll()) do - local playerViewModel = { name = ply:Nick() } - table.insert(playerList, playerViewModel) - end + local playerList = {} + for k, ply in pairs(player.GetAll()) do + local playerViewModel = { name = ply:Nick() } + table.insert(playerList, playerViewModel) + end - local activePlayer = { - name = LocalPlayer():Nick() - } + local activePlayer = { + name = LocalPlayer():Nick() + } - local jsonPlayerList = string.JavascriptSafe(util.TableToJSON(playerList)) - local jsonActivePlayer = string.JavascriptSafe(util.TableToJSON(activePlayer)) + local jsonPlayerList = string.JavascriptSafe(util.TableToJSON(playerList)) + local jsonActivePlayer = string.JavascriptSafe(util.TableToJSON(activePlayer)) - self.htmlElement:QueueJavascript("emojiChat.setActive(" .. desination .. ",'" .. jsonPlayerList .. "', '" .. jsonActivePlayer .. "')") + self.htmlElement:QueueJavascript("emojiChat.setActive(" .. desination .. ",'" .. jsonPlayerList .. "', '" .. jsonActivePlayer .. "')") end function HTMLChatComponent.SetInactive(self) - self.htmlElement:QueueJavascript("emojiChat.setInactive()") + self.htmlElement:QueueJavascript("emojiChat.setInactive()") end function HTMLChatComponent.UpdateFadeTime(self, durationInSeconds) - self.htmlElement:QueueJavascript("emojiChat.setFadeTime(" .. durationInSeconds .. ")") + self.htmlElement:QueueJavascript("emojiChat.setFadeTime(" .. durationInSeconds .. ")") end function HTMLChatComponent.ReloadPlayerList(self) - local playerList = {} - for k, ply in pairs(player.GetAll()) do - local playerViewModel = { name = ply:Nick() } - table.insert(playerList, playerViewModel) - end - - local json = string.JavascriptSafe(util.TableToJSON(playerList)) - self.htmlElement:QueueJavascript("emojiChat.reloadPlayerList('" .. json .. "')") + local playerList = {} + for k, ply in pairs(player.GetAll()) do + local playerViewModel = { name = ply:Nick() } + table.insert(playerList, playerViewModel) + end + + local json = string.JavascriptSafe(util.TableToJSON(playerList)) + self.htmlElement:QueueJavascript("emojiChat.reloadPlayerList('" .. json .. "')") end diff --git a/emojichat/lua/emojichat/cl_init.lua b/emojichat/lua/emojichat/cl_init.lua index d646d61..6cb17ab 100644 --- a/emojichat/lua/emojichat/cl_init.lua +++ b/emojichat/lua/emojichat/cl_init.lua @@ -3,137 +3,137 @@ TextComponentBuilder.SetTimestampChatColour(eChat.config.timestampColour) TextComponentBuilder.SetTimestampsEnabled(eChat.config.timestamps) surface.CreateFont( "eChat_18", { - font = "Roboto Lt", - size = 18, - weight = 500, - antialias = true, - shadow = true, - extended = true, + font = "Roboto Lt", + size = 18, + weight = 500, + antialias = true, + shadow = true, + extended = true, }) function eChat.buildBox() - eChat.frame = vgui.Create("DFrame") - eChat.frame:MoveToBack() - eChat.frame:SetSize( ScrW()*0.375, ScrH()*0.25 ) - eChat.frame:SetTitle("") - eChat.frame:ShowCloseButton( false ) - eChat.frame:SetDraggable( true ) - eChat.frame:SetSizable( false ) - eChat.frame:SetPos( ScrW()*0.0116, (ScrH() - eChat.frame:GetTall()) - ScrH()*0.177) - eChat.frame:SetMinWidth( 300 ) - eChat.frame:SetMinHeight( 100 ) - eChat.frame.Paint = function( self, w, h ) - if not eChat.Active then return end - - BlurPanel( self, 10, 20, 255 ) - draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 200 ) ) - - draw.RoundedBox( 0, 0, 0, w, 25, Color( 80, 80, 80, 100 ) ) - end - - local serverName = vgui.Create("DLabel", eChat.frame) - serverName:SetText( GetHostName() ) - serverName:SetFont( "eChat_18") - serverName:SizeToContents() - serverName:SetPos( 5, 4 ) - - eChat.chatLog = vgui.Create( "DHTML" , eChat.frame ) - eChat.chatLog:SetSize( eChat.frame:GetWide() - 10, eChat.frame:GetTall() - 40 ) - eChat.chatLog:SetPos( 5, 35 ) - eChat.chatLog.Paint = function( self, w, h ) - if not eChat.Active then return end - --draw.RoundedBox( 0, -5, -5, w + 10, h + 10, Color( 30, 30, 30, 100 ) ) - end - eChat.chatLog:SetVisible( true ) - eChat.chatLog:SetHTML(eChat.config.html) - eChat.chatLog:SetAllowLua( true ) - - eChat.HTMLOutput = HTMLChatComponent.New(eChat.chatLog) - - eChat.UpdateFadeTime() - - eChat.Ready = true - eChat.RenderExistingMessages() - - if(eChat.Active) then - eChat.showBox(eChat.ChatMode) - else - eChat.hideBox() - end + eChat.frame = vgui.Create("DFrame") + eChat.frame:MoveToBack() + eChat.frame:SetSize( ScrW()*0.375, ScrH()*0.25 ) + eChat.frame:SetTitle("") + eChat.frame:ShowCloseButton( false ) + eChat.frame:SetDraggable( true ) + eChat.frame:SetSizable( false ) + eChat.frame:SetPos( ScrW()*0.0116, (ScrH() - eChat.frame:GetTall()) - ScrH()*0.177) + eChat.frame:SetMinWidth( 300 ) + eChat.frame:SetMinHeight( 100 ) + eChat.frame.Paint = function( self, w, h ) + if not eChat.Active then return end + + BlurPanel( self, 10, 20, 255 ) + draw.RoundedBox( 0, 0, 0, w, h, Color( 30, 30, 30, 200 ) ) + + draw.RoundedBox( 0, 0, 0, w, 25, Color( 80, 80, 80, 100 ) ) + end + + local serverName = vgui.Create("DLabel", eChat.frame) + serverName:SetText( GetHostName() ) + serverName:SetFont( "eChat_18") + serverName:SizeToContents() + serverName:SetPos( 5, 4 ) + + eChat.chatLog = vgui.Create( "DHTML" , eChat.frame ) + eChat.chatLog:SetSize( eChat.frame:GetWide() - 10, eChat.frame:GetTall() - 40 ) + eChat.chatLog:SetPos( 5, 35 ) + eChat.chatLog.Paint = function( self, w, h ) + if not eChat.Active then return end + --draw.RoundedBox( 0, -5, -5, w + 10, h + 10, Color( 30, 30, 30, 100 ) ) + end + eChat.chatLog:SetVisible( true ) + eChat.chatLog:SetHTML(eChat.config.html) + eChat.chatLog:SetAllowLua( true ) + + eChat.HTMLOutput = HTMLChatComponent.New(eChat.chatLog) + + eChat.UpdateFadeTime() + + eChat.Ready = true + eChat.RenderExistingMessages() + + if (eChat.Active) then + eChat.showBox(eChat.ChatMode) + else + eChat.hideBox() + end end function eChat.RenderExistingMessages() - for _, message in pairs( eChat.ExistingMessages ) do - eChat.AddLine(message) - end + for _, message in pairs( eChat.ExistingMessages ) do + eChat.AddLine(message) + end end function eChat.hideBox() - if not eChat.Ready then - eChat.Active = false - return - end - - eChat.HTMLOutput:SetInactive() - - local children = eChat.frame:GetChildren() - for _, pnl in pairs( children ) do - if pnl == eChat.frame.btnMaxim or pnl == eChat.frame.btnClose or pnl == eChat.frame.btnMinim then continue end - - if pnl != eChat.chatLog then - pnl:SetVisible( false ) - end - end - - eChat.frame:SetMouseInputEnabled( false ) - eChat.frame:SetKeyboardInputEnabled( false ) - eChat.frame:MoveToBack() - gui.EnableScreenClicker( false ) - - eChat.Active = false - hook.Run("FinishChat") + if not eChat.Ready then + eChat.Active = false + return + end + + eChat.HTMLOutput:SetInactive() + + local children = eChat.frame:GetChildren() + for _, pnl in pairs( children ) do + if pnl == eChat.frame.btnMaxim or pnl == eChat.frame.btnClose or pnl == eChat.frame.btnMinim then continue end + + if pnl != eChat.chatLog then + pnl:SetVisible( false ) + end + end + + eChat.frame:SetMouseInputEnabled( false ) + eChat.frame:SetKeyboardInputEnabled( false ) + eChat.frame:MoveToBack() + gui.EnableScreenClicker( false ) + + eChat.Active = false + hook.Run("FinishChat") end function eChat.showBox(mode) - if not eChat.Ready then - eChat.Active = true - eChat.ChatMode = mode - return - end - - eChat.HTMLOutput:SetActive(mode) - - local children = eChat.frame:GetChildren() - for _, pnl in pairs( children ) do - if pnl == eChat.frame.btnMaxim or pnl == eChat.frame.btnClose or pnl == eChat.frame.btnMinim then continue end - - pnl:SetVisible( true ) - end - - eChat.frame:MakePopup() - eChat.chatLog:RequestFocus() - - eChat.Active = true - hook.Run("StartChat") + if not eChat.Ready then + eChat.Active = true + eChat.ChatMode = mode + return + end + + eChat.HTMLOutput:SetActive(mode) + + local children = eChat.frame:GetChildren() + for _, pnl in pairs( children ) do + if pnl == eChat.frame.btnMaxim or pnl == eChat.frame.btnClose or pnl == eChat.frame.btnMinim then continue end + + pnl:SetVisible( true ) + end + + eChat.frame:MakePopup() + eChat.chatLog:RequestFocus() + + eChat.Active = true + hook.Run("StartChat") end function eChat.AddLine(textComponents) - if not eChat.Ready then - table.insert(eChat.ExistingMessages, textComponents) - else - eChat.HTMLOutput:RenderTextLine(textComponents) - end + if not eChat.Ready then + table.insert(eChat.ExistingMessages, textComponents) + else + eChat.HTMLOutput:RenderTextLine(textComponents) + end end function eChat.AddServerMessage(message) - eChat.AddLine(TextComponentBuilder.Build(eChat.config.serverMessageColour, message)) + eChat.AddLine(TextComponentBuilder.Build(eChat.config.serverMessageColour, message)) end function eChat.UpdateFadeTime(durationInSeconds) - if(durationInSeconds != nil) then - eChat.config.fadeTime = durationInSeconds; - end + if (durationInSeconds != nil) then + eChat.config.fadeTime = durationInSeconds; + end - eChat.HTMLOutput:UpdateFadeTime(eChat.config.fadeTime) + eChat.HTMLOutput:UpdateFadeTime(eChat.config.fadeTime) end diff --git a/emojichat/lua/emojichat/cl_text-component.lua b/emojichat/lua/emojichat/cl_text-component.lua index 6c9d49d..3990c19 100644 --- a/emojichat/lua/emojichat/cl_text-component.lua +++ b/emojichat/lua/emojichat/cl_text-component.lua @@ -1,48 +1,48 @@ TextComponent = { } function TextComponent.Create(text, colour) - local self = {} - self.text = text - self.colour = colour - return self + local self = {} + self.text = text + self.colour = colour + return self end TextComponentBuilder = {} function TextComponentBuilder.SetDefaultChatColour(colour) - TextComponentBuilder.DefaultChatColour = colour + TextComponentBuilder.DefaultChatColour = colour end function TextComponentBuilder.SetTimestampChatColour(colour) - TextComponentBuilder.TimestampColour = colour + TextComponentBuilder.TimestampColour = colour end function TextComponentBuilder.SetTimestampsEnabled(areEnabled) - TextComponentBuilder.TimestampsEnabled = areEnabled + TextComponentBuilder.TimestampsEnabled = areEnabled end function TextComponentBuilder.Build(...) - local activeColour = TextComponentBuilder.DefaultChatColour - local textComponents = {} - - for _, obj in pairs( {...} ) do - if type(obj) == "table" then - activeColour = obj - elseif type(obj) == "string" then - table.insert( textComponents, TextComponent.Create(obj, activeColour)) - elseif obj:IsPlayer() then - local ply = obj - - if TextComponentBuilder.TimestampsEnabled then - table.insert( textComponents, TextComponent.Create("["..os.date("%X").."] ", TextComponentBuilder.TimestampColour)) - end - - local col = GAMEMODE:GetTeamColor( ply ) - table.insert( textComponents, TextComponent.Create(ply:Nick(), Color(col.r, col.g, col.b, 255))) - elseif IsEntity(obj) then - table.insert( textComponents, TextComponent.Create(obj:GetClass(), TextComponentBuilder.DefaultChatColour)) - end - end + local activeColour = TextComponentBuilder.DefaultChatColour + local textComponents = {} + + for _, obj in pairs( {...} ) do + if type(obj) == "table" then + activeColour = obj + elseif type(obj) == "string" then + table.insert( textComponents, TextComponent.Create(obj, activeColour)) + elseif obj:IsPlayer() then + local ply = obj + + if TextComponentBuilder.TimestampsEnabled then + table.insert( textComponents, TextComponent.Create("["..os.date("%X").."] ", TextComponentBuilder.TimestampColour)) + end + + local col = GAMEMODE:GetTeamColor( ply ) + table.insert( textComponents, TextComponent.Create(ply:Nick(), Color(col.r, col.g, col.b, 255))) + elseif IsEntity(obj) then + table.insert( textComponents, TextComponent.Create(obj:GetClass(), TextComponentBuilder.DefaultChatColour)) + end + end return textComponents end \ No newline at end of file diff --git a/emojichat/lua/emojichat/cl_util.lua b/emojichat/lua/emojichat/cl_util.lua index 63c7886..dc37b7c 100644 --- a/emojichat/lua/emojichat/cl_util.lua +++ b/emojichat/lua/emojichat/cl_util.lua @@ -1,16 +1,16 @@ local blur = Material( "pp/blurscreen" ) function BlurPanel( panel, layers, density, alpha ) - local x, y = panel:LocalToScreen(0, 0) + local x, y = panel:LocalToScreen(0, 0) - surface.SetDrawColor( 255, 255, 255, alpha ) - surface.SetMaterial( blur ) + surface.SetDrawColor( 255, 255, 255, alpha ) + surface.SetMaterial( blur ) - for i = 1, 3 do - blur:SetFloat( "$blur", ( i / layers ) * density ) - blur:Recompute() + for i = 1, 3 do + blur:SetFloat( "$blur", ( i / layers ) * density ) + blur:Recompute() - render.UpdateScreenEffectTexture() - surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() ) - end + render.UpdateScreenEffectTexture() + surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() ) + end end \ No newline at end of file diff --git a/emojichat/lua/emojichat/sh_html_init.lua b/emojichat/lua/emojichat/sh_html_init.lua index f783bbf..770dfd3 100644 --- a/emojichat/lua/emojichat/sh_html_init.lua +++ b/emojichat/lua/emojichat/sh_html_init.lua @@ -1,7 +1,7 @@ if SERVER then AddCSLuaFile() - + AddCSLuaFile('emojichat/cl_html/html0.lua') AddCSLuaFile('emojichat/cl_html/html1.lua') AddCSLuaFile('emojichat/cl_html/html2.lua') @@ -9,7 +9,7 @@ if SERVER then AddCSLuaFile('emojichat/cl_html/html4.lua') elseif CLIENT then emojichatHTML = { } - + include('emojichat/cl_html/html0.lua') include('emojichat/cl_html/html1.lua') include('emojichat/cl_html/html2.lua') diff --git a/emojichat/lua/emojichat/sv_chat.lua b/emojichat/lua/emojichat/sv_chat.lua index b8ec029..6575ac9 100644 --- a/emojichat/lua/emojichat/sv_chat.lua +++ b/emojichat/lua/emojichat/sv_chat.lua @@ -1,6 +1,6 @@ hook.Remove("PlayerConnect", "echat_playerconnect") hook.Add("PlayerConnect", "echat_playerconnect", function(name, ip) - PrintMessage(HUD_PRINTTALK, name .. " has joined the server.") + PrintMessage(HUD_PRINTTALK, name .. " has joined the server.") end) hook.Remove("PlayerInitialSpawn", "echat_playerinitialspawn")