115 lines
2.8 KiB
Lua
115 lines
2.8 KiB
Lua
local Color = Color
|
|
|
|
local surface = surface
|
|
|
|
local surface_DrawRect = surface.DrawRect
|
|
local surface_SetDrawColor = surface.SetDrawColor
|
|
|
|
local INPUT_TEXT_COLOR = Color(221, 221, 221)
|
|
local INPUT_HIGHLIGHT_COLOR = Color(192, 28, 0, 140)
|
|
|
|
cbox.chatbox.AddTab("\1chat", "Chat", "icon16/comments.png", function()
|
|
local wrapper = vgui.Create("EditablePanel")
|
|
|
|
-- TODO: custom richtext panel
|
|
local history = vgui.Create("RichText", wrapper)
|
|
history:Dock(FILL)
|
|
function history:Paint(w, h)
|
|
surface_SetDrawColor(0, 0, 0, 128)
|
|
surface_DrawRect(0, 0, w, h)
|
|
end
|
|
cbox.chatbox.panels.history = history
|
|
|
|
function history:PerformLayout()
|
|
-- TODO: configurable font
|
|
history:SetFontInternal("ChatFont")
|
|
end
|
|
|
|
local input_wrapper = vgui.Create("EditablePanel", wrapper)
|
|
input_wrapper:SetHeight(20)
|
|
input_wrapper:DockMargin(0, 8, 0, 0)
|
|
input_wrapper:Dock(BOTTOM)
|
|
|
|
local input = vgui.Create("DTextEntry", input_wrapper)
|
|
input:DockMargin(4, 0, 0, 0)
|
|
input:Dock(FILL)
|
|
input:SetFont("ChatFont")
|
|
cbox.chatbox.panels.input = input
|
|
|
|
function input:Paint(w, h)
|
|
surface_SetDrawColor(0, 0, 0, 128)
|
|
surface_DrawRect(0, 0, w, h)
|
|
|
|
self:DrawTextEntryText(INPUT_TEXT_COLOR, INPUT_HIGHLIGHT_COLOR, INPUT_TEXT_COLOR)
|
|
end
|
|
|
|
local mode_switch = vgui.Create("DButton", input_wrapper)
|
|
mode_switch:SetFont("ChatFont")
|
|
mode_switch:SetTextColor(INPUT_TEXT_COLOR)
|
|
mode_switch:SetText("Say")
|
|
mode_switch:SizeToContents()
|
|
mode_switch:Dock(LEFT)
|
|
cbox.chatbox.panels.mode_switch = mode_switch
|
|
|
|
function mode_switch:Paint(w, h)
|
|
surface_SetDrawColor(0, 0, 0, 128)
|
|
surface_DrawRect(0, 0, w, h)
|
|
end
|
|
|
|
function mode_switch:DoClick()
|
|
-- TODO
|
|
end
|
|
function mode_switch:DoRightClick()
|
|
-- TODO
|
|
end
|
|
|
|
function input:OnKeyCodeTyped(key)
|
|
if key == KEY_ESCAPE then
|
|
cbox.chatbox.Close()
|
|
gui.HideGameUI()
|
|
elseif key == KEY_BACKQUOTE then
|
|
gui.HideGameUI()
|
|
elseif key == KEY_ENTER then
|
|
local text = self:GetText():Trim()
|
|
if text ~= "" then
|
|
RunConsoleCommand("say", text)
|
|
end
|
|
|
|
cbox.chatbox.Close()
|
|
elseif key == KEY_TAB then
|
|
if #self:GetText() == 0 then
|
|
-- TODO: mode switch
|
|
else
|
|
-- TODO: autocomplete
|
|
end
|
|
else
|
|
hook.Run("ChatTextChanged", self:GetText())
|
|
end
|
|
end
|
|
|
|
return wrapper
|
|
end)
|
|
|
|
hook.Add("OnChatAddText", "cbox.chatbox.history", function(args)
|
|
local history = cbox.chatbox.panels.history
|
|
for _, arg in ipairs(args) do
|
|
if IsColor(arg) then
|
|
history:InsertColorChange(arg.r, arg.g, arg.b, 255)
|
|
elseif isstring(arg) then
|
|
history:AppendText(arg)
|
|
elseif isentity(arg) then
|
|
if IsValid(arg) and arg:IsPlayer() then
|
|
local col = hook.Run("GetTeamColor", arg)
|
|
history:InsertColorChange(col.r, col.g, col.b, 255)
|
|
history:AppendText(arg:Name())
|
|
else
|
|
local col = cbox.utils.colors.BRAND
|
|
history:InsertColorChange(col.r, col.g, col.b, 255)
|
|
history:AppendText("???")
|
|
end
|
|
end
|
|
end
|
|
|
|
history:AppendText("\n")
|
|
end)
|