diff --git a/src/ui/advertising.cpp b/src/ui/advertising.cpp index 169ee50..56521da 100644 --- a/src/ui/advertising.cpp +++ b/src/ui/advertising.cpp @@ -858,6 +858,7 @@ void AdvertisingScreen::draw_notification(Image& out) const { bool AdvertisingScreen::dismiss_notification() { if (!notification_open()) return false; notification_dismissed_ = true; + refresh_hover(); return true; } @@ -894,6 +895,7 @@ void AdvertisingScreen::open_spending_calculator(int display_slot) { void AdvertisingScreen::close_spending_calculator() { spending_calculator_open_ = false; spending_backdrop_.reset(); + refresh_hover(); } bool AdvertisingScreen::accept_spending_calculator() { @@ -1001,11 +1003,20 @@ bool AdvertisingScreen::reject_action(std::string reason) { (void)utf8_to_original(reason); if (pending_->kind == AdvertisingActionKind::set_spending) close_spending_calculator(); pending_.reset(); + refresh_hover(); feedback_ = std::move(reason); return true; } +void AdvertisingScreen::refresh_hover() { + if (pointer_position_) (void)move((*pointer_position_)[0], (*pointer_position_)[1]); + else hovered_target_ = -1; +} + bool AdvertisingScreen::move(int x, int y) { + // Modal input freezes the parent view, but its last physical position must + // be sampled again as soon as that modal returns. + pointer_position_ = std::array{x, y}; if (close_requested_ || pending_ || notification_open() || spending_calculator_open_ || offer_open_) return false; int target = -1; @@ -1026,6 +1037,7 @@ bool AdvertisingScreen::move(int x, int y) { } bool AdvertisingScreen::click(int x, int y) { + pointer_position_ = std::array{x, y}; if (close_requested_ || pending_ || x < 0 || y < 0 || x >= 320 || y >= 240) return false; if (notification_open()) return dismiss_notification(); if (spending_calculator_open_) { @@ -1056,6 +1068,7 @@ bool AdvertisingScreen::click(int x, int y) { offer_open_ = false; selected_offer_ = -1; feedback_.clear(); + refresh_hover(); return true; } if (x >= 164 && x <= 229 && y >= 191 && y <= 200) { @@ -1133,7 +1146,12 @@ bool AdvertisingScreen::key(std::string_view value) { return text(value); } if (value == "ESC") { - if (offer_open_) { offer_open_ = false; selected_offer_ = -1; return true; } + if (offer_open_) { + offer_open_ = false; + selected_offer_ = -1; + refresh_hover(); + return true; + } close_requested_ = true; return true; } diff --git a/src/ui/advertising.hpp b/src/ui/advertising.hpp index ce9b304..4969d00 100644 --- a/src/ui/advertising.hpp +++ b/src/ui/advertising.hpp @@ -114,6 +114,7 @@ public: bool reject_action(std::string reason); int selected_contract() const { return selected_contract_; } int hovered_target() const { return hovered_target_; } + std::optional> pointer_position() const { return pointer_position_; } int selected_offer() const { return selected_offer_; } bool offer_open() const { return offer_open_; } bool spending_calculator_open() const { return spending_calculator_open_; } @@ -139,6 +140,7 @@ private: std::optional spending_backdrop_; int selected_contract_ = -1; int hovered_target_ = -1; + std::optional> pointer_position_; int selected_spending_slot_ = -1; int selected_offer_ = -1; uint64_t next_request_id_ = 1; @@ -160,6 +162,7 @@ private: bool accept_spending_calculator(); void close_spending_calculator(); bool dismiss_notification(); + void refresh_hover(); void draw_spending_calculator(Image&) const; void draw_notification(Image&) const; void pattern_rect(Image&, int x, int y, int width, int height) const; diff --git a/src/ui/advertising_tests.cpp b/src/ui/advertising_tests.cpp index e51d67b..0bbd935 100644 --- a/src/ui/advertising_tests.cpp +++ b/src/ui/advertising_tests.cpp @@ -407,6 +407,17 @@ int main(int argc, char** argv) { offers.close_requested(), "cancel closes the offer browser first; a second ESC closes the screen"); + AdvertisingScreen resumed_offers(data, offer_state); + const auto closed_offer_pixels = resumed_offers.render().pixels; + check(resumed_offers.open_offers(0) && !resumed_offers.move(-1, -1) && + resumed_offers.key("ESC") && resumed_offers.hovered_target() == -1 && + resumed_offers.render().pixels == closed_offer_pixels, + "offer ESC rechecks the pointer moved during the modal without another motion event"); + check(resumed_offers.open_offers(0) && resumed_offers.click(110, 195) && + resumed_offers.hovered_target() == -1 && + resumed_offers.render().pixels == closed_offer_pixels, + "offer cancel rechecks its own click position and removes the old target outline"); + // The three source spending controls open the original calculator. All // editing remains local; only J/Enter on a changed value creates a // manager/revision-bound request for the app controller. @@ -470,6 +481,20 @@ int main(int argc, char** argv) { unchanged_budget.spending_input() == 10000 && unchanged_budget.key("J") && !unchanged_budget.pending() && !unchanged_budget.spending_calculator_open(), "accepting an unchanged monthly budget closes locally without an engine request"); + AdvertisingScreen resumed_budget(data, spending_state); + const auto closed_budget_pixels = resumed_budget.render().pixels; + check(resumed_budget.click(budget_x, budget_y) && !resumed_budget.move(-1, -1) && + resumed_budget.key("ESC") && resumed_budget.hovered_target() == -1 && + resumed_budget.render().pixels == closed_budget_pixels, + "calculator ESC restores the current off-target pointer without another motion event"); + AdvertisingScreen expected_parent(data, spending_state); + check(expected_parent.move(empty_x, empty_y) && + resumed_budget.click(budget_x, budget_y) && !resumed_budget.move(empty_x, empty_y) && + resumed_budget.key("J") && !resumed_budget.pending() && + resumed_budget.hovered_target() == empty_slot && + resumed_budget.render().pixels == expected_parent.render().pixels, + "unchanged calculator acceptance resumes hover over the current parent target"); + AdvertisingScreen preset_budget(data, spending_state, 0x300000018ULL); const int preset0_x = 103 + exe.u16(::bmh::layout::Advertising_Click_RuntimeField + 15 * 2); diff --git a/src/ui/preparation_flow.cpp b/src/ui/preparation_flow.cpp index 3e15eed..8c8a78d 100644 --- a/src/ui/preparation_flow.cpp +++ b/src/ui/preparation_flow.cpp @@ -1144,6 +1144,7 @@ FlowResult StartupFlow::pointer_down(int x,int y,bool right) { return {changed}; } if (environment_) return {environment_->pointer_down(x,y,right)}; + if (advertising_) return {advertising_->move(x,y)}; if(pitch_){ const std::string before=pitch_->state_json(); const auto request=pitch_->pointer_down(x,y,right); @@ -2293,6 +2294,8 @@ void StartupFlow::acknowledge_advertising(AdvertisingState state, DeskState desk // Only contract acceptance resumes the next offer. Spending closes its calculator. if (request.kind == AdvertisingActionKind::accept_offer) (void)next_advertising->open_offers(request.offer.display_slot); + if (const auto pointer = advertising_->pointer_position()) + (void)next_advertising->move((*pointer)[0], (*pointer)[1]); desktop_ = std::move(next_desktop); preparation_ = std::move(next_preparation); advertising_ = std::move(next_advertising); diff --git a/tests/app_controller_tests.cpp b/tests/app_controller_tests.cpp index c4de96f..709f5ef 100644 --- a/tests/app_controller_tests.cpp +++ b/tests/app_controller_tests.cpp @@ -1618,7 +1618,14 @@ void check_advertising_controller(const std::filesystem::path& data) { "independent source commit accepts the two-board offer"); const auto expected_bytes = save_stream(expected); const int32_t cash_before = signed_u32(game.manager_records, record + 0x314); + const auto advertising_exe = load_le(asset_path(data, "BMH.exe")); + check(!flow.move_action( + advertising_exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + 18 * 2) + 2, + advertising_exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + 18 * 2) + 2).changed, + "accepted offer remembers a moved pointer while its pending browser stays frozen"); serve(action); + check(flow.state_json().find("\"hovered_target\":18") != std::string::npos, + "accepted final offer resumes current hover outside its original contract target"); check(save_stream(game) == expected_bytes && revision == original_revision + 1 && !flow.pending_advertising_action() && flow.screen_name() == "advertising" && flow.desktop()->state().revision == revision && @@ -1822,7 +1829,11 @@ void check_advertising_spending_controller(const std::filesystem::path& data) { const auto before = save_stream(g); const auto w = session->rand(); const auto gr = session->game(); open(17); flow.text("5000"); (void)flow.render(); - serve(flow.send_key("ESC")); + check(!flow.pointer_down(0, 0, true).changed, + "right DOWN records its position while the calculator still owns input"); + serve(flow.click(0, 0, true)); + check(flow.state_json().find("\"hovered_target\":-1") != std::string::npos, + "calculator right release removes its old outline without a motion event"); check(save_stream(g) == before && session->rand().calls() == w.calls() && session->game().calls() == gr.calls(), "calculator input and cancel are read-only"); open(17); flow.text("5000"); @@ -1832,7 +1843,14 @@ void check_advertising_spending_controller(const std::filesystem::path& data) { check(save_stream(g) == before && !flow.pending_advertising_action(), "forged monthly request cannot mutate state"); open(17); flow.text("5000"); monthly = submit(); + const int resumed_x = exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + 18 * 2) + 2; + const int resumed_y = exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + 18 * 2) + 2; + check(!flow.move_action(resumed_x, resumed_y).changed, + "pending calculator keeps its parent frozen while remembering the latest pointer"); serve(monthly); + check(flow.state_json().find("\"hovered_target\":18") != std::string::npos && + !flow.move_action(resumed_x, resumed_y).changed, + "spending acknowledgement resumes the last pointer over its refreshed parent without new motion"); check(signed_u32(g.manager_records, record + 0x854) == 5000 && signed_u32(g.manager_records, record + 0x314) == 500000 && session->rand().calls() == w.calls() && session->game().calls() == gr.calls(),