Synchronize match reveals and restore pitch input feedback (by Codex)

Hold scoreboard digits through chance animations, retain overview gesture ownership through moved releases, and restore original affinity swatches and colored pointer from each edition. Preserve simulation and RNG boundaries; cover source observer and UI projections.

Refs: #43, #44, #45
This commit is contained in:
Codex committed 2026-11-01 18:03:53 +01:00
1 parent 86e2bfd32a
commit 540178b264
16 files changed
+269 -17

No files matched your search

+25 -9
View File
@@ -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<uint32_t> 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<Uint64> timed_notice_presented_at;
std::optional<Uint8> 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<ui::LiveChanceProjection> live_chance_context;
std::unique_ptr<ui::RealityFieldScreen> reality_field;
ui::RealityReporterLayoutState reality_layout;
@@ -2911,7 +2924,7 @@ int main(int argc, char** argv) {
}, [&](const LiveBallEvent& event, const std::vector<MatchGroup>& 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<MatchGroup>& 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<MatchGroup>& 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);
+50
View File
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <SDL.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <optional>
#include <vector>
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<std::array<uint32_t,121>>& 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<uint32_t> 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<std::array<uint32_t,121>> pixels_;
int scale_ = 1;
};
} // namespace bmh::app
+8
View File
@@ -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;
+4
View File
@@ -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;
}
+3
View File
@@ -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, {}},
+1 -1
View File
@@ -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);
+4
View File
@@ -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)
+3
View File
@@ -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<std::array<uint32_t,121>> pitch_pointer_cursor(const Palette& palette) const {
return pitch_ && screen_name() == "pitch" ? pitch_->pointer_cursor(palette) : std::nullopt;
}
std::optional<Image> 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;}
+24
View File
@@ -2,6 +2,7 @@
#pragma once
#include <filesystem>
#include <optional>
#include <array>
#include <string>
#include <string_view>
@@ -46,6 +47,29 @@ struct LiveMatchdayFrame {
LiveMatchdayFrame live_matchday_frame(int minute, const std::vector<MatchGroup>& 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<LiveMatchdayFrame> preview_;
};
struct LiveChanceProjection {
LiveChanceStage stage = LiveChanceStage::preview;
int minute = 0, group = 0, match = 0, side = 0;
+37
View File
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "ui/live_matchday.hpp"
#include <stdexcept>
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");
}
+42 -4
View File
@@ -3,6 +3,7 @@
#include "ui/pitch.hpp"
#include <algorithm>
#include <cstdlib>
#include <sstream>
#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<std::pair<int,int>> 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<std::array<uint32_t, 121>> 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<uint32_t, 121> 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<std::pair<int,int>> 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<LineupScreen>(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\":"<<state_.manager_slot<<",\"runtime_club\":"<<state_.runtime_club
+5
View File
@@ -3,6 +3,7 @@
#include "ui/lineup.hpp"
#include "ui/sprite_font.hpp"
#include "formats/palette.hpp"
#include <memory>
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<std::pair<int,int>> position_feedback() const;
std::optional<std::array<uint32_t, 121>> 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<Image> formation_save_feedback(bool restored) const;
@@ -116,6 +120,7 @@ private:
std::optional<PitchRequest> pending_;
std::optional<int> selected_, hovered_;
std::optional<std::pair<int,int>> ghost_;
std::optional<std::pair<int,int>> pointer_grid_;
std::optional<std::pair<int,int>> order_hover_grid_;
int scroll_ = 0;
bool close_ = false, return_team_ = false;
+29
View File
@@ -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&&