From 74bba46c30efbd06efd69e64872447915dc03442 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Mon, 1 Jul 2024 14:38:49 -0600 Subject: [PATCH] padding, right click menu at top of frame, reset metrics command, basic tab complete support --- lua/cbox/cl_chatbox.lua | 77 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-) diff --git a/lua/cbox/cl_chatbox.lua b/lua/cbox/cl_chatbox.lua index 97a34eb..50901df 100644 --- a/lua/cbox/cl_chatbox.lua +++ b/lua/cbox/cl_chatbox.lua @@ -137,13 +137,12 @@ local function CreateChatbox() frame:SetDeleteOnClose(false) frame:SetSizable(true) frame:SetScreenLock(true) - frame:DockPadding(8, 8, 8, 8) + frame:DockPadding(16, 20, 16, 12) local dx, dy, dw, dh = GetDefaultBounds() - -- TODO: make this configurable - frame:SetMinWidth(dw) - frame:SetMinHeight(dh) + frame:SetMinWidth(math.min(256, dw)) + frame:SetMinHeight(math.min(128, dh)) local x = frame:GetCookie("pos_x", dx) local y = frame:GetCookie("pos_y", dy) @@ -202,6 +201,53 @@ local function CreateChatbox() end end + function frame:OnMousePressed(button) + local screenX, screenY = self:LocalToScreen( 0, 0 ) + + if self.m_bSizable and gui.MouseX() > (screenX + self:GetWide() - 20) and gui.MouseY() > (screenY + self:GetTall() - 20) then + self.Sizing = {gui.MouseX() - self:GetWide(), gui.MouseY() - self:GetTall()} + self:MouseCapture(true) + return + end + + if self:GetDraggable() and gui.MouseY() < (screenY + 16) then + if button == MOUSE_LEFT then + self.Dragging = {gui.MouseX() - self.x, gui.MouseY() - self.y} + self:MouseCapture(true) + elseif button == MOUSE_RIGHT then + local menu = DermaMenu() + + local settings = menu:AddOption("Settings", function() end) + settings:SetIcon("icon16/cog.png") + + local metrics = menu:AddOption("Reset Metrics", function() + RunConsoleCommand("cbox_chatbox_reset_metrics") + if IsValid(cbox.chatbox.panels.input) then + cbox.chatbox.panels.input:RequestFocus() + end + end) + metrics:SetIcon("icon16/arrow_out.png") + + menu:AddSpacer() + + local reload = menu:AddOption("Reload Chatbox", function() + RunConsoleCommand((input.IsKeyDown(KEY_LSHIFT) or input.IsKeyDown(KEY_RSHIFT)) and "_cbox_chatbox_fullreload" or "cbox_chatbox_reload") + end) + reload:SetIcon("icon16/arrow_refresh.png") + + menu:AddSpacer() + + local close = menu:AddOption("Close", function() + cbox.chatbox.Close() + end) + close:SetIcon("icon16/cross.png") + + menu:Open() + end + return + end + end + function frame:Paint(w, h) local alpha = CHATBOX_ALPHA:GetInt() @@ -380,9 +426,13 @@ local function CreateChatbox() if #self:GetText() == 0 then mode_switch:NextMode() else - -- TODO: autocomplete + local tab_text = hook.Run("OnChatTab", self:GetText()) + self:SetText(tab_text) end - timer.Simple(0, function() self:RequestFocus() end) + timer.Simple(0, function() + self:RequestFocus() + self:SetCaretPos(self:GetText():len()) + end) else hook.Run("ChatTextChanged", self:GetText()) end @@ -529,6 +579,21 @@ concommand.Add("cbox_chatbox_reload", function() CreateChatbox() end, nil, "Reloads the chatbox") +concommand.Add("cbox_chatbox_reset_metrics", function() + if IsValid(cbox.chatbox.panels.frame) then + local frame = cbox.chatbox.panels.frame + local dx, dy, dw, dh = GetDefaultBounds() + + frame:SetCookie("pos_x", dx) + frame:SetCookie("pos_y", dy) + frame:SetCookie("width", dw) + frame:SetCookie("height", dh) + + frame:SetPos(dx, dy) + frame:SetSize(dw, dh) + end +end, nil, "Resets the metrics (size and position) of the chatbox") + concommand.Add("_cbox_chatbox_fullreload", function() if IsValid(cbox.chatbox.panels.frame) then cbox.chatbox.panels.frame:Remove()