From 631874aebc4d183234f4cc079e283ca3255017af Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Mon, 18 Dec 2023 14:46:16 -0700 Subject: [PATCH] actually load tabs, load in init hook, chat tab error handling --- lua/cbox/cl_chatbox.lua | 56 +++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/lua/cbox/cl_chatbox.lua b/lua/cbox/cl_chatbox.lua index bc5bb3c..e184f79 100644 --- a/lua/cbox/cl_chatbox.lua +++ b/lua/cbox/cl_chatbox.lua @@ -16,7 +16,6 @@ cbox.chatbox = cbox.chatbox or {} cbox.chatbox.tabs = cbox.chatbox.tabs or {} cbox.chatbox.panels = cbox.chatbox.panels or {} - local CHATBOX_COLOR = CreateClientConVar("cbox_chatbox_color", "160 160 160", true, false, "Chatbox background color") local CHATBOX_ALPHA = CreateClientConVar("cbox_chatbox_alpha", "128", true, false, "Chatbox background alpha") local CHATBOX_BLUR = CreateClientConVar("cbox_chatbox_blur", "0", true, false, "Chatbox background is blurred") @@ -108,7 +107,7 @@ local function CreateChatbox() tabs:SetPadding(0) function tabs:Paint(w, h) - surface_SetDrawColor(0, 0, 0, 72) + surface_SetDrawColor(0, 0, 0, 128) surface_DrawRect(0, 20, w, h - 20) end @@ -130,8 +129,24 @@ local function CreateChatbox() frame.btnClose:SetZPos(99) end -if not IsValid(cbox.chatbox.panels.frame) then - CreateChatbox() +local function Init() + local tab_files = file.Find("cbox/tabs/*", "LUA") + for _, name in ipairs(tab_files) do + cbox.utils.RealmPrint("Loading chatbox tab:", name) + include("cbox/tabs/" .. name) + end + + if not IsValid(cbox.chatbox.panels.frame) then + CreateChatbox() + end + + hook.Add("PlayerBindPress", "cbox.chatbox", function(ply, bind, pressed) + if bind ~= "messagemode" and bind ~= "messagemode2" then return end + + cbox.chatbox.Open(bind == "messagemode2") + + return true + end) end ---Opens the chatbox @@ -145,6 +160,24 @@ function cbox.chatbox.Open(alt) cbox.chatbox.panels.frame:SetVisible(true) cbox.chatbox.panels.frame:MakePopup() + + if not IsValid(cbox.chatbox.panels.input) then + -- attempt to reinit + if IsValid(cbox.chatbox.panels.frame) then + cbox.chatbox.panels.frame:Remove() + end + Init() + end + + if not IsValid(cbox.chatbox.panels.input) then + cbox.utils.RealmError("Input isn't valid, chat tab failed to load, bailing!") + if IsValid(cbox.chatbox.panels.frame) then + cbox.chatbox.panels.frame:Remove() + end + hook.Remove("PlayerBindPress", "cbox.chatbox") + return + end + cbox.chatbox.panels.input:RequestFocus() hook.Run("StartChat") @@ -160,14 +193,15 @@ function cbox.chatbox.Close() hook.Run("ChatTextChanged", "") end -hook.Add("PlayerBindPress", "cbox.chatbox", function(ply, bind, pressed) - if bind ~= "messagemode" and bind ~= "messagemode2" then return end - - cbox.chatbox.Open(bind == "messagemode2") - - return true -end) +hook.Add("Initialize", "cbox.chatbox", Init) concommand.Add("cbox_chatbox_reload", function() CreateChatbox() end, nil, "Reloads the chatbox") + +concommand.Add("_cbox_chatbox_fullreload", function() + if IsValid(cbox.chatbox.panels.frame) then + cbox.chatbox.panels.frame:Remove() + end + Init() +end, nil, "Fully reinitializes the chatbox, use only in extreme breakage.")