diff --git a/CorePreview.lua b/CorePreview.lua index f6d5355..ba97aac 100644 --- a/CorePreview.lua +++ b/CorePreview.lua @@ -14,6 +14,9 @@ end function FN.PRE.simulate() -- Guard against simulating in redundant places: + if FN.PRE.five_second_coroutine and coroutine.status(FN.PRE.five_second_coroutine) == "suspended" then + coroutine.resume(FN.PRE.five_second_coroutine) + end if not (G.STATE == G.STATES.SELECTING_HAND or G.STATE == G.STATES.DRAW_TO_HAND or G.STATE == G.STATES.PLAY_TAROT) @@ -59,6 +62,9 @@ end local orig_hl = CardArea.parse_highlighted function CardArea:parse_highlighted() orig_hl(self) + if not FN.PRE.lock_updates and FN.PRE.show_preview then + FN.PRE.show_preview = false + end FN.PRE.add_update_event("immediate") end @@ -86,6 +92,8 @@ function FN.PRE.update_on_card_order_change(cardarea) then return end -- Important not to update on G.STATES.HAND_PLAYED, because it would reset the preview text! + if (G.STATE == G.STATES.HAND_PLAYED) then return end + local prev_order = nil if cardarea.config.type == 'joker' and cardarea.cards[1].ability.set == 'Joker' then if cardarea.cards[1].edition and cardarea.cards[1].edition.mp_phantom then @@ -118,7 +126,9 @@ function FN.PRE.update_on_card_order_change(cardarea) elseif cardarea.config.type == 'hand' then FN.PRE.hand_order = prev_order end - + if FN.PRE.show_preview and not FN.PRE.lock_updates then + FN.PRE.show_preview = false + end FN.PRE.add_update_event("immediate") end end @@ -159,41 +169,59 @@ end function G.FUNCS.fn_pre_score_UI_set(e) local new_preview_text = "" local should_juice = false - if FN.PRE.data then - if true and (FN.PRE.data.score.min ~= FN.PRE.data.score.max) then - -- Format as 'X - Y' : - if e.config.id == "fn_pre_l" then - new_preview_text = FN.PRE.format_number(FN.PRE.data.score.min) .. " - " - if FN.PRE.is_enough_to_win(FN.PRE.data.score.min) then should_juice = true end - elseif e.config.id == "fn_pre_r" then - new_preview_text = FN.PRE.format_number(FN.PRE.data.score.max) - if FN.PRE.is_enough_to_win(FN.PRE.data.score.max) then should_juice = true end + if FN.PRE.lock_updates then + if e.config.id == "fn_pre_l" then + new_preview_text = " CALCULATING " + should_juice = true + end + else + if FN.PRE.data then + if FN.PRE.show_preview and (FN.PRE.data.score.min ~= FN.PRE.data.score.max) then + -- Format as 'X - Y' : + if e.config.id == "fn_pre_l" then + new_preview_text = FN.PRE.format_number(FN.PRE.data.score.min) .. " - " + if FN.PRE.is_enough_to_win(FN.PRE.data.score.min) then should_juice = true end + elseif e.config.id == "fn_pre_r" then + new_preview_text = FN.PRE.format_number(FN.PRE.data.score.max) + if FN.PRE.is_enough_to_win(FN.PRE.data.score.max) then should_juice = true end + end + else + -- Format as single number: + if e.config.id == "fn_pre_l" then + if true then + -- Spaces around number necessary to distinguish Min/Max text from Exact text, + -- which is itself necessary to force a HUD update when switching between Min/Max and Exact. + if FN.PRE.show_preview then + new_preview_text = " " .. FN.PRE.format_number(FN.PRE.data.score.min) .. " " + if FN.PRE.is_enough_to_win(FN.PRE.data.score.min) then should_juice = true end + else + if FN.PRE.is_enough_to_win(FN.PRE.data.score.min) then + should_juice = true + new_preview_text = " " + else + if FN.PRE.is_enough_to_win(FN.PRE.data.score.max) then + new_preview_text = " " + should_juice = true + else + new_preview_text = " " + end + end + end + end + else + new_preview_text = "" + end end else - -- Format as single number: + -- Spaces around number necessary to distinguish Min/Max text from Exact text, same as above ^ if e.config.id == "fn_pre_l" then - if true then - -- Spaces around number necessary to distinguish Min/Max text from Exact text, - -- which is itself necessary to force a HUD update when switching between Min/Max and Exact. - new_preview_text = " " .. FN.PRE.format_number(FN.PRE.data.score.min) .. " " - if FN.PRE.is_enough_to_win(FN.PRE.data.score.min) then should_juice = true end - else - new_preview_text = number_format(FN.PRE.data.score.exact) - if FN.PRE.is_enough_to_win(FN.PRE.data.score.exact) then should_juice = true end + if true then new_preview_text = " ?????? " + else new_preview_text = "??????" end else new_preview_text = "" end end - else - -- Spaces around number necessary to distinguish Min/Max text from Exact text, same as above ^ - if e.config.id == "fn_pre_l" then - if true then new_preview_text = " ?????? " - else new_preview_text = "??????" - end - else - new_preview_text = "" - end end if (not FN.PRE.text.score[e.config.id:sub(-1)]) or new_preview_text ~= FN.PRE.text.score[e.config.id:sub(-1)] then diff --git a/InitPreview.lua b/InitPreview.lua index a5332e8..d63633c 100644 --- a/InitPreview.lua +++ b/InitPreview.lua @@ -14,9 +14,42 @@ FN.PRE = { dollars = {top = "", bot = ""} }, joker_order = {}, - hand_order = {} + hand_order = {}, + show_preview = false, + lock_updates = false, + on_startup = true, + five_second_coroutine = nil } +function FN.PRE.start_new_coroutine() + if FN.PRE.five_second_coroutine and coroutine.status(FN.PRE.five_second_coroutine) ~= "dead" then + FN.PRE.five_second_coroutine = nil -- Reset the coroutine + end + + -- Create and start a new coroutine + FN.PRE.five_second_coroutine = coroutine.create(function() + -- Show UI updates + FN.PRE.lock_updates = true + FN.PRE.show_preview = true + FN.PRE.add_update_event("immediate") -- Force UI refresh + + local start_time = os.time() + while os.time() - start_time < 5 do + FN.PRE.simulate() -- Force a simulation run + FN.PRE.add_update_event("immediate") -- Ensure UI updates + coroutine.yield() -- Allow game to continue running + end + -- Delay for 5 seconds + FN.PRE.lock_updates = false + FN.PRE.show_preview = true + FN.PRE.add_update_event("immediate") -- Refresh UI again + end) + + coroutine.resume(FN.PRE.five_second_coroutine) -- Start it immediately +end + + + FN.PRE._start_up = Game.start_up function Game:start_up() FN.PRE._start_up(self) diff --git a/InterfacePreview.lua b/InterfacePreview.lua index 3c4d9f7..9b8f597 100644 --- a/InterfacePreview.lua +++ b/InterfacePreview.lua @@ -6,18 +6,42 @@ local orig_hud = create_UIBox_HUD function create_UIBox_HUD() local contents = orig_hud() + - local score_node_wrap = {n=G.UIT.R, config={id = "fn_pre_score_wrap", align = "cm", padding = 0.1}, nodes={}} - if G.SETTINGS.FN.preview_score then table.insert(score_node_wrap.nodes, FN.PRE.get_score_node()) end + local score_node_wrap = {n=G.UIT.R, config={id = "fn_pre_score_wrap", align = "cm", padding = 0.05}, nodes={}} + table.insert(score_node_wrap.nodes, FN.PRE.get_score_node()) + local calculate_score_button = {n = G.UIT.R, + config = { + align = "cm", + padding = 0.01, + }, + nodes = { + UIBox_button({ + id = "calculate_score_button", + label = { + "Calculate Score" + }, + colour = G.C.RED, + button = "calculate_score_button", + scale = 0.5, + }), + }, + } + table.insert(contents.nodes[1].nodes[1].nodes[4].nodes[1].nodes, score_node_wrap) + table.insert(contents.nodes[1].nodes[1].nodes[4].nodes[1].nodes, calculate_score_button) - local dollars_node_wrap = {n=G.UIT.C, config={id = "fn_pre_dollars_wrap", align = "cm"}, nodes={}} + --[[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) + 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_score_node() local text_scale = nil if true then text_scale = 0.5 @@ -29,7 +53,7 @@ function FN.PRE.get_score_node() }} end -function FN.PRE.get_dollars_node() +--[[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 @@ -46,7 +70,7 @@ function FN.PRE.get_dollars_node() {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 +end--]] -- -- SETTINGS: