Skip to content

Commit

Permalink
vgui: Toggleable Role Indicator (#1724)
Browse files Browse the repository at this point in the history
Added option to show and hide these indicators for `DRoleImageTTT2`.


![image](https://github.com/user-attachments/assets/87a6d233-2cf3-411b-a730-a1d4e923ef60)

---------

Co-authored-by: nike4613 <[email protected]>
  • Loading branch information
TimGoll and nike4613 authored Jan 20, 2025
1 parent c70a015 commit cb34ac0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
41 changes: 27 additions & 14 deletions gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,9 @@ end
function SKIN:PaintRoleImageTTT2(panel, w, h)
local widthBorder = 2
local widthBorder2 = widthBorder * 2
local sizeIconRole = w - widthBorder2
local padding = 3
local sizeMode = 18
local sizeMode = 18 * w / 64
local sizeIconMode = sizeMode - 2 * padding
local posIconModeX = w - sizeMode + padding
local posIconModeY = h - sizeMode + padding
Expand All @@ -1744,23 +1745,31 @@ function SKIN:PaintRoleImageTTT2(panel, w, h)

local colorBorderIcon = utilGetDefaultColor(colorBorder)

drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, colorBorder)
if panel:GetIsActiveIndicator() then
drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, colorBorder)

drawRoundedBox(
sizes.cornerRadius,
widthBorder,
widthBorder,
w - widthBorder2,
h - widthBorder2,
colorBackground
)
drawRoundedBox(
sizes.cornerRadius,
widthBorder,
widthBorder,
w - widthBorder2,
h - widthBorder2,
colorBackground
)
else
drawRoundedBox(sizes.cornerRadius, 0, 0, w, h, colorBackground)

widthBorder = 0
widthBorder2 = 0
sizeIconRole = w
end

if panel:GetValue() then
drawFilteredShadowedTexture(
widthBorder,
widthBorder,
w - widthBorder2,
h - widthBorder2,
sizeIconRole - widthBorder2,
sizeIconRole - widthBorder2,
panel:GetMaterial(),
colorIcon.a,
colorIcon
Expand All @@ -1769,14 +1778,18 @@ function SKIN:PaintRoleImageTTT2(panel, w, h)
drawFilteredTexture(
widthBorder,
widthBorder,
w - widthBorder2,
h - widthBorder2,
sizeIconRole - widthBorder2,
sizeIconRole - widthBorder2,
panel:GetMaterial(),
colorIcon.a * 0.5,
colorIcon
)
end

if not panel:GetIsActiveIndicator() then
return
end

drawRoundedBoxEx(
sizes.cornerRadius,
w - sizeMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function PANEL:Init()
self.data = {
color = COLOR_WHITE,
icon = nil,
indicatorState = false,
}
end

Expand Down Expand Up @@ -49,6 +50,20 @@ function PANEL:DoRightClick()
self:ValueChanged(newValue)
end

---
-- @param boolean state
-- @realm client
function PANEL:SetIsActiveIndicator(state)
self.data.indicatorState = state
end

---
-- @return boolean
-- @realm client
function PANEL:GetIsActiveIndicator()
return self.data.indicatorState or false
end

---
-- @ignore
function PANEL:Paint(w, h)
Expand Down
1 change: 1 addition & 0 deletions lua/terrortown/menus/gamemode/roles/rolelayering.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ hook.Add("TTT2ReceivedRolelayerData", "received_layer_data", function(role, laye
ic:SetTooltip(roleData.name)
ic:SetTooltipFixedPosition(0, 64)
ic:SetServerConVar("ttt_" .. roleData.name .. "_enabled")
ic:SetIsActiveIndicator(true)

ic.subrole = subrole

Expand Down

0 comments on commit cb34ac0

Please sign in to comment.