improve board view with visual cues of the properties owned

This commit is contained in:
Adolfo Reyna
2026-01-31 23:02:25 -05:00
parent 63c4324561
commit d5a80235b4
5 changed files with 95 additions and 70 deletions

View File

@@ -61,16 +61,13 @@ public:
}
void draw() override {
renderer->clear_buffer();
int win_w = 160;
int win_h = 160;
int win_x = (width - win_w) / 2;
int win_y = (height - win_h) / 2;
int win_w = width - 2 * (width / 7) - 4;
int win_h = height - 2 * (height / 7) - 4;
int win_x = width / 7 + 2;
int win_y = height / 7 + 2;
char buf[128];
if (players && players_count > 0) {
// Find current player position (who is interacting with the modal)
// In MonopolyGame, p is players[current_player_idx]
// We don't have the idx here directly, but we can highlight the property itself
int property_idx = -1;
for(int i=0; i<40; i++) if(&MONOPOLY_BOARD[i] == property) property_idx = i;
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count, property_idx);
@@ -82,10 +79,10 @@ public:
renderer->draw_rectangle(win_x + 3, win_y + 3, win_w - 6, win_h - 6, true, 1);
// Header Title Bar
renderer->draw_filled_rectangle(win_x + 4, win_y + 4, win_w - 8, 30, true, 1);
renderer->draw_filled_rectangle(win_x + 4, win_y + 4, win_w - 8, 35, true, 1);
renderer->set_text_color(false); // White text
snprintf(buf, sizeof(buf), "%s", property->name);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 6) / 2, win_y + 8, buf, 1);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 12) / 2, win_y + 10, buf, 2);
renderer->set_text_color(true);
// Subtitle (Type)
@@ -93,14 +90,14 @@ public:
if (property->type == TILE_RAILROAD) type_str = "RAILROAD";
else if (property->type == TILE_UTILITY) type_str = "UTILITY";
snprintf(buf, sizeof(buf), "%s", type_str);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 6) / 2, win_y + 40, buf, 1);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 12) / 2, win_y + 45, buf, 2);
// Info box center
int info_y = win_y + 60;
int info_y = win_y + 75;
// Price
snprintf(buf, sizeof(buf), "PRICE: $%d", property->cost);
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
info_y += 15;
renderer->draw_string_scaled(win_x + 20, info_y, buf, 2);
info_y += 25;
// Rent
if (property->type == TILE_PROPERTY) {
@@ -110,8 +107,8 @@ public:
} else if (property->type == TILE_RAILROAD) {
snprintf(buf, sizeof(buf), "RENT: $25");
}
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
info_y += 15;
renderer->draw_string_scaled(win_x + 20, info_y, buf, 2);
info_y += 25;
// Owner
if (is_owned && owner_name) {
@@ -119,26 +116,24 @@ public:
} else {
snprintf(buf, sizeof(buf), "OWNER: %s", is_owned ? "PLAYER" : "BANK");
}
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
renderer->draw_string_scaled(win_x + 20, info_y, buf, 2);
// Action Buttons
int btn_y = win_y + win_h - 60;
int btn_w = win_w - 30;
int btn_h = 25;
int btn_y = win_y + win_h - 85;
int btn_w = win_w - 40;
int btn_h = 35;
if (is_owned && owner_id != -1) {
// Option: Pay Rent (A or B)
renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
renderer->draw_filled_rectangle(win_x + 20, btn_y, btn_w, btn_h, true, 1);
renderer->set_text_color(false);
int rent = 0;
if (property->type == TILE_PROPERTY) {
rent = property->rent[0];
} else if (property->type == TILE_RAILROAD) {
// Calculate Railroad rent based on owner's count
int rr_count = 0;
if (owner_id != -1 && owner_id < players_count) {
for (int i = 0; i < players[owner_id].property_count; ++i) {
// Find the property in the global board to check type (or just trust the index)
int prop_idx = players[owner_id].properties_owned[i];
if (MONOPOLY_BOARD[prop_idx].type == TILE_RAILROAD) {
rr_count++;
@@ -149,42 +144,38 @@ public:
else if (rr_count == 2) rent = 50;
else if (rr_count == 3) rent = 100;
else if (rr_count == 4) rent = 200;
else rent = 25; // Fallback
else rent = 25;
} else if (property->type == TILE_UTILITY) {
// Simplified 40 or use a more complex check
rent = 40;
}
snprintf(buf, sizeof(buf), ">PAY RENT ($%d)", rent);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 6) / 2, btn_y + 8, buf, 1);
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 12) / 2, btn_y + 10, buf, 2);
renderer->set_text_color(true);
} else if (!is_owned && can_afford) {
// Choice: Buy (A) or Pass (B). Changed to: A cycles, B selects.
// Buy Button
if (selected_choice == 0) renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
else renderer->draw_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
if (selected_choice == 0) renderer->draw_filled_rectangle(win_x + 20, btn_y, btn_w, btn_h, true, 1);
else renderer->draw_rectangle(win_x + 20, btn_y, btn_w, btn_h, true, 1);
if (selected_choice == 0) renderer->set_text_color(false);
snprintf(buf, sizeof(buf), "%sBUY ($%d)", (selected_choice == 0 ? "> " : " "), property->cost);
renderer->draw_string_scaled(win_x + 20, btn_y + 8, buf, 1);
renderer->draw_string_scaled(win_x + 25, btn_y + 10, buf, 2);
renderer->set_text_color(true);
btn_y += 30;
btn_y += 40;
// Pass Button
if (selected_choice == 1) renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
if (selected_choice == 1) renderer->draw_filled_rectangle(win_x + 20, btn_y, btn_w, btn_h, true, 1);
if (selected_choice == 1) renderer->set_text_color(false);
snprintf(buf, sizeof(buf), "%sPASS", (selected_choice == 1 ? "> " : " "));
renderer->draw_string_scaled(win_x + 20, btn_y + 8, buf, 1);
renderer->draw_string_scaled(win_x + 25, btn_y + 10, buf, 2);
renderer->set_text_color(true);
// Helpful hint
renderer->draw_string_scaled(win_x + 15, win_y + win_h - 15, "A:Next B:Sel", 1);
renderer->draw_string_scaled(win_x + 20, win_y + win_h - 20, "A:Next B:Sel", 1);
} else {
// Only one option: PASS (B) (e.g. if owned by self or can't afford)
renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
renderer->draw_filled_rectangle(win_x + 20, btn_y, btn_w, btn_h, true, 1);
renderer->set_text_color(false);
renderer->draw_string_scaled(win_x + 25, btn_y + 8, ">B PASS", 1);
renderer->draw_string_scaled(win_x + (win_w - 7 * 12) / 2, btn_y + 10, ">B PASS", 2);
renderer->set_text_color(true);
}
}