diff --git a/src/ui/advertising.cpp b/src/ui/advertising.cpp index 44347c5..169ee50 100644 --- a/src/ui/advertising.cpp +++ b/src/ui/advertising.cpp @@ -679,16 +679,14 @@ Image AdvertisingScreen::render() const { draw_finance(state_.finance_preview.expenses_text, 198, 222); text(image, 254, 218, state_.finance_preview.balance_text, 0x6b, 64); - if (selected_contract_ >= 0) { - const auto& contract = selected_contract_ < kBoardCount - ? state_.boards[size_t(selected_contract_)] - : selected_contract_ == 14 ? state_.shirt : state_.television; - if (selected_contract_ < 16) { - const int i = selected_contract_; - rectangle(image, exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + uint32_t(i) * 2), exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + uint32_t(i) * 2), - exe.u16(::bmh::layout::Advertising_Click_RuntimeField5 + uint32_t(i) * 2), exe.u16(::bmh::layout::Advertising_Click_RuntimeField6 + uint32_t(i) * 2), 0x27); - } - const auto& offer_list = state_.offers[size_t(selected_contract_)]; + // The original details panel follows the pointer until the offer browser owns it. + const int details_target = offer_open_ ? selected_contract_ : + hovered_target_ >= 0 && hovered_target_ < 16 ? hovered_target_ : -1; + if (details_target >= 0) { + const auto& contract = details_target < kBoardCount + ? state_.boards[size_t(details_target)] + : details_target == 14 ? state_.shirt : state_.television; + const auto& offer_list = state_.offers[size_t(details_target)]; const bmh::AdvertisingOfferCandidate* offer = nullptr; if (offer_open_ && selected_offer_ >= 0) for (const auto& candidate : offer_list.offers) @@ -732,7 +730,7 @@ Image AdvertisingScreen::render() const { } text(image, 156, 185, show_offer ? state_.offer_label : state_.bonus_label, 0x6c, 34); text(image, 191, 185, original_to_utf8(exe_.cstring(::bmh::layout::Advertising_FormatError_ExecutableField)) + (show_offer - ? state_.offer_amount_text[size_t(selected_contract_)][size_t(selected_offer_)] + ? state_.offer_amount_text[size_t(details_target)][size_t(selected_offer_)] : contract.amount_text), 0x6c, 100); if (!offer_open_ && contract.active && contract.months_remaining == 0 && contract.extension_months != 0) @@ -761,10 +759,12 @@ Image AdvertisingScreen::render() const { button(image, 164, 191, 66, state_.accept_label); } } - if (selected_spending_slot_ >= 16 && selected_spending_slot_ <= 18) { - const uint32_t i = uint32_t(selected_spending_slot_); - rectangle(image, exe_.u16(::bmh::layout::Advertising_Click_RuntimeField3 + i * 2), exe_.u16(::bmh::layout::Advertising_Click_RuntimeField4 + i * 2), - exe_.u16(::bmh::layout::Advertising_Click_RuntimeField5 + i * 2), exe_.u16(::bmh::layout::Advertising_Click_RuntimeField6 + i * 2), 0x27); + if (hovered_target_ >= 0) { + const uint32_t at = uint32_t(hovered_target_) * 2; + rectangle(image, exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + at), + exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + at), + exe.u16(::bmh::layout::Advertising_Click_RuntimeField5 + at), + exe.u16(::bmh::layout::Advertising_Click_RuntimeField6 + at), 0x27); } if (spending_calculator_open_ && spending_backdrop_) image = *spending_backdrop_; if (notification_open()) draw_notification(image); @@ -941,6 +941,7 @@ bool AdvertisingScreen::text(std::string_view input) { void AdvertisingScreen::begin_offer_browser(int display_slot) { selected_contract_ = display_slot; + hovered_target_ = display_slot; offer_open_ = true; selected_offer_ = -1; const auto& offers = state_.offers[size_t(display_slot)].offers; @@ -1004,6 +1005,26 @@ bool AdvertisingScreen::reject_action(std::string reason) { return true; } +bool AdvertisingScreen::move(int x, int y) { + if (close_requested_ || pending_ || notification_open() || spending_calculator_open_ || offer_open_) + return false; + int target = -1; + for (int i = 0; i < 19; ++i) { + const uint32_t at = uint32_t(i) * 2; + const int left = exe_.u16(::bmh::layout::Advertising_Click_RuntimeField3 + at); + const int top = exe_.u16(::bmh::layout::Advertising_Click_RuntimeField4 + at); + const int width = exe_.u16(::bmh::layout::Advertising_Click_RuntimeField5 + at); + const int height = exe_.u16(::bmh::layout::Advertising_Click_RuntimeField6 + at); + if (x >= left && x < left + width && y >= top && y < top + height) { + target = i; + break; + } + } + if (target == hovered_target_) return false; + hovered_target_ = target; + return true; +} + bool AdvertisingScreen::click(int x, int y) { if (close_requested_ || pending_ || x < 0 || y < 0 || x >= 320 || y >= 240) return false; if (notification_open()) return dismiss_notification(); @@ -1056,6 +1077,7 @@ bool AdvertisingScreen::click(int x, int y) { const int right = left + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField5 + uint32_t(i) * 2); const int bottom = top + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField6 + uint32_t(i) * 2); if (x >= left && x < right && y >= top && y < bottom) { + (void)move(x, y); const auto& projected = state_.offers[size_t(i)]; const bool renewal_due = projected.contract_slot >= 0 && projected.contract_slot < 16 && (projected.contract_bytes[6] & 0x7f) != 0 && projected.contract_bytes[5] == 0; @@ -1086,6 +1108,7 @@ bool AdvertisingScreen::click(int x, int y) { const int right = left + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField5 + uint32_t(i) * 2); const int bottom = top + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField6 + uint32_t(i) * 2); if (x >= left && x < right && y >= top && y < bottom) { + (void)move(x, y); selected_contract_ = -1; selected_spending_slot_ = i; open_spending_calculator(i); @@ -1122,6 +1145,7 @@ std::string AdvertisingScreen::state_json() const { if (!result.empty() && result.back() == '}') result.pop_back(); result += ",\"spending_calculator_open\":" + std::string(spending_calculator_open_ ? "true" : "false") + + ",\"hovered_target\":" + std::to_string(hovered_target_) + ",\"selected_spending_slot\":" + std::to_string(selected_spending_slot_) + ",\"spending_input\":" + std::to_string(spending_input_) + ",\"notification_open\":" + std::string(notification_open() ? "true" : "false"); diff --git a/src/ui/advertising.hpp b/src/ui/advertising.hpp index 5a81fed..ce9b304 100644 --- a/src/ui/advertising.hpp +++ b/src/ui/advertising.hpp @@ -105,6 +105,7 @@ public: AdvertisingScreen(const std::filesystem::path& data, AdvertisingState state, uint64_t request_id_seed = 1); Image render() const; + bool move(int x, int y); bool click(int x, int y); bool key(std::string_view key); bool open_offers(int display_slot); @@ -112,6 +113,7 @@ public: const std::optional& pending() const { return pending_; } bool reject_action(std::string reason); int selected_contract() const { return selected_contract_; } + int hovered_target() const { return hovered_target_; } int selected_offer() const { return selected_offer_; } bool offer_open() const { return offer_open_; } bool spending_calculator_open() const { return spending_calculator_open_; } @@ -136,6 +138,7 @@ private: std::optional badge_atlas_; std::optional spending_backdrop_; int selected_contract_ = -1; + int hovered_target_ = -1; int selected_spending_slot_ = -1; int selected_offer_ = -1; uint64_t next_request_id_ = 1; diff --git a/src/ui/advertising_tests.cpp b/src/ui/advertising_tests.cpp index 6b3e566..e51d67b 100644 --- a/src/ui/advertising_tests.cpp +++ b/src/ui/advertising_tests.cpp @@ -3,6 +3,7 @@ #include "ui/advertising.hpp" #include "ui/source_notice_test_helpers.hpp" +#include #include #include #include @@ -281,6 +282,54 @@ int main(int argc, char** argv) { check(pixel(first, exe.u16(::bmh::layout::Advertising_Click_RuntimeField3) + x, exe.u16(::bmh::layout::Advertising_Click_RuntimeField4) + y) == pixel(logos, x, y), "active board logos use the original KB/34 partner sprite and hitbox coordinates"); + // Motion alone must display the original rectangle and details; it must + // never open negotiations, spending, or emit an engine action. + AdvertisingScreen hover(data, state); + for (int target = 0; target < 19; ++target) { + const uint32_t at = uint32_t(target) * 2; + const int x = exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + at); + const int y = exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + at); + const int width = exe.u16(::bmh::layout::Advertising_Click_RuntimeField5 + at); + const int height = exe.u16(::bmh::layout::Advertising_Click_RuntimeField6 + at); + check(hover.move(x + 1, y + 1) && hover.hovered_target() == target && + !hover.move(x + 2, y + 2) && !hover.pending() && !hover.offer_open() && + !hover.spending_calculator_open() && hover.selected_contract() == -1, + "pointer motion follows every original advertising target without an action"); + const auto highlighted = hover.render(); + for (int dx = 0; dx < width; ++dx) + check(pixel(highlighted, x + dx, y) == 0x27 && + pixel(highlighted, x + dx, y + height - 1) == 0x27, + "hover paints the original yellow top and bottom rectangle edges"); + for (int dy = 0; dy < height; ++dy) + check(pixel(highlighted, x, y + dy) == 0x27 && + pixel(highlighted, x + width - 1, y + dy) == 0x27, + "hover paints the original yellow left and right rectangle edges"); + check(hover.move(-1, -1) && hover.hovered_target() == -1 && + hover.render().pixels == first.pixels && !hover.move(-1, -1), + "leaving a target restores both the outline and details without sticky selection"); + } + const int empty_slot = int(std::find_if(state.boards.begin(), state.boards.end(), + [](const auto& contract) { return !contract.active; }) - state.boards.begin()); + check(empty_slot < 14 && !state.space_available_text.empty(), + "fixture provides an empty advertising surface and edition-specific help"); + auto no_help_state = state; + no_help_state.space_available_text.clear(); + AdvertisingScreen no_help(data, no_help_state); + const int empty_x = exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + empty_slot * 2) + 1; + const int empty_y = exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + empty_slot * 2) + 1; + check(hover.move(empty_x, empty_y) && no_help.move(empty_x, empty_y) && + hover.render().pixels != no_help.render().pixels && + state.space_available_text == original_to_utf8(message_text(game, + ::bmh::layout::Advertising_FormatError_TextPointer7)), + "empty-surface hover renders help from the installation's actual TEXTD pointer"); + AdvertisingScreen spending_hover(data, state); + const int spending_x = exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + 17 * 2) + 1; + const int spending_y = exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + 17 * 2) + 1; + check(spending_hover.move(spending_x, spending_y) && hover.move(spending_x, spending_y) && + hover.render().pixels == spending_hover.render().pixels, + "moving directly from empty-surface help to spending clears the contract detail panel"); + check(game.manager_records == records_before, + "all hover targets and help rendering leave the manager records unchanged"); check(screen.click(exe.u16(::bmh::layout::Advertising_Click_RuntimeField3) + 1, exe.u16(::bmh::layout::Advertising_Click_RuntimeField4) + 1) && screen.selected_contract() == 0, "a board click selects a local read-only details panel"); @@ -295,6 +344,9 @@ int main(int argc, char** argv) { screen.key("ESC") && screen.close_requested() && !screen.key("LEFT"), "ESC closes an existing offer browser before the screen"); } else { + check(screen.move(-1, -1) && screen.render().pixels == first.pixels && + screen.selected_contract() == 0, + "a clicked contract without offers does not leave a sticky outline or details"); check(screen.key("ESC") && screen.close_requested() && !screen.key("LEFT"), "without a saved offer, ESC closes the contract details directly"); } @@ -318,6 +370,10 @@ int main(int argc, char** argv) { const bool opened = offers.open_offers(0); check(opened && offers.offer_open() && offers.selected_offer() == 5, "opening the source offer browser selects the highest saved raw offer"); + const auto offer_pixels = offers.render().pixels; + check(!offers.move(empty_x, empty_y) && offers.render().pixels == offer_pixels && + offers.selected_offer() == 5 && !offers.pending(), + "offer browser keeps its input and details when the pointer crosses the parent targets"); check(offers.click(140, 164) && offers.selected_offer() == 4 && !offers.click(190, 195) && !offers.pending(), "an empty raw slot cannot create an acceptance request"); @@ -377,6 +433,9 @@ int main(int argc, char** argv) { "the original merchandise hitbox opens its calculator with the saved value"); const auto calculator_art = load_vga(asset_path(data / "KB", "6.VGA")); const auto calculator_image = merchandise.render(); + check(!merchandise.move(empty_x, empty_y) && + merchandise.render().pixels == calculator_image.pixels && !merchandise.pending(), + "spending calculator retains its captured parent and does not hover through it"); check(calculator_image.pixels[size_t(55) * 320 + 103] == calculator_art.pixels[0], "the calculator opens over the original advertising screen using KB/6 at source coordinates"); check(merchandise.text("200000") && merchandise.spending_input() == 200000 && diff --git a/src/ui/flow.cpp b/src/ui/flow.cpp index e52627a..8a30e59 100644 --- a/src/ui/flow.cpp +++ b/src/ui/flow.cpp @@ -30,6 +30,7 @@ FlowResult StartupFlow::move_action(int x, int y) { if (friendly_match_) return {friendly_match_->move(x,y)}; if(league_pairings_)return {league_pairings_->move(x,y)}; if(stadium_)return {stadium_->pointer_move(x,y)}; + if(advertising_)return {advertising_->move(x,y)}; if(environment_)return {}; if (outgoing_transfer_) return {}; if (transfer_market_ && !player_card_) { diff --git a/tests/app_controller_tests.cpp b/tests/app_controller_tests.cpp index a650e85..e91408f 100644 --- a/tests/app_controller_tests.cpp +++ b/tests/app_controller_tests.cpp @@ -1523,6 +1523,18 @@ void check_advertising_controller(const std::filesystem::path& data) { }; serve(flow.send_key("W")); check(flow.screen_name() == "advertising", "Original W opens advertising through the controller"); + const auto unhovered_pixels = flow.render().pixels; + const auto moved = flow.move_action(40, 30); + check(moved.changed && moved.request == FlowRequest::none && + flow.state_json().find("\"hovered_target\":") != std::string::npos && + flow.render().pixels != unhovered_pixels && !flow.pending_advertising_action(), + "production flow routes advertising motion into the original hover and help view"); + check(!flow.pointer_down(40, 30).changed && !flow.pending_advertising_action(), + "advertising DOWN does not duplicate the release-owned offer action"); + unchanged(); + check(flow.move_action(-1, -1).changed && flow.render().pixels == unhovered_pixels, + "production flow restores the advertising view when the pointer leaves"); + unchanged(); serve(flow.click(40, 30)); (void)flow.render(); unchanged();