Files
Dreierpack-Manager/src/ui/setup.hpp
T
ClaudeandClaude Sonnet 5.5 e65bd27375 Minus and plus of the start menu show the original pressed picture
The buttons of the game setup (and of the joining manager's setup) use the darker
picture from the bottom of the setup atlas while the mouse button is held, as in a
recording of the real game; the release redraws even when the value is at its limit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 20:09:07 +01:00

70 lines
2.7 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// Start-up setup screen: season duration, difficulty, number of managers, game mode and league/world options,
// with buttons to start a new game or load one. State: SetupOptions in the original representation (duration 5 =
// unlimited, difficulty 0..9 shown as 1..10). It mutates only its own options; a click can return a
// SetupRequest (new or load) for the caller to act on. Implemented in setup.cpp.
#pragma once
#include <array>
#include <filesystem>
#include <string>
#include "formats/le.hpp"
#include "formats/vga.hpp"
namespace bmh::ui {
// Values are the original setup representation: duration 5 = unlimited;
// difficulty 0..9 is displayed as 1..10 balls. No engine state is mutated here.
// Engine handoff, LE/save mapping and required side effects: ENGINE_BINDING.md.
struct SetupOptions {
int duration = 5;
int difficulty = 2;
int managers = 1;
int mode = 3;
bool league = true;
bool world = true;
bool operator==(const SetupOptions&) const = default;
};
enum class SetupRequest { none, new_game, load_game };
struct SetupResult {
bool changed = false;
SetupRequest request = SetupRequest::none;
};
// SetupScreen2 / SetupScreen, with layout tables read from the user's BMH.exe.
// Render and hit testing share the same tables. Coordinates are native 320x240.
class SetupScreen {
public:
explicit SetupScreen(const std::filesystem::path& data);
// Original joining-manager setup: continue from the active setup values.
SetupScreen(const std::filesystem::path& data, SetupOptions current);
const SetupOptions& options() const { return options_; }
SetupResult click(int x, int y, bool right_button = false);
// Mouse DOWN on a minus or plus button: drawn pressed until the release (click()). True when the picture changed.
bool press(int x, int y);
Image render() const;
private:
int button_at(int x, int y) const;
SetupResult handle_click(int x, int y, bool right);
int pressed_button_ = -1; // minus/plus button held down by the mouse
SetupOptions options_;
Image background_, atlas_;
std::array<int, 8> button_x_{}, button_y_{};
std::array<int, 8> joining_arrow_permission_{};
std::array<int, 4> minimum_{}, maximum_{};
std::array<int, 3> toggle_x_{}, toggle_source_x_{};
std::array<int, 6> toggle_source_y_{};
std::array<int, 4> display_width_{}, display_height_{};
int button_source_y_ = 0;
bool joining_ = false, difficulty_arrows_locked_ = false;
};
// Match DOS filename case on Linux without modifying or renaming original files.
std::filesystem::path asset_path(const std::filesystem::path& directory, const std::string& name);
std::string setup_json(const SetupOptions& options);
} // namespace bmh::ui