-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
341 lines (320 loc) · 6.22 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
--- STEAMODDED HEADER
--- MOD_NAME: Balatro Safety
--- MOD_ID: balatro-safety
--- MOD_AUTHOR: [Zei33]
--- MOD_DESCRIPTION: Protects you from accidentally making dangerous decisions. You'll be presented with a confirmation before some choices.
--- BADGE_COLOUR: 3576de
--- VERSION: 1.0.0
--- PREFIX: zei
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
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)
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