actually load tabs, load in init hook, chat tab error handling
This commit is contained in:
parent
fad1e8eba6
commit
631874aebc
1 changed files with 45 additions and 11 deletions
|
@ -16,7 +16,6 @@ cbox.chatbox = cbox.chatbox or {}
|
||||||
cbox.chatbox.tabs = cbox.chatbox.tabs or {}
|
cbox.chatbox.tabs = cbox.chatbox.tabs or {}
|
||||||
cbox.chatbox.panels = cbox.chatbox.panels 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_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_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")
|
local CHATBOX_BLUR = CreateClientConVar("cbox_chatbox_blur", "0", true, false, "Chatbox background is blurred")
|
||||||
|
@ -108,7 +107,7 @@ local function CreateChatbox()
|
||||||
tabs:SetPadding(0)
|
tabs:SetPadding(0)
|
||||||
|
|
||||||
function tabs:Paint(w, h)
|
function tabs:Paint(w, h)
|
||||||
surface_SetDrawColor(0, 0, 0, 72)
|
surface_SetDrawColor(0, 0, 0, 128)
|
||||||
surface_DrawRect(0, 20, w, h - 20)
|
surface_DrawRect(0, 20, w, h - 20)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,10 +129,26 @@ local function CreateChatbox()
|
||||||
frame.btnClose:SetZPos(99)
|
frame.btnClose:SetZPos(99)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
if not IsValid(cbox.chatbox.panels.frame) then
|
||||||
CreateChatbox()
|
CreateChatbox()
|
||||||
end
|
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
|
---Opens the chatbox
|
||||||
---@param alt? boolean Was this request to open made by messagemode2 (team chat)
|
---@param alt? boolean Was this request to open made by messagemode2 (team chat)
|
||||||
function cbox.chatbox.Open(alt)
|
function cbox.chatbox.Open(alt)
|
||||||
|
@ -145,6 +160,24 @@ function cbox.chatbox.Open(alt)
|
||||||
|
|
||||||
cbox.chatbox.panels.frame:SetVisible(true)
|
cbox.chatbox.panels.frame:SetVisible(true)
|
||||||
cbox.chatbox.panels.frame:MakePopup()
|
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()
|
cbox.chatbox.panels.input:RequestFocus()
|
||||||
|
|
||||||
hook.Run("StartChat")
|
hook.Run("StartChat")
|
||||||
|
@ -160,14 +193,15 @@ function cbox.chatbox.Close()
|
||||||
hook.Run("ChatTextChanged", "")
|
hook.Run("ChatTextChanged", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
hook.Add("PlayerBindPress", "cbox.chatbox", function(ply, bind, pressed)
|
hook.Add("Initialize", "cbox.chatbox", Init)
|
||||||
if bind ~= "messagemode" and bind ~= "messagemode2" then return end
|
|
||||||
|
|
||||||
cbox.chatbox.Open(bind == "messagemode2")
|
|
||||||
|
|
||||||
return true
|
|
||||||
end)
|
|
||||||
|
|
||||||
concommand.Add("cbox_chatbox_reload", function()
|
concommand.Add("cbox_chatbox_reload", function()
|
||||||
CreateChatbox()
|
CreateChatbox()
|
||||||
end, nil, "Reloads the chatbox")
|
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.")
|
||||||
|
|
Loading…
Reference in a new issue