diff --git a/docs/COMPATIBILITY.md b/docs/COMPATIBILITY.md index 237cee4..fe77687 100644 --- a/docs/COMPATIBILITY.md +++ b/docs/COMPATIBILITY.md @@ -104,3 +104,11 @@ currency formatting, including values beyond a signed native account word. Saved cash, deposits, loan fields and holdings retain their original widths. This prevents a positive combined portfolio from appearing negative; it does not recover amounts that have already overflowed inside a native saved field. + +Live ball, set-piece and shot animations retain +visible scoreboard digits at the chance-preview value until the result view. +The simulation still commits goals, statistics and random draws at their existing +boundaries. Post-match overview dismissal owns its full mouse gesture, including +release after pointer movement, before the following calendar decision can open. +The pitch uses each edition's original position-distance tables, atlas swatches +and pointer bitmap for placement feedback; this display state is not serialized. diff --git a/docs/formats/EXECUTABLE_LAYOUT.md b/docs/formats/EXECUTABLE_LAYOUT.md index 68dcdaf..efe1ab5 100644 --- a/docs/formats/EXECUTABLE_LAYOUT.md +++ b/docs/formats/EXECUTABLE_LAYOUT.md @@ -1490,6 +1490,14 @@ declarations change. Game text, resort, image and audio fallbacks belong outside | `Pitch_FormatError_TextPointer2` | `0xaf178` | German-compatible image / runtime field | | `Pitch_FormatError_TextPointer3` | `0xaf17c` | German-compatible image / runtime field | | `Pitch_Render_RuntimeField` | `0xa3cbc` | German-compatible image / runtime field | +| `PitchPreferenceDepthBases` | `0xa3cc3` | Four position-depth bases for native pitch feedback | +| `PitchPreferenceRed` | `0xa3cc7` | Ten native pointer red components | +| `PitchPreferenceGreen` | `0xa3cd1` | Ten native pointer green components | +| `OriginalPointerPixels` | `0xa45b4` | Native 11 by 11 indexed pointer bitmap | +| `EnglishPitchPreferenceDepthBases` | `0x6e230` | English position-depth bases | +| `EnglishPitchPreferenceRed` | `0x6e234` | English pointer red components | +| `EnglishPitchPreferenceGreen` | `0x6e240` | English pointer green components | +| `EnglishOriginalPointerPixels` | `0x70554` | English 11 by 11 indexed pointer bitmap | | `Pitch_Render_TextPointer` | `0xae0e4` | German-compatible image / runtime field | | `Pitch_Render_TextPointer2` | `0xae0ec` | German-compatible image / runtime field | | `Pitch_Render_TextPointer3` | `0xae0f0` | German-compatible image / runtime field | diff --git a/src/app/main.cpp b/src/app/main.cpp index 0fe3799..a66f1fb 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -33,6 +33,7 @@ #include "version.hpp" #include "app/video_session.hpp" #include "app/live_matchday_events.hpp" +#include "app/pitch_pointer.hpp" #include "audio/playback.hpp" #include "app/audio.hpp" #include "formats/palette.hpp" @@ -215,6 +216,7 @@ int main(int argc, char** argv) { SDL_RenderSetLogicalSize(renderer, 320, 240); SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 240); if (!texture) throw FormatError(SDL_GetError()); + app::PitchPointer pitch_pointer; std::vector pixels(320 * 240); ui::LiveMatchdayScreen live_screen(data); ui::RealityReporterPanel reality_reporter(data); @@ -1702,6 +1704,7 @@ int main(int argc, char** argv) { std::optional timed_notice_presented_at; std::optional timed_notice_release; auto handle = [&](const ui::FlowResult& r) { + pitch_pointer.show({}, renderer); if (r.request == ui::FlowRequest::end_session && !quit_confirmation.confirm()) { flow.reject_desk_action(english_game ? "Quit cancelled." : "Beenden abgebrochen."); dirty = true; @@ -1781,6 +1784,7 @@ int main(int argc, char** argv) { bool closed = false; const auto apply_live_pitch = [&](const ui::PitchRequest& action) { if (action.kind == ui::PitchRequestKind::none) return; + pitch_pointer.show({}, renderer); if (action.kind == ui::PitchRequestKind::open_player_info) { try { if (action.row < 0 || size_t(action.row) >= screen.state().players.size() || @@ -1820,6 +1824,7 @@ int main(int argc, char** argv) { }; bool left_held = false, left_release_consumed = false, right_held = false; while (running && !closed) { + pitch_pointer.show(screen.pointer_cursor(palette), renderer); const Image image = screen.render(); for (size_t i = 0; i < pixels.size(); ++i) pixels[i] = palette.argb[image.pixels[i]]; @@ -1880,8 +1885,10 @@ int main(int argc, char** argv) { scope_finished = true; completed = true; } + pitch_pointer.show({}, renderer); SDL_SetWindowTitle(window, "OpenBMH - live_matchday"); } catch (const std::exception& e) { + pitch_pointer.show({}, renderer); if (scope_started && !scope_finished) dispatch_scope(app::LiveInterventionBoundary::abort, 2, selected_manager, selected_team, scope_error); @@ -2096,11 +2103,16 @@ int main(int argc, char** argv) { } }; SDL_FlushEvent(SDL_KEYUP); - while (running && !closed) { + while (running && (!closed || down)) { SDL_Event input; bool redrawn = false; while (quit_confirmation.poll(&input)) { if (input.type == SDL_QUIT) { running = false; break; } + if (closed) { + if (input.type == SDL_MOUSEBUTTONUP && down && + input.button.button == down->button) { down.reset(); break; } + continue; + } if (input.type == SDL_MOUSEMOTION) { const bool changed = table_screen ? table_screen->move(input.motion.x, input.motion.y) : pairings_screen ? pairings_screen->move(input.motion.x, input.motion.y) @@ -2119,8 +2131,7 @@ int main(int argc, char** argv) { else cup_screen->pointer_down(input.button.x, input.button.y, input.button.button == SDL_BUTTON_RIGHT); } else if (input.type == SDL_MOUSEBUTTONUP && down && - input.button.button == down->button && input.button.x == down->x && - input.button.y == down->y) { + input.button.button == down->button) { down.reset(); if (table_screen) table_screen->click(input.button.x, input.button.y, input.button.button == SDL_BUTTON_RIGHT); @@ -2141,19 +2152,21 @@ int main(int argc, char** argv) { else if (cup_screen && cup_screen->pending()) action = *cup_screen->pending(); if (action) { dispatch_action(*action); redrawn = true; } - if (closed || !running) break; + if ((closed && !down) || !running) break; } - if (!running || closed) break; + if (!running || (closed && !down)) break; + if (closed) { SDL_Delay(8); continue; } if (pairings_screen && pairings_screen->tick_source_seconds(overview_source_seconds())) { if (pairings_screen->pending()) dispatch_action(app::CareerSession::LiveOverviewAction{*pairings_screen->pending()}); redrawn = true; } - if (closed || !running) break; + if ((closed && !down) || !running) break; if (!redrawn) SDL_Delay(8); } return running && closed; }; + ui::LiveScoreReveal live_score_reveal; std::optional live_chance_context; std::unique_ptr reality_field; ui::RealityReporterLayoutState reality_layout; @@ -2911,7 +2924,7 @@ int main(int argc, char** argv) { }, [&](const LiveBallEvent& event, const std::vector& groups, const GameState& state) { if (!running || live_skipped) return; - const auto frame = ui::live_matchday_frame(event.minute, groups, state); + const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state)); if (frame.matches.empty()) return; const auto present = [&](const Image& image) { for (size_t i = 0; i < pixels.size(); ++i) pixels[i] = palette.argb[image.pixels[i]]; @@ -2958,6 +2971,7 @@ int main(int argc, char** argv) { const GameState& state) { if (!running || live_skipped) return; const auto frame = ui::live_matchday_frame(event.minute, groups, state); + live_score_reveal.observe(event.stage, frame); if (frame.matches.empty()) return; const auto chance = ui::live_chance_projection(event, groups, state, season_exe); if (event.stage == LiveChanceStage::preview) live_chance_context = chance; @@ -2990,7 +3004,7 @@ int main(int argc, char** argv) { }, [&](const LiveShotEvent& event, const std::vector& groups, const GameState& state) { if (!running || live_skipped) return; - const auto frame = ui::live_matchday_frame(event.minute, groups, state); + const auto frame = live_score_reveal.project(ui::live_matchday_frame(event.minute, groups, state)); if (frame.matches.empty()) return; const auto frames = live_screen.render_shot(frame, event); const auto shot_colors = live_screen.shot_palette(palette, event, groups, state); @@ -3048,7 +3062,7 @@ int main(int argc, char** argv) { }, [&](const LiveSetPieceEvent& event, const std::vector& groups, const GameState& state) { if (!running || live_skipped) return; - const auto frame=ui::live_matchday_frame(event.minute,groups,state); + const auto frame=live_score_reveal.project(ui::live_matchday_frame(event.minute,groups,state)); if (frame.matches.empty()) return; const auto images=live_screen.render_set_piece(frame,event); LiveShotEvent palette_event; @@ -3915,6 +3929,7 @@ int main(int argc, char** argv) { throw std::runtime_error(std::string("Source modal texture: ") + SDL_GetError()); dirty = false; } + pitch_pointer.show(flow.pitch_pointer_cursor(palette), renderer); const int cleared = SDL_RenderClear(renderer); const int copied = SDL_RenderCopy(renderer, texture, nullptr, nullptr); if (source_modal_redraw && (cleared != 0 || copied != 0)) @@ -3939,6 +3954,7 @@ int main(int argc, char** argv) { SDL_Delay(10); } SDL_StopTextInput(); + pitch_pointer.clear(); SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); diff --git a/src/app/pitch_pointer.hpp b/src/app/pitch_pointer.hpp new file mode 100644 index 0000000..7c65e88 --- /dev/null +++ b/src/app/pitch_pointer.hpp @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace bmh::app { + +// SDL owns pointer position; the UI supplies only the original bitmap/colors. +class PitchPointer { +public: + ~PitchPointer() { clear(); } + void clear() { + if (cursor_) { + SDL_SetCursor(SDL_GetDefaultCursor()); + SDL_FreeCursor(cursor_); + cursor_ = nullptr; + } + pixels_.reset(); + } + void show(const std::optional>& pixels, SDL_Renderer* renderer) { + if (!pixels) { SDL_SetCursor(SDL_GetDefaultCursor()); return; } + int width = 320, height = 240; + SDL_GetRendererOutputSize(renderer, &width, &height); + const int scale = std::max(1, std::min(width / 320, height / 240)); + if (!cursor_ || pixels != pixels_ || scale != scale_) { + std::vector enlarged(size_t(11 * scale) * size_t(11 * scale)); + for (int y = 0; y < 11 * scale; ++y) for (int x = 0; x < 11 * scale; ++x) + enlarged[size_t(y) * size_t(11 * scale) + size_t(x)] = + pixels->at(size_t(y / scale) * 11 + size_t(x / scale)); + SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom(enlarged.data(), + 11 * scale, 11 * scale, 32, 11 * scale * 4, SDL_PIXELFORMAT_ARGB8888); + SDL_Cursor* next = surface ? SDL_CreateColorCursor(surface, 0, 0) : nullptr; + if (surface) SDL_FreeSurface(surface); + if (!next) return; // A headless SDL driver may not support host cursors. + clear(); cursor_ = next; pixels_ = pixels; scale_ = scale; + } + SDL_SetCursor(cursor_); + } +private: + SDL_Cursor* cursor_ = nullptr; + std::optional> pixels_; + int scale_ = 1; +}; + +} // namespace bmh::app diff --git a/src/formats/executable_layout.hpp b/src/formats/executable_layout.hpp index 732827d..5218abe 100644 --- a/src/formats/executable_layout.hpp +++ b/src/formats/executable_layout.hpp @@ -1476,6 +1476,14 @@ inline constexpr auto Pitch_Render_TextPointer2 = 0xae0ec; inline constexpr auto Pitch_Render_TextPointer3 = 0xae0f0; inline constexpr auto Pitch_Render_TextPointer4 = 0xae0f4; inline constexpr auto Pitch_Render_TextPointer5 = 0xae0f8; +inline constexpr auto PitchPreferenceDepthBases = 0xa3cc3; +inline constexpr auto PitchPreferenceRed = 0xa3cc7; +inline constexpr auto PitchPreferenceGreen = 0xa3cd1; +inline constexpr auto OriginalPointerPixels = 0xa45b4; +inline constexpr auto EnglishPitchPreferenceDepthBases = 0x6e230; +inline constexpr auto EnglishPitchPreferenceRed = 0x6e234; +inline constexpr auto EnglishPitchPreferenceGreen = 0x6e240; +inline constexpr auto EnglishOriginalPointerPixels = 0x70554; inline constexpr auto PitchOrderPositionPointers = 0xa2a37; inline constexpr auto PitchOrderZoneMasks = 0xa2a4b; inline constexpr auto PitchOrderZoneTextPointers = 0xae818; diff --git a/src/launch/fltd.cpp b/src/launch/fltd.cpp index cc36a22..60f904e 100644 --- a/src/launch/fltd.cpp +++ b/src/launch/fltd.cpp @@ -124,6 +124,10 @@ LeImage translate_fltd(const fs::path& fltd_exe) { // verifies that layout before reading its year and weekday. for (uint32_t i = 0; i < 14; ++i) put(layout::CalendarDateSetup + i, en(kEnglishCalendarDateSetup + i)); + // The native 11x11 pointer is an edition-owned indexed bitmap. + for (uint32_t i = 0; i < 11 * 11; ++i) + put(::bmh::layout::OriginalPointerPixels + i, + en(::bmh::layout::EnglishOriginalPointerPixels + i)); LeImage out = LeImage::from_bytes(kDeBase, std::move(image)); return out; } diff --git a/src/launch/fltd_map.inc b/src/launch/fltd_map.inc index 74ed650..ea0fec9 100644 --- a/src/launch/fltd_map.inc +++ b/src/launch/fltd_map.inc @@ -225,6 +225,9 @@ {::bmh::layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField2, 5, Kind::copy, ::bmh::layout::EnglishLayoutTranslation156, {}}, {::bmh::layout::ClubPlayerDetail_DrawPortrait_RuntimeField7, 10, Kind::copy, ::bmh::layout::EnglishLayoutTranslation157, {}}, {::bmh::layout::Pitch_Render_RuntimeField, 3, Kind::copy, ::bmh::layout::EnglishLayoutTranslation163, {}}, + {::bmh::layout::PitchPreferenceDepthBases, 4, Kind::copy, ::bmh::layout::EnglishPitchPreferenceDepthBases, {}}, + {::bmh::layout::PitchPreferenceRed, 10, Kind::copy, ::bmh::layout::EnglishPitchPreferenceRed, {}}, + {::bmh::layout::PitchPreferenceGreen, 10, Kind::copy, ::bmh::layout::EnglishPitchPreferenceGreen, {}}, {::bmh::layout::SeasonEntrants_FormatError_ExecutableField, 8, Kind::copy, ::bmh::layout::EnglishLayoutTranslation176, {}}, {::bmh::layout::SeasonEntrants_FormatError_ExecutableField2, 8, Kind::copy, ::bmh::layout::EnglishLayoutTranslation177, {}}, {::bmh::layout::SeasonEntrants_FormatError_ExecutableField3, 6, Kind::copy, ::bmh::layout::EnglishLayoutTranslation178, {}}, diff --git a/src/launch/game_data.cpp b/src/launch/game_data.cpp index fb903e1..e1a4aca 100644 --- a/src/launch/game_data.cpp +++ b/src/launch/game_data.cpp @@ -379,7 +379,7 @@ ResolvedGame resolve_game(const fs::path& input, const fs::path& cache) { const fs::path marker = prepared / ".openbmh-english"; // the version of the translation (launch/fltd.cpp, fltd_map.inc): a cache built // by another version is built again - constexpr const char* kTranslation = "english translation 14"; // 14: preserve verified English calendar epoch operands + constexpr const char* kTranslation = "english translation 15"; // 15: original pitch affinity tables and pointer bitmap (14: calendar epoch) std::string built; { std::ifstream in(marker); diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 38d6dd3..3425f81 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -243,3 +243,7 @@ bmh_add_data_test(NAME transfer_history_tests COMMAND transfer_history_tests "${ add_executable(sportschau_ui_tests ../../tests/sportschau_ui_tests.cpp) target_link_libraries(sportschau_ui_tests PRIVATE bmhui) bmh_add_data_test(NAME sportschau_ui_tests COMMAND sportschau_ui_tests "${BMH_DATA}") + +add_executable(live_score_reveal_tests live_score_reveal_tests.cpp) +target_link_libraries(live_score_reveal_tests PRIVATE bmhui) +add_test(NAME live_score_reveal_tests COMMAND live_score_reveal_tests) diff --git a/src/ui/flow.hpp b/src/ui/flow.hpp index fe50c46..3a5bb83 100644 --- a/src/ui/flow.hpp +++ b/src/ui/flow.hpp @@ -103,6 +103,9 @@ public: FlowResult expire_stadium_tip(); bool in_stadium() const { return bool(stadium_); } bool in_pitch() const { return bool(pitch_); } + std::optional> pitch_pointer_cursor(const Palette& palette) const { + return pitch_ && screen_name() == "pitch" ? pitch_->pointer_cursor(palette) : std::nullopt; + } std::optional pitch_formation_save_feedback(bool restored) const; FlowResult pitch_held_left(int x, int y, uint64_t source_ticks); void consume_orphaned_pitch_release(){pitch_release_barrier_=false;} diff --git a/src/ui/live_matchday.hpp b/src/ui/live_matchday.hpp index cb3558b..0e75a2c 100644 --- a/src/ui/live_matchday.hpp +++ b/src/ui/live_matchday.hpp @@ -2,6 +2,7 @@ #pragma once #include +#include #include #include #include @@ -46,6 +47,29 @@ struct LiveMatchdayFrame { LiveMatchdayFrame live_matchday_frame(int minute, const std::vector& groups, const GameState& state); +// The engine commits a chance before its ball/set-piece/shot presentation. Keep +// the observed preview scores until the result hook, without delaying simulation. +class LiveScoreReveal { +public: + void observe(LiveChanceStage stage, const LiveMatchdayFrame& frame) { + if (stage == LiveChanceStage::preview) preview_ = frame; + else preview_.reset(); + } + LiveMatchdayFrame project(LiveMatchdayFrame frame) const { + if (!preview_ || preview_->minute != frame.minute) return frame; + for (auto& row : frame.matches) for (const auto& before : preview_->matches) + if (row.home_team == before.home_team && row.away_team == before.away_team) { + row.home_goals = before.home_goals; + row.away_goals = before.away_goals; + row.score_known = before.score_known; + break; + } + return frame; + } +private: + std::optional preview_; +}; + struct LiveChanceProjection { LiveChanceStage stage = LiveChanceStage::preview; int minute = 0, group = 0, match = 0, side = 0; diff --git a/src/ui/live_score_reveal_tests.cpp b/src/ui/live_score_reveal_tests.cpp new file mode 100644 index 0000000..fa08bbe --- /dev/null +++ b/src/ui/live_score_reveal_tests.cpp @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "ui/live_matchday.hpp" +#include +using namespace bmh::ui; +int main() { + LiveMatchdayFrame frame; + frame.minute=23; + LiveMatchRow home;home.home_team=10;home.away_team=11;home.score_known=true; + home.home_goals=2;home.away_goals=1;frame.matches.push_back(home); + LiveMatchRow other=home;other.home_team=20;other.away_team=21;frame.matches.push_back(other); + LiveScoreReveal reveal; + if(reveal.project(frame)!=frame)throw std::runtime_error("idle reveal changed scores"); + for (int side : {0,1}) { + reveal.observe(bmh::LiveChanceStage::preview,frame); + auto resolved=frame; + (side==0?resolved.matches[0].home_goals:resolved.matches[0].away_goals)++; + resolved.matches[0].spectators=12500; + // Animation frames can be rendered repeatedly without committing scores. + for(int animation=0;animation<18;++animation) { + const auto shown=reveal.project(resolved); + if(shown.matches[0].home_goals!=2 || shown.matches[0].away_goals!=1 || + shown.matches[0].spectators!=12500 || shown.matches[1]!=resolved.matches[1]) + throw std::runtime_error("animation leaked score or replaced unrelated fields"); + } + reveal.observe(bmh::LiveChanceStage::result,resolved); + if(reveal.project(resolved)!=resolved)throw std::runtime_error("result did not reveal goal"); + } + reveal.observe(bmh::LiveChanceStage::preview,frame); + if(reveal.project(frame)!=frame)throw std::runtime_error("miss changed score"); + auto next=frame;next.minute++; + if(reveal.project(next)!=next)throw std::runtime_error("old chance held a later minute"); + // Team identity, rather than row index, survives a reordered board. + auto reversed=frame;std::swap(reversed.matches[0],reversed.matches[1]); + reversed.matches[1].away_goals++; + if(reveal.project(reversed)!=LiveMatchdayFrame{frame.minute,frame.minute_text,frame.gradient_text, + {frame.matches[1],frame.matches[0]}})throw std::runtime_error("reordered board used wrong score"); +} diff --git a/src/ui/pitch.cpp b/src/ui/pitch.cpp index 79bc2a6..c65a5a2 100644 --- a/src/ui/pitch.cpp +++ b/src/ui/pitch.cpp @@ -3,6 +3,7 @@ #include "ui/pitch.hpp" #include +#include #include #include "formats/savestate.hpp" @@ -195,7 +196,7 @@ PitchScreen::PitchScreen(const std::filesystem::path& data,LineupState state,Pit PitchScreen::PitchScreen(const PitchScreen& other) :PitchScreen(other.data_,other.state_,other.extras_){ pending_=other.pending_;selected_=other.selected_;hovered_=other.hovered_;ghost_=other.ghost_; - order_hover_grid_=other.order_hover_grid_; + order_hover_grid_=other.order_hover_grid_;pointer_grid_=other.pointer_grid_; scroll_=other.scroll_;close_=other.close_;return_team_=other.return_team_;rejection_=other.rejection_; weights_dirty_=other.weights_dirty_; shooter_editor_open_=other.shooter_editor_open_;shooter_selection_=other.shooter_selection_; @@ -291,6 +292,35 @@ bool PitchScreen::automatic_page()const{ // their respective areas even when that bit is retained underneath. return !shooter_editor_open_&&(extras_.native_display_word&0x18)==0x18; } +std::optional> PitchScreen::position_feedback() const { + if (!pointer_grid_ || close_ || !(extras_.native_display_word & 8)) return {}; + const auto row = selected_ ? selected_ : hovered_; + if (!row || size_t(*row) >= state_.players.size()) return {}; + const auto& p = state_.players.at(size_t(*row)); + if (p.player_id < 0 || !(p.slot & 0xc000) || ((p.attributes.w364 >> 16) & 31)) return {}; + const int depth = int(exe_.u8(::bmh::layout::PitchPreferenceDepthBases + p.attributes.position())) - 2 + + int((p.attributes.w35c >> 21 & 7) >> 1); + const int lane = int((p.attributes.w35c >> 24 & 7) * 800 / 7); + const auto band = [&](int x, int y) { + return std::min(9, (std::abs(depth - x) * 100 + std::abs(lane - y * 100)) / 200); + }; + return std::pair{band(int8_t(p.board[0x41]), int8_t(p.board[0x42])), + band(pointer_grid_->first, pointer_grid_->second)}; +} +std::optional> PitchScreen::pointer_cursor(const Palette& palette) const { + const auto feedback = position_feedback(); + if (!feedback) return {}; + const auto band = uint32_t(feedback->second); + const uint32_t fill = 0xff000000u | + (uint32_t(vga_dac_rgb8(uint8_t(exe_.u8(::bmh::layout::PitchPreferenceRed + band) << 4))) << 16) | + (uint32_t(vga_dac_rgb8(uint8_t(exe_.u8(::bmh::layout::PitchPreferenceGreen + band) << 4))) << 8); + std::array pixels{}; + for (uint32_t i = 0; i < pixels.size(); ++i) { + const auto index = exe_.u8(::bmh::layout::OriginalPointerPixels + i); + pixels[i] = index == 0 ? 0 : index == 0x11 ? fill : palette.argb[index]; + } + return pixels; +} Image PitchScreen::render()const{ // PitchScreen's page redraw copies the owned offscreen sheet from y=20: all // 190 rows when source bit 0x08 is clear, only the upper 88 rows when it is @@ -472,6 +502,10 @@ Image PitchScreen::render()const{ rect(out,0x105,y+9,value,1,0);rect(out,0x103+value,y+2,1,8,0);} } } + // Native lower-right swatches compare the current position with the pointer. + const auto feedback = position_feedback(); + copy(out,atlas_,feedback ? 259 + feedback->first * 5 : 309,68,305,233,5,4,0xc0); + copy(out,atlas_,feedback ? 259 + feedback->second * 5 : 309,68,312,230,5,4,0xc0); return out; } std::optional> PitchScreen::grid(int x,int y){ @@ -570,10 +604,12 @@ PitchRequest PitchScreen::order_request(int aspect,int value){ } PitchRequest PitchScreen::click(int x,int y,bool right){ if(pending_||close_)return {}; + pointer_grid_=grid(x,y); const uint16_t display_word=shooter_editor_open_ ? uint16_t(extras_.native_display_word&0xff0f) : extras_.native_display_word; if(right){ + pointer_grid_.reset(); if((display_word&0x08)==0){sheet_->click(x,y,true);close_=sheet_->close_requested();} else if(selected_){selected_.reset();ghost_.reset();} else {close_=true;zone_cover_open_=false;} @@ -740,11 +776,13 @@ PitchRequest PitchScreen::save_formation(int x,int y){ pending_=r;return r; } bool PitchScreen::move(int x,int y){if(pending_||close_)return false; + const auto old_pointer_grid=pointer_grid_; if((extras_.native_display_word&0x08)==0)return sheet_->move(x,y); + pointer_grid_=grid(x,y); const auto old=hovered_;const auto oldghost=ghost_;hovered_=hit_row(x,y);ghost_=selected_?grid(x,y):std::nullopt; const auto old_grid=order_hover_grid_; order_hover_grid_=order_panel_open_?grid(x,y):std::nullopt; - return old!=hovered_||oldghost!=ghost_||old_grid!=order_hover_grid_; + return old!=hovered_||oldghost!=ghost_||old_grid!=order_hover_grid_||old_pointer_grid!=pointer_grid_; } PitchRequest PitchScreen::key(std::string_view key){ // PitchScreen's desktop pages cancel selection/return on mouse event 8. @@ -916,13 +954,13 @@ void PitchScreen::acknowledge(LineupState s,PitchExtras e){ } void PitchScreen::reject_action(std::string reason){if(!pending_||reason.empty())throw FormatError("pitch: rejection requires pending action and reason"); if(sheet_->pending())sheet_=std::make_unique(data_,state_); - pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();order_hover_grid_.reset();marking_target_row_.reset();rejection_=std::move(reason); + pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();pointer_grid_.reset();order_hover_grid_.reset();marking_target_row_.reset();rejection_=std::move(reason); } void PitchScreen::resolve_local_navigation(){ if(!pending_||pending_->kind!=PitchRequestKind::open_player_info) throw FormatError("pitch: only player info can resolve locally"); if(sheet_->pending())sheet_->resolve_local_navigation(LineupRequestKind::open_player_info); - pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();rejection_.clear(); + pending_.reset();selected_.reset();hovered_.reset();ghost_.reset();pointer_grid_.reset();rejection_.clear(); } std::string PitchScreen::state_json()const{std::ostringstream out; out<<"{\"screen\":\"pitch\",\"manager_slot\":"< namespace bmh::ui { @@ -81,6 +82,9 @@ public: PitchScreen(PitchScreen&&) noexcept = default; PitchScreen& operator=(PitchScreen&&) noexcept = default; Image render() const; + // Current/proposed native distance bands, available only over the pitch. + std::optional> position_feedback() const; + std::optional> pointer_cursor(const Palette&) const; // PitchScreen: outline only, before the pending save is dispatched/ACKed. static constexpr int formation_save_flash_ms = 5 * 20; // DecodeTaxAnimationScript2(5) std::optional formation_save_feedback(bool restored) const; @@ -116,6 +120,7 @@ private: std::optional pending_; std::optional selected_, hovered_; std::optional> ghost_; + std::optional> pointer_grid_; std::optional> order_hover_grid_; int scroll_ = 0; bool close_ = false, return_team_ = false; diff --git a/src/ui/pitch_tests.cpp b/src/ui/pitch_tests.cpp index 739d262..6a5898c 100644 --- a/src/ui/pitch_tests.cpp +++ b/src/ui/pitch_tests.cpp @@ -38,6 +38,35 @@ int main(int argc,char**argv){try{ PitchScreen pitch(data,s,e);const auto pixels=pitch.render().pixels; check(pixels.size()==320*240&&pitch.render().pixels==pixels,"pitch render is deterministic"); check(pitch.state().players[3].board[0x41]==3&&!pitch.pending(),"render does not mutate authoritative positions"); + auto affinity_state=s; + affinity_state.players[3].attributes.w364=1; // defender + affinity_state.players[3].attributes.w35c=(6u<<21)|(4u<<24); + PitchScreen affinity(data,affinity_state,e); + const auto affinity_initial=affinity.render(); + const auto colors=load_palette(asset_path(data,"M3PC.COL")); + check(!affinity.position_feedback()&&!affinity.pointer_cursor(colors), + "idle pitch leaves host cursor and position colors unmodified"); + affinity.click(30,164);affinity.move(40,164); + check(affinity.position_feedback()==std::pair{0,0}, + "near preferred defender depth/lane uses the best native distance band"); + const auto near_cursor=affinity.pointer_cursor(colors); + const auto near_image=affinity.render(); + affinity.move(160,208); + check(affinity.position_feedback()==std::pair{0,9}&& + affinity.pointer_cursor(colors)&&affinity.pointer_cursor(colors)!=near_cursor, + "far placement reaches the worst native band and changes cursor fill"); + const auto far_image=affinity.render(); + bool swatch_changed=false; + for(int y=230;y<234;++y)for(int x=312;x<317;++x) + swatch_changed|=near_image.pixels[size_t(y)*320+size_t(x)]!=far_image.pixels[size_t(y)*320+size_t(x)]; + check(swatch_changed&&affinity.state().players[3].board==s.players[3].board&&!affinity.pending(), + "original proposed-position swatch changes without moving a player or dispatching"); + affinity.move(300,220); + check(!affinity.position_feedback()&&!affinity.pointer_cursor(colors), + "leaving pitch restores ordinary cursor and clears affinity colors"); + affinity.click(0,0,true); + check(affinity.render().pixels==affinity_initial.pixels&&!affinity.pointer_cursor(colors), + "cancelled placement restores original footer and cursor"); const auto idle_pitch=pitch.state_json(); check(pitch.key("ESC").kind==PitchRequestKind::none&& pitch.key("ESCAPE").kind==PitchRequestKind::none&& diff --git a/tests/app_controller_tests.cpp b/tests/app_controller_tests.cpp index 166c33c..a650e85 100644 --- a/tests/app_controller_tests.cpp +++ b/tests/app_controller_tests.cpp @@ -4955,6 +4955,7 @@ void check_live_observer_determinism(const std::filesystem::path& data) { int events = 0; bool home_seen = false, away_seen = false; std::optional preview; uint8_t preview_score = 0; + ui::LiveScoreReveal score_reveal; int previews = 0, outcomes = 0; const auto source_exe = load_le(asset_path(data, "BMH.exe")); int shot_count = 0; @@ -4977,7 +4978,11 @@ void check_live_observer_determinism(const std::filesystem::path& data) { if (step.sprites[i].figure != 24) check(step.sprites[i-1].y <= step.sprites[i].y,"Source figures retain stable depth order"); } - const auto frame = ui::live_matchday_frame(event.minute,groups,state); + const auto frame = score_reveal.project(ui::live_matchday_frame(event.minute,groups,state)); + if (preview && !frame.matches.empty()) + check(frame.matches[0].home_goals == (preview_score >> 4) && + frame.matches[0].away_goals == (preview_score & 15), + "ball/set-piece/shot scoreboard retains preview until the visible result"); const auto images = boundary_screen.render_set_piece(frame,event); check(images.size() == scene.size(),"each Source marker produces exactly one complete displayed frame"); const auto backdrop = boundary_screen.render(frame); @@ -5000,7 +5005,11 @@ void check_live_observer_determinism(const std::filesystem::path& data) { const auto before = save_stream(state); const auto g_seed = game.seed(); const auto w_seed = rng.seed(); const auto g_calls = game.calls(); const auto w_calls = rng.calls(); - const auto frame = ui::live_matchday_frame(event.minute, groups, state); + const auto frame = score_reveal.project(ui::live_matchday_frame(event.minute, groups, state)); + if (preview && !frame.matches.empty()) + check(frame.matches[0].home_goals == (preview_score >> 4) && + frame.matches[0].away_goals == (preview_score & 15), + "ball/set-piece/shot scoreboard retains preview until the visible result"); const auto rendered = boundary_screen.render_shot(frame, event); const auto repeat = boundary_screen.render_shot(frame, event); const auto palette = load_palette(asset_path(data, "M3PC.COL")); @@ -5030,6 +5039,8 @@ void check_live_observer_determinism(const std::filesystem::path& data) { const auto g_calls = game.calls(); const auto w_calls = rng.calls(); const auto projection = ui::live_chance_projection(event, groups, state, source_exe); const auto frame = ui::live_matchday_frame(event.minute, groups, state); + score_reveal.observe(event.stage,frame); + check(score_reveal.project(frame)==frame,"preview and visible result publish their own score"); (void)boundary_screen.render_chance(frame, projection); (void)boundary_screen.render_chance(frame, projection); check(save_stream(state) == before && game.seed() == g_seed && rng.seed() == w_seed && @@ -5055,7 +5066,11 @@ void check_live_observer_determinism(const std::filesystem::path& data) { check((distance >= 40 && distance <= 50) || distance == 52, "live ball uses the already drawn Watcom distance or the Source goal endpoint"); home_seen |= event.displacement > 0; away_seen |= event.displacement < 0; - const auto frame = ui::live_matchday_frame(event.minute, groups, state); + const auto frame = score_reveal.project(ui::live_matchday_frame(event.minute, groups, state)); + if (preview && !frame.matches.empty()) + check(frame.matches[0].home_goals == (preview_score >> 4) && + frame.matches[0].away_goals == (preview_score & 15), + "ball/set-piece/shot scoreboard retains preview until the visible result"); for (int i = 0; i < ui::LiveMatchdayScreen::ball_frame_count(event.displacement); ++i) (void)boundary_screen.render_ball(frame, event.displacement, i); ++events;