Skip to content

Commit

Permalink
UI/Bindings: Added Run Button to Bindings Menu (#1516)
Browse files Browse the repository at this point in the history
Added a run button to all bindings. When pressing the button, the
binding is executed, even if no key is added to that binding.


![image](https://github.com/TTT-2/TTT2/assets/13639408/08c43db4-4df6-4be4-bfd3-9f014e82525a)

It also fixes a small rendering issue introduced in #1509
  • Loading branch information
TimGoll authored May 20, 2024
1 parent 310e1b9 commit ed8548b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Added a new generic button to F1 menu elements to be used in custom menus (by @TimGoll)
- Added toggle and run buttons to many F1 menu elements (by @TimGoll)
- Added combo cards to the UI, clickable cards that act like combo boxes (by @TimGoll)
- Added a run button to bindings in the bindings menu (by @TimGoll)
- Added a new admin commands menu (by @TimGoll)
- Added a submenu to change maps

Expand Down
16 changes: 10 additions & 6 deletions gamemodes/terrortown/gamemode/client/cl_vskin/default_skin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,6 @@ function SKIN:PaintFormButtonIconTTT2(panel, w, h)
end
end

local iconMaterial = panel.iconMaterial

if not iconMaterial.GetTexture then
iconMaterial = iconMaterial[panel.state or 1]
end

local colorBoxBack = colors.settingsBox
local colorText = ColorAlpha(utilGetDefaultColor(colors.accent), 150)
local shift = 0
Expand Down Expand Up @@ -761,6 +755,16 @@ function SKIN:PaintFormButtonIconTTT2(panel, w, h)

drawRoundedBox(sizes.cornerRadius, 1, 1, w - 2, h - 2, colorBox)

local iconMaterial = panel.iconMaterial or panel.material

if not iconMaterial then
return
end

if not iconMaterial.GetTexture then
iconMaterial = iconMaterial[panel.state or 1]
end

drawFilteredShadowedTexture(
pad,
pad + shift,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,17 @@ function PANEL:MakeBinder(data)

local reset = MakeResetButton(self)

-- optional buttons
local toggle, run

if data.enableToggle then
toggle = MakeToggleButton(self, data)
end

if data.enableRun then
run = MakeRunButton(self, data)
end

if data.default ~= nil then
reset.DoClick = function(slf)
right.binder:SetValue(data.default)
Expand All @@ -624,7 +635,7 @@ function PANEL:MakeBinder(data)
reset.noDefault = true
end

self:AddItem(left, right, reset)
self:AddItem(left, right, reset, toggle, run)

if IsValid(data.master) and isfunction(data.master.AddSlave) then
data.master:AddSlave(left)
Expand All @@ -635,6 +646,16 @@ function PANEL:MakeBinder(data)
right:SetMaster(data.master)
reset:SetMaster(data.master)

if IsValid(toggle) then
toggle:SetMaster(data.master)
data.master:AddSlave(toggle)
end

if IsValid(run) then
run:SetMaster(data.master)
data.master:AddSlave(run)
end

left:DockMargin(left:GetIndentationMargin(), 0, 0, 0)
end

Expand Down
19 changes: 19 additions & 0 deletions lua/terrortown/menus/gamemode/bindings/bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ local function AddBindingCategory(category, parent)

currentBinding = keyNum
end,
enableRun = true,
OnClickRun = function(button)
local bindingData = bind.registry[binding.name]

if not bindingData or not isfunction(bindingData.OnPressed) then
return
end

bindingData.OnPressed()

-- run the release key binding a moment later
timer.Simple(0.1, function()
if not bindingData or not isfunction(bindingData.OnReleased) then
return
end

bindingData.OnReleased()
end)
end,
})
end
end
Expand Down

0 comments on commit ed8548b

Please sign in to comment.