-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModConfigMenu.lua
More file actions
336 lines (297 loc) · 10.7 KB
/
Copy pathModConfigMenu.lua
File metadata and controls
336 lines (297 loc) · 10.7 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
ModUtil.RegisterMod("ModConfigMenu")
ModConfigMenu.Menus = {}
ModConfigMenu.CurrentMenuIdx = 1
function ModConfigMenu.Register(config)
table.insert(ModConfigMenu.Menus, config)
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 ShowCurrentMenu( screen )
local rowStartX = 350
local columnSpacingX = 600
local itemLocationX = rowStartX
local itemLocationY = 250
local itemSpacingX = 250
local itemSpacingY = 50
local itemsPerRow = 3
local parentComponents = screen.Components
-- clear previous menu
local ids = {}
for name, component in pairs(screen.MenuComponents) do
parentComponents[name] = nil
table.insert(ids, component.Id)
end
CloseScreen( ids )
screen.MenuComponents = {}
local components = screen.MenuComponents
local currentMenu = ModConfigMenu.Menus[ModConfigMenu.CurrentMenuIdx]
if not currentMenu then
return
end
ModifyTextBox({
Id = parentComponents["SelectedMenu"].Id,
Text = currentMenu.ModName or "Unknown Mod"
})
local itemsInRow = 0
for name, value in orderedPairs( currentMenu ) do
local previousItemLocationX = itemLocationX
if value == true or value == false or type(value) == "number" then
itemsInRow = itemsInRow + 1
if itemsInRow > itemsPerRow then
itemLocationX = rowStartX
previousItemLocationX = itemLocationX
itemLocationY = itemLocationY + itemSpacingY
itemsInRow = itemsInRow - itemsPerRow
end
components[name .. "TextBox"] = CreateScreenComponent({
Name = "BlankObstacle",
Scale = 1,
X = itemLocationX,
Y = itemLocationY,
Group = "Combat_Menu" })
CreateTextBox({
Id = 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"
})
itemLocationX = itemLocationX + itemSpacingX
end
if value == true or value == false then
components[name .. "CheckBox"] = CreateScreenComponent({
Name = "RadioButton",
Scale = 1,
X = itemLocationX,
Y = itemLocationY,
Group = "CombatMenu"
})
UpdateCheckBox(components[name .. "CheckBox"], value)
components[name .. "CheckBox"].MenuItemName = name
components[name .. "CheckBox"].OnPressedFunctionName = "ModConfigMenu__ToggleBoolean"
itemLocationX = previousItemLocationX + columnSpacingX
elseif type(value) == "number" then
components[name .. "ButtonPlus"] = CreateScreenComponent({
Name = "LevelUpArrowRight",
Scale = 1,
X = itemLocationX - 40,
Y = itemLocationY,
Group = "CombatMenu"
})
components[name .. "ButtonPlus"].MenuItemName = name
components[name .. "ButtonPlus"].OnPressedFunctionName = "ModConfigMenu__ButtonPlus"
components[name .. "ButtonMinus"] = CreateScreenComponent({
Name = "LevelUpArrowLeft",
Scale = 1,
X = itemLocationX,
Y = itemLocationY,
Group = "CombatMenu"
})
components[name .. "ButtonMinus"].MenuItemName = name
components[name .. "ButtonMinus"].OnPressedFunctionName = "ModConfigMenu__ButtonMinus"
components[name .. "NumberText"] = CreateScreenComponent({
Name = "BlankObstacle",
Scale = 1,
X = itemLocationX + 40,
Y = itemLocationY,
Group = "Combat_Menu" })
CreateTextBox({
Id = components[name .. "NumberText"].Id,
Text = tostring(value),
FontSize = 16,
OffsetX = 0, OffsetY = 0,
Font = "AlegrayaSansSCRegular",
Justification = "Center"
})
itemLocationX = previousItemLocationX + columnSpacingX
end
end
for k, v in pairs(components) do
parentComponents[k] = v
end
end
function ModConfigMenu__MenuLeft( screen, button )
ModConfigMenu.CurrentMenuIdx = ModConfigMenu.CurrentMenuIdx - 1
if ModConfigMenu.CurrentMenuIdx < 1 then
ModConfigMenu.CurrentMenuIdx = #ModConfigMenu.Menus
end
ShowCurrentMenu( screen )
end
function ModConfigMenu__MenuRight( screen, button )
ModConfigMenu.CurrentMenuIdx = ModConfigMenu.CurrentMenuIdx + 1
if ModConfigMenu.CurrentMenuIdx > #ModConfigMenu.Menus then
ModConfigMenu.CurrentMenuIdx = 1
end
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__ButtonPlus(screen, button)
local menu = ModConfigMenu.Menus[ModConfigMenu.CurrentMenuIdx]
local name = button.MenuItemName
print(name, menu[name])
menu[name] = menu[name] + 1
ModifyTextBox({ Id = screen.Components[name .. "NumberText"].Id, Text = tostring(menu[name]) })
end
function ModConfigMenu__ButtonMinus(screen, button)
local menu = ModConfigMenu.Menus[ModConfigMenu.CurrentMenuIdx]
local name = button.MenuItemName
menu[name] = menu[name] - 1
ModifyTextBox({ Id = screen.Components[name .. "NumberText"].Id, Text = tostring(menu[name]) })
end
function ModConfigMenu__Open()
CloseAdvancedTooltipScreen()
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"
})
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.WrapBaseFunction("CreatePrimaryBacking", function ( baseFunc )
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__Open"
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)