-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Combo-Cards. They act like combo boxes (only one of them can be selected at any time), but they are clickable boxes: ![image](https://github.com/TTT-2/TTT2/assets/13639408/8cbf4009-df2a-477e-a879-b91e9a712969) ```lua local form = vgui.CreateTTT2Form(parent, "header_maps_select") -- Create combo boxes to select element from comboBase = form:MakeIconLayout() for i = 1, #maps do local mapName = maps[i] local prefix = map.GetPrefix(mapName) form:MakeComboCard({ icon = map.GetIcon(mapName), label = mapName, tag = prefix, colorTag = util.StringToColor(prefix or ""), }, comboBase) end ``` Similar to other tileable elements in our UI system, this needs an icon layout as well. This is then used as a base for these combo cards. There is no limit to combo cards. All cards that have the same icon layout as a base are tied together. `comboBase.checked` contains the checked element. It is `nil` if none is checked. Example where these boxes are used: #1512 **Note:** I previously added different cards. To make it more clear I renamed those. Maybe there is the possibility to merge them in the future, but right now I'm not in favor of that because that would make the code more convoluted.
- Loading branch information
Showing
8 changed files
with
291 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
gamemodes/terrortown/gamemode/client/cl_vskin/vgui/dcombocard_ttt2.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
--- | ||
-- @class PANEL | ||
-- @section DComboCardTTT2 | ||
|
||
local PANEL = {} | ||
|
||
--- | ||
-- @ignore | ||
function PANEL:Init() | ||
self:SetContentAlignment(5) | ||
|
||
self:SetTall(22) | ||
self:SetMouseInputEnabled(true) | ||
self:SetKeyboardInputEnabled(true) | ||
|
||
self:SetCursor("hand") | ||
self:SetFont("DermaTTT2TextLarge") | ||
|
||
-- remove label and overwrite function | ||
self:SetText("") | ||
self.SetText = function(slf, text) | ||
slf.data.text = text | ||
end | ||
|
||
self.data = { | ||
title = "", | ||
icon = nil, | ||
checked = false, | ||
} | ||
end | ||
|
||
--- | ||
-- @return string | ||
-- @realm client | ||
function PANEL:GetText() | ||
return self.data.text | ||
end | ||
|
||
--- | ||
-- @param Material icon | ||
-- @realm client | ||
function PANEL:SetIcon(icon) | ||
self.data.icon = icon | ||
end | ||
|
||
--- | ||
-- @return Matieral | ||
-- @realm client | ||
function PANEL:GetIcon() | ||
return self.data.icon | ||
end | ||
|
||
--- | ||
-- @param string text | ||
-- @realm client | ||
function PANEL:SetTagText(text) | ||
self.data.tagtext = text | ||
end | ||
|
||
--- | ||
-- @return string | ||
-- @realm client | ||
function PANEL:GetTagText() | ||
return self.data.tagtext | ||
end | ||
|
||
--- | ||
-- @param Color color | ||
-- @realm client | ||
function PANEL:SetTagColor(color) | ||
self.data.tagcolor = color | ||
end | ||
|
||
--- | ||
-- @return Color | ||
-- @realm client | ||
function PANEL:GetTagColor() | ||
return self.data.tagcolor | ||
end | ||
|
||
--- | ||
-- @param number mode | ||
-- @realm client | ||
function PANEL:SetChecked(mode) | ||
self.data.checked = mode or false | ||
end | ||
|
||
--- | ||
-- @return number | ||
-- @realm client | ||
function PANEL:GetChecked() | ||
return self.data.checked | ||
end | ||
|
||
--- | ||
-- @param number keyCode | ||
-- @realm client | ||
function PANEL:OnMouseReleased(keyCode) | ||
self.BaseClass.OnMouseReleased(self, keyCode) | ||
|
||
if keyCode ~= MOUSE_LEFT then | ||
return | ||
end | ||
|
||
local parent = self:GetParent() | ||
|
||
if not IsValid(parent) then | ||
return | ||
end | ||
|
||
local oldChecked = self:GetChecked() | ||
|
||
self:SetChecked(true) | ||
|
||
local checked = parent.checked | ||
|
||
parent.checked = self | ||
|
||
self:OnClick(oldChecked, true) | ||
|
||
if not IsValid(checked) or checked == self then | ||
return | ||
end | ||
|
||
checked:SetChecked(false) | ||
end | ||
|
||
--- | ||
-- @param number old | ||
-- @param number new | ||
-- @realm client | ||
function PANEL:OnClick(old, new) end | ||
|
||
--- | ||
-- @return boolean | ||
-- @realm client | ||
function PANEL:IsDown() | ||
return self.Depressed | ||
end | ||
|
||
--- | ||
-- @ignore | ||
function PANEL:Paint(w, h) | ||
derma.SkinHook("Paint", "ComboCardTTT2", self, w, h) | ||
|
||
return false | ||
end | ||
|
||
derma.DefineControl( | ||
"DComboCardTTT2", | ||
"A special button where only one can be set at a time", | ||
PANEL, | ||
"DButtonTTT2" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters