Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then return end
- local ShowTimeStamps = false // show timestamps by default
- local ScrollDownWhenTurnedOff = true // scroll down after hitting Enter or Escape by default
- local MaxMessageHistory = 150 // how much messages should be displayed in the history
- local MessageFadeoutTime = 10 // how much time in seconds before a new message fades out
- local PrintChatToConsole = false // should everything said in chat be also added to the console log
- local ShowMessageIcons = true // show join/leave + chat print messages with an icon below
- local InfoMessageIcon = Material("icon16/information.png") // message icon for join/leave + blue chat print messages
- local ShowIconsForPlayers = true // show player avatar/rank icons NOTE:Players can enable/disable this
- local ShowPlayerAvatars = false // show player Avatar icons, WARNING:Overrides user rank icons
- local ShowPlayerRanks = true // show player Rank icons, avatar icons must be turned off(false)
- local EnableRankGlow = true // show glowing rank labels in front of player names. ex:[Admin] TOMASAS: 123
- local RankLabelGlowSize = 0.8 // the size of the glow, anywhere from 0.5 to 1.5 should be good. Default is 0.8
- local RankGlowUserGroups = {}// display ranks with glow, format RankGlowUserGroups["userGroupHere"] = {"RankNameHere", Color(1,2,3)}
- RankGlowUserGroups["vip"] = {"VIP", Color(255, 255, 0)}
- RankGlowUserGroups["admin"] = {"GFL Admin", Color(0, 255, 0)}
- RankGlowUserGroups["superadmin"] = {"Super Admin", Color(255, 140, 0)}
- RankGlowUserGroups["owner"] = {"Owner", Color(255, 0, 0)}
- local DefaultUserIcon = Material("icon16/user.png") // default user icon
- local AdminIcon = Material("C:/garrysmod/garrysmod/materials/icon16/admin.png") // IsAdmin viable player icon
- local SuperAdminIcon = Material("C:/garrysmod/garrysmod/materials/icon16/shield_rainbow.png") // IsSuperAdmin viable player icon
- local OwnerIcon = Material("C:/garrysmod/garrysmod/materials/icon16/shield_rainbow.png") // ULX Owner custom group, added to custom code below.
- // chat colors, ex "[red]" will be [red] in chat
- // color format Color(Red, Green, Blue), numbers are from 0-255 intensity
- local ChatColorTags = {["[red]"] = Color(255, 0, 0),
- ["[green]"] = Color(0, 255, 0),
- ["[blue]"] = Color(0, 0, 255),
- ["[white]"] = Color(255, 255, 255),
- }
- local EnableChatColorTags = false // enable or disable [color] tags in chat
- // CHANGE SKIN TYPE HERE, 1 to 3
- local SkinType = 1 // default skin - 1, round skin - 2, full round skin - 3
- local font = "Segoe UI" //type of font to use, recommended use default - Segoe UI
- local ChatTextboxColor = Color(255, 255, 255, 255) //textbox that you enter text background color
- local ChatHighlightColor = Color(255, 255, 255, 100) // chat text highlighting color
- local white, black = Color(255, 255, 255, 255), Color(10, 10, 10, 255) //default message color, all message shadow color
- // screen pos is multiplied by a percent of your screen to look the same on different resolutions
- local ChatPosX = ScrW() * 0.0125 //chat position on the x axis
- local ChatPosY = ScrH() * 0.5725 //chat position on the y axis
- --------------------------------- DONT EDIT AFTER THIS LINE IF YOU DON'T CODE LUA ------------------------------------------
- local surface, draw, Color, type = surface, draw, Color, type
- font = (font == "Segoe UI" and system.IsWindows()) and "Segoe UI" or font == "Segoe UI" and "Verdana" or font
- surface.CreateFont("ChatTextNormal", {
- font = font,
- size = 23,
- weight = 500
- })
- surface.SetFont("ChatTextNormal")
- local _, Ftall = surface.GetTextSize("AbC1230")
- local function shouldDrawPaint(self)
- if !NewChatIsOpen then
- return
- else
- local ctime = CurTime()+4.5
- for i=1, #self.pList.Can.Items do // make them fade in
- self.pList.Can.Items[i].CreateTime = ctime
- end
- return true
- end
- end
- --[[Skin Templates:
- SkinTable[1] = {}
- SkinTable[1].EntryPaint = SkinTable[1].EntryPaint
- SkinTable[1].GearPaint = SkinTable[1].GearPaint // args: teamSay = true/false, self
- SkinTable[1].Init = function(self) // OPTIONAL FUNCTION
- end
- SkinTable[1].Paint = function(self)
- if !shouldDrawPaint(self) then return end
- end
- SkinTable[1].PaintOver = function(self)// OPTIONAL FUNCTION
- if !NewChatIsOpen then return end
- end
- ]]
- local GearMat = Material("icon16/cog.png")
- local SkinTable = {}
- SkinTable[1] = {}
- SkinTable[1].EntryPaint = function(self)
- surface.SetDrawColor(0, 0, 0, 255)
- DisableClipping(true)
- surface.DrawOutlinedRect(0, 0, self:GetWide()+1, self:GetTall())
- DisableClipping(false)
- surface.SetDrawColor(ChatTextboxColor)
- surface.DrawRect(1, 1, self:GetWide()-1, self:GetTall()-2)
- self:DrawTextEntryText(self.m_colText, self.m_colHighlight, self.m_colCursor)
- end
- SkinTable[1].GearPaint = function(teamSay, self)
- surface.SetDrawColor(teamSay and 0 or 255,teamSay and 215 or 255,teamSay and 0 or 255, 255)
- surface.DrawRect(0, 0, self:GetWide(), self:GetTall())
- surface.SetDrawColor(0, 0, 0, 255)
- surface.DrawLine(0, 0, self:GetWide(), 0)
- surface.DrawLine(0, self:GetTall()-1, self:GetWide(), self:GetTall()-1)
- DisableClipping(true)
- surface.DrawLine(-1, 0, -1, self:GetTall())
- DisableClipping(false)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(GearMat)
- surface.DrawTexturedRect(2, 2, 16, 16)
- end
- SkinTable[1].Paint = function(self)
- if !shouldDrawPaint(self) then return end
- surface.SetDrawColor(189, 195, 199, 255)
- surface.DrawLine(0, self:GetTall()-26, self:GetWide(), self:GetTall()-26)
- surface.SetDrawColor(136, 140, 141, 100)
- DisableClipping(true)
- surface.DrawRect(0, 0, self:GetWide(), self:GetTall()+5)
- DisableClipping(false)
- end
- SkinTable[1].PaintOver = function(self)
- if !NewChatIsOpen then return end
- DisableClipping(true)
- surface.SetDrawColor(44, 62, 80, 255)
- surface.DrawOutlinedRect(-1, -1, self:GetWide()+2, self:GetTall()+6)
- DisableClipping(false)
- end
- SkinTable[2] = {}
- SkinTable[2].EntryPaint = SkinTable[1].EntryPaint
- SkinTable[2].GearPaint = SkinTable[1].GearPaint
- SkinTable[2].Init = function(self)
- self.Grip.LowestAlpha = 125
- self.Grip.Paint = function()
- local a = self.Grip:GetAlpha()
- draw.RoundedBox(4, 0, 0, self.Grip:GetWide(), self.Grip:GetTall(), Color(0, 0, 0, a))
- end
- end
- SkinTable[2].Paint = function(self)
- if !shouldDrawPaint(self) then return end
- DisableClipping(true)
- draw.RoundedBox(6, -2, -2, self:GetWide()+4, self:GetTall()+9, Color(0, 0, 0, 150))
- DisableClipping(false)
- end
- SkinTable[3] = {}
- SkinTable[3].EntryPaint = function(self)
- DisableClipping(true)
- draw.RoundedBoxEx(6, 0, 0, self:GetWide()+2, self:GetTall(), Color(0, 0, 0, 150), false, true, false, true)
- DisableClipping(false)
- self:DrawTextEntryText(Color(255, 255, 255, 255), self.m_colHighlight, Color(255, 255, 255, 255))
- end
- SkinTable[3].GearPaint = function(teamSay, self)
- DisableClipping(true)
- draw.RoundedBoxEx(6, -2, 0, self:GetWide()+2, self:GetTall(), Color(0,teamSay and 215 or 0,0, 150), true, false, true, false)
- DisableClipping(false)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(GearMat)
- surface.DrawTexturedRect(2, 2, 16, 16)
- end
- SkinTable[3].Init = function(self)
- self.Grip.LowestAlpha = 125
- self.Grip.Paint = function()
- local a = self.Grip:GetAlpha()
- draw.RoundedBox(4, 0, 0, self.Grip:GetWide(), self.Grip:GetTall(), Color(0, 0, 0, a))
- end
- end
- SkinTable[3].Paint = function(self)
- if !shouldDrawPaint(self) then return end
- DisableClipping(true)
- draw.RoundedBox(6, -2, -2, self:GetWide()+4, self:GetTall()-22, Color(0, 0, 0, 150))
- DisableClipping(false)
- end
- local function toBit(s) return s and 1 or 0 end // take care of chat config save and loading
- local ChatConVar = CreateClientConVar("tomasas_chatbox_cfg", table.concat({toBit(ShowMessageIcons), toBit(ShowIconsForPlayers), toBit(ShowTimeStamps), toBit(ScrollDownWhenTurnedOff)}, "|"), true, false)
- local chat_cfg = string.Explode("|", ChatConVar:GetString())
- ShowMessageIcons = tobool(chat_cfg[1])
- ShowIconsForPlayers = tobool(chat_cfg[2])
- ShowTimeStamps = tobool(chat_cfg[3])
- ScrollDownWhenTurnedOff = tobool(chat_cfg[4])
- local function SaveChatConfig()
- RunConsoleCommand("tomasas_chatbox_cfg", table.concat({toBit(ShowMessageIcons), toBit(ShowIconsForPlayers), toBit(ShowTimeStamps), toBit(ScrollDownWhenTurnedOff)}, "|"))
- end
- chat.GetChatBoxPos = function() return ChatPosX, ChatPosY end
- local menu, PanelPaint = ChatframePanel
- local function OpenChat()
- if menu and menu.IsValid and menu:IsValid() then if menu.Entry then menu.CFG:Remove() menu.Entry:Remove() end menu.Grip:Remove() menu.pList.Can:Remove() menu.pList:Remove() menu:Remove() end
- menu = vgui.Create("DFrame")
- ChatframePanel = menu // make the chat accessable globally
- menu:SetTitle("")
- for k, v in pairs(SkinTable[SkinType]) do // handle skins
- if k != "Init" then
- menu[k] = v
- end
- end
- menu:ShowCloseButton(false)
- menu:SetDraggable(false)
- menu:SetSize(320 * (ScrH()/480), ScreenScale(99)*0.5+26)
- local chatx, chaty = chat.GetChatBoxPos()
- menu:SetPos(chatx, chaty)
- chatx, chaty = menu:GetSize()
- local pList = vgui.Create("DPanel", menu)
- menu.pList = pList
- pList:SetPaintBackground(false)
- pList:SetSize(chatx, chaty-26)
- pList:SetPos(0, 0)
- pList.Can = vgui.Create("DPanel", pList)
- pList.Can:SetPaintBackground(false)
- pList.Can.Items = {}
- pList.Can:SetSize(pList:GetWide(), 0)
- pList.OnMouseWheeled = function(self, dir)
- if self.Can:GetTall() <= self:GetTall() then return end
- local x, y = self.Can:GetPos()
- self.Can:SetPos(0, math.Clamp(y+dir*math.Round(self:GetTall()*0.15), -self.Can:GetTall()+self:GetTall(), 0))
- end
- menu.AddItem = function(self, item)
- self = pList
- local size = #self.Can.Items
- if size == MaxMessageHistory then // limit it off at MaxMessageHistory messages
- table.remove(self.Can.Items, 1):Remove()
- local itemSize
- table.insert(self.Can.Items, item)
- item:SetParent(self.Can)
- local curPos = 0
- for i=1, #self.Can.Items do //rebuild positions
- itemSize = self.Can.Items[i-1] and self.Can.Items[i-1]:GetTall()+3 or 0
- curPos = curPos+itemSize
- self.Can.Items[i]:SetPos(0, curPos)
- end
- local x, y = self.Can.Items[#self.Can.Items]:GetPos()
- itemSize = self.Can.Items[#self.Can.Items]:GetTall()
- y = y+itemSize
- local tallsize, ypos = self.Can:GetPos()
- tallsize = -self.Can:GetTall()+self:GetTall()
- self.Can:SetTall(y)
- if ypos == tallsize then
- self.Can:SetPos(0, -self.Can:GetTall()+self:GetTall())
- end
- return
- end
- local itemSize = item:GetTall()+3
- self.Can:SetTall(self.Can:GetTall() + itemSize)
- table.insert(self.Can.Items, item)
- item:SetParent(self.Can)
- item:SetPos(0, self.Can:GetTall()-itemSize)
- local x, y = self.Can:GetPos()
- if size < 5 or y == -self.Can:GetTall()+self:GetTall()+itemSize then
- self.Can:SetPos(0, -self.Can:GetTall()+self:GetTall())
- end
- end
- local grip = vgui.Create("DButton", menu)
- menu.Grip = grip
- grip.LowestAlpha = 70
- grip.MaxAlpha = 255
- grip:SetText("")
- grip:SetSize(6, 20)
- grip:SetPos(20, pList:GetWide()-20)
- grip.Think = function(self)
- self:SetAlpha(!NewChatIsOpen and 0 or (!self.Hovered and !self.Holding) and self.LowestAlpha or self.MaxAlpha)
- local Cx, Cy = pList.Can:GetPos()
- local gripSize = math.Clamp(pList:GetTall()/pList.Can:GetTall()*(pList:GetTall()-4), 20, (pList:GetTall()-4))
- local trackScrollAreaSize = pList:GetTall()-4 - gripSize
- if self.Holding and !input.IsMouseDown(MOUSE_LEFT) then
- self.Holding = false
- elseif self.Holding and Cy<1 then
- local mPosDelta = self.LastMouseY - gui.MouseY()
- local x, y = pList.Can:GetPos()
- pList.Can:SetPos(0, math.Clamp(y+mPosDelta*(trackScrollAreaSize/gripSize), -pList.Can:GetTall()+pList:GetTall(), 0))
- end
- local windowScrollAreaSize = pList:GetTall() - pList.Can:GetTall()
- local windowPositionRatio = Cy/windowScrollAreaSize
- local gripPositionOnTrack = trackScrollAreaSize * windowPositionRatio
- grip:SetSize(10, gripSize)
- self:SetPos(menu:GetWide()-12, gripPositionOnTrack+2)
- self.LastMouseY = gui.MouseY()
- end
- grip.OnMousePressed = function(self) self.Holding = true end
- grip.OnCursorEntered = function(self) self.Hovered = true end
- grip.OnCursorExited = function(self) self.Hovered = false end
- if SkinTable[SkinType].Init then
- SkinTable[SkinType].Init(menu)
- end
- end
- timer.Simple(0, OpenChat)
- local ignoreNotify
- function chat.IgnoreNextNotify() // USE: call this before when you don't want chat.AddText to trigger player name to player entity convertion
- ignoreNotify = true // for ex. when chat.AddText("[OOC]TOMASAS", Color(1,2,3), ":blabla") turns to ("[OOC]", plyEntity, ...)
- end
- chat.AddText = function(...) // USE: chat.AddText( [Icon IMaterial], Any arguments )
- if !menu then return end // so dumb scripts can't add text before Derma and chat is loaded
- local TextTable, TextPosX, TextPosY, NoFirstPlayer, icon, avatar = {...}, 0, 0
- local type1 = type(TextTable[1])
- if type1 == "IMaterial" then
- icon = TextTable[1]
- TextPosX = 17
- table.remove(TextTable, 1)
- NoFirstPlayer = true
- end
- if !ignoreNotify and (ShowIconsForPlayers or EnableRankGlow) and type(TextTable[2]) == "string" then // slight hack for non-player object player chat, shooting names instead of players
- local tbl = player.GetAll()
- for i=1, #tbl do
- local nick = tbl[i]:Nick()
- local placeFound = string.find(TextTable[2], nick, 1, true)
- if placeFound then
- local part1 = string.Replace(TextTable[2], nick, "")
- local part2 = part1:sub(placeFound)
- part1 = part1:sub(1, placeFound-1)
- table.insert(TextTable, 2, part1)
- TextTable[3] = tbl[i]
- if part2 != "" then
- if type(TextTable[1]) == "table" then
- table.insert(TextTable, 4, TextTable[1])
- table.insert(TextTable, 5, part2)
- else
- table.insert(TextTable, 4, part2)
- end
- end
- break
- end
- end
- end
- if ShowTimeStamps then
- table.insert(TextTable, 1, os.date("%H:%M "))
- end
- local i, TextTableNum = 0, #TextTable //take care of player/entity objects + avatar/rank icon if needed
- while i != TextTableNum do
- i = i + 1
- local t = type(TextTable[i])
- if t == "Player" then
- if EnableRankGlow then // insert rank labels with a glow table if needed
- for k,v in pairs(RankGlowUserGroups) do
- if TextTable[i]:IsUserGroup(k) then
- table.insert(TextTable, i, "[")
- table.insert(TextTable, i+1, v)
- table.insert(TextTable, i+2, "] ")
- i = i + 3
- TextTableNum = TextTableNum + 3
- break
- end
- end
- end
- table.insert(TextTable, i+1, TextTable[i]:Nick())
- TextTableNum = TextTableNum + 1
- if !NoFirstPlayer and ShowIconsForPlayers then
- if ShowPlayerAvatars then
- avatar = vgui.Create("AvatarImage")
- avatar:SetPlayer(TextTable[i], 16)
- avatar:SetSize(16, 16)
- TextPosX = 17
- elseif ShowPlayerRanks then
- if TextTable[i]:IsSuperAdmin() then
- icon = SuperAdminIcon
- elseif TextTable[i]:IsAdmin() then
- icon = AdminIcon
- elseif TextTable[i]:IsUserGroup("owner") then
- icon = OwnerIcon
- else
- icon = DefaultUserIcon
- end
- TextPosX = 17
- end
- NoFirstPlayer = true
- end
- TextTable[i] = team.GetColor(TextTable[i]:Team())
- i = i + 1
- elseif t != "string" and t != "table" then
- if TextTable[i].IsValid and TextTable[i]:IsValid() then
- TextTable[i] = TextTable[i]:GetClass()
- else
- TextTable[i] = "NULL"
- end
- end
- end
- if EnableChatColorTags then // take care of color tags
- local noTagsLeft
- while !noTagsLeft do
- local foundTag
- for i=1, #TextTable do
- if type(TextTable[i]) == "string" then//ChatColorTags
- for k, v in pairs(ChatColorTags) do
- local pos = string.find(TextTable[i], k, 1, true)
- if pos then
- local str1, str2 = TextTable[i]:sub(1, pos-1), TextTable[i]:sub(pos+k:len())
- TextTable[i] = str1
- table.insert(TextTable, i+1, v)
- table.insert(TextTable, i+2, str2)
- foundTag = true
- break
- end
- end
- end
- end
- noTagsLeft = !foundTag
- end
- end
- local FinalText = {}
- local windowSizeX = 320 * (ScrH()/480)-4 //4 is the padding offset
- surface.SetFont("ChatTextNormal")
- local _, tall = surface.GetTextSize("AbC1230")
- TextTableNum = #TextTable
- local pos = 0
- local LineText = ""
- local LastColor = Color(255, 255, 255, 255)
- while pos != TextTableNum do
- pos = pos + 1
- if type(TextTable[pos]) == "table" and type(TextTable[pos][2]) == "table" then // glow table
- local text = TextTable[pos][1]
- local x, y = surface.GetTextSize(text)
- table.insert(FinalText, {text, TextPosX, TextPosY, TextTable[pos][2], 1})
- TextPosX = TextPosX + x
- else // color or text
- while type(TextTable[pos]) == "table" do
- LastColor = Color(TextTable[pos].r, TextTable[pos].g, TextTable[pos].b, TextTable[pos].a)
- pos = pos + 1
- end
- local text = TextTable[pos]
- local x, y = surface.GetTextSize(text)
- if TextPosX + x >= windowSizeX then
- local startpos, t, t2, size = #FinalText
- for line in (text):gmatch("[^%s]+") do //wordwrap
- if t then
- t2 = table.concat({t, line}, " ")
- else
- t2 = line
- t = ""
- end
- size = surface.GetTextSize(t2)
- if TextPosX + size >= windowSizeX then
- table.insert(FinalText, {t, TextPosX, TextPosY, LastColor})
- TextPosX = 0
- TextPosY = TextPosY + tall
- t = line
- else
- t = t2
- end
- end
- table.insert(FinalText, {t, TextPosX, TextPosY, LastColor})
- //FinalText[startpos][1] = string.sub(FinalText[startpos][1], 2)
- size = surface.GetTextSize(t2)
- TextPosX = TextPosX + size
- else
- table.insert(FinalText, {text, TextPosX, TextPosY, LastColor})
- TextPosX = TextPosX + x
- end
- end
- end
- local ListItem = vgui.Create("DPanel", menu.pList)
- ListItem.IsChatTextPanel = true
- if avatar then
- ListItem.Avatar = avatar
- avatar:SetParent(ListItem)
- avatar:SetPos(4, 5)
- else
- ListItem.Icon = icon
- end
- ListItem.CreateTime = CurTime()+MessageFadeoutTime
- ListItem.Text = FinalText
- ListItem:SetSize(menu.pList:GetWide(), TextPosY+tall)
- ListItem.Paint = PanelPaint
- ListItem:SetPaintBackground(false)
- local TextTable = {}
- for i=1, #FinalText do
- local len = FinalText[i][1]:len()
- local TextX, TextY = FinalText[i][2], FinalText[i][3]
- for a=1, len do
- local x = surface.GetTextSize(FinalText[i][1][a])
- TextX = TextX + x
- table.insert(TextTable, {FinalText[i][1][a], TextX, TextY})
- end
- end
- ListItem.TextTable = TextTable
- menu:AddItem(ListItem)
- if PrintChatToConsole then
- local pack, a = {}, 0
- for i=1, #FinalText do
- a = a + 1
- pack[a] = FinalText[i][4]
- a = a + 1
- pack[a] = FinalText[i][1]
- end
- pack[a+1] = "\n"
- MsgC(unpack(pack))
- end
- ignoreNotify = false
- end
- local MousePressedX, MousePressedY, MouseReleasedX, MouseReleasedY, SelectedChatMsg, SelectingText
- local function MousePress()
- local pan = vgui.GetHoveredPanel()
- if !pan or !pan.IsChatTextPanel then return end
- MousePressedX, MousePressedY = pan:CursorPos()
- SelectedChatMsg = pan
- SelectingText = true
- end
- local function MouseRelease()
- SelectingText = false
- local pan = vgui.GetHoveredPanel()
- if !pan or !pan.IsChatTextPanel then return end
- MouseReleasedX, MouseReleasedY = pan:CursorPos()
- end
- local mouseDown
- local function ChatThink() // GUIMousePressed/Released hooks are both broken, thanks garry :^) (aren't called when pressed on chat)
- local down = input.IsMouseDown(MOUSE_LEFT)
- if down and !mouseDown then
- MousePress()
- mouseDown = true
- elseif !down and mouseDown then
- MouseRelease()
- mouseDown = false
- elseif !down and !mouseDown and SelectedChatMsg and input.IsMouseDown(MOUSE_RIGHT) then
- SelectedChatMsg = nil
- elseif SelectedChatMsg and SelectedChatMsg:IsValid() and input.IsKeyDown(KEY_LCONTROL) and input.IsKeyDown(KEY_C) then
- local str = ""
- for i=1, #SelectedChatMsg.TextTable do
- if SelectedChatMsg.TextTable[i][4] then
- str = table.concat({str, SelectedChatMsg.TextTable[i][1]}, "")
- end
- end
- SetClipboardText(str)
- end
- end
- function PanelPaint(self)
- local curtime = CurTime()
- local a = self.CreateTime - curtime <= 1 and (self.CreateTime-curtime)*255 or 255
- if a < 0 then return end
- if SelectedChatMsg == self then
- if SelectingText then
- MouseReleasedX, MouseReleasedY = self:CursorPos()
- for i=1, #self.TextTable do
- if (MousePressedX < self.TextTable[i][2] and MousePressedY-Ftall <= self.TextTable[i][3] and MouseReleasedY-Ftall > self.TextTable[i][3]) or (MousePressedX <= self.TextTable[i][2] and MouseReleasedX >= self.TextTable[i][2] and MousePressedY-Ftall < self.TextTable[i][3] and MouseReleasedY > self.TextTable[i][3]) or (MousePressedY <= Ftall and MouseReleasedY > Ftall and self.TextTable[i][3] >= Ftall and self.TextTable[i][3] <= Ftall and MouseReleasedX>=self.TextTable[i][2]) then
- self.TextTable[i][4] = true
- else
- self.TextTable[i][4] = nil
- end
- end
- end
- local lines = self.TextTable[#self.TextTable][3]/Ftall + 1
- surface.SetDrawColor(ChatHighlightColor)
- for i=1, lines do
- local xsize, x, start = 0, 0
- for a=1, #self.TextTable do
- if self.TextTable[a][4] and self.TextTable[a][3] == i*Ftall-Ftall then
- x = a== 1 and 4 or x == 0 and self.TextTable[a][2]-4 or x
- xsize = self.TextTable[a][2]-x+4
- end
- end
- surface.DrawRect(x, Ftall*i-Ftall, xsize, Ftall)
- end
- end
- if self.Icon then
- surface.SetDrawColor(255, 255, 255, a)
- surface.SetMaterial(self.Icon)
- surface.DrawTexturedRect(4, 5, 16, 16)
- elseif self.Avatar then
- self.Avatar:SetAlpha(a)
- end
- for i=1, #self.Text do
- self.Text[i][4].a = a
- if self.Text[i][5] then // glow table
- local pulse = math.cos(curtime*2)*127.5+127.5
- pulse = pulse <= a and pulse or a
- draw.SimpleTextOutlined(self.Text[i][1], "ChatTextNormal", 4+self.Text[i][2], self.Text[i][3], self.Text[i][4], 0, 0, RankLabelGlowSize, Color(self.Text[i][4].r, self.Text[i][4].g, self.Text[i][4].b, pulse))
- else // just text
- draw.SimpleTextOutlined(self.Text[i][1], "ChatTextNormal", 4+self.Text[i][2], self.Text[i][3], self.Text[i][4], 0, 0, 0.5, Color(black.r, black.g, black.b, a))
- end
- end
- end
- local cfg// hackish~ fix for options not going away, I blame derma
- local function ConfigButton(teamSay)
- if cfg and cfg:IsValid() then cfg:Remove() cfg = nil end
- cfg = vgui.Create("DButton")
- menu.CFG = cfg
- cfg:SetSize(20, 20)
- local x, y = menu.Entry:GetPos()
- cfg:SetPos(x-20, y)
- cfg:SetText("")
- cfg.Paint = function(self, x, y) SkinTable[SkinType].GearPaint(teamSay, self, x, y) end
- cfg.DoClick = function(self)
- if self.CFGPanel and self.CFGPanel:IsValid() then self.CFGPanel:Remove() return end
- local panel = vgui.Create("DPanel")
- panel:SetPos(x-20, y+20)
- local x, y = menu.Entry:GetSize()
- panel:SetSize(x+20, 25)
- self.CFGPanel = panel
- local oldRemove = self.Remove //hacky, derma sucks anyway
- self.Remove = function() self.CFGPanel:Remove() oldRemove(self) end
- panel.Paint = function(self)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.DrawRect(0, 0, self:GetWide(), self:GetTall())
- draw.SimpleText("Show info icons", "Default", 22, 6, Color(0, 0, 0, 255))
- draw.SimpleText("Show player icons", "Default", 157, 6, Color(0, 0, 0, 255))
- draw.SimpleText("Show timestamps", "Default", 293, 6, Color(0, 0, 0, 255))
- draw.SimpleText("Scroll chat down on close", "Default", 428, 6, Color(0, 0, 0, 255))
- end
- local CB1 = vgui.Create("DCheckBox", panel)
- CB1:SetPos(5, 5)
- CB1:SetValue(toBit(ShowMessageIcons))
- CB1.OnChange = function(self, state)
- ShowMessageIcons = state
- SaveChatConfig()
- end
- local CB2 = vgui.Create("DCheckBox", panel)
- CB2:SetPos(140, 5)
- CB2:SetValue(toBit(ShowIconsForPlayers))
- CB2.OnChange = function(self, state)
- ShowIconsForPlayers = state
- SaveChatConfig()
- end
- local CB3 = vgui.Create("DCheckBox", panel)
- CB3:SetPos(275, 5)
- CB3:SetValue(toBit(ShowTimeStamps))
- CB3.OnChange = function(self, state)
- ShowTimeStamps = state
- SaveChatConfig()
- end
- local CB4 = vgui.Create("DCheckBox", panel)
- CB4:SetPos(410, 5)
- CB4:SetValue(toBit(ScrollDownWhenTurnedOff))
- CB4.OnChange = function(self, state)
- ScrollDownWhenTurnedOff = state
- SaveChatConfig()
- end
- end
- end
- hook.Add("PlayerBindPress", "NewChatText", function(ply, bind, press)
- if bind == "messagemode" or bind == "messagemode2" then
- if press then
- local teamSay = bind == "messagemode2"
- hook.Call("StartChat", GAMEMODE, teamSay)
- local entry = vgui.Create("DTextEntry")
- local chatx, chaty = menu:GetPos()
- entry:SetAllowNonAsciiCharacters(true)
- entry:SetPos(chatx+20, chaty+menu:GetTall()-20)
- entry:SetSize(menu:GetWide()-20, 20)
- menu.Entry = entry
- menu.Entry.Paint = SkinTable[SkinType].EntryPaint
- menu.Entry.OnTextChanged = function(self)
- if self:GetValue():len() > 126 then
- self:SetText(self:GetValue():sub(1, 126))
- self:SetCaretPos(126)
- surface.PlaySound("/resource/warning.wav")
- end
- hook.Call("ChatTextChanged", GAMEMODE, self:GetValue())
- end
- menu.Entry.OnEnter = function(self)
- local txt = self:GetValue()
- RunConsoleCommand(!teamSay and "say" or "say_team", txt)
- self:SetText("")
- hook.Call("FinishChat", GAMEMODE)
- SelectedChatMsg = nil
- menu.CFG:Remove()
- self:Remove()
- end
- menu.Entry.OnKeyCodeTyped = function(self, key)
- if key == KEY_ESCAPE then
- hook.Call("FinishChat", GAMEMODE)
- SelectedChatMsg = nil
- menu.CFG:Remove()
- menu.Entry:Remove()
- gui.HideGameUI()
- elseif key == KEY_ENTER then
- self:OnEnter()
- end
- end
- ConfigButton(teamSay)
- menu.Entry:MakePopup()
- menu.Entry:SetKeyboardInputEnabled(true)
- menu.Entry:RequestFocus()
- local x, y =menu.Entry:GetPos()
- gui.SetMousePos(x, y+20)
- end
- return true
- end
- end)
- hook.Add("ChatText", "NewChatText", function(id, name, str, stype)
- chat.IgnoreNextNotify() //need to escape and tell it's a notify, Player.ChatPrint and alike won't trigger player name matching and mess up
- if ShowMessageIcons then
- chat.AddText(InfoMessageIcon, stype=="joinleave" and Color(161, 255, 161) or Color(151, 211, 255), str)
- else
- chat.AddText(stype=="joinleave" and Color(161, 255, 161) or Color(151, 211, 255), str)
- end
- return true
- end)
- hook.Add("HUDShouldDraw", "DisableDefaultChat", function(t) if t=="CHudChat" then return false end end )
- hook.Add("StartChat", "NewChatIsOpen", function() NewChatIsOpen = true end)
- hook.Add("FinishChat", "NewChatIsOpen", function()
- NewChatIsOpen = false
- if ScrollDownWhenTurnedOff then
- menu.pList.Can:SetPos(0, -menu.pList.Can:GetTall()+menu.pList:GetTall())
- end
- end)
- hook.Add("Think", "NewChatThink", ChatThink)
- //©Tomasas 2013-2015[/code]
Advertisement
Add Comment
Please, Sign In to add comment