// PropertyModalGame.h #pragma once #include "../../lib/game.h" #include "../../display/low_level_render.h" #include "../../display/low_level_gui.h" #include "input_manager.h" #include "monopoly_board.h" #include "player.h" #include "MonopolyBoardRenderer.h" class PropertyModalGame : public Game { const BoardTile* property; bool dismissed; bool is_owned; const char* owner_name; bool can_afford; int selected_choice; // 0: Buy, 1: Cancel bool buy_requested; Player* players; int players_count; public: PropertyModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, const BoardTile* prop, bool owned, const char* owner, bool affordable, Player* p_list = nullptr, int p_count = 0) : Game(width, height, renderer, gui, input_manager), property(prop), dismissed(false), is_owned(owned), owner_name(owner), can_afford(affordable), selected_choice(0), buy_requested(false), players(p_list), players_count(p_count) { if (is_owned || !can_afford) selected_choice = 1; } void init() override { dismissed = false; buy_requested = false; } bool update(const InputEvent& event) override { if (event.type == INPUT_BUTTON_0) { // BUTTON A -> BUY if (!is_owned && can_afford) { buy_requested = true; dismissed = true; return true; } else if (is_owned || !can_afford) { // If it's just the "OK" state, either button works? // Image shows >B CONTINUE in my code, so maybe Button 1. } } if (event.type == INPUT_BUTTON_1) { // BUTTON B -> AUCTION / DISMISS dismissed = true; return true; } return false; } 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; char buf[128]; if (players && players_count > 0) { MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count); } // Window background (White box) renderer->draw_filled_rectangle(win_x, win_y, win_w, win_h, false, 0); // Clear background renderer->draw_rectangle(win_x, win_y, win_w, win_h, true, 2); 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->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->set_text_color(true); // Subtitle (Type) const char* type_str = "PROPERTY"; 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); // Info box center int info_y = win_y + 60; // Price snprintf(buf, sizeof(buf), "PRICE: $%d", property->cost); renderer->draw_string_scaled(win_x + 15, info_y, buf, 1); info_y += 15; // Rent if (property->type == TILE_PROPERTY) { snprintf(buf, sizeof(buf), "RENT: $%d", property->rent[0]); } else if (property->type == TILE_UTILITY) { snprintf(buf, sizeof(buf), "RENT: 4x DICE"); } 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; // Owner if (is_owned && owner_name) { snprintf(buf, sizeof(buf), "OWNER: %s", owner_name); } else { snprintf(buf, sizeof(buf), "OWNER: %s", is_owned ? "PLAYER" : "BANK"); } renderer->draw_string_scaled(win_x + 15, info_y, buf, 1); // Action Buttons int btn_y = win_y + win_h - 60; int btn_w = win_w - 30; int btn_h = 25; if (is_owned || !can_afford) { // Only one option: CONTINUE (B) renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1); renderer->set_text_color(false); renderer->draw_string_scaled(win_x + 25, btn_y + 8, ">B CONTINUE", 1); renderer->set_text_color(true); } else { // Choice: Buy (A) or Auction (B) // Buy Button renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1); renderer->set_text_color(false); snprintf(buf, sizeof(buf), ">A BUY ($%d)", property->cost); renderer->draw_string_scaled(win_x + 20, btn_y + 8, buf, 1); renderer->set_text_color(true); btn_y += 30; // Auction Button renderer->draw_string_scaled(win_x + 20, btn_y + 8, ">B AUCTION", 1); } } bool is_dismissed() const { return dismissed; } bool wants_to_buy() const { return buy_requested; } };