Skip to content

Commit

Permalink
vastly simplified color handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Feb 5, 2025
1 parent 6f1808d commit deee032
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,22 @@ function PANEL:OnVSkinUpdate()

-- PANEL IS PRESSED
elseif self:IsDepressed() or self:IsSelected() or self:GetToggle() then
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
util.GetActiveColor(self:GetColor() or vskin.GetAccentColor()),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorBackground = util.GetActiveColor(self:GetColor() or vskin.GetAccentColor())
colorText = ColorAlpha(util.GetDefaultColor(colorBackground), 220)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
util.GetActiveColor(self:GetOutlineColor() or vskin.GetDarkAccentColor()),
self:GetOutlineColorShift() or 0
),
self:GetOutlineAlpha()
)
colorOutline = util.GetActiveColor(self:GetOutlineColor() or vskin.GetDarkAccentColor())

-- PANEL IS HOVERED
elseif self:IsHovered() then
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
util.GetHoverColor(self:GetColor() or vskin.GetAccentColor()),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorBackground =
util.GetHoverColor(self:GetColor() or vskin.GetAccentColor()), self:GetColorShift()
colorText = ColorAlpha(util.GetDefaultColor(colorBackground), 220)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
util.GetActiveColor(self:GetOutlineColor() or vskin.GetDarkAccentColor()),
self:GetOutlineColorShift() or 0
),
self:GetOutlineAlpha()
)
colorOutline = util.GetActiveColor(self:GetOutlineColor() or vskin.GetDarkAccentColor())

-- NORMAL COLORS
else
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
self:GetColor() or vskin.GetAccentColor(),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorBackground = self:GetColor() or vskin.GetAccentColor()
colorText = ColorAlpha(util.GetDefaultColor(colorBackground), 220)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
self:GetOutlineColor() or vskin.GetDarkAccentColor(),
self:GetOutlineColorShift() or 0
),
self:GetOutlineAlpha()
)
colorOutline = self:GetOutlineColor() or vskin.GetDarkAccentColor()
end

self:ApplyVSkinColor("background", colorBackground)
Expand Down
42 changes: 3 additions & 39 deletions gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dlabel_ttt2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ AccessorFunc(PANEL, "m_cColor", "Color", FORCE_COLOR, true)
-- @realm client
AccessorFunc(PANEL, "m_cOutlineColor", "OutlineColor", FORCE_COLOR, true)

