Skip to content

Instantly share code, notes, and snippets.

@Earu
Last active April 18, 2020 01:05
Show Gist options
  • Save Earu/b22ec3af9e8206bf16cbdcfc6391adcb to your computer and use it in GitHub Desktop.
Save Earu/b22ec3af9e8206bf16cbdcfc6391adcb to your computer and use it in GitHub Desktop.
A simple EasyChat tab module that allows you to outsource your local Garry's Mod chat.
local tag = "local_tab"
local EC_LEGACY_ENTRY = GetConVar("easychat_legacy_entry")
local EC_LEGACY_TEXT = GetConVar("easychat_legacy_text")
local HAS_CHROMIUM = jit.arch == "x64"
local use_new_text_entry = (EC_LEGACY_ENTRY and not EC_LEGACY_ENTRY:GetBool()) or not EC_LEGACY_ENTRY
local use_new_richtext = (EC_LEGACY_TEXT and not EC_LEGACY_TEXT:GetBool()) or not EC_LEGACY_TEXT
local tab = vgui.Create("DPanel")
local textentry = tab:Add(HAS_CHROMIUM and use_new_text_entry and "TextEntryX" or "DTextEntry")
textentry:Dock(BOTTOM)
textentry:SetTall(25)
textentry:SetText("")
if use_new_text_entry then
textentry:SetBackgroundColor(EasyChat.TabColor)
local border_color = EasyChat.TabOutlineColor.a == 0 and EasyChat.OutlayColor or EasyChat.TabOutlineColor
textentry:SetBorderColor(border_color)
textentry:SetTextColor(EasyChat.TextColor)
else
local selection_color = Color(255, 0, 0, 127)
function textentry:Paint(w, h)
surface.SetDrawColor(EasyChat.TabColor)
surface.DrawRect(0, 0, w, h)
local border_color = EasyChat.TabOutlineColor.a == 0
and EasyChat.OutlayColor or EasyChat.TabOutlineColor
surface.SetDrawColor(border_color)
surface.DrawOutlinedRect(0, 0, w, h)
self:DrawTextEntryText(EasyChat.TextColor, selection_color, EasyChat.TextColor)
end
end
function textentry:OnEnter()
local local_mode = EasyChat.Modes[2]
local_mode.Callback(self:GetText())
self:SetText("")
EasyChat.Close()
end
local richtext = tab:Add(HAS_CHROMIUM and use_new_richtext and "RichTextX" or "RichText")
richtext:Dock(FILL)
richtext:DockMargin(5, 10, 5, 10)
function richtext:PerformLayout()
self:SetFontInternal("EasyChatFont")
self:SetFGColor(EasyChat.UseDermaSkin and EasyChat.TextColor or Color(0, 0, 0, 255))
end
EasyChat.AddTab("Local", tab, "icon16/user_comment.png")
EasyChat.SetFocusForOn("Local", textentry)
hook.Add("ECSecondaryOpen", tag, function(mode_name)
if mode_name == "local" then
EasyChat.OpenTab("Local")
return true
end
end)
hook.Add("OnPlayerChat", tag, function(ply, msg, _, _, is_local)
if is_local then
EasyChat.FlashTab("Local")
EasyChat.AddText(richtext, ply, color_white, ": ", msg)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment