-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
402 lines (366 loc) · 7.32 KB
/
main.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
local logging = require("logging")
local logger = logging.getLogger("balatro-safety")
local function create_multiline_text(text, text_scale, alignment, padding)
local text = text or { }
for i, v in ipairs(text) do
text[i] = {
n = G.UIT.R,
config = {
align = alignment or "cm",
padding = padding or 0.05
},
nodes = {
{
n = G.UIT.T,
config = {
text = v,
scale = text_scale or 1,
colour = G.C.UI.TEXT_LIGHT,
shadow = true
}
}
}
};
end;
return text
end
local function create_card_desc_text(card_desc)
local output = { }
for i, v in ipairs(card_desc) do
for i2, v2 in ipairs(v) do
v2.config.scale = 0.45
if v2.config.colour == G.C.UI.TEXT_DARK then
v2.config.colour = G.C.SO_2.Hearts
end
end
output[i] = {
n = G.UIT.R,
config = {
align = "cm",
padding = 0.05
},
nodes = v
}
end
return output
end
local function create_UIBox_generic_container(options)
options = options or {
content = {}
}
return {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.03,
colour = G.C.UI.TRANSPARENT_LIGHT,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.05,
colour = G.C.DYN_UI.MAIN,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
colour = G.C.DYN_UI.BOSS_DARK,
minw = options.width or 10,
minh = options.height or 4,
r = 1,
padding = 0.08
},
nodes = options.content
}
}
}
}
}
}
end
local function create_UIBox_confirmation(options)
options = options or {}
return {
{
n = G.UIT.C,
config = {
align = "cm",
padding = 0,
minw = 5,
minh = 4,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0,
minw = 5,
minh = 4,
r = 1
},
nodes = {
{
n = G.UIT.O,
config = {
align = "cm",
object = options.card
}
}
}
},
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0,
minw = 5,
minh = 2.4,
r = 1,
colour = G.C.UI.BACKGROUND_WHITE
},
nodes = create_card_desc_text(options.card_desc)
}
}
},
{
n = G.UIT.C,
config = {
align = "cr",
padding = 0,
minw = 5,
minh = 4,
r = 1,
colour = G.C.UI.BACKGROUND_DARK
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.025,
minw = 5,
minh = 4,
maxw = 5,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.3,
minw = 5,
minh = 2,
maxw = 5,
r = 1
},
nodes = create_multiline_text({
"Are you SURE",
"you want to do this?"
}, 0.75, "cm", 0.02, 1)
}
}
},
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.025,
minw = 5,
minh = 2,
maxw = 5,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.025,
minw = 5,
minh = 2,
maxw = 5,
r = 1
},
nodes = {
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.05,
minw = 4.75,
minh = 1,
maxw = 4.75,
r = 1
},
nodes = {
UIBox_button({
button = 'safety_confirm_action',
label = { "CONFIRM" },
minw = 4.75,
minh = 0.95,
scale = 0.5,
colour = G.C.GREEN,
id = 'safety_confirm'
})
}
},
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0.05,
minw = 4.75,
minh = 1,
maxw = 5,
r = 1
},
nodes = {
UIBox_button({
button = 'safety_cancel_action',
label = { "CANCEL" },
minw = 4.75,
minh = 0.95,
scale = 0.5,
colour = G.C.RED,
id = 'safety_cancel'
})
}
},
{
n = G.UIT.R,
config = {
align = "cm",
padding = 0,
minw = 4.5,
minh = 0.1,
maxw = 5,
r = 1
}
}
}
}
}
}
}
}
}
end
local confirm_action = nil
local safety_card = nil
local danger_cards = { "c_hex", "c_ankh" }
local function has_value(tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
local function on_enable()
G.UIDEF.safety_box = function(card)
local display_card = Card(0, 0, G.CARD_W, G.CARD_H, card.config.center, card.config.center)
display_card.no_ui = true
card.area:unhighlight_all()
card_desc = {}
localize{type = 'descriptions', key = card.config.center.key, set = card.config.center.set, nodes = card_desc, vars = { } }
return {
n = G.UIT.ROOT,
config = {
align = "cm",
padding = 0.1,
r = 2
},
nodes = create_UIBox_generic_container({
content = create_UIBox_confirmation({
card = display_card,
card_desc = card_desc
})
})
}
end
G.FUNCS.safety_confirm_action = function()
if confirm_action then
confirm_action()
end
end
G.FUNCS.safety_cancel_action = function()
G.FUNCS.exit_overlay_menu()
safety_card = nil
confirm_action = nil
end
G.FUNCS.safety_use_card = G.FUNCS.use_card
G.FUNCS.use_card = function(e, mute, nosave)
logger:debug(e.config.ref_table.config.center)
safety_card = e.config.ref_table
if safety_card.config.center.set == "Spectral" and has_value(danger_cards, safety_card.config.center.key) then
confirm_action = function()
G.FUNCS.safety_use_card(e, mute, nosave)
G.FUNCS.exit_overlay_menu()
end
G.FUNCS.overlay_menu({definition = G.UIDEF.safety_box(safety_card) })
else
confirm_action = nil
safety_card = nil
G.FUNCS.safety_use_card(e, mute, nosave)
end
end
end
local function on_disable()
G.FUNCS.safety_confirm_action = nil
G.FUNCS.safety_cancel_action = nil
G.FUNCS.use_card = G.FUNCS.safety_use_card
G.UIDEF.safety_box = nil
end
local function menu()
end
local function on_game_load(args)
end
local function on_game_quit()
end
local function on_key_pressed(key)
end
local function on_key_released(key)
end
local function on_mouse_pressed(button, x, y, touch)
end
local function on_mouse_released(button, x, y)
end
local function on_mousewheel(x, y)
end
local function on_pre_render()
end
local function on_post_render()
end
local function on_error(message)
end
local function on_pre_update(dt)
end
local function on_post_update(dt)
end
return {
on_enable = on_enable,
on_disable = on_disable,
menu = menu,
on_game_load = on_game_load,
on_game_quit = on_game_quit,
on_key_pressed = on_key_pressed,
on_key_released = on_key_released,
on_mouse_pressed = on_mouse_pressed,
on_mouse_released = on_mouse_released,
on_mousewheel = on_mousewheel,
on_pre_render = on_pre_render,
on_post_render = on_post_render,
on_error = on_error,
on_pre_update = on_pre_update,
on_post_update = on_post_update,
}