cbox/lua/cbox/tabs/chat.lua

84 lines
2.0 KiB
Lua

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)
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:Dock(BOTTOM)
local input = vgui.Create("DTextEntry", input_wrapper)
input:Dock(FILL)
cbox.chatbox.panels.input = input
local mode_switch = vgui.Create("DButton", input_wrapper)
mode_switch:SetText("Say")
mode_switch:SizeToContents()
mode_switch:Dock(LEFT)
cbox.chatbox.panels.mode_switch = mode_switch
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)