---
-- @accessor number
-- @realm client
AccessorFunc(PANEL, "m_nColorShift", "ColorShift", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
AccessorFunc(PANEL, "m_nOutlineColorShift", "OutlineColorShift", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
Expand Down Expand Up @@ -118,21 +108,6 @@ AccessorFunc(PANEL, "m_nHorizontalTextAlign", "HorizontalTextAlign", FORCE_NUMBE
-- @realm client
AccessorFunc(PANEL, "m_nVerticalTextAlign", "VerticalTextAlign", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
AccessorFunc(PANEL, "m_nPadding", "Padding", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
AccessorFunc(PANEL, "m_nBackgroundAlpha", "BackgroundAlpha", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
AccessorFunc(PANEL, "m_nOutlineAlpha", "OutlineAlpha", FORCE_NUMBER, true)

---
-- @accessor number
-- @realm client
Expand Down Expand Up @@ -948,20 +923,9 @@ end
-- @hook
-- @realm client
function PANEL:OnVSkinUpdate()
local colorBackground, colorText, colorOutline

colorBackground = util.GetAlphaColorColorAlpha(
util.GetChangedColor(
self:GetColor() or self:GetParentColor() or vskin.GetBackgroundColor(),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorText = util.GetDefaultColor(colorBackground)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(self:GetOutlineColor() or colorText, self:GetOutlineColorShift() or 0),
self:GetOutlineAlpha()
)
local colorBackground = self:GetColor() or self:GetParentColor() or vskin.GetBackgroundColor()
local colorText = util.GetDefaultColor(colorBackground)
local colorOutline = self:GetOutlineColor() or colorText

self:ApplyVSkinColor("background", colorBackground)
self:ApplyVSkinColor("text", colorText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,19 @@ function PANEL:OnVSkinUpdate()

-- PANEL IS PRESSED or PANEL IS HOVERED
if self:IsDepressed() or self:IsSelected() or self:GetToggle() or self:IsHovered() then
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
self:GetColor() or vskin.GetBackgroundColor(),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorBackground = self:GetColor() or vskin.GetBackgroundColor()
colorText = util.GetChangedColor(util.GetDefaultColor(colorBackground), 50)
olorDescription = util.GetChangedColor(util.GetDefaultColor(colorBackground), 135)
colorIcon = util.GetChangedColor(util.GetDefaultColor(colorBackground), 160)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
self:GetOutlineColor() or colorBackground,
135 + (self:GetOutlineColorShift() or 0)
),
self:GetOutlineAlpha()
)
colorOutline = util.GetChangedColor(self:GetOutlineColor() or colorBackground, 135)

-- NORMAL COLORS
else
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
self:GetColor() or vskin.GetBackgroundColor(),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha()
)
colorBackground = self:GetColor() or vskin.GetBackgroundColor()
colorText = util.GetChangedColor(util.GetDefaultColor(colorBackground), 65)
colorDescription = util.GetChangedColor(util.GetDefaultColor(colorBackground), 145)
colorIcon = util.GetChangedColor(util.GetDefaultColor(colorBackground), 170)
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
self:GetOutlineColor() or colorBackground,
170 + (self:GetOutlineColorShift() or 0)
),
self:GetOutlineAlpha()
)
colorOutline = util.GetChangedColor(self:GetOutlineColor() or colorBackground, 170)
end

self:ApplyVSkinColor("background", colorBackground)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,21 @@ function PANEL:OnVSkinUpdate()

-- PANEL IS PRESSED
if self:IsDepressed() or self:IsSelected() or self:GetToggle() then
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
self:GetColor() or util.GetActiveColor(vskin.GetAccentColor()),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha() or 50
)
colorBackground =
util.GetAlphaColor(self:GetColor() or util.GetActiveColor(vskin.GetAccentColor()), 50)
colorText =
util.GetActiveColor(util.GetChangedColor(util.GetDefaultColor(colorBackground), 25))
colorIcon = util.GetActiveColor(util.GetChangedColor(COLOR_WHITE, 32))
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
self:GetOutlineColor() or util.GetActiveColor(vskin.GetAccentColor()),
self:GetOutlineColorShift() or 0
),
self:GetOutlineAlpha()
)
colorOutline = self:GetOutlineColor() or util.GetActiveColor(vskin.GetAccentColor())

-- PANEL IS HOVERED or NORMAL COLORS
else
colorBackground = util.GetAlphaColor(
util.GetChangedColor(
self:GetColor() or util.GetHoverColor(vskin.GetAccentColor()),
self:GetColorShift() or 0
),
self:GetBackgroundAlpha() or 50
)
colorBackground =
util.GetAlphaColor(self:GetColor() or util.GetHoverColor(vskin.GetAccentColor()), 50)
colorText =
util.GetHoverColor(util.GetChangedColor(util.GetDefaultColor(colorBackground), 75))
colorIcon = util.GetHoverColor(util.GetChangedColor(COLOR_WHITE, 48))
colorOutline = util.GetAlphaColor(
util.GetChangedColor(
self:GetOutlineColor() or util.GetHoverColor(vskin.GetAccentColor()),
self:GetOutlineColorShift() or 0
),
self:GetOutlineAlpha()
)
colorOutline = self:GetOutlineColor() or util.GetHoverColor(vskin.GetAccentColor())
end

self:ApplyVSkinColor("background", colorBackground)
Expand Down

0 comments on commit deee032

Please sign in to comment.