Skip to content

Commit 11488e0

Browse files
committed
refactor(YHV1): Replace GridRenderer with CustomToggle
1 parent 1980f49 commit 11488e0

2 files changed

Lines changed: 45 additions & 28 deletions

File tree

SSV2/includes/features/YimHeistsV1.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
---@field public name string
1212
---@field public val integer
1313
---@field public cooldown_name string
14-
---@field public cooldown_gvar string
14+
---@field public cooldown_gvar string GVar path name
15+
---@field public gvar fun(set_val?: boolean): boolean? Getter/setter for cooldown GVar
1516

1617
---@class HeistInfo
1718
---@field public get_name fun(): string

SSV2/includes/frontend/yhv1_ui.lua

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ local HEIST_TYPES = {
3535
val = 31,
3636
cooldown_name = "MPX_SALV23_CFR_COOLDOWN",
3737
cooldown_gvar = "cfr_cd",
38-
}
38+
gvar = function(set)
39+
if (type(set) ~= "boolean") then
40+
return GVars.features.yim_heists.cfr_cd
41+
end
42+
GVars.features.yim_heists.cfr_cd = set
43+
end,
44+
},
3945
},
4046
{ -- KnoWay
4147
get_name = function()
@@ -49,6 +55,12 @@ local HEIST_TYPES = {
4955
val = 4,
5056
cooldown_name = "MPX_M25_AVI_MISSION_CD",
5157
cooldown_gvar = "knoway_cd",
58+
gvar = function(set)
59+
if (type(set) ~= "boolean") then
60+
return GVars.features.yim_heists.knoway_cd
61+
end
62+
GVars.features.yim_heists.knoway_cd = set
63+
end,
5264
},
5365
},
5466
{ -- Dr Dre
@@ -63,6 +75,12 @@ local HEIST_TYPES = {
6375
val = 4095,
6476
cooldown_name = "MPX_FIXER_STORY_COOLDOWN",
6577
cooldown_gvar = "dre_cd",
78+
gvar = function(set)
79+
if (type(set) ~= "boolean") then
80+
return GVars.features.yim_heists.dre_cd
81+
end
82+
GVars.features.yim_heists.dre_cd = set
83+
end,
6684
}
6785
},
6886
{ -- Oscar Guzman
@@ -77,6 +95,12 @@ local HEIST_TYPES = {
7795
val = 31,
7896
cooldown_name = "MPX_HACKER24_MFM_COOLDOWN",
7997
cooldown_gvar = "ogfa_cd",
98+
gvar = function(set)
99+
if (type(set) ~= "boolean") then
100+
return GVars.features.yim_heists.ogfa_cd
101+
end
102+
GVars.features.yim_heists.ogfa_cd = set
103+
end,
80104
},
81105
opt_info = "Complete first mission on Hard first!"
82106
},
@@ -85,9 +109,6 @@ local HEIST_TYPES = {
85109
local function drawBasicTab()
86110
for i, heist in ipairs(HEIST_TYPES) do
87111
local heist_name = heist.get_name()
88-
-- It is risky to skip these cooldowns since replaying heists too quickly may get you flagged, so probably best to just check if cooldown is active and disable skipping
89-
-- If a heist is on cooldown, just do a different one while you wait
90-
-- TODO: User should have option to skip cooldown anyways, as long as they acknowledge the risk
91112
local cooldown_time = stats.get_int(heist.stat.cooldown_name) -- POSIX
92113
local seconds_left = cooldown_time - Time.Epoch()
93114
local on_cooldown = cooldown_time > Time.Epoch()
@@ -108,8 +129,6 @@ local function drawBasicTab()
108129
end
109130
ImGui.EndDisabled()
110131

111-
ImGui.SameLine()
112-
113132
ImGui.BeginDisabled(is_done or on_cooldown)
114133
if GUI:Button(_T("SY_COMPLETE_PREPARATIONS")) then
115134
YHV1:SkipPrep(heist.stat.name, heist.stat.val, heist_name)
@@ -120,18 +139,19 @@ local function drawBasicTab()
120139
GUI:Tooltip(_F(_T("CP_COOLDOWN_BYPASS_STATUS_FORMAT"), seconds_left / 60))
121140
end
122141

123-
-- Trying to add a normal toggle would not work so copied this from yrv3/misc.lua, hopefully didn't miss anything else
124-
local cooldownsGrid = GridRenderer.new(1)
125-
cooldownsGrid:AddCheckbox("CP_HEIST_COOLDOWN_DISABLE", "features.yim_heists." .. heist.stat.cooldown_gvar, {
126-
persistent = true,
127-
isTranslatorLabel = true,
142+
ImGui.EndDisabled()
143+
ImGui.SameLine()
144+
145+
local new_cd_state, cd_state_changed = GUI:CustomToggle(_T("CP_HEIST_COOLDOWN_DISABLE"), heist.stat.gvar(), {
128146
onClick = function()
129147
YRV3:SetCooldownStateDirty(heist.stat.cooldown_gvar, true)
130148
end
131149
})
132150

133-
cooldownsGrid:Draw()
134-
ImGui.EndDisabled()
151+
if (cd_state_changed) then
152+
heist.stat.gvar(new_cd_state)
153+
end
154+
135155
ImGui.PopID()
136156

137157
ImGui.Spacing()
@@ -274,27 +294,23 @@ local function drawCayoTab()
274294

275295
-- https://www.unknowncheats.me/forum/3058973-post602.html
276296
if GUI:Button(_T "CP_HEIST_UNLOCK_ALL") then
277-
-- Also gotta figure out wtf these actually do, currently they're just here to hopefully prevent bugs
278-
stats.set_int("MPX_H4CNF_BS_GEN", 131071)
279-
stats.set_int("MPX_H4CNF_BS_ENTR", 63)
280-
stats.set_int("MPX_H4CNF_BS_ABIL", 63)
281297
stats.set_int("MPX_H4CNF_WEP_DISRP", 3)
282298
stats.set_int("MPX_H4CNF_ARM_DISRP", 3)
283299
stats.set_int("MPX_H4CNF_HEL_DISRP", 3)
300+
-- Also gotta figure out wtf these below actually do, currently they're just here to hopefully prevent bugs
301+
stats.set_int("MPX_H4CNF_BS_GEN", 131071)
302+
stats.set_int("MPX_H4CNF_BS_ENTR", 63)
303+
stats.set_int("MPX_H4CNF_BS_ABIL", 63)
284304
stats.set_int("MPX_H4_MISSIONS", 65535)
285305
stats.set_int("MPX_H4_PLAYTHROUGH_STATUS", 40000)
286306
end
287307

288-
local cooldownsGrid = GridRenderer.new(1)
289-
cooldownsGrid:AddCheckbox("CP_HEIST_COOLDOWN_DISABLE", "features.yim_heists.cayo_cd", {
290-
persistent = true,
291-
isTranslatorLabel = true,
292-
onClick = function()
293-
YRV3:SetCooldownStateDirty("cayo_cd", true)
294-
end
295-
})
296-
297-
cooldownsGrid:Draw()
308+
GVars.features.yim_heists.cayo_cd, _ = GUI:CustomToggle(_T("CP_HEIST_COOLDOWN_DISABLE"),
309+
GVars.features.yim_heists.cayo_cd, {
310+
onClick = function()
311+
YRV3:SetCooldownStateDirty("cayo_cd", true)
312+
end
313+
})
298314

299315
if (GVars.backend.debug_mode) then
300316
-- This button should only be used if something is severely wrong

0 commit comments

Comments
 (0)