toujours plus de settings

This commit is contained in:
2025-03-22 10:49:55 +01:00
parent c25abec6ba
commit 0e17996c35
12 changed files with 78 additions and 9 deletions

View File

@@ -6,6 +6,9 @@
#include <memory>
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>(PiecesList());

View File

@@ -5,8 +5,7 @@
#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 MAXIMUM_PIECES_SIZE = 15; // the maximum size of available pieces
/**

View File

@@ -8,7 +8,7 @@
#include <memory>
#include <SFML/Graphics.hpp>
static const double TIME_BETWEEN_FRAMES = (1000.f / 60.f);
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
GraphApp::GraphApp() {

View File

@@ -20,7 +20,7 @@ class Keybinds {
void saveKeybindsToFile() const;
void createDefaultKeybindsFile() const;
void resetCustomLayoutFile() const;
void addKey(Action action, sfKey key);

View File

@@ -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);
}

View File

@@ -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<std::pair<PiecesType, int>>& Settings::getSelectedPieces() const {
return this->selectedPieces;
}

View File

@@ -2,6 +2,7 @@
#include "../Core/Menu.h"
#include "Keybinds.h"
#include "PiecesType.h"
#include <SFML/Graphics.hpp>
#include <vector>
@@ -14,6 +15,7 @@ class Settings {
int chosenKeybinds;
Gamemode gamemode;
int windowSizeMode;
std::vector<std::pair<PiecesType, int>> 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<std::pair<PiecesType, int>>& getSelectedPieces() const;
};