Fix automation preview, desktop drag highlight and macOS keyboard startup (by Codex)
This commit is contained in:
1 parent
998b037d3d
commit
184a421512
11 files changed
+231
-5
No files matched your search
+4
-3
@@ -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<app::VideoSession> 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<app::CareerSession> 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <SDL.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -107,6 +107,7 @@ struct DeskState {
|
||||
bool mailbox_notification_pending = false; // MailboxRecipientMask active-manager bit; transient, non-FBM
|
||||
std::optional<DeskItem> menu_layout_shortcut; // final bar cell returns native record 53/kind 72, then dispatches MEN
|
||||
std::array<uint8_t, 5> automation{};
|
||||
std::optional<std::array<uint8_t, 22>> automation_formation;
|
||||
std::array<std::optional<bool>, 10> warnings{};
|
||||
std::vector<DeskItem> items; // Original linked-list drawing / hit-test order.
|
||||
std::string source;
|
||||
|
||||
+23
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user