From 0e17996c355d91239ce7c4249fa2ff1820173762 Mon Sep 17 00:00:00 2001 From: zulianc Date: Sat, 22 Mar 2025 10:49:55 +0100 Subject: [PATCH] toujours plus de settings --- .../keybinds/{custom.bin => layout1.bin} | 0 .../keybinds/{default1.bin => layout2.bin} | 0 .../keybinds/{default2.bin => layout3.bin} | 0 .../keybinds/{default3.bin => layout4.bin} | 0 .../keybinds/{default4.bin => layout5.bin} | 0 src/Core/Menu.cpp | 3 ++ src/Core/Menu.h | 5 +-- src/GraphicalUI/GraphApp.cpp | 2 +- src/GraphicalUI/Keybinds.h | 2 +- src/GraphicalUI/PiecesType.h | 21 ++++++++++ src/GraphicalUI/Settings.cpp | 42 +++++++++++++++++-- src/GraphicalUI/Settings.h | 12 +++++- 12 files changed, 78 insertions(+), 9 deletions(-) rename data/config/keybinds/{custom.bin => layout1.bin} (100%) rename data/config/keybinds/{default1.bin => layout2.bin} (100%) rename data/config/keybinds/{default2.bin => layout3.bin} (100%) rename data/config/keybinds/{default3.bin => layout4.bin} (100%) rename data/config/keybinds/{default4.bin => layout5.bin} (100%) create mode 100644 src/GraphicalUI/PiecesType.h diff --git a/data/config/keybinds/custom.bin b/data/config/keybinds/layout1.bin similarity index 100% rename from data/config/keybinds/custom.bin rename to data/config/keybinds/layout1.bin diff --git a/data/config/keybinds/default1.bin b/data/config/keybinds/layout2.bin similarity index 100% rename from data/config/keybinds/default1.bin rename to data/config/keybinds/layout2.bin diff --git a/data/config/keybinds/default2.bin b/data/config/keybinds/layout3.bin similarity index 100% rename from data/config/keybinds/default2.bin rename to data/config/keybinds/layout3.bin diff --git a/data/config/keybinds/default3.bin b/data/config/keybinds/layout4.bin similarity index 100% rename from data/config/keybinds/default3.bin rename to data/config/keybinds/layout4.bin diff --git a/data/config/keybinds/default4.bin b/data/config/keybinds/layout5.bin similarity index 100% rename from data/config/keybinds/default4.bin rename to data/config/keybinds/layout5.bin diff --git a/src/Core/Menu.cpp b/src/Core/Menu.cpp index 8d2d9e1..f76d05a 100644 --- a/src/Core/Menu.cpp +++ b/src/Core/Menu.cpp @@ -6,6 +6,9 @@ #include +static const int DEFAULT_BOARD_WIDTH = 10; // the default width of the board when starting the menu +static const int DEFAULT_BOARD_HEIGHT = 20; // the default height of the board when starting the menu + Menu::Menu() { this->piecesList = std::make_shared(PiecesList()); diff --git a/src/Core/Menu.h b/src/Core/Menu.h index 346e9a9..688338e 100644 --- a/src/Core/Menu.h +++ b/src/Core/Menu.h @@ -4,9 +4,8 @@ #include "Player.h" #include "Game.h" -static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind -static const int DEFAULT_BOARD_WIDTH = 10; // the default width of the board when starting the menu -static const int DEFAULT_BOARD_HEIGHT = 20; // the default height of the board when starting the menu +static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the app were choosen with this number in mind +static const int MAXIMUM_PIECES_SIZE = 15; // the maximum size of available pieces /** diff --git a/src/GraphicalUI/GraphApp.cpp b/src/GraphicalUI/GraphApp.cpp index f13d60f..93dcce4 100644 --- a/src/GraphicalUI/GraphApp.cpp +++ b/src/GraphicalUI/GraphApp.cpp @@ -8,7 +8,7 @@ #include #include -static const double TIME_BETWEEN_FRAMES = (1000.f / 60.f); +static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND); GraphApp::GraphApp() { diff --git a/src/GraphicalUI/Keybinds.h b/src/GraphicalUI/Keybinds.h index b29639e..f703b16 100644 --- a/src/GraphicalUI/Keybinds.h +++ b/src/GraphicalUI/Keybinds.h @@ -20,7 +20,7 @@ class Keybinds { void saveKeybindsToFile() const; - void createDefaultKeybindsFile() const; + void resetCustomLayoutFile() const; void addKey(Action action, sfKey key); diff --git a/src/GraphicalUI/PiecesType.h b/src/GraphicalUI/PiecesType.h new file mode 100644 index 0000000..5d9c071 --- /dev/null +++ b/src/GraphicalUI/PiecesType.h @@ -0,0 +1,21 @@ +#pragma once + + +enum PiecesType { + CONVEX, + HOLELESS, + OTHERS, + ALL, + SINGLE +}; + + +inline int getSizeOfPieces(PiecesType type) { + if (type < SINGLE) return 0; + + else return (type - SINGLE + 1); +} + +inline PiecesType createSinglePieceType(int size) { + return PiecesType(SINGLE + size - 1); +} diff --git a/src/GraphicalUI/Settings.cpp b/src/GraphicalUI/Settings.cpp index d97e222..7cb7c0c 100644 --- a/src/GraphicalUI/Settings.cpp +++ b/src/GraphicalUI/Settings.cpp @@ -30,7 +30,7 @@ void Settings::saveSettingsToFile() const { } -void Settings::createDefaultSettingsFile() const { +void Settings::resetSettingsFile() const { } @@ -50,6 +50,10 @@ bool Settings::canModifyCurrentKeybinds() const { return (this->chosenKeybinds == CUSTOMIZABLE_KEYBINDS); } +void Settings::setGamemode(Gamemode gamemode) { + this->gamemode = gamemode; +} + bool Settings::widenWindow() { if (this->windowSizeMode < WINDOW_SIZE_LAST_MODE) { this->windowSizeMode++; @@ -62,8 +66,36 @@ bool Settings::shortenWindow() { } } -void Settings::setGamemode(Gamemode gamemode) { - this->gamemode = gamemode; +void Settings::selectPieces(PiecesType type, int value) { + this->selectedPieces.emplace_back(type, value); +} + +void Settings::unselectPieces(int index) { + if (index >= this->selectedPieces.size()) return; + + this->selectedPieces.erase(this->selectedPieces.begin() + index); +} + +void Settings::confirmSelectedPieces() { + this->menu.getPiecesList().unselectAll(); + + for (const auto& [type, value] : this->selectedPieces) { + int size = getSizeOfPieces(type); + + if (size == 0) { + switch (type) { + case CONVEX : {this->menu.getPiecesList().selectConvexPieces(value); break;} + case HOLELESS : {this->menu.getPiecesList().selectHolelessPieces(value); break;} + case OTHERS : {this->menu.getPiecesList().selectOtherPieces(value); break;} + case ALL : {this->menu.getPiecesList().selectAllPieces(value); break;} + } + } + else { + if (size > 15) return; + + this->menu.getPiecesList().selectPiece(size, value); + } + } } Menu& Settings::getMenu() { @@ -85,3 +117,7 @@ int Settings::getWindowSizeMultiplier() const { const sf::VideoMode& Settings::getVideoMode() const { return sf::VideoMode(BASE_WINDOW_SIZE * (unsigned int) WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]); } + +const std::vector>& Settings::getSelectedPieces() const { + return this->selectedPieces; +} diff --git a/src/GraphicalUI/Settings.h b/src/GraphicalUI/Settings.h index fe7e4fa..5c01587 100644 --- a/src/GraphicalUI/Settings.h +++ b/src/GraphicalUI/Settings.h @@ -2,6 +2,7 @@ #include "../Core/Menu.h" #include "Keybinds.h" +#include "PiecesType.h" #include #include @@ -14,6 +15,7 @@ class Settings { int chosenKeybinds; Gamemode gamemode; int windowSizeMode; + std::vector> selectedPieces; public: Settings(); @@ -22,7 +24,7 @@ class Settings { void saveSettingsToFile() const; - void createDefaultSettingsFile() const; + void resetSettingsFile() const; bool selectNextKeybinds(); @@ -36,6 +38,12 @@ class Settings { bool shortenWindow(); + void selectPieces(PiecesType type, int value); + + void unselectPieces(int index); + + void confirmSelectedPieces(); + Menu& getMenu(); Keybinds& getKeybinds(); @@ -45,4 +53,6 @@ class Settings { int getWindowSizeMultiplier() const; const sf::VideoMode& getVideoMode() const; + + const std::vector>& getSelectedPieces() const; };