padding, right click menu at top of frame, reset metrics command, basic tab complete support

This commit is contained in:
Cynthia Foxwell 2024-07-01 14:38:49 -06:00
parent 41b976c973
commit 74bba46c30

View file

@ -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()