Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
IBarLayout.cpp
Go to the documentation of this file.
1#include "IBarLayout.hpp"
2
3#include <array>
4
6{
7 namespace
8 {
9 constexpr std::array<int, 42> PropertyConversion{{
10 -1, 0,-1, 1,-1, 2, 3,-1, 4, 5,
11 -1, 6, 7, 8, 9,10,11,-1,12,13,
12 -1,14,-1,15,16,17,18,19,20,21,
13 -1,22,23,-1,24,25,-1,26,-1,27,
14 -1,-1
15 }};
16
17 constexpr std::array<int, 28> PropertyBarOrder{{
18 11, 9, 2, 14,13,12, 17,8,16,15,
19 0,20,19,18, 23,22,21,5, 26,25,6,24,
20 29,28,27, 3,32,30
21 }};
22 }
23 int propertyIndex(int square) noexcept
24 {
25 if (square < 0 || square >= static_cast<int>(PropertyConversion.size()))
26 return -1;
27 return PropertyConversion[static_cast<std::size_t>(square)];
28 }
29
30
31 PropertyMask propertyBit(int square) noexcept
32 {
33 const int index = propertyIndex(square);
35 }
36
37
38 int propertyBarOrder(int square) noexcept
39 {
40 const int index = propertyIndex(square);
41 if (index < 0) return -1;
42 return PropertyBarOrder[static_cast<std::size_t>(index)];
43 }
44
45
46 Rect propertyRect(int square) noexcept
47 {
48 const int order = propertyBarOrder(square);
49 if (order < 0) return {};
50
51 int x = 0;
52 int y = 0;
53 if (order < 18)
54 {
55 x = 28 + 54 * (order / 3) - 5 * (order % 3);
56 y = 495 + 10 * (order % 3);
57 }
58 else
59 {
60 x = 482 + 54 * ((order - 18) / 3) + 5 * (order % 3);
61 y = 495 + 10 * (order % 3);
62 }
63 return {x, y, x + 34, y + 42};
64 }
65
66
67 std::optional<int> propertyHit(
68 int x, int y, PropertyMask visibleProperties) noexcept
69 {
70 for (int square = 41; square >= 0; --square)
71 {
72 const auto bit = propertyBit(square);
73 if (bit == 0 || (visibleProperties & bit) == 0) continue;
74 if (propertyRect(square).contains(x, y)) return square;
75 }
76 return std::nullopt;
77 }
78
79
81 int numberOfPlayers) noexcept
82 {
83 return
84 numberOfPlayers <= 4
87 }
88
89
90 int scoreX(
91 int playerIndex,
92 int numberOfPlayers,
93 int playerWidth) noexcept
94 {
95 if (
96 playerIndex < 0 ||
97 numberOfPlayers <= 0 ||
98 playerIndex >= numberOfPlayers)
99 {
100 return -1;
101 }
102
103
104 const int availableWidth =
106 ScoreBorder * 2 -
107 BankWidth;
108
109
110 const int spacing =
111 (
113 numberOfPlayers *
115 ) /
116 (
117 numberOfPlayers + 1
118 );
119
120
121 return
123 spacing *
124 (playerIndex + 1) +
126 playerIndex;
127 }
128
129
131 int playerIndex,
132 int numberOfPlayers) noexcept
133 {
134 const int width =
136 numberOfPlayers
137 );
138
139
140 const int x =
141 scoreX(
142 playerIndex,
143 numberOfPlayers,
144 width
145 );
146
147
148 if (x < 0)
149 {
150 return {};
151 }
152
153
154 // L'original prend la hauteur directement dans
155 // PlayerColorBarShownID.
156 //
157 // Les DAT_MAIN graphiques correspondants ne sont pas
158 // présents dans l'archive source actuelle.
159 //
160 // Pour le Player Select uniquement, la barre occupe la
161 // région basse connue :
162 //
163 // DISPLAY_ScoreY = 560
164 // framebuffer = 600
165 //
166 // Lorsque TAB_inpsl0 / TAB_inpss0 seront décodés,
167 // seule cette hauteur sera remplacée par celle du chunk.
168 return
169 {
170 x,
171 ScoreY,
172 x + width,
174 };
175 }
176
179 ActionButtonLayout layout) noexcept
180 {
181 static constexpr std::array<Rect, 9> GeneralRects{{
182 { 10, 455, 69, 483},
183 { 70, 455, 132, 483},
184 {148, 455, 252, 483},
185 {569, 455, 672, 483},
186 {256, 455, 357, 483},
187 {464, 455, 567, 483},
188 {361, 455, 463, 483},
189 {690, 456, 727, 483},
190 {732, 456, 789, 483}
191 }};
192
193 const int index = static_cast<int>(slot);
194 if (index < 0 || index >= static_cast<int>(GeneralRects.size()))
195 return {};
196
197 Rect result = GeneralRects[static_cast<std::size_t>(index)];
198 switch (layout)
199 {
202 {
203 result.left = 251;
204 result.right = 354;
205 }
207 {
208 result.left = 467;
209 result.right = 569;
210 }
211 break;
214 {
215 result.left = 254;
216 result.right = 355;
217 }
219 {
220 result.left = 464;
221 result.right = 567;
222 }
223 break;
226 result = {349, 420, 449, 448};
228 result = {224, 420, 324, 448};
230 result = {473, 420, 573, 448};
231 break;
233 default:
234 break;
235 }
236 return result;
237 }
238
239
240 std::optional<ActionButtonSlot> actionButtonHit(
241 int x,
242 int y,
243 ActionButtonLayout layout,
244 ActionButtonMask activeSlots) noexcept
245 {
246 for (int index = 0;
248 ++index)
249 {
250 const auto slot = static_cast<ActionButtonSlot>(index);
251 if ((activeSlots & actionButtonBit(slot)) == 0)
252 continue;
253 if (actionButtonRect(slot, layout).contains(x, y))
254 return slot;
255 }
256 return std::nullopt;
257 }
258
259}
PlayerNumber slot
std::uint32_t width
unsigned index
int propertyIndex(int square) noexcept
std::uint32_t PropertyMask
Rect propertyRect(int square) noexcept
int scoreX(int playerIndex, int numberOfPlayers, int playerWidth) noexcept
PropertyMask propertyBit(int square) noexcept
std::optional< int > propertyHit(int x, int y, PropertyMask visibleProperties) noexcept
std::optional< ActionButtonSlot > actionButtonHit(int x, int y, ActionButtonLayout layout, ActionButtonMask activeSlots) noexcept
Rect actionButtonRect(ActionButtonSlot slot, ActionButtonLayout layout) noexcept
constexpr int VirtualHeight
Definition IBarLayout.hpp:9
constexpr int ScoreBorder
unsigned int ActionButtonMask
constexpr int VirtualWidth
Definition IBarLayout.hpp:8
constexpr int ScoreBoxSmallWidth
int scoreBoxWidth(int numberOfPlayers) noexcept
Rect playerSetupHitRect(int playerIndex, int numberOfPlayers) noexcept
int propertyBarOrder(int square) noexcept
constexpr int BankWidth
constexpr int ScoreBoxLargeWidth
constexpr ActionButtonMask actionButtonBit(ActionButtonSlot slot) noexcept
bool contains(int x, int y) const noexcept