more visual stuff

This commit is contained in:
Cynthia Foxwell 2023-12-18 19:18:41 -07:00
parent fe2785825b
commit 682cfba243
6 changed files with 100 additions and 17 deletions

View file

@ -223,7 +223,7 @@ local function CreateChatbox()
end
end
local r, g, b = CHATBOX_COLOR:GetString():match("(%d+) (%d+) (%d+)")
local r, g, b = cbox.utils.ParseColorString(CHATBOX_COLOR:GetString())
surface_SetDrawColor(r, g, b, alpha)
surface_DrawRect(0, 0, w, h)
@ -259,6 +259,34 @@ local function CreateChatbox()
local sheet = tabs:AddSheet(tab.name, ret, tab.icon)
sheet.Panel.cbox_id = id
function sheet.Tab:ApplySchemeSettings()
local ExtraInset = 8
if self.Image then
ExtraInset = ExtraInset + self.Image:GetWide()
end
self:SetTextInset(ExtraInset, 2)
local w, h = self:GetContentSize()
h = self:GetTabHeight()
self:SetSize(w + 8, h)
DLabel.ApplySchemeSettings( self )
end
-- TODO: configurable font
sheet.Tab:SetFont("ChatFont")
function sheet.Tab:Paint(w, h)
if self:IsActive() then
surface_SetDrawColor(0, 0, 0, 128)
surface_DrawRect(0, 0, w, 20)
else
surface_SetDrawColor(0, 0, 0, 64)
surface_DrawRect(0, 2, w, 18)
end
end
end
end
@ -299,6 +327,7 @@ function cbox.chatbox.Open(alt)
if frame.animFade and CHATBOX_FADE:GetBool() then
frame.animFade:Start(0.1, false)
else
frame:SetAlpha(255)
frame:MakePopup()
end

View file

@ -1,3 +1,6 @@
local CHATPRINT_COLOR = CreateClientConVar("cbox_chatprint_color", "151 211 255", true, false, "Color for system messages")
local JOINLEAVE_COLOR = CreateClientConVar("cbox_joinleave_color", "161 255 161", true, false, "Color for join/leave messages")
local hookTable = {}
if cbox.hooks then
hookTable = cbox.hooks.GetTable()
@ -63,3 +66,14 @@ function chat.AddText(...)
hook.Run("OnChatAddText", args)
end
hook.Add("ChatText", "cbox.chattext", function(index, name, text, type)
local col = cbox.utils.ParseColorStringToColor(CHATPRINT_COLOR:GetString())
if type == "joinleave" then
col = cbox.utils.ParseColorStringToColor(JOINLEAVE_COLOR:GetString())
end
chat.AddText(col, text)
return true
end)

View file

@ -9,7 +9,7 @@ cbox.hooks.Add("PreChatAddText", "cbox.greentext", function(args)
for i, arg in ipairs(args) do
if isstring(arg) and arg:StartsWith(": >") then
args[i] = arg:sub(3)
table.insert(args, i, cbox.utils.ParseColorString(COLOR:GetString()))
table.insert(args, i, cbox.utils.ParseColorStringToColor(COLOR:GetString()))
table.insert(args, i, ": ")
table.insert(args, i, color_white)
break

View file

@ -2,11 +2,15 @@ local ENABLED = CreateClientConVar("cbox_timestamps", "1", true, false, "Enables
local TRUETIME = CreateClientConVar("cbox_timestamps_24hr", "1", true, false, "Whether timestamps should be 24 hour instead of 12 hour", 0, 1)
local SECONDS = CreateClientConVar("cbox_timestamps_seconds", "0", true, false, "Whether timestamps should display seconds", 0, 1)
local COLOR = CreateClientConVar("cbox_timestamps_color", "151 211 255", true, false, "Color timestamps should be")
local SEPARATOR_COLOR = CreateClientConVar("cbox_timestamps_separator_color", "255 255 255", true, false, "Color for the timestamp separator")
local BRACKETS = CreateClientConVar("cbox_timestamps_brackets", "0", true, false, "Whether to replace the separator with surrounded brackets", 0, 1)
local ALL_MESSAGES = CreateClientConVar("cbox_timestamps_all", "1", true, false, "Apply timestamps to all messages or just players", 0, 1)
local color_white = Color(255, 255, 255)
cbox.hooks.Add("PreChatAddText", "cbox.timestamps", function(args)
if not ENABLED:GetBool() then return end
if not ALL_MESSAGES:GetBool() then return end
local use24 = TRUETIME:GetBool()
local stamp = ""
@ -27,7 +31,23 @@ cbox.hooks.Add("PreChatAddText", "cbox.timestamps", function(args)
stamp = stamp .. os.date(" %p")
end
local new_args = {cbox.utils.ParseColorString(COLOR:GetString()), stamp, color_white, " - "}
local new_args = {}
if BRACKETS:GetBool() then
new_args[#new_args + 1] = cbox.utils.ParseColorStringToColor(SEPARATOR_COLOR:GetString())
new_args[#new_args + 1] = "["
end
new_args[#new_args + 1] = cbox.utils.ParseColorStringToColor(COLOR:GetString())
new_args[#new_args + 1] = stamp
new_args[#new_args + 1] = cbox.utils.ParseColorStringToColor(SEPARATOR_COLOR:GetString())
if BRACKETS:GetBool() then
new_args[#new_args + 1] = "] "
else
new_args[#new_args + 1] = " - "
end
for _, arg in ipairs(args) do
new_args[#new_args + 1] = arg
end

View file

@ -8,10 +8,6 @@ local ipairs = ipairs
local tonumber = tonumber
local tostring = tostring
local string = string
local string_Explode = string.Explode
local color_white = Color(255, 255, 255)
local utils = {}
@ -23,19 +19,31 @@ utils.colors = {
ERROR = Color(255, 90, 90),
}
---Parses a string into separate numbers
---@param str string Input color as "R G B" or "R G B A"
---@param alpha? boolean Whether to parse alpha or not (default false)
---@return number r
---@return number g
---@return number b
---@return number a
function utils.ParseColorString(str, alpha)
alpha = alpha ~= nil and alpha or false
local r, g, b = str:match("(%d+) (%d+) (%d+)")
local a = 255
if alpha then
a = str:match("%d+ %d+ %d+ (%d+)")
end
return r, g, b, a
end
---Parses a string into a color
---@param str string Input color as "R G B" or "R G B A"
---@param alpha? boolean Whether to parse alpha or not (default false)
---@return Color
function utils.ParseColorString(str, alpha)
alpha = alpha ~= nil and alpha or false
local split = string_Explode(" ", str)
local r = tonumber(split[1]) or 255
local g = tonumber(split[2]) or 255
local b = tonumber(split[3]) or 255
local a = alpha and tonumber(split[4] or 255) or 255
function utils.ParseColorStringToColor(str, alpha)
local r, g, b, a = utils.ParseColorString(str, alpha)
return Color(r, g, b, a)
end

View file

@ -44,7 +44,6 @@ cbox.chatbox.AddTab("\1chat", "Chat", "icon16/comments.png", function()
end
local mode_switch = vgui.Create("DButton", input_wrapper)
mode_switch:SetFont("ChatFont")
mode_switch:SetTextColor(INPUT_TEXT_COLOR)
mode_switch:SetText("Say")
mode_switch:SizeToContents()
@ -56,6 +55,19 @@ cbox.chatbox.AddTab("\1chat", "Chat", "icon16/comments.png", function()
surface_DrawRect(0, 0, w, h)
end
function mode_switch:ApplySchemeSettings()
local ExtraInset = 8
self:SetTextInset(ExtraInset, 0)
local w, h = self:GetContentSize()
self:SetSize(w + 8, 20)
DLabel.ApplySchemeSettings(self)
end
mode_switch:SetFont("ChatFont")
function mode_switch:DoClick()
-- TODO
end