monopoly Main UI Changes
This commit is contained in:
92
games/monopoly/ChanceModalGame.h
Normal file
92
games/monopoly/ChanceModalGame.h
Normal file
@@ -0,0 +1,92 @@
|
||||
// ChanceModalGame.h
|
||||
#pragma once
|
||||
#include "../../lib/game.h"
|
||||
#include "../../display/low_level_render.h"
|
||||
#include "../../display/low_level_gui.h"
|
||||
#include "input_manager.h"
|
||||
#include "chance.h"
|
||||
#include "player.h"
|
||||
|
||||
#include "MonopolyBoardRenderer.h"
|
||||
|
||||
class ChanceModalGame : public Game {
|
||||
const ChanceCard* card;
|
||||
bool dismissed;
|
||||
Player* players;
|
||||
int players_count;
|
||||
int player_pos;
|
||||
|
||||
public:
|
||||
ChanceModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, const ChanceCard* 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_CHANCE; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int win_w = 180;
|
||||
int win_h = 120;
|
||||
int win_x = (width - win_w) / 2;
|
||||
int win_y = (height - win_h) / 2;
|
||||
char buf[256];
|
||||
|
||||
// Window background
|
||||
renderer->draw_filled_rectangle(win_x, win_y, win_w, win_h, false, 0);
|
||||
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
|
||||
renderer->draw_filled_rectangle(win_x + 4, win_y + 4, win_w - 8, 25, true, 1);
|
||||
renderer->set_text_color(false);
|
||||
renderer->draw_string_scaled(win_x + (win_w - 6 * 6) / 2, win_y + 8, "CHANCE", 1);
|
||||
renderer->set_text_color(true);
|
||||
|
||||
// Card Description (with simple word wrap)
|
||||
int text_y = win_y + 40;
|
||||
int max_chars_per_line = (win_w - 20) / 6;
|
||||
const char* text = card->description;
|
||||
char line[64];
|
||||
int start = 0;
|
||||
int len = strlen(text);
|
||||
|
||||
while (start < len) {
|
||||
int count = 0;
|
||||
// Find how many chars fit - very basic wrapping
|
||||
while (count < max_chars_per_line && (start + count) < len) {
|
||||
count++;
|
||||
}
|
||||
// Try to find last space if not at end
|
||||
if (start + count < len) {
|
||||
while (count > 0 && text[start + count] != ' ') count--;
|
||||
if (count == 0) count = max_chars_per_line; // fallback
|
||||
}
|
||||
|
||||
int copy_len = (count < 63) ? count : 63;
|
||||
strncpy(line, text + start, copy_len);
|
||||
line[copy_len] = '\0';
|
||||
renderer->draw_string_scaled(win_x + 10, text_y, line, 1);
|
||||
text_y += 10;
|
||||
start += count;
|
||||
if (text[start] == ' ') start++; // Skip the space
|
||||
}
|
||||
|
||||
// Prompt
|
||||
renderer->draw_string_scaled(win_x + (win_w - 12 * 6) / 2, win_y + win_h - 15, "Press ANY Button", 1);
|
||||
}
|
||||
|
||||
bool is_dismissed() const { return dismissed; }
|
||||
};
|
||||
Reference in New Issue
Block a user