-
Notifications
You must be signed in to change notification settings - Fork 0
/
RerollSettingsUI.lua
432 lines (385 loc) · 17.2 KB
/
RerollSettingsUI.lua
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
-- Map of reroll type to display name in the in-game UI
EllosRerollEverythingMod.RerollTypeToInGameName = {
Hammer = "Daedalus Hammers",
Chaos = "Chaos Boons",
Hermes = "Hermes Boons",
Boon = "Other God Boons",
Pom = "Poms of Power",
Shop = "Wells of Charon",
SellTrait = "Purging Pools",
Door = "Room Rewards"
}
-- Order to show the reroll types in the UI
EllosRerollEverythingMod.RerollTypeOrdering = {
Hammer = 1,
Chaos = 2,
Hermes = 3,
Boon = 4,
Pom = 5,
Shop = 6,
SellTrait = 7,
Door = 8,
}
RerollSettingsMenu = {}
-- Function to iterate through the reroll types in the order specified by EllosRerollEverythingMod.RerollTypeOrdering
function IterateSortedByRerollType(t)
local keys = {}
for k in pairs(t) do
keys[#keys + 1] = k
end
table.sort(keys, function(key1, key2)
return EllosRerollEverythingMod.RerollTypeOrdering[key1] > EllosRerollEverythingMod.RerollTypeOrdering[key2]
end)
local j = 0
return
function()
j = j + 1
local k = keys[j]
if k ~= nil then
return k, t[k]
end
end
end
ModUtil.WrapBaseFunction("CreatePrimaryBacking", function ( baseFunc )
if not IsScreenOpen( "RunClear" ) then
local components = ScreenAnchors.TraitTrayScreen.Components
components.RerollConfigButton = CreateScreenComponent({ Name = "ButtonDefault", Scale = 1.0, Group = "TraitTrayTraits", X = CombatUI.TraitUIStart + 105 + 300, Y = 930 })
components.RerollConfigButton.OnPressedFunctionName = "OpenRerollSettingsScreen"
CreateTextBox({ Id = components.RerollConfigButton.Id,
Text = "Reroll Options",
FontSize = 22,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2},
Justification = "Center",
DataProperties =
{
OpacityWithOwner = true,
},
})
end
baseFunc()
end, EllosRerollEverythingMod)
function ModifyNumRerolls(screen, button)
local numRerolls = ((EllosRerollEverythingMod.config.NumStartingRerolls or CurrentRun.NumRerolls) or 0)
numRerolls = numRerolls + button.ModifyAmount
numRerolls = math.max(numRerolls, 0)
EllosRerollEverythingMod.config.NumStartingRerolls = numRerolls
ModifyTextBox({ Id = button.TextLabelId, Text = tostring(numRerolls) })
UpdateRerollUI( EllosRerollEverythingMod.config.NumStartingRerolls )
end
-- Update the BaseRerollCost for a reroll type
function ModifyRerollConfig(screen, button)
local configToUpdate = EllosRerollEverythingMod.config[button.ConfigToUpdate]
local baseRerollCostForType = configToUpdate[button.RerollType]
-- Apply config modification
baseRerollCostForType = baseRerollCostForType + button.ModifyAmount
-- Clamp it to a minimum of -1 or 0 depending
configToUpdate[button.RerollType] = math.max(baseRerollCostForType, -1)
if button.ConfigToUpdate == "RerollIncrements" then
configToUpdate[button.RerollType] = math.max(baseRerollCostForType, 0)
end
-- Update the text box
ModifyTextBox({ Id = button.TextLabelId, Text = configToUpdate[button.RerollType] })
-- If we are at the minimum, change the text to disabled
if configToUpdate[button.RerollType] == -1 then
ModifyTextBox({ Id = button.TextLabelId, ColorTarget = Color.MetaUpgradePointsInvalid, Text = "Disabled" })
else
ModifyTextBox({ Id = button.TextLabelId, ColorTarget = Color.White })
end
end
function MakeAllRerollsFree(screen, button)
for key, value in pairs(EllosRerollEverythingMod.config.BaseRerollCosts) do
EllosRerollEverythingMod.config.BaseRerollCosts[key] = 0
end
for key, value in pairs(EllosRerollEverythingMod.config.RerollIncrements) do
EllosRerollEverythingMod.config.RerollIncrements[key] = 0
end
updateRerollConfigTextBoxes(screen)
end
function DisableRerolls(screen, button)
for key, value in pairs(EllosRerollEverythingMod.config.BaseRerollCosts) do
EllosRerollEverythingMod.config.BaseRerollCosts[key] = -1
end
updateRerollConfigTextBoxes(screen)
end
function ResetRerollConfigToDefault(screen, button)
EllosRerollEverythingMod.config = {
BaseRerollCosts = { -- Cost of first reroll, set to -1 to disable reroll
Hammer = 1, -- Hammers
Chaos = 1, -- Chaos
Hermes = 1, -- Hermes
Boon = 1, -- Boons
Pom = 1, -- Poms
Shop = 1, -- Wells of Charon
SellTrait = 1, -- Purging Pools
Door = 1, -- Exit Doors
},
RerollIncrements = { -- Amount the reroll cost increases after each reroll
Hammer = 1,
Chaos = 1,
Hermes = 1,
Boon = 1,
Pom = 1,
Shop = 1,
SellTrait = 1,
Door = 0,
}
}
updateRerollConfigTextBoxes(screen)
end
function updateRerollConfigTextBoxes(screen)
for _, value in pairs(screen.TextBoxes) do
local text = EllosRerollEverythingMod.config[value.ConfigType][value.RerollType]
local color = Color.White
if text == -1 then
color = Color.MetaUpgradePointsInvalid
text = "Disabled"
end
ModifyTextBox({ Id = value.Id, Text = text, ColorTarget = color})
end
end
function UseRerollSettingsMenu( usee, args )
PlayInteractAnimation( usee.ObjectId )
UseableOff({ Id = usee.ObjectId })
StopStatusAnimation( usee )
EnableShopGamepadCursor()
OpenRerollSettingsMenu()
UseableOn({ Id = usee.ObjectId })
end
function OpenRerollSettingsScreen(screen, button)
CloseAdvancedTooltipScreen()
UseRerollSettingsMenu(CurrentRun.Hero)
end
function OpenRerollSettingsMenu( args )
RerollSettingsMenu = {}
local screen = RerollSettingsMenu
screen.TextBoxes = {}
screen.Components = {}
local components = screen.Components
screen.CloseAnimation = "QuestLogBackground_Out"
OnScreenOpened({ Flag = screen.Name, PersistCombatUI = true })
FreezePlayerUnit()
SetConfigOption({ Name = "FreeFormSelectWrapY", Value = false })
SetConfigOption({ Name = "FreeFormSelectStepDistance", Value = 8 })
SetConfigOption({ Name = "FreeFormSelectSuccessDistanceStep", 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 = "QuestLogBackground_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 = "Reroll Options", FontSize = 34, OffsetX = 0, OffsetY = -460, Color = Color.White, Font = "SpectralSCLightTitling", ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2}, Justification = "Center" })
CreateTextBox({ Id = components.ShopBackground.Id, Text = "Roll the Dice; Change what is Fated", FontSize = 15, OffsetX = 0, OffsetY = -410, Width = 840, Color = {120, 120, 120, 255}, Font = "CrimsonTextItalic", ShadowBlur = 0, ShadowColor = {0,0,0,0}, ShadowOffset={0, 2}, Justification = "Center" })
-- Options
local offsetX = 0
local offsetY = -250
components.rerollRow = {}
components.ColumnHeaders = CreateScreenComponent({ Name = "BlankObstacle", Scale = 1.0, Group = "Combat_Menu" })
Attach({ Id = components.ColumnHeaders.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX, OffsetY = offsetY})
CreateTextBox({
Id = components.ColumnHeaders.Id,
Text = "Reroll Type",
FontSize = 18,
OffsetX = -535,
OffsetY = -45,
Color = {120, 120, 120, 255},
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Left"})
CreateTextBox({
Id = components.ColumnHeaders.Id,
Text = "Base Cost to Reroll",
FontSize = 18,
OffsetX = 0,
OffsetY = -45,
Color = {120, 120, 120, 255},
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Left"})
CreateTextBox({
Id = components.ColumnHeaders.Id,
Text = "Cost Increase Per Reroll",
FontSize = 18,
OffsetX = 340,
OffsetY = -45,
Color = {120, 120, 120, 255},
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Left"})
for rerollType, rerollAmount in IterateSortedByRerollType(EllosRerollEverythingMod.config.BaseRerollCosts) do
local rerollRow = CreateScreenComponent({ Name = "BlankObstacle", Scale = 1.0, Group = "Combat_Menu" })
components["RerollRow" .. rerollType] = rerollRow
Attach({ Id = rerollRow.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX, OffsetY = offsetY})
-- First Column
local leftArrowOffsetX = 85
local leftArrow = CreateScreenComponent({ Name = "LevelUpArrowLeft", Scale = 1.0, Group = "Combat_Menu" })
leftArrow.OnPressedFunctionName = "ModifyRerollConfig"
leftArrow.ConfigToUpdate = "BaseRerollCosts"
leftArrow.ModifyAmount = -1
leftArrow.RerollType = rerollType
leftArrow.TextLabelId = leftArrow.Id
components[rerollType .. "Col1LeftArrow"] = leftArrow
Attach({ Id = leftArrow.Id, DestinationId = rerollRow.Id, OffsetX = leftArrowOffsetX, OffsetY = 0 })
local rightArrow = CreateScreenComponent({ Name = "LevelUpArrowRight", Scale = 1.0, Group = "Combat_Menu" })
rightArrow.OnPressedFunctionName = "ModifyRerollConfig"
rightArrow.ConfigToUpdate = "BaseRerollCosts"
rightArrow.ModifyAmount = 1
rightArrow.RerollType = rerollType
rightArrow.TextLabelId = leftArrow.Id
components[rerollType .. "Col1RightArrow"] = rightArrow
Attach({ Id = rightArrow.Id, DestinationId = rerollRow.Id, OffsetX = leftArrowOffsetX + 35, OffsetY = 0 })
CreateTextBox({
Id = leftArrow.Id,
Text = EllosRerollEverythingMod.config.BaseRerollCosts[rerollType],
FontSize = 28,
OffsetX = -35,
Color = Color.White,
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Right"})
table.insert(screen.TextBoxes, {Id = leftArrow.Id, ConfigType = leftArrow.ConfigToUpdate, RerollType = rerollType})
-- Second Column
local leftArrowOffsetX = 460
local leftArrow = CreateScreenComponent({ Name = "LevelUpArrowLeft", Scale = 1.0, Group = "Combat_Menu" })
leftArrow.OnPressedFunctionName = "ModifyRerollConfig"
leftArrow.ConfigToUpdate = "RerollIncrements"
leftArrow.ModifyAmount = -1
leftArrow.RerollType = rerollType
leftArrow.TextLabelId = leftArrow.Id
components[rerollType .. "Col2LeftArrow"] = leftArrow
Attach({ Id = leftArrow.Id, DestinationId = rerollRow.Id, OffsetX = leftArrowOffsetX, OffsetY = 0 })
local rightArrow = CreateScreenComponent({ Name = "LevelUpArrowRight", Scale = 1.0, Group = "Combat_Menu" })
rightArrow.OnPressedFunctionName = "ModifyRerollConfig"
rightArrow.ConfigToUpdate = "RerollIncrements"
rightArrow.ModifyAmount = 1
rightArrow.RerollType = rerollType
rightArrow.TextLabelId = leftArrow.Id
components[rerollType .. "Col2RightArrow"] = rightArrow
Attach({ Id = rightArrow.Id, DestinationId = rerollRow.Id, OffsetX = leftArrowOffsetX + 35, OffsetY = 0 })
CreateTextBox({
Id = leftArrow.Id,
Text = EllosRerollEverythingMod.config.RerollIncrements[rerollType],
FontSize = 28,
OffsetX = -35,
Color = Color.White,
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Right"})
table.insert(screen.TextBoxes, {Id = leftArrow.Id, ConfigType = leftArrow.ConfigToUpdate, RerollType = rerollType})
local rerollTypeText = EllosRerollEverythingMod.RerollTypeToInGameName[rerollType]
CreateTextBox({
Id = rerollRow.Id,
Text = rerollTypeText,
FontSize = 28,
OffsetX = - 500 - 135,
Color = {255, 235, 128, 255},
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Left"})
offsetY = offsetY + 60
end
-- Starting Reroll Count
local startingRerollCount = CreateScreenComponent({ Name = "BlankObstacle", Scale = 1.0, Group = "Combat_Menu" })
components["StartingRerollCount"] = startingRerollCount
Attach({ Id = startingRerollCount.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX, OffsetY = offsetY})
-- First Column
local leftArrowOffsetX = 85
local leftArrow = CreateScreenComponent({ Name = "LevelUpArrowLeft", Scale = 1.0, Group = "Combat_Menu" })
leftArrow.OnPressedFunctionName = "ModifyNumRerolls"
leftArrow.ModifyAmount = -1
leftArrow.TextLabelId = leftArrow.Id
components["StartingRerollCostCol1LeftArrow"] = leftArrow
Attach({ Id = leftArrow.Id, DestinationId = startingRerollCount.Id, OffsetX = leftArrowOffsetX, OffsetY = 0 })
local rightArrow = CreateScreenComponent({ Name = "LevelUpArrowRight", Scale = 1.0, Group = "Combat_Menu" })
rightArrow.OnPressedFunctionName = "ModifyNumRerolls"
rightArrow.ModifyAmount = 1
rightArrow.TextLabelId = leftArrow.Id
components["StartingRerollCostCol1RightArrow"] = rightArrow
Attach({ Id = rightArrow.Id, DestinationId = startingRerollCount.Id, OffsetX = leftArrowOffsetX + 35, OffsetY = 0 })
CreateTextBox({
Id = leftArrow.Id,
Text = ((EllosRerollEverythingMod.config.NumStartingRerolls or CurrentRun.NumRerolls) or 0),
FontSize = 28,
OffsetX = -35,
Color = Color.White,
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Right"})
CreateTextBox({
Id = startingRerollCount.Id,
Text = "# of Starting Rerolls",
FontSize = 28,
OffsetX = - 500 - 135,
Color = {255, 235, 128, 255},
Font = "AlegreyaSansSCBold",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 3},
OutlineThickness = 12, OutlineColor = {0,0,0,1},
Justification = "Left"})
-- Macros
components.MakeAllRerollsFree = CreateScreenComponent({ Name = "ButtonDefault", Group = "Combat_Menu"})
Attach({ Id = components.MakeAllRerollsFree.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX - 300, OffsetY = offsetY + 100 })
components.MakeAllRerollsFree.OnPressedFunctionName = "MakeAllRerollsFree"
CreateTextBox({ Id = components.MakeAllRerollsFree.Id,
Text = "Make All Rerolls Free",
FontSize = 22,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2},
Justification = "Center"
})
components.ResetToDefault = CreateScreenComponent({ Name = "ButtonDefault", Group = "Combat_Menu"})
Attach({ Id = components.ResetToDefault.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX, OffsetY = offsetY + 100 })
components.ResetToDefault.OnPressedFunctionName = "ResetRerollConfigToDefault"
CreateTextBox({ Id = components.ResetToDefault.Id,
Text = "Reset to Mod Defaults",
FontSize = 22,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
ShadowBlur = 0, ShadowColor = {0,0,0,1}, ShadowOffset={0, 2},
Justification = "Center"
})
components.DisableRerolls = CreateScreenComponent({ Name = "ButtonDefault", Group = "Combat_Menu"})
Attach({ Id = components.DisableRerolls.Id, DestinationId = components.ShopBackground.Id, OffsetX = offsetX + 300, OffsetY = offsetY + 100 })
components.DisableRerolls.OnPressedFunctionName = "DisableRerolls"
CreateTextBox({ Id = components.DisableRerolls.Id,
Text = "Disable All Rerolls",
FontSize = 22,
Color = Color.White,
Font = "AlegreyaSansSCRegular",
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 = "CloseRerollSettingsMenu"
components.CloseButton.ControlHotkey = "Cancel"
wait(0.1)
screen.KeepOpen = true
thread( HandleWASDInput, screen )
HandleScreenInput( screen )
end
function CloseRerollSettingsMenu( screen, button )
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" })
DisableShopGamepadCursor()
CloseScreen( GetAllIds( screen.Components ), 0.1 )
UnfreezePlayerUnit()
screen.KeepOpen = false
OnScreenClosed({ Flag = screen.Name })
updateRerollCostsFromConfig()
end