Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
TradeUI.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Actions.hpp"
4#include "Display.hpp"
5#include "RuleTypes.hpp"
6#include "UIMessages.hpp"
7
8#include <array>
9#include <cstddef>
10#include <cstdint>
11#include <optional>
12#include <vector>
13
14namespace monopoly::tradeui
15{
16 inline constexpr std::size_t MaxTradeMessages =
17 28 + 15 + rules::MaxCountHitSets + 2;
18 static_assert(MaxTradeMessages == 105);
19
20 inline constexpr int PlayerSelectX = 306;
21 inline constexpr int PlayerSelectY = 234;
22 inline constexpr int PlayerSelectWidth = 188;
23 inline constexpr int PlayerSelectHeight = 209;
24 inline constexpr std::uint16_t PlayerSelectPriority = 205;
25 inline constexpr std::uint8_t OffBoardSquare = 41;
26
27 struct Rect
28 {
29 int left{};
30 int top{};
31 int right{};
32 int bottom{};
33
34 [[nodiscard]] constexpr bool contains(int x, int y) const noexcept
35 {
36 return x >= left && x < right && y >= top && y < bottom;
37 }
38
39 bool operator==(const Rect&) const = default;
40 };
41
42 inline constexpr Rect CashTradeAT1{19, 395, 52, 425};
43 inline constexpr Rect CashTradeAT2{9, 425, 61, 440};
44 inline constexpr Rect CashTradeBT1{619, 395, 652, 425};
45 inline constexpr Rect CashTradeBT2{609, 425, 661, 440};
46 inline constexpr Rect CashTradeAM1{219, 358, 252, 388};
47 inline constexpr Rect CashTradeAM2{209, 388, 261, 403};
48 inline constexpr Rect CashTradeBM1{419, 358, 452, 388};
49 inline constexpr Rect CashTradeBM2{409, 388, 461, 403};
50 inline constexpr Rect ProposeRect{202, 420, 303, 450};
51 inline constexpr Rect CancelRect{306, 420, 407, 450};
52
53 inline constexpr std::array<Rect, 4> ChanceJailRects{{
54 {66, 395, 99, 414}, {666, 395, 699, 414},
55 {266, 358, 299, 377}, {466, 358, 499, 377}}};
56 inline constexpr std::array<Rect, 4> CommunityJailRects{{
57 {66, 420, 99, 439}, {666, 420, 699, 439},
58 {266, 383, 299, 402}, {466, 383, 499, 402}}};
59 inline constexpr Rect FutureTradeAT{104, 398, 165, 413};
60 inline constexpr Rect FutureTradeBT{704, 398, 765, 413};
61 inline constexpr Rect FutureTradeAM{304, 361, 365, 376};
62 inline constexpr Rect FutureTradeBM{504, 361, 565, 376};
63 inline constexpr Rect ImmunityTradeAT{104, 422, 165, 437};
64 inline constexpr Rect ImmunityTradeBT{704, 422, 765, 437};
65 inline constexpr Rect ImmunityTradeAM{304, 385, 365, 400};
66 inline constexpr Rect ImmunityTradeBM{504, 385, 565, 400};
67 inline constexpr Rect FutureNewRect{607, 197, 701, 220};
68 inline constexpr Rect ImmunityNewRect{704, 197, 798, 220};
69 inline constexpr Rect ContractOkayRect{660, 187, 740, 209};
70 inline constexpr Rect ContractUpRect{767, 115, 785, 141};
71 inline constexpr Rect ContractDownRect{767, 155, 785, 181};
72 inline constexpr std::array<Rect, 5> ContractListRects{{
73 {614,114,764,128}, {614,128,764,142}, {614,142,764,156},
74 {614,156,764,170}, {614,170,764,184}}};
75
77 {
78 std::int32_t hitCount{};
79 std::uint32_t properties{};
80 bool selected{};
81 };
82
84 {
85 int square{-1};
86 std::uint8_t fromBox{};
87 std::uint8_t toBox{};
88 bool mortgaged{};
91
92 bool operator==(const PropertyMoveRequest&) const = default;
93 };
94
95 enum class CashDialogFeedback : std::uint8_t
96 {
97 None,
98 Clear,
99 Okay,
100 Cancel
101 };
102
103 struct State
104 {
108 bool editMode{true};
111 bool proposed{};
114 // Presentation configuration; retained by reset, never part of RULE.
118 std::array<std::int64_t, 4> cashDesired{};
119 std::array<std::uint8_t, 2> jailCardDesired{};
120 std::array<std::uint8_t, 2> immunityFutureDesired{};
122 std::uint8_t cashDialogSide{};
123 std::int64_t cashTradeAmount{};
124 std::array<std::int64_t, 2> cashOriginalOffers{};
129 std::uint8_t contractDialogMode{};
130 std::uint8_t contractDialogSide{};
131 std::uint32_t contractProperties{};
132 std::int32_t contractAmount{};
134 std::vector<ContractListEntry> contractList;
135 std::optional<PropertyMoveRequest> propertyMove;
136 std::vector<actions::Message> items;
137 };
138
139 using PropertyMask = std::uint32_t;
140
142 {
143 std::array<PropertyMask, 2> before{};
144 std::array<PropertyMask, 2> beforeMortgaged{};
145 std::array<PropertyMask, 2> offered{};
146 std::array<PropertyMask, 2> offeredMortgaged{};
147 std::array<PropertyMask, 2> after{};
148 std::array<PropertyMask, 2> afterMortgaged{};
149 std::array<std::array<Rect, rules::SquareCount>, 4> hitRects{};
150 std::array<std::array<int, rules::SquareCount>, 4> priorities{};
151 };
152
154 {
155 bool consumed{};
157 std::optional<display::Screen2D> requestedBackdrop;
158 std::vector<actions::Message> outgoing;
159 };
160
162 {
163 std::optional<display::Screen2D> requestedBackdrop;
164 };
165
166 void reset(State& state) noexcept;
167
168 [[nodiscard]] bool beginLocalTrade(
169 State& state,
171 rules::PlayerNumber source) noexcept;
172
173 [[nodiscard]] std::optional<Rect> playerTokenRect(
174 const State& state,
176 rules::PlayerNumber player) noexcept;
177
178 [[nodiscard]] std::optional<rules::PlayerNumber> planPartnerSelection(
179 State& state,
182 const uimsg::Message& message) noexcept;
183
184 [[nodiscard]] bool selectPartner(
185 State& state,
187 rules::PlayerNumber player) noexcept;
188
190 State& state,
193
195 State& state,
196 const rules::GameState& gameState) noexcept;
197
199 const State& state,
200 const rules::GameState& gameState) noexcept;
201
202 [[nodiscard]] std::optional<int> propertyHit(
203 const PropertyProjection& projection,
204 int x,
205 int y) noexcept;
206
208 State& state,
211 const uimsg::Message& message);
212
213 [[nodiscard]] std::vector<actions::Message> planEditorSubmission(
214 const State& state,
216 std::uint32_t localHumanMask);
217
218 [[nodiscard]] bool addTradeItem(
219 State& state,
221 const actions::Message& message);
222
223 [[nodiscard]] bool addUiImmunity(
227 rules::CountHitType hitType,
228 std::int32_t hitCount,
229 std::uint32_t properties,
230 bool tradingItem) noexcept;
231
233 State& state,
235 const actions::Message& message,
237 std::uint32_t localHumanMask,
238 bool restoreAutonomousPortfolio = false);
239}
std::shared_ptr< const data::HmdTextureImage > source
unsigned state
unsigned index
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr std::size_t MaxCountHitSets
Definition RuleTypes.hpp:53
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14
constexpr Rect CashTradeAT2
Definition TradeUI.hpp:43
PropertyProjection projectProperties(const State &state, const rules::GameState &gameState) noexcept
Definition TradeUI.cpp:811
bool addUiImmunity(rules::GameState &gameState, rules::PlayerNumber from, rules::PlayerNumber to, rules::CountHitType hitType, std::int32_t hitCount, std::uint32_t properties, bool tradingItem) noexcept
Definition TradeUI.cpp:1525
constexpr Rect FutureTradeBT
Definition TradeUI.hpp:60
constexpr Rect CashTradeAT1
Definition TradeUI.hpp:42
constexpr int PlayerSelectY
Definition TradeUI.hpp:21
std::optional< int > propertyHit(const PropertyProjection &projection, int x, int y) noexcept
Definition TradeUI.cpp:988
constexpr Rect ImmunityTradeAM
Definition TradeUI.hpp:65
constexpr Rect CashTradeAM1
Definition TradeUI.hpp:46
constexpr std::array< Rect, 4 > CommunityJailRects
Definition TradeUI.hpp:56
constexpr Rect ImmunityTradeAT
Definition TradeUI.hpp:63
constexpr Rect ContractDownRect
Definition TradeUI.hpp:71
constexpr Rect CashTradeAM2
Definition TradeUI.hpp:47
bool abortIfParticipantOffBoard(State &state, rules::GameState &gameState, display::Screen2D desiredView) noexcept
Definition TradeUI.cpp:882
RuleUpdate processRuleMessage(State &state, rules::GameState &gameState, const actions::Message &message, display::Screen2D currentView, std::uint32_t localHumanMask, bool restoreAutonomousPortfolio)
Definition TradeUI.cpp:1600
constexpr Rect CancelRect
Definition TradeUI.hpp:51
bool beginLocalTrade(State &state, const rules::GameState &gameState, rules::PlayerNumber source) noexcept
Definition TradeUI.cpp:693
constexpr Rect ContractUpRect
Definition TradeUI.hpp:70
bool selectPartner(State &state, const rules::GameState &gameState, rules::PlayerNumber player) noexcept
Definition TradeUI.cpp:787
constexpr Rect FutureTradeBM
Definition TradeUI.hpp:62
constexpr Rect ImmunityTradeBT
Definition TradeUI.hpp:64
constexpr Rect ImmunityTradeBM
Definition TradeUI.hpp:66
constexpr Rect CashTradeBM1
Definition TradeUI.hpp:48
InputUpdate processInput(State &state, const rules::GameState &gameState, display::Screen2D desiredView, const uimsg::Message &message)
Definition TradeUI.cpp:1021
constexpr int PlayerSelectHeight
Definition TradeUI.hpp:23
std::vector< actions::Message > planEditorSubmission(const State &state, rules::PlayerNumber editor, std::uint32_t localHumanMask)
Definition TradeUI.cpp:1414
constexpr std::array< Rect, 5 > ContractListRects
Definition TradeUI.hpp:72
void reset(State &state) noexcept
Definition TradeUI.cpp:659
constexpr Rect FutureTradeAM
Definition TradeUI.hpp:61
constexpr std::uint8_t OffBoardSquare
Definition TradeUI.hpp:25
std::uint32_t PropertyMask
Definition TradeUI.hpp:139
constexpr Rect CashTradeBM2
Definition TradeUI.hpp:49
constexpr std::uint16_t PlayerSelectPriority
Definition TradeUI.hpp:24
constexpr Rect CashTradeBT1
Definition TradeUI.hpp:44
constexpr int PlayerSelectX
Definition TradeUI.hpp:20
void refreshContractProjection(State &state, const rules::GameState &gameState) noexcept
Definition TradeUI.cpp:908
std::optional< rules::PlayerNumber > planPartnerSelection(State &state, const rules::GameState &gameState, display::Screen2D desiredView, const uimsg::Message &message) noexcept
Definition TradeUI.cpp:748
constexpr Rect CashTradeBT2
Definition TradeUI.hpp:45
constexpr std::array< Rect, 4 > ChanceJailRects
Definition TradeUI.hpp:53
constexpr int PlayerSelectWidth
Definition TradeUI.hpp:22
constexpr Rect ProposeRect
Definition TradeUI.hpp:50
constexpr Rect ContractOkayRect
Definition TradeUI.hpp:69
std::optional< Rect > playerTokenRect(const State &state, const rules::GameState &gameState, rules::PlayerNumber player) noexcept
Definition TradeUI.cpp:728
constexpr std::size_t MaxTradeMessages
Definition TradeUI.hpp:16
constexpr Rect FutureNewRect
Definition TradeUI.hpp:67
constexpr Rect FutureTradeAT
Definition TradeUI.hpp:59
constexpr Rect ImmunityNewRect
Definition TradeUI.hpp:68
bool addTradeItem(State &state, const rules::GameState &gameState, const actions::Message &message)
Definition TradeUI.cpp:1434
std::optional< display::Screen2D > requestedBackdrop
Definition TradeUI.hpp:157
std::vector< actions::Message > outgoing
Definition TradeUI.hpp:158
bool operator==(const PropertyMoveRequest &) const =default
std::array< std::array< Rect, rules::SquareCount >, 4 > hitRects
Definition TradeUI.hpp:149
std::array< PropertyMask, 2 > before
Definition TradeUI.hpp:143
std::array< PropertyMask, 2 > offeredMortgaged
Definition TradeUI.hpp:146
std::array< std::array< int, rules::SquareCount >, 4 > priorities
Definition TradeUI.hpp:150
std::array< PropertyMask, 2 > offered
Definition TradeUI.hpp:145
std::array< PropertyMask, 2 > after
Definition TradeUI.hpp:147
std::array< PropertyMask, 2 > afterMortgaged
Definition TradeUI.hpp:148
std::array< PropertyMask, 2 > beforeMortgaged
Definition TradeUI.hpp:144
bool operator==(const Rect &) const =default
constexpr bool contains(int x, int y) const noexcept
Definition TradeUI.hpp:34
std::optional< display::Screen2D > requestedBackdrop
Definition TradeUI.hpp:163
std::array< std::int64_t, 4 > cashDesired
Definition TradeUI.hpp:118
std::uint8_t cashDialogSide
Definition TradeUI.hpp:122
std::int32_t contractAmount
Definition TradeUI.hpp:132
rules::PlayerNumber tradeFrom
Definition TradeUI.hpp:107
rules::PlayerNumber playerB
Definition TradeUI.hpp:106
std::array< std::uint8_t, 2 > jailCardDesired
Definition TradeUI.hpp:119
display::Screen2D formerView
Definition TradeUI.hpp:116
std::vector< ContractListEntry > contractList
Definition TradeUI.hpp:134
rules::PlayerNumber playerA
Definition TradeUI.hpp:105
std::uint32_t contractProperties
Definition TradeUI.hpp:131
std::vector< actions::Message > items
Definition TradeUI.hpp:136
std::array< std::int64_t, 2 > cashOriginalOffers
Definition TradeUI.hpp:124
std::int64_t cashTradeAmount
Definition TradeUI.hpp:123
std::array< std::uint8_t, 2 > immunityFutureDesired
Definition TradeUI.hpp:120
std::uint8_t contractDialogMode
Definition TradeUI.hpp:129
CashDialogFeedback cashDialogFeedback
Definition TradeUI.hpp:125
rules::TradeItemKind contractDialogKind
Definition TradeUI.hpp:128
std::uint8_t contractDialogSide
Definition TradeUI.hpp:130
std::optional< PropertyMoveRequest > propertyMove
Definition TradeUI.hpp:135