Files
basic1/games/monopoly/CommunityChestModalGame.h
2026-02-02 23:14:14 -05:00

93 lines
3.2 KiB
C++

// CommunityChestModalGame.h
#pragma once
#include "../../lib/game.h"
#include "../../display/low_level_render.h"
#include "../../display/low_level_gui.h"
#include "input_manager.h"
#include "community_chest.h"
#include "player.h"
#include "MonopolyBoardRenderer.h"
#include "sprites.h"
class CommunityChestModalGame : public Game {
const CommunityCard* card;
bool dismissed;
Player* players;
int players_count;
int player_pos;
public:
CommunityChestModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, const CommunityCard* c, Player* p_list = nullptr, int p_count = 0, int p_pos = -1)
: Game(width, height, renderer, gui, input_manager), card(c), dismissed(false), players(p_list), players_count(p_count), player_pos(p_pos) {}
void init() override { dismissed = false; }
Type get_type() const override { return Type::MONOPOLY_COMMUNITY_CHEST; }
bool update(const InputEvent& event) override {
if (event.type == INPUT_BUTTON_0 || event.type == INPUT_BUTTON_1) {
dismissed = true;
return true;
}
return false;
}
void draw() override {
renderer->clear_buffer();
if (players && players_count > 0) {
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count, player_pos);
}
// --- Inner UI (Center Area) ---
int cw = width / 7;
int ch = height / 7;
int ix = cw + 2, iy = ch + 2;
int iw = width - 2 * cw - 4, ih = height - 2 * ch - 4;
// Window background
renderer->draw_filled_rectangle(ix, iy, iw, ih, false, 0);
renderer->draw_rectangle(ix, iy, iw, ih, true, 1);
// Header
renderer->draw_filled_rectangle(ix + 2, iy + 2, iw - 4, 30, true, 1);
renderer->set_text_color(false);
renderer->draw_string_scaled(ix + (iw - 15 * 12) / 2, iy + 10, "COMMUNITY CHEST", 2);
renderer->set_text_color(true);
// Card Description
int text_y = iy + 45;
int max_chars_per_line = (iw - 10) / 12;
const char* text = card->description;
char line[64];
int start = 0;
int len = strlen(text);
while (start < len) {
int count = 0;
while (count < max_chars_per_line && (start + count) < len) {
count++;
}
if (start + count < len) {
while (count > 0 && text[start + count] != ' ') count--;
if (count == 0) count = max_chars_per_line;
}
int copy_len = (count < 63) ? count : 63;
strncpy(line, text + start, copy_len);
line[copy_len] = '\0';
renderer->draw_string_scaled(ix + (iw - copy_len * 12) / 2, text_y, line, 2);
text_y += 18;
start += count;
if (text[start] == ' ') start++;
}
// Draw Community Chest sprite
renderer->draw_bitmap(epd_bitmap_CommunityChest, ix + iw - 105, iy + ih - 105, 100, 100, true);
// Prompt
renderer->draw_string_scaled(ix + (iw - 12 * 12) / 2, iy + ih - 20, "Press BUTTON", 2);
}
bool is_dismissed() const { return dismissed; }
};