-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInterfacePreview.lua
More file actions
147 lines (127 loc) · 5.95 KB
/
InterfacePreview.lua
File metadata and controls
147 lines (127 loc) · 5.95 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
--- Original: Divvy's Preview for Balatro - Interface.lua
--
-- The user interface components that display simulation results.
-- Append node for preview text to the HUD:
local orig_hud = create_UIBox_HUD
function create_UIBox_HUD()
local contents = orig_hud()
local hand_text_area = FN.PRE.find_hand_text_area(contents)
if not hand_text_area then return contents end
table.insert(hand_text_area.nodes[1].nodes, FN.PRE.get_preview_container())
--[[local dollars_node_wrap = {n=G.UIT.C, config={id = "fn_pre_dollars_wrap", align = "cm"}, nodes={}}
if G.SETTINGS.FN.preview_dollars then table.insert(dollars_node_wrap.nodes, FN.PRE.get_dollars_node()) end
table.insert(contents.nodes[1].nodes[1].nodes[5].nodes[2].nodes[3].nodes[1].nodes[1].nodes[1].nodes, dollars_node_wrap) --]]
return contents
end
function G.FUNCS.calculate_score_button()
FN.PRE.start_new_coroutine()
end
function FN.PRE.get_preview_container()
return {n=G.UIT.R, config={id = "fn_preview_container", align = "cm"}, nodes={
{n=G.UIT.C, config={align = "cm"}, nodes={
{n=G.UIT.R, config={id = "fn_pre_score_wrap", align = "cm", padding = 0.1}, nodes={
FN.PRE.get_score_node()
}},
{n=G.UIT.R, config={id = "fn_calculate_score_button_wrap", align = "cm", padding = 0.1}, nodes={
FN.PRE.get_calculate_score_button()
}}
}}
}}
end
function FN.PRE.get_calculate_score_button()
return {n=G.UIT.C, config={id = "calculate_score_button", button = "calculate_score_button", align = "cm", minh = 0.42, padding = 0.05, r = 0.02, colour = G.C.RED, hover = true, shadow = true}, nodes={
{n=G.UIT.R, config={align = "cm"}, nodes={
{n=G.UIT.T, config={text = " Calculate Score ", colour = G.C.UI.TEXT_LIGHT, shadow = true, scale = 0.36}}
}}
}}
end
function FN.PRE.get_score_node()
local text_scale = nil
if true then text_scale = 0.5
else text_scale = 0.75 end
return {n = G.UIT.C, config = {id = "fn_pre_score", align = "cm"}, nodes={
{n=G.UIT.O, config={id = "fn_pre_l", func = "fn_pre_score_UI_set", object = DynaText({string = {{ref_table = FN.PRE.text.score, ref_value = "l"}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, float = true, scale = text_scale})}},
{n=G.UIT.O, config={id = "fn_pre_r", func = "fn_pre_score_UI_set", object = DynaText({string = {{ref_table = FN.PRE.text.score, ref_value = "r"}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, float = true, scale = text_scale})}},
}}
end
function FN.PRE.find_hand_text_area(node)
if node.config and node.config.id == "hand_text_area" then
return node
end
if node.nodes then
for _, child in ipairs(node.nodes) do
local found = FN.PRE.find_hand_text_area(child, id)
if found then return found end
end
end
return nil
end
--[[function FN.PRE.get_dollars_node()
local top_color = FN.PRE.get_dollar_colour(0)
local bot_color = top_color
if FN.PRE.data ~= nil then
top_color = FN.PRE.get_dollar_colour(FN.PRE.data.dollars.max)
bot_color = FN.PRE.get_dollar_colour(FN.PRE.data.dollars.min)
else
end
return {n=G.UIT.C, config={id = "fn_pre_dollars", align = "cm"}, nodes={
{n=G.UIT.R, config={align = "cm"}, nodes={
{n=G.UIT.O, config={id = "fn_pre_dollars_top", func = "fn_pre_dollars_UI_set", object = DynaText({string = {{ref_table = FN.PRE.text.dollars, ref_value = "top"}}, colours = {top_color}, shadow = true, spacing = 2, bump = true, scale = 0.5})}}
}},
{n=G.UIT.R, config={minh = 0.05}, nodes={}},
{n=G.UIT.R, config={align = "cm"}, nodes={
{n=G.UIT.O, config={id = "fn_pre_dollars_bot", func = "fn_pre_dollars_UI_set", object = DynaText({string = {{ref_table = FN.PRE.text.dollars, ref_value = "bot"}}, colours = {bot_color}, shadow = true, spacing = 2, bump = true, scale = 0.5})}},
}}
}}
end--]]
--
-- SETTINGS:
--
function FN.get_preview_settings_page()
local function preview_score_toggle_callback(e)
if not G.HUD then return end
if G.SETTINGS.FN.preview_score then
-- Preview was just enabled, so add preview node:
G.HUD:add_child(FN.PRE.get_score_node(), G.HUD:get_UIE_by_ID("fn_pre_score_wrap"))
FN.PRE.data = FN.PRE.simulate()
else
-- Preview was just disabled, so remove preview node:
G.HUD:get_UIE_by_ID("fn_pre_score").parent:remove()
end
G.HUD:recalculate()
end
local function preview_dollars_toggle_callback(_)
if not G.HUD then return end
if G.SETTINGS.FN.preview_dollars then
-- Preview was just enabled, so add preview node:
G.HUD:add_child(FN.PRE.get_dollars_node(), G.HUD:get_UIE_by_ID("fn_pre_dollars_wrap"))
FN.PRE.data = FN.PRE.simulate()
else
-- Preview was just disabled, so remove preview node:
G.HUD:get_UIE_by_ID("fn_pre_dollars").parent:remove()
end
G.HUD:recalculate()
end
local function face_down_toggle_callback(_)
if not G.HUD then return end
FN.PRE.data = FN.PRE.simulate()
G.HUD:recalculate()
end
return
{n=G.UIT.ROOT, config={align = "cm", padding = 0.05, colour = G.C.CLEAR}, nodes={
create_toggle({id = "score_toggle",
label = "Enable Score Preview",
ref_table = G.SETTINGS.FN,
ref_value = "preview_score",
callback = preview_score_toggle_callback}),
create_toggle({id = "dollars_toggle",
label = "Enable Money Preview",
ref_table = G.SETTINGS.FN,
ref_value = "preview_dollars",
callback = preview_dollars_toggle_callback}),
create_toggle({label = "Hide Preview if Any Card is Face-Down",
ref_table = G.SETTINGS.FN,
ref_value = "hide_face_down",
callback = face_down_toggle_callback})
}}
end