updates and fixes

This commit is contained in:
Bernardo Magri
2026-02-25 13:36:13 +00:00
parent 3bc1645721
commit 23316594f7
7 changed files with 383 additions and 1737 deletions
+27 -85
View File
@@ -1,98 +1,40 @@
#pragma once
#include "minefield.hpp"
#include <memory>
#include <gtkmm.h>
#include <sigc++/sigc++.h>
#include <vector>
#include <string>
#include <fstream>
#include <filesystem>
#include <memory>
#include "minefield.hpp"
#include "board_widget.hpp"
class MainWindow : public Gtk::ApplicationWindow
{
class MainWindow : public Gtk::ApplicationWindow {
public:
MainWindow();
virtual ~MainWindow() = default;
~MainWindow() override;
private:
// UI containers
Gtk::Box m_boxMain{Gtk::Orientation::VERTICAL};
Gtk::HeaderBar m_headerBar;
Gtk::Box m_statusBox{Gtk::Orientation::HORIZONTAL};
Gtk::Grid m_grid;
Gtk::Overlay m_overlay;
// UI Setup
void setup_header_bar();
void setup_board();
// Game status widgets
Gtk::Label m_minesLabel;
Gtk::Label m_flagsLabel;
Gtk::Label m_timeLabel;
// Actions
void start_new_game(const GameDifficulty& difficulty);
void on_game_state_changed();
bool on_timer_tick();
void show_game_over_dialog(bool won);
// Widgets
Gtk::HeaderBar header_bar_;
Gtk::Button btn_new_game_;
Gtk::MenuButton btn_difficulty_;
Gtk::Popover menu_difficulty_;
Gtk::Box box_difficulty_; // Content for popover
// Header bar controls
Gtk::Button m_newGameButton;
Gtk::MenuButton m_difficultyButton;
Gtk::Label lbl_time_;
Gtk::Label lbl_flags_;
// Game field and buttons
std::unique_ptr<MineField> m_field;
std::vector<std::shared_ptr<Gtk::ToggleButton>> m_buttons;
BoardWidget board_widget_;
// Resources
std::shared_ptr<Gdk::Texture> m_textureBomb;
std::shared_ptr<Gdk::Texture> m_textureFlag;
std::shared_ptr<Gdk::Texture> m_textureFlagBomb;
std::shared_ptr<Gdk::Texture> m_textureExplosion;
// Game state tracking
bool m_firstClick;
sigc::connection m_timerConnection;
// Leaderboard
std::vector<GameScore> m_leaderboard;
Gtk::Dialog* m_leaderboardDialog;
Gtk::Dialog* m_difficultyDialog;
Gtk::Dialog* m_winDialog;
Gtk::Dialog* m_nameDialog;
std::string m_currentDifficulty;
// Methods
void setupUI();
void setupHeaderBar();
void setupStatusBar();
void setupGameBoard();
void setupLeaderboard();
void setupCSSProviders();
void loadResources();
// Event handlers
void onCellClick(int x, int y);
void onCellRightClick(int n_press, double n_x, double n_y, int index);
void onNewGameClick();
void onDifficultySelected(const GameDifficulty& difficulty);
void showDifficultyDialog();
// Game callbacks
void updateCell(int x, int y);
void updateFlagsLabel(int flags);
void updateTimeLabel();
bool updateTimer();
void onGameOver();
void onGameWon(int time);
void showGameOverAnimation();
void showGameWonAnimation();
void revealAllBombs();
// Leaderboard methods
void loadLeaderboard();
void saveLeaderboard();
void showLeaderboard();
void addScoreToLeaderboard(const std::string& playerName, const std::string& difficulty, int time);
std::string formatTime(int milliseconds) const;
// Helper methods
void resetGame();
void startNewGame(int cols, int rows, int mines, const std::string& difficulty);
void clearBoard();
void setupConfetti();
void showNameInputDialog(int time);
std::filesystem::path getConfigDir() const;
// Game State
std::shared_ptr<Minefield> minefield_;
sigc::connection timer_conn_;
GameDifficulty current_difficulty_ = Minefield::DifficultyEasy;
};