Add virtual touch buttons for Monopoly game and centralize configuration in ModalButtonHelper
This commit is contained in:
@@ -23,6 +23,7 @@ extern "C" {
|
||||
#include "ChanceModalGame.h"
|
||||
#include "CommunityChestModalGame.h"
|
||||
#include "TurnModalGame.h"
|
||||
#include "ModalButtonHelper.h"
|
||||
#include "sprites.h"
|
||||
#include "MonopolyBoardRenderer.h"
|
||||
|
||||
@@ -39,6 +40,9 @@ MonopolyGame::MonopolyGame(uint16_t width, uint16_t height, LowLevelRenderer* re
|
||||
|
||||
// --- Initialize game state ---
|
||||
void MonopolyGame::init() {
|
||||
// Initialize regions for touch buttons
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
|
||||
// Hardcoded 2 players for minimal version
|
||||
init_player(&players[0], 0, "Elias", "Top Hat");
|
||||
init_player(&players[1], 1, "Adolfo", "Racecar");
|
||||
@@ -114,6 +118,7 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
|
||||
// Immediately check if we need to show a property modal
|
||||
if (modal_property_index >= 0) {
|
||||
@@ -141,10 +146,14 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
active_modal = new CommunityChestModalGame(width, height, renderer, gui, input_manager, &COMMUNITY_DECK[last_drawn_community_idx], players, players_count, p->position);
|
||||
// We'll apply the effect when CommunityChestModal is dismissed
|
||||
}
|
||||
if (active_modal) active_modal->init();
|
||||
return needs_redraw;
|
||||
} else if (chance_modal && chance_modal->is_dismissed()) {
|
||||
const ChanceCard* card = &CHANCE_DECK[last_drawn_chance_idx];
|
||||
last_drawn_chance_idx = -1;
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
|
||||
// Apply card effects
|
||||
bool position_changed = false;
|
||||
@@ -204,6 +213,7 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
|
||||
if (position_changed) {
|
||||
// If we moved, check if we landed on a property
|
||||
@@ -269,6 +279,7 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
|
||||
if (position_changed) {
|
||||
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
|
||||
@@ -360,14 +371,17 @@ bool MonopolyGame::update(const InputEvent& event) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
} else if (board_modal && board_modal->is_dismissed()) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
} else if (turn_modal && turn_modal->is_dismissed()) {
|
||||
delete active_modal;
|
||||
active_modal = nullptr;
|
||||
needs_redraw = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
}
|
||||
return needs_redraw;
|
||||
}
|
||||
@@ -544,4 +558,6 @@ void MonopolyGame::draw() {
|
||||
renderer->draw_string_scaled(ix + 15, content_y, buf, 2);
|
||||
content_y += 25;
|
||||
}
|
||||
|
||||
ModalButtonHelper::draw_virtual_buttons(renderer, input_manager);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user