forked from ellomenop/HadesSpeedrunningModPack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModConfigMenu.lua
More file actions
311 lines (275 loc) · 9.82 KB
/
Copy pathModConfigMenu.lua
File metadata and controls
311 lines (275 loc) · 9.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
ModUtil.Mod.Register("ModConfigMenu")
ModConfigMenu.Menus = {}
ModConfigMenu.CurrentMenuIdx = 1
ModConfigMenu.MenuOverride = {}
function ModConfigMenu.Register(config)
table.insert(ModConfigMenu.Menus, config)
end
function ModConfigMenu.RegisterMenuOverride(configObject, createMenuFunction)
table.insert(ModConfigMenu.Menus, configObject)
local menuIdx = #ModConfigMenu.Menus
ModConfigMenu.MenuOverride[menuIdx] = {createMenu = createMenuFunction}
end
ModUtil.LoadOnce(function()
-- this table is intentionally not excluded from saves, so
-- that mod config settings can be persisted in the save file
if not ModConfigMenuSavedSettings then
ModConfigMenuSavedSettings = {
Version = "1.0",
Menus = {}
}
end
if ModConfigMenuSavedSettings.Version == "1.0" then
for i, config in pairs(ModConfigMenu.Menus) do
local savedMenu = ModConfigMenuSavedSettings[config.ModName]
if savedMenu then
for k,v in pairs(savedMenu) do
if config[k] ~= nil then
config[k] = v
end
end
end
ModConfigMenuSavedSettings[config.ModName] = config
end
end
end)
local function PrettifyName( name )
local first = true
local prettyName = name:gsub("%u", function(c)
if first then
first = false
return c
else
return ' ' .. c
end
end)
return prettyName
end
local function UpdateCheckBox( button, value )
local radioButtonValue = "RadioButton_Unselected"
if value then
radioButtonValue = "RadioButton_Selected"
end
SetThingProperty({
DestinationId = button.Id,
Property = "Graphic",
Value = radioButtonValue
})
end
local function ClearPreviousMenu( screen )
local ids = {}
for name, component in pairs(screen.Components) do
if screen.EvergreenComponents[name] == nil then
screen.Components[name] = nil
table.insert(ids, component.Id)
end
end
CloseScreen( ids )
end
local function ShowCurrentMenu( screen )
-- Update Menu title if menu exists
local currentMenu = ModConfigMenu.Menus[ModConfigMenu.CurrentMenuIdx]
if not currentMenu then
return
end
ModifyTextBox({
Id = screen.Components["SelectedMenu"].Id,
Text = currentMenu.ModName or "Unknown Mod"
})
-- If menu is a custom menu, call the creation callback
if ModConfigMenu.MenuOverride[ModConfigMenu.CurrentMenuIdx] ~= nil then
ModConfigMenu.MenuOverride[ModConfigMenu.CurrentMenuIdx].createMenu( screen )
return
end
-- Otherwise create a standardized menu based on config content
local rowStartX = 350
local columnSpacingX = 600
local itemLocationX = rowStartX
local itemLocationY = 250
local itemSpacingX = 250
local itemSpacingY = 50
local itemsPerRow = 3
local itemsInRow = 0
for name, value in orderedPairs( currentMenu ) do
if value == true or value == false then
itemsInRow = itemsInRow + 1
if itemsInRow > itemsPerRow then
itemLocationX = rowStartX
itemLocationY = itemLocationY + itemSpacingY
itemsInRow = itemsInRow - itemsPerRow
end
screen.Components[name .. "TextBox"] = CreateScreenComponent({
Name = "BlankObstacle",
Scale = 1,
X = itemLocationX,
Y = itemLocationY,
Group = "Combat_Menu" })
CreateTextBox({
Id = screen.Components[name .. "TextBox"].Id,
Text = PrettifyName(name),
Color = Color.BoonPatchCommon,
FontSize = 16,
OffsetX = 0, OffsetY = 0,
Font = "AlegrayaSansSCRegular",
ShadowBlur = 0, ShadowColor = { 0, 0, 0, 1 }, ShadowOffset = { 0, 2 },
Justification = "Center"
})
local previousItemLocationX = itemLocationX
itemLocationX = itemLocationX + itemSpacingX
screen.Components[name .. "CheckBox"] = CreateScreenComponent({
Name = "RadioButton",
Scale = 1,
X = itemLocationX,
Y = itemLocationY,
Group = "CombatMenu"
})
UpdateCheckBox(screen.Components[name .. "CheckBox"], value)
screen.Components[name .. "CheckBox"].MenuItemName = name
screen.Components[name .. "CheckBox"].OnPressedFunctionName = "ModConfigMenu__ToggleBoolean"
CreateTextBox({
Id = screen.Components[name .. "CheckBox"].Id,
FontSize = 16,
OffsetX = 0, OffsetY = 0,
Font = "AlegrayaSansSCRegular",
Justification = "Center"
})
itemLocationX = previousItemLocationX + columnSpacingX
end
end
end
function ModConfigMenu__MenuLeft( screen, button )
ModConfigMenu.CurrentMenuIdx = ModConfigMenu.CurrentMenuIdx - 1
if ModConfigMenu.CurrentMenuIdx < 1 then
ModConfigMenu.CurrentMenuIdx = #ModConfigMenu.Menus
end
ClearPreviousMenu( screen )
ShowCurrentMenu( screen )
end
function ModConfigMenu__MenuRight( screen, button )
ModConfigMenu.CurrentMenuIdx = ModConfigMenu.CurrentMenuIdx + 1
if ModConfigMenu.CurrentMenuIdx > #ModConfigMenu.Menus then
ModConfigMenu.CurrentMenuIdx = 1
end
ClearPreviousMenu( screen )
ShowCurrentMenu( screen )
end
function ModConfigMenu__ToggleBoolean(screen, button)
local menu = ModConfigMenu.Menus[ModConfigMenu.CurrentMenuIdx]
local name = button.MenuItemName
menu[name] = not menu[name]
UpdateCheckBox(button, menu[name])
end
function ModConfigMenu__OpenFromAdvancedTooltipScreen()
CloseAdvancedTooltipScreen()
ModConfigMenu__Open()
end
function ModConfigMenu__Open()
local components = {}
local screen = {
Components = components,
MenuComponents = {},
CloseAnimation = "QuestLogBackground_Out"
}
OnScreenOpened({ Flag = screen.Name, PersistCombatUI = true})
FreezePlayerUnit()
EnableShopGamepadCursor()
SetConfigOption({ Name = "FreeFormSelectWrapY", Value = false })
SetConfigOption({ Name = "FreeFormSelectStepDistance", Value = 8 })
components.ShopBackgroundDim = CreateScreenComponent({ Name = "rectangle01", Group = "Combat_Menu"})
components.ShopBackgroundSplatter = CreateScreenComponent({ Name = "LevelUpBackground", Group = "Combat_Menu"})
components.ShopBackground = CreateScreenComponent({ Name = "rectangle01", Group = "Combat_Menu"})
SetAnimation({ DestinationId = components.ShopBackground.Id, Name = "QuestLogBackgroun_In", OffsetY = 30 })
SetScale({ Id = components.ShopBackgroundDim.Id, Fraction = 4})
SetColor({ Id = components.ShopBackgroundDim.Id, Color = { 0.090, 0.055, 0.157, 0.8 } })
PlaySound({ Name = "/SFX/Menu Sounds/FatedListOpen" })
wait(0.2)
-- Title
CreateTextBox({ Id = components.ShopBackground.Id, Text = "Configure your Mods", FontSize = 34, OffsetX = 0, OffsetY = -460,
Color = Color.White, Font = "SpectralSCLightTitling", ShadowBlur = 0, ShadowColor = { 0, 0, 0, 1 }, ShadowOffset = { 0, 2 },
Justification = "Center" })
-- Close Button
components.CloseButton = CreateScreenComponent({ Name = "ButtonClose", Scale = 0.7, Group = "Combat_Menu"})
Attach({ Id = components.CloseButton.Id, DestinationId = components.ShopBackground.Id, OffsetX = -6, OffsetY = 456 })
components.CloseButton.OnPressedFunctionName = "ModConfigMenu__Close"
components.CloseButton.ControlHotkey = "Cancel"
components["MenuLeft"] = CreateScreenComponent({
Name = "ButtonCodexLeft",
X = 650,
Y = 175,
Scale = 1.0,
Group = "Combat_Menu"
})
components["MenuLeft"].OnPressedFunctionName = "ModConfigMenu__MenuLeft"
components["MenuRight"] = CreateScreenComponent({
Name = "ButtonCodexRight",
X = 1300,
Y = 175,
Scale = 1.0,
Group = "Combat_Menu"
})
components["MenuRight"].OnPressedFunctionName = "ModConfigMenu__MenuRight"
components["SelectedMenu"] = CreateScreenComponent({
Name = "BlankObstacle",
X = 975,
Y = 175,
Scale = 0.5,
Group = "Combat_Menu"
})
components["MenuRight"].OnPressedFunctionName = "ModConfigMenu__MenuRight"
CreateTextBox({
Id = components["SelectedMenu"].Id,
Text = "No Mods To Configure",
OffsetX = 0, OffsetY = 0,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
ShadowBlur = 0, ShadowColor = { 0, 0, 0, 1 }, ShadowOffset = { 0, 2 },
Justification = "Center"
})
screen.EvergreenComponents = DeepCopyTable(components)
ClearPreviousMenu( screen )
ShowCurrentMenu( screen )
screen.KeepOpen = true
thread( HandleWASDInput, screen )
HandleScreenInput( screen )
end
function ModConfigMenu__Close( screen, button )
DisableShopGamepadCursor()
SetConfigOption({ Name = "FreeFormSelectWrapY", Value = false })
SetConfigOption({ Name = "FreeFormSelectStepDistance", Value = 16 })
SetConfigOption({ Name = "FreeFormSelectSuccessDistanceStep", Value = 8})
SetAnimation({ DestinationId = screen.Components.ShopBackground.Id, Name = screen.CloseAnimation })
PlaySound({ Name = "/SFX/Menu Sounds/FatedListClose" })
CloseScreen( GetAllIds( screen.Components ), 0.1)
UnfreezePlayerUnit()
screen.KeepOpen = false
OnScreenClosed({ Flag = screen.Name })
end
ModUtil.Path.Wrap("CreatePrimaryBacking", function ( baseFunc )
-- Only show menu between runs
if not ModUtil.Path.Get("CurrentDeathAreaRoom") then
return baseFunc()
end
local components = ScreenAnchors.TraitTrayScreen.Components
components.ModConfigButton = CreateScreenComponent({
Name = "ButtonDefault",
Scale = 0.8,
Group = "Combat_Menu_TraitTray",
X = CombatUI.TraitUIStart + 135,
Y = 185 })
components.ModConfigButton.OnPressedFunctionName = "ModConfigMenu__OpenFromAdvancedTooltipScreen"
CreateTextBox({ Id = components.ModConfigButton.Id,
Text = "Configure Mods",
OffsetX = 0, OffsetY = 0,
FontSize = 22,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2},
Justification = "Center",
DataProperties =
{
OpacityWithOwner = true,
},
})
Attach({ Id = components.ModConfigButton.Id, DestinationId = components.ModConfigButton, OffsetX = 500, OffsetY = 500 })
baseFunc()
end, ModConfigMenu)