From cb34ac03f11993486f33ccdbb007a89648814ee2 Mon Sep 17 00:00:00 2001 From: Tim Goll Date: Mon, 20 Jan 2025 09:12:42 +0100 Subject: [PATCH] vgui: Toggleable Role Indicator (#1724) 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 --- .../gamemode/client/cl_vskin/default_skin.lua | 41 ++++++++++++------- .../client/cl_vskin/vgui/droleimage_ttt2.lua | 15 +++++++ .../menus/gamemode/roles/rolelayering.lua | 1 + 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua b/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua index 25920cf79f..e54b0a9f4b 100644 --- a/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua +++ b/gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua @@ -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 @@ -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 @@ -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, diff --git a/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/droleimage_ttt2.lua b/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/droleimage_ttt2.lua index d51875211b..470b880938 100644 --- a/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/droleimage_ttt2.lua +++ b/gamemodes/terrortown/gamemode/client/cl_vskin/vgui/droleimage_ttt2.lua @@ -9,6 +9,7 @@ function PANEL:Init() self.data = { color = COLOR_WHITE, icon = nil, + indicatorState = false, } end @@ -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) diff --git a/lua/terrortown/menus/gamemode/roles/rolelayering.lua b/lua/terrortown/menus/gamemode/roles/rolelayering.lua index 268ad4d888..a490d3700f 100644 --- a/lua/terrortown/menus/gamemode/roles/rolelayering.lua +++ b/lua/terrortown/menus/gamemode/roles/rolelayering.lua @@ -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