From 184a421512691f0b4d0d251025800d7d48b594f4 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 30 Oct 2026 23:13:44 +0100 Subject: [PATCH] Fix automation preview, desktop drag highlight and macOS keyboard startup (by Codex) --- CMakeLists.txt | 19 +++++++- docs/release/1.0/RELEASE_NOTES.md | 10 +++++ docs/release/1.0/VALIDATION.md | 6 +++ src/app/main.cpp | 7 +-- src/app/video_session.hpp | 22 ++++++++++ src/ui/desk_state.cpp | 14 ++++++ src/ui/desk_state.hpp | 1 + src/ui/desktop.cpp | 24 +++++++++- tests/desktop_feedback_tests.cpp | 73 +++++++++++++++++++++++++++++++ tests/mac_video_picker_tests.mm | 43 ++++++++++++++++++ tests/video_session_tests.cpp | 17 +++++++ 11 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 src/app/video_session.hpp create mode 100644 tests/desktop_feedback_tests.cpp create mode 100644 tests/mac_video_picker_tests.mm create mode 100644 tests/video_session_tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ccb2e8..72b5f44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-3.0-only cmake_minimum_required(VERSION 3.24) -project(OpenBMH VERSION 1.0.0 LANGUAGES CXX C) +project(OpenBMH VERSION 1.0.1 LANGUAGES CXX C) set(OPENBMH_PRERELEASE "" CACHE STRING "Prerelease identifier; empty for final release") set(OPENBMH_PRODUCT_VERSION "${PROJECT_VERSION}") if(OPENBMH_PRERELEASE) @@ -1132,3 +1132,20 @@ add_test(NAME lineup_foreign_limit_tests COMMAND lineup_foreign_limit_tests) add_executable(calendar_epoch_tests tests/calendar_epoch_tests.cpp) target_link_libraries(calendar_epoch_tests PRIVATE bmhui) add_test(NAME calendar_epoch_tests COMMAND calendar_epoch_tests) + +add_executable(video_session_tests tests/video_session_tests.cpp) +target_include_directories(video_session_tests PRIVATE src) +target_link_libraries(video_session_tests PRIVATE ${BMH_SDL_TARGET}) +add_test(NAME video_session_tests COMMAND video_session_tests) +if(APPLE) + enable_language(OBJCXX) + add_executable(mac_video_picker_tests tests/mac_video_picker_tests.mm) + set_target_properties(mac_video_picker_tests PROPERTIES OBJCXX_STANDARD 20 OBJCXX_STANDARD_REQUIRED YES) + target_include_directories(mac_video_picker_tests PRIVATE src) + target_link_libraries(mac_video_picker_tests PRIVATE ${BMH_SDL_TARGET} nfd::nfd "-framework Cocoa") + add_test(NAME mac_video_picker_tests COMMAND mac_video_picker_tests) +endif() + +add_executable(desktop_feedback_tests tests/desktop_feedback_tests.cpp) +target_link_libraries(desktop_feedback_tests PRIVATE bmhui) +bmh_add_data_test(NAME desktop_feedback_tests COMMAND desktop_feedback_tests "${BMH_DATA}") diff --git a/docs/release/1.0/RELEASE_NOTES.md b/docs/release/1.0/RELEASE_NOTES.md index f0c7281..52dab8f 100644 --- a/docs/release/1.0/RELEASE_NOTES.md +++ b/docs/release/1.0/RELEASE_NOTES.md @@ -1,3 +1,13 @@ +# OpenBMH 1.0.1 + +The automatic-lineup monitor now draws the selected formation from the actual manager formation table. Outdoor, indoor and custom formation slots retain their original coordinates and palette. Dragging a desktop element shows the original yellow outline, which disappears when the drag ends. + +SDL video initialization now precedes the initial native file picker. On macOS this lets SDL establish the Cocoa application and keyboard activation policy before the picker creates or modifies NSApp. It addresses keyboard input missing throughout the game, including entering the manager name. A native macOS regression checks the activation policy after the picker initialization/shutdown lifecycle. + +Native interactive Mac keyboard acceptance remains human QA; automated checks do not represent physical typing on a user's Mac. + +--- + # OpenBMH 1.0.0 Classic direct-installation runtime restored from v0.1.2. The game executable is OpenBMH / OpenBMH.exe; openbmh_cli remains available. diff --git a/docs/release/1.0/VALIDATION.md b/docs/release/1.0/VALIDATION.md index feecf77..d07ec93 100644 --- a/docs/release/1.0/VALIDATION.md +++ b/docs/release/1.0/VALIDATION.md @@ -33,3 +33,9 @@ After the final lineup, qualification and once-per-player season-reset correctio The duplicate-player defect was reproduced and captured before correction: a temporary offer referenced a player already owned by a club, then the extended market-retirement pass regenerated that player a second time. Frozen private before/after saves and a cached-reference regression support the correction. Save-envelope diagnostics use a separate RNG and do not consume either gameplay stream. Calendar epoch regression covers the original CD and Diamond parameters, engine weekdays, desktop dates, save-header dates, year rollover and atomic rejection of invalid/unknown setup instructions. The original and checked Diamond date routines differ only in their weekday/year operands. After installing the original CD calendar parameters, the 600-turn run with contract and advertising policies completed eleven season-end desks without invariant failures. + +## 1.0.1 desktop and macOS regressions + +The desktop feedback test checks selected saved formations against their original table, compares changed miniature pixels, and checks the original yellow outline during a drag and its removal afterward. Private CD and Diamond render captures use the original assets. The SDL lifetime test checks initialization before the picker scope, normal destruction and failed initialization cleanup. + +A macOS-only native Cocoa test initializes SDL before the native picker lifecycle, checks regular activation, creates a keyboard-focused window and verifies that a Cocoa key event produces both SDL key and text events. This automated native event test supplements human keyboard QA; it is not a claim of physical typing on the user's machine. diff --git a/src/app/main.cpp b/src/app/main.cpp index c2f7a14..e76d7c4 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -31,6 +31,7 @@ #include "launch/file_dialog.hpp" #include "launch/game_data.hpp" #include "version.hpp" +#include "app/video_session.hpp" #include "app/live_matchday_events.hpp" #include "audio/playback.hpp" #include "app/audio.hpp" @@ -151,6 +152,9 @@ int main(int argc, char** argv) { data = launch::path_from_utf8(args[i]); } } + std::optional video; + try { video.emplace(); } + catch (const std::exception& error) { show_start_error(error.what()); return 1; } // the game: as given (directory, EXE or archive); else the directory OpenBMH itself lies in, // when it holds a playable game (the simplest install: openbmh next to BMH.EXE); else // chosen in the file dialog @@ -194,7 +198,6 @@ int main(int argc, char** argv) { ui::StartupFlow flow(data, save_directory); std::unique_ptr session; uint64_t revision = 0; - if (SDL_Init(SDL_INIT_VIDEO) != 0) throw FormatError(SDL_GetError()); openbmh::audio::Playback playback; std::string audio_error; playback.initialize(audio_error); // Audio is optional; the game continues without a device. @@ -3903,11 +3906,9 @@ int main(int argc, char** argv) { SDL_DestroyWindow(window); mouse_sound.detach(); // Remove event producers before closing the audio device. playback.shutdown(); - SDL_Quit(); return 0; } catch (const std::exception& e) { std::fprintf(stderr, "error: %s\n", e.what()); - SDL_Quit(); return 1; } } diff --git a/src/app/video_session.hpp b/src/app/video_session.hpp new file mode 100644 index 0000000..fa00666 --- /dev/null +++ b/src/app/video_session.hpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include +#include +#include +namespace bmh::app { +// Establish SDL's native application before any file picker can create NSApp. +// Cocoa otherwise retains the picker's non-keyboard activation policy. +class VideoSession { +public: + VideoSession() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + const std::string error = SDL_GetError(); + SDL_Quit(); + throw std::runtime_error(error); + } + } + ~VideoSession() { SDL_Quit(); } + VideoSession(const VideoSession&) = delete; + VideoSession& operator=(const VideoSession&) = delete; +}; +} diff --git a/src/ui/desk_state.cpp b/src/ui/desk_state.cpp index cdd5f54..1bb0bd5 100644 --- a/src/ui/desk_state.cpp +++ b/src/ui/desk_state.cpp @@ -488,6 +488,18 @@ DeskDate desk_date(uint32_t counter, const LeImage& exe) { return d; } +namespace { +void project_automation_formation(DeskState& desk, const Bytes& formations, bool indoor) { + const int selected = desk.automation[0]; + if (selected == 0) return; + if (selected > 8) throw FormatError("desktop: invalid automatic formation"); + const size_t offset = size_t(desk.manager_slot) * 0x160 + size_t(indoor) * 0xb0 + size_t(selected - 1) * 22; + if (offset + 22 > formations.size()) throw FormatError("desktop: missing automatic formation"); + desk.automation_formation.emplace(); + std::copy_n(formations.begin() + offset, 22, desk.automation_formation->begin()); +} +} + DeskState desk_from_save(const SaveState& s, const LeImage& exe, uint64_t revision) { StaticMemory memory(s); auto manager = block_copy(s, ::bmh::layout::ManagerRecords), tactics = block_copy(s, ::bmh::layout::TacticsBoards), options = block_copy(s, ::bmh::layout::ManagerAutomation); @@ -510,6 +522,7 @@ DeskState desk_from_save(const SaveState& s, const LeImage& exe, uint64_t revisi project_table_position(d, table_source); project_drawer_rows(d, exe, manager, s.pool(0), offsets, position_history, results_by_opponent, rounds, std::nullopt); + project_automation_formation(d, block_copy(s, layout::Formations), false); d.source = "original_save_read_only"; return d; } @@ -520,6 +533,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi auto d = project(g.memory, {g.manager_records, g.tactics, g.manager_options, g.stocks, g.club_heap_78, g.club_names, g.club_ids, g.squad_slots, g.players, g.team_morale, g.manager_teams, g.league_rounds}, exe, g.level, g.date, g.season_day(), g.season, revision); + project_automation_formation(d, g.formations, g.indoor); // DeskDate only auto-opens for an ordinary club manager; the national // runtime (0x165) suppresses this consumer while manual mailbox access remains valid. if (d.runtime_club != kNoTeam && d.manager_slot >= 0 && d.manager_slot < 32 && g.memory.has(::bmh::layout::MailboxRecipientMask)) diff --git a/src/ui/desk_state.hpp b/src/ui/desk_state.hpp index 7bd70ec..c818637 100644 --- a/src/ui/desk_state.hpp +++ b/src/ui/desk_state.hpp @@ -107,6 +107,7 @@ struct DeskState { bool mailbox_notification_pending = false; // MailboxRecipientMask active-manager bit; transient, non-FBM std::optional menu_layout_shortcut; // final bar cell returns native record 53/kind 72, then dispatches MEN std::array automation{}; + std::optional> automation_formation; std::array, 10> warnings{}; std::vector items; // Original linked-list drawing / hit-test order. std::string source; diff --git a/src/ui/desktop.cpp b/src/ui/desktop.cpp index f3eb608..c7dd7ee 100644 --- a/src/ui/desktop.cpp +++ b/src/ui/desktop.cpp @@ -218,7 +218,14 @@ void DesktopScreen::draw_item(Image& out, const DeskItem& item) const { copy(out, icons_, 97, 111, x + 3 + i * 33, y + 2, 32, 30); const auto value = state_.automation[i]; if ((i == 4 ? value & 1 : value) != 0) copy(out, icons_, 129 + i * 16, 111, x + i * 33 + 10, y + 4, 17, 11); - // Individual automatic-formation dots need a separately verified renderer. + if (i == 0 && value != 0 && state_.automation_formation) { + const auto& formation = *state_.automation_formation; + // The original miniature excludes the keeper and unused positions. + for (int row = 1; row < 11; ++row) + if (formation[size_t(row)] != 0) + rect(out, x + 10 + formation[size_t(row)] * 15 / 18, + y + 5 + formation[size_t(row + 11)], 1, 1, 0x27); + } } break; case 15: @@ -275,6 +282,20 @@ Image DesktopScreen::render() const { if (shortcut_hover_record_ >= 0) text(out, 0, 235, texts_[text_id(::bmh::layout::Desktop_Render_TextPointer + uint32_t(shortcut_hover_record_) * 4)], 0x5f, 319); } + if (layout_drag_ && layout_preview_) { + const auto selected = std::find_if(visible.items.begin(), visible.items.end(), + [&](const DeskItem& item) { return item.id == layout_drag_->item; }); + if (selected != visible.items.end()) { + draw_item(out, *selected); + const auto& item = *selected; + const int w = item.width - (item.kind >= 50 && !item.open ? 8 : 0); + const int h = item.height - (item.kind >= 50 && !item.open ? 8 : 0); + rect(out, item.x, item.y, w, 1, 0x27); + rect(out, item.x, item.y + h - 1, w, 1, 0x27); + rect(out, item.x, item.y, 1, h, 0x27); + rect(out, item.x + w - 1, item.y, 1, h, 0x27); + } + } return out; } @@ -722,6 +743,7 @@ std::string DesktopScreen::state_json() const { ",\"shortcut_hover_record\":" + std::to_string(shortcut_hover_record_) + ",\"socket_confirmation_armed\":" + std::string(socket_confirmation_armed_ ? "true" : "false") + ",\"bin_mode\":" + std::string(bin_mode_ ? "true" : "false") + + ",\"dragging_item\":" + (layout_drag_ ? std::to_string(layout_drag_->item) : "null") + ",\"pending_action\":" + (pending_ ? desk_request_json(*pending_) : "null") + ",\"last_rejection\":" + (last_rejection_.empty() ? "null" : json_quote(last_rejection_)) + "}"; return out; diff --git a/tests/desktop_feedback_tests.cpp b/tests/desktop_feedback_tests.cpp new file mode 100644 index 0000000..2efbff4 --- /dev/null +++ b/tests/desktop_feedback_tests.cpp @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "ui/desktop.hpp" +#include "formats/palette.hpp" +#include "formats/le.hpp" +#include "formats/fbm.hpp" +#include "formats/savestate.hpp" +#include "formats/executable_layout.hpp" +#include +#include +#include +#include +using namespace bmh; +using namespace bmh::ui; +void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);} +void capture(const std::filesystem::path& dir,const char* name,const Image& image,const Palette& palette){ + if(dir.empty())return; + std::filesystem::create_directories(dir); + std::ofstream out(dir/name,std::ios::binary);out<<"P6\n"<>shift));} +} +int main(int argc,char**argv)try{ + if(argc<2||!*argv[1])return 77; + const std::filesystem::path data=argv[1],output=argc>2?argv[2]:""; + const auto palette=load_palette(data/"M3PC.COL"); + if (argc > 3) { + const auto file = load_savegame(argv[3]); + check(file.checksum_ok,"reference save checksum invalid"); + const auto exe = load_le(data/"BMH.exe"); + const SaveState original(file.stream); + const auto option_offset = original.block(layout::ManagerAutomation).offset; + for (int selected=0; selected<=4; ++selected) { + auto stream = file.stream; + stream.at(option_offset)=uint8_t(selected); + const SaveState saved(stream); + auto projected = desk_from_save(saved,exe,1); + check(projected.automation_formation.has_value()==(selected!=0),"formation visibility did not follow saved automation option"); + if(selected)for(size_t i=0;i<22;++i) + check(projected.automation_formation->at(i)==saved.data(layout::Formations)[size_t(selected-1)*22+i], + "miniature did not use the selected saved formation"); + projected.items={{1,20,20,173,40,64,0,0,true,false}}; + const auto rendered = DesktopScreen(data,projected).render(); + const std::string name="saved-formation-"+std::to_string(selected)+".ppm"; + capture(output,name.c_str(),rendered,palette); + } + } + DeskState state;state.options.managers=1;state.options.duration=5;state.options.mode=3;state.options.difficulty=2; + state.options.league=true;state.options.world=true; + state.manager_slot=0;state.runtime_club=0;state.manager_teams={0};state.manager_name="QA";state.club_name="QA"; + DeskManagerIdentity manager;manager.runtime_club=0;manager.club_identity_key=0;manager.name="QA";manager.league=0;manager.portrait=0;manager.badge=0; + state.managers={manager};state.league=0;state.portrait=0;state.badge=0; + state.items={{1,20,20,173,40,64,0,0,true,false}}; + state.automation[0]=1;state.automation_formation.emplace();state.automation_formation->fill(0); + (*state.automation_formation)[1]=18;(*state.automation_formation)[12]=3; + const auto first=DesktopScreen(data,state).render(); + check(first.pixels[size_t(32)*320+49]==0x27,"formation player not rendered at the original miniature coordinate"); + state.automation[0]=2;(*state.automation_formation)[1]=6;(*state.automation_formation)[12]=2; + const auto second=DesktopScreen(data,state).render(); + check(first.pixels!=second.pixels,"changing selected formation left the monitor unchanged"); + capture(output,"formation-1.ppm",first,palette);capture(output,"formation-2.ppm",second,palette); + state.items={{1,20,20,32,25,0,0,0,false,false}};state.drawer_handles=true; + DesktopScreen drag(data,state);const auto normal=drag.render(); + const auto idle=drag.state_json(); + drag.pointer_down(25,25,true); + check(drag.state_json()!=idle,"drag press did not invalidate the rendered desktop"); + drag.pointer_move(65,65); + const auto moving=drag.render(); + check(moving.pixels[size_t(60)*320+60]==0x27 && moving.pixels[size_t(84)*320+91]==0x27,"moving icon lacks inclusive yellow outline"); + const auto request=drag.pointer_up(65,65,true); + check(request.kind==DeskRequestKind::change_layout,"drag did not retain its layout transaction"); + check(drag.render().pixels==normal.pixels,"yellow preview survived release without acknowledgement"); + capture(output,"drag-normal.ppm",normal,palette);capture(output,"drag-active.ppm",moving,palette); + std::cout<<"Automation formation changes and transient yellow drag border passed\n";return 0; +}catch(const std::exception&e){std::cerr< +#include "app/video_session.hpp" +#include +#include +#include +#include +int main() { @autoreleasepool { + SDL_setenv("SDL_VIDEODRIVER", "cocoa", 1); + try { + bmh::app::VideoSession video; + if ([NSApp activationPolicy] != NSApplicationActivationPolicyRegular) return 1; + if (NFD_Init() != NFD_OKAY) return 2; + NFD_Quit(); + if ([NSApp activationPolicy] != NSApplicationActivationPolicyRegular) return 3; + SDL_Window* window=SDL_CreateWindow("Keyboard startup QA",0,0,320,240,0); + if(!window)return 4; + SDL_SysWMinfo info{}; SDL_VERSION(&info.version); + if(!SDL_GetWindowWMInfo(window,&info))return 5; + [NSApp activateIgnoringOtherApps:YES]; + [info.info.cocoa.window makeKeyAndOrderFront:nil]; + for(int i=0;i<100 && SDL_GetKeyboardFocus()!=window;++i){SDL_PumpEvents();SDL_Delay(10);} + if(SDL_GetKeyboardFocus()!=window){std::cerr<<"Cocoa window did not acquire keyboard focus\n";return 6;} + SDL_StartTextInput(); + SDL_Event input;while(SDL_PollEvent(&input)){} + NSEvent* key=[NSEvent keyEventWithType:NSEventTypeKeyDown location:NSZeroPoint + modifierFlags:0 timestamp:[[NSProcessInfo processInfo] systemUptime] windowNumber:[info.info.cocoa.window windowNumber] + context:nil characters:@"q" charactersIgnoringModifiers:@"q" isARepeat:NO keyCode:12]; + [NSApp postEvent:key atStart:NO]; + bool key_received=false,text_received=false; + for(int i=0;i<100 && !(key_received&&text_received);++i){ + while(SDL_PollEvent(&input)){ + key_received|=input.type==SDL_KEYDOWN; + text_received|=input.type==SDL_TEXTINPUT && std::strcmp(input.text.text,"q")==0; + } + SDL_Delay(10); + } + SDL_DestroyWindow(window); + if(!key_received||!text_received){std::cerr<<"Native key="< +int main()try { + SDL_setenv("SDL_VIDEODRIVER","dummy",1); + { bmh::app::VideoSession video; + if (!(SDL_WasInit(SDL_INIT_VIDEO) & SDL_INIT_VIDEO)) return 1; + // The initial chooser executes inside this scope, not before it. + } + if (SDL_WasInit(SDL_INIT_VIDEO)) return 1; + SDL_setenv("SDL_VIDEODRIVER","unavailable-openbmh-test-driver",1); + bool rejected=false; + try { bmh::app::VideoSession failed; } catch(const std::exception&) { rejected=true; } + if(!rejected || SDL_WasInit(SDL_INIT_VIDEO))return 1; + std::cout<<"Video lifetime initializes before picker and releases on early return\n"; + return 0; +}catch(const std::exception& e){std::cerr<