Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
StatsUI.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Display.hpp"
4#include "IBarLayout.hpp"
5#include "IBarRuleState.hpp"
6#include "RuleTypes.hpp"
7#include "UIMessages.hpp"
8
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <optional>
13
14namespace monopoly::statsui
15{
16 enum class Screen : std::uint8_t
17 {
18 Player = 0,
19 Deed = 1,
20 Bank = 2
21 };
22
23 enum class BankDeedState : std::uint8_t
24 {
25 Hidden = 0,
27 Sold,
29 };
30
31 struct Rect
32 {
33 int left{};
34 int top{};
35 int right{};
36 int bottom{};
37
38 [[nodiscard]] constexpr bool contains(int x, int y) const noexcept
39 {
40 return x >= left && x < right && y >= top && y < bottom;
41 }
42
43 friend bool operator==(const Rect&, const Rect&) = default;
44 };
45
46 struct State
47 {
49 std::array<std::uint8_t, 3> lastSort{};
50 std::uint8_t activeSort{};
51 std::array<rules::PlayerNumber, rules::MaxPlayers> playerOrder{};
52 std::array<std::int64_t, rules::MaxPlayers> playerMetric{};
53 std::size_t playerCount{};
54 std::array<std::uint8_t, rules::SquareCount> deedOrder{};
55 std::array<std::int64_t, rules::SquareCount> deedMetric{};
56 std::array<int, rules::MaxPlayers> bankPlayerHouses{};
57 std::array<int, rules::MaxPlayers> bankPlayerHotels{};
60 std::array<BankDeedState, rules::SquareCount> bankDeeds{};
70 int mouseX{};
71 int mouseY{};
72 bool mouseKnown{};
76 };
77
78 [[nodiscard]] constexpr Rect categoryRect(std::uint8_t index) noexcept
79 {
80 const int left = 54 + 93 * static_cast<int>(index);
81 return {left, 510, left + 77 - 3 * static_cast<int>(index), 550};
82 }
83
84 [[nodiscard]] constexpr Rect sortRect(std::uint8_t index) noexcept
85 {
86 const int left = 495 + 70 * static_cast<int>(index);
87 return {left, 510, left + 56 + 2 * static_cast<int>(index), 550};
88 }
89
90 void reset(State& state) noexcept;
91 void refresh(State& state, const rules::GameState& gameState) noexcept;
92 void syncView(
93 State& state, const rules::GameState& gameState,
94 display::Screen2D view) noexcept;
96 State& state, Screen screen, const rules::GameState& gameState) noexcept;
97 [[nodiscard]] bool selectSort(
98 State& state, std::uint8_t sortIndex,
99 const rules::GameState& gameState) noexcept;
100 [[nodiscard]] std::optional<Screen> categoryHit(int x, int y) noexcept;
101 [[nodiscard]] std::optional<std::uint8_t> sortHit(int x, int y) noexcept;
103 rules::PlayerNumber player, bool localHuman,
107 bool modernPlayerLayout = false) noexcept;
109 const rules::GameState& gameState, rules::PlayerNumber player) noexcept;
110 // Shared owned-deed positions for Player rendering and BSSM picking.
112 const State& state, const rules::GameState& gameState,
113 std::size_t column, int square) noexcept;
115 const State& state, const rules::GameState& gameState,
116 int x, int y) noexcept;
117 [[nodiscard]] bool processInput(
118 State& state, const rules::GameState& gameState,
119 display::Screen2D view, const uimsg::Message& message) noexcept;
120 // Returns one font line to scroll, matching the two account-history arrows.
121 [[nodiscard]] int historyScrollInput(State& state, display::Screen2D view,
122 const uimsg::Message& message) noexcept;
123}
std::atomic< float > left
ibar::layout::PropertyMask mortgageProperties
Definition Engine.cpp:279
ibar::layout::PropertyMask sellProperties
Definition Engine.cpp:278
ibar::layout::PropertyMask buildProperties
Definition Engine.cpp:277
unsigned state
unsigned index
std::uint32_t PropertyMask
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
std::optional< std::uint8_t > sortHit(int x, int y) noexcept
Definition StatsUI.cpp:335
constexpr Rect sortRect(std::uint8_t index) noexcept
Definition StatsUI.hpp:84
void refresh(State &state, const rules::GameState &gameState) noexcept
Definition StatsUI.cpp:282
std::optional< int > propertyActionHit(const State &state, const rules::GameState &gameState, int x, int y) noexcept
Definition StatsUI.cpp:427
bool selectSort(State &state, std::uint8_t sortIndex, const rules::GameState &gameState) noexcept
Definition StatsUI.cpp:316
std::optional< Screen > categoryHit(int x, int y) noexcept
Definition StatsUI.cpp:326
void syncView(State &state, const rules::GameState &gameState, display::Screen2D view) noexcept
Definition StatsUI.cpp:297
constexpr Rect categoryRect(std::uint8_t index) noexcept
Definition StatsUI.hpp:78
void reset(State &state) noexcept
Definition StatsUI.cpp:273
std::optional< Rect > playerPropertyRect(const State &state, const rules::GameState &gameState, std::size_t column, int square) noexcept
Definition StatsUI.cpp:380
bool modernPlayerGridActive(const State &state, const rules::GameState &gameState, rules::PlayerNumber player) noexcept
Definition StatsUI.cpp:361
void setPropertyActionContext(State &state, ibar::RuleMode mode, rules::PlayerNumber player, bool localHuman, ibar::layout::PropertyMask buildProperties, ibar::layout::PropertyMask sellProperties, ibar::layout::PropertyMask mortgageProperties, bool modernPlayerLayout) noexcept
Definition StatsUI.cpp:344
int historyScrollInput(State &state, display::Screen2D view, const uimsg::Message &message) noexcept
Definition StatsUI.cpp:440
bool selectCategory(State &state, Screen screen, const rules::GameState &gameState) noexcept
Definition StatsUI.cpp:308
bool processInput(State &state, const rules::GameState &gameState, display::Screen2D view, const uimsg::Message &message) noexcept
Definition StatsUI.cpp:465
constexpr bool contains(int x, int y) const noexcept
Definition StatsUI.hpp:38
friend bool operator==(const Rect &, const Rect &)=default
rules::PlayerNumber propertyActionPlayer
Definition StatsUI.hpp:63
std::array< BankDeedState, rules::SquareCount > bankDeeds
Definition StatsUI.hpp:60
std::array< std::int64_t, rules::SquareCount > deedMetric
Definition StatsUI.hpp:55
std::array< rules::PlayerNumber, rules::MaxPlayers > playerOrder
Definition StatsUI.hpp:51
ibar::layout::PropertyMask sellProperties
Definition StatsUI.hpp:68
std::array< std::uint8_t, 3 > lastSort
Definition StatsUI.hpp:49
std::array< int, rules::MaxPlayers > bankPlayerHouses
Definition StatsUI.hpp:56
std::uint8_t activeSort
Definition StatsUI.hpp:50
ibar::RuleMode propertyActionMode
Definition StatsUI.hpp:62
std::array< std::uint8_t, rules::SquareCount > deedOrder
Definition StatsUI.hpp:54
ibar::layout::PropertyMask buildProperties
Definition StatsUI.hpp:67
std::array< std::int64_t, rules::MaxPlayers > playerMetric
Definition StatsUI.hpp:52
std::array< int, rules::MaxPlayers > bankPlayerHotels
Definition StatsUI.hpp:57
std::size_t playerCount
Definition StatsUI.hpp:53
ibar::layout::PropertyMask mortgageProperties
Definition StatsUI.hpp:69