Compare commits
2 Commits
1a95765877
...
d5ac79559e
| Author | SHA1 | Date | |
|---|---|---|---|
| d5ac79559e | |||
| 5ea47ddd25 |
@@ -37,6 +37,8 @@ _Repeat for every avaible actions._
|
|||||||
|
|
||||||
The settings file has the following format:
|
The settings file has the following format:
|
||||||
|
|
||||||
|
- The versions of the file format, stored with 1 byte
|
||||||
|
- The previous maximum pieces size selected, stored with 1 byte
|
||||||
- The number of the chosen keybinds (from 0 to 4), stored with 1 byte
|
- The number of the chosen keybinds (from 0 to 4), stored with 1 byte
|
||||||
- The DAS of the player, stored with 1 byte
|
- The DAS of the player, stored with 1 byte
|
||||||
- The ARR of the player, stored with 1 byte
|
- The ARR of the player, stored with 1 byte
|
||||||
@@ -47,8 +49,11 @@ The settings file has the following format:
|
|||||||
- The last selected width of the board, stored with 1 byte
|
- The last selected width of the board, stored with 1 byte
|
||||||
- The last selected height of the board, stored with 1 byte
|
- The last selected height of the board, stored with 1 byte
|
||||||
- The uniformity mode (0 for default distribution, 1 for uniformous distribution, 2 for custom distribution), stored with 1 byte
|
- The uniformity mode (0 for default distribution, 1 for uniformous distribution, 2 for custom distribution), stored with 1 byte
|
||||||
- For each size, store the custom proportion (from 0 to 10) (15x1 byte total)
|
- For each size, store the custom proportion (from 0 to 20) (15x1 byte total)
|
||||||
- Every selected pieces
|
- Every selected pieces
|
||||||
- For every groupe of piece (ALL, CONVEX, HOLELESS, OTHER), use 1 byte for the type (once again converted from an Enum) and 1 byte for the size
|
- For every groupe of piece (ALL, CONVEX, HOLELESS, OTHER), use 1 byte for the type (once again converted from an Enum) and 1 byte for the size
|
||||||
- For every single piece, use 1 byte for (the size + encoding that it is a single piece),
|
- For every single piece, use 1 byte for (the size + encoding that it is a single piece),
|
||||||
and 3 bytes to store the number of the piece (allows number up to 16M, size 15 has 6M pieces).
|
and 3 bytes to store the number of the piece (allows number up to 16M, size 15 has 6M pieces).
|
||||||
|
|
||||||
|
The current file format version is 10.
|
||||||
|
If the file starts with a number lower than that, it will be regenerated upon launching the game.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr<PiecesList>& piecesList, int nextQueueLength) :
|
GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr<PiecesList>& piecesList, int nextQueueLength) :
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
GameParameters::GameParameters(Gamemode gamemode, const Player& controls) :
|
GameParameters::GameParameters(Gamemode gamemode, const Player& controls) :
|
||||||
gamemode(gamemode),
|
gamemode(gamemode),
|
||||||
controls(controls) {
|
controls(controls) {
|
||||||
|
|
||||||
this->reset();
|
this->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,8 +120,6 @@ void GamePlayingAppMenu::drawFrame() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end coutdown
|
|
||||||
|
|
||||||
if (drawActivePiece) {
|
if (drawActivePiece) {
|
||||||
// ghost piece
|
// ghost piece
|
||||||
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
|
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
|
||||||
|
|||||||
74
src/GraphicalUI/AppMenus/StartUpAppMenu.cpp
Normal file
74
src/GraphicalUI/AppMenus/StartUpAppMenu.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#include "StartUpAppMenu.h"
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "MainAppMenu.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
StartUpAppMenu::StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
|
playerCursor({LOADED_PIECES_SIZE + 1}) {
|
||||||
|
|
||||||
|
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartUpAppMenu::computeFrame() {
|
||||||
|
this->updateMetaBinds();
|
||||||
|
this->playerCursor.updatePosition();
|
||||||
|
|
||||||
|
if (this->playerCursor.getPosition().x < MINIMUM_PIECES_SIZE) {
|
||||||
|
if (this->playerCursor.movedLeft()) {
|
||||||
|
this->playerCursor.goToPosition({LOADED_PIECES_SIZE, 0});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->enterReleased) {
|
||||||
|
*this->settings = Settings(this->playerCursor.getPosition().x);
|
||||||
|
this->menuStack->pop();
|
||||||
|
|
||||||
|
if (this->settings->hasLoadedPieces()) {
|
||||||
|
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "ERROR: COULD NOT LOAD PIECES" << std::endl;
|
||||||
|
std::cout << "ARGUMENT WAS: " << this->playerCursor.getPosition().x << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this->escReleased) {
|
||||||
|
this->menuStack->pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartUpAppMenu::drawFrame() const {
|
||||||
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||||
|
text.setFillColor(sf::Color(0, 0, 0));
|
||||||
|
text.setOutlineColor(sf::Color(255, 255, 255));
|
||||||
|
|
||||||
|
this->placeTitle(text, {}, "SELECT THE LOADED PIECES MAXIMUM SIZE", 10.f, {});
|
||||||
|
this->placeTitle(text, this->playerCursor, "< " + std::to_string(this->playerCursor.getPosition().x) + " >", 25.f, this->playerCursor.getPosition());
|
||||||
|
|
||||||
|
text.setOutlineColor({0, 0, 0});
|
||||||
|
if (this->playerCursor.getPosition().x <= 10) {
|
||||||
|
text.setFillColor({0, 255, 0});
|
||||||
|
this->placeTitle(text, {}, "LOW LOAD TIME", 40.f, {});
|
||||||
|
}
|
||||||
|
else if (this->playerCursor.getPosition().x <= 13) {
|
||||||
|
text.setFillColor({255, 255, 0});
|
||||||
|
this->placeTitle(text, {}, "MEDIUM LOAD TIME", 40.f, {});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text.setFillColor({255, 0, 0});
|
||||||
|
this->placeTitle(text, {}, "LONG LOAD TIME", 40.f, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
this->renderWindow->display();
|
||||||
|
}
|
||||||
21
src/GraphicalUI/AppMenus/StartUpAppMenu.h
Normal file
21
src/GraphicalUI/AppMenus/StartUpAppMenu.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class StartUpAppMenu : public AppMenu {
|
||||||
|
private:
|
||||||
|
PlayerCursor playerCursor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
StartUpAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
|
void computeFrame() override;
|
||||||
|
|
||||||
|
void drawFrame() const override;
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "GraphApp.h"
|
#include "GraphApp.h"
|
||||||
|
|
||||||
#include "AppMenus/AppMenu.h"
|
#include "AppMenus/AppMenu.h"
|
||||||
#include "AppMenus/MainAppMenu.h"
|
#include "AppMenus/StartUpAppMenu.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@@ -11,15 +11,15 @@
|
|||||||
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
||||||
|
|
||||||
|
|
||||||
GraphApp::GraphApp(int maximumPiecesSize) {
|
GraphApp::GraphApp() {
|
||||||
this->settings = std::make_shared<Settings>(maximumPiecesSize);
|
this->settings = std::make_shared<Settings>(0);
|
||||||
this->menuStack = std::make_shared<MenuStack>();
|
this->menuStack = std::make_shared<MenuStack>();
|
||||||
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
this->renderWindow = std::make_shared<sf::RenderWindow>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphApp::run() {
|
void GraphApp::run() {
|
||||||
this->settings->changeVideoMode(*this->renderWindow);
|
this->settings->changeVideoMode(*this->renderWindow);
|
||||||
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<StartUpAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
double timeAtNextFrame = 0;
|
double timeAtNextFrame = 0;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class GraphApp {
|
|||||||
std::shared_ptr<sf::RenderWindow> renderWindow;
|
std::shared_ptr<sf::RenderWindow> renderWindow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphApp(int maximumPiecesSize);
|
GraphApp();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include "../Core/Menu.h"
|
#include "../Core/Menu.h"
|
||||||
#include "Keybinds.h"
|
#include "Keybinds.h"
|
||||||
|
#include "PiecesType.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
@@ -11,27 +13,54 @@ static const sf::Vector2u BASE_WINDOW_SIZE = {80, 50};
|
|||||||
static const int WINDOW_SIZE_MULTIPLIERS[] = {4, 6, 10, 14, 20, 30, 40};
|
static const int WINDOW_SIZE_MULTIPLIERS[] = {4, 6, 10, 14, 20, 30, 40};
|
||||||
static const int WINDOW_SIZE_LAST_MODE = (sizeof(WINDOW_SIZE_MULTIPLIERS) / sizeof(int)) - 1;
|
static const int WINDOW_SIZE_LAST_MODE = (sizeof(WINDOW_SIZE_MULTIPLIERS) / sizeof(int)) - 1;
|
||||||
static const int START_TIMER_MAX = 4;
|
static const int START_TIMER_MAX = 4;
|
||||||
static const int DISTRIBUTION_MAX = 10;
|
static const int DISTRIBUTION_MAX = 20;
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings(int maximumPiecesSize) {
|
Settings::Settings(bool loadPieces) {
|
||||||
this->maximumPiecesSize = maximumPiecesSize;
|
|
||||||
for (int i = 1; i <= this->maximumPiecesSize; i++) {
|
|
||||||
this->menu.getPiecesList().loadPieces(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
|
this->keybinds.reserve(NUMBER_OF_KEYBINDS);
|
||||||
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
this->keybinds.emplace_back(i);
|
this->keybinds.emplace_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->loadSettingsFromFile();
|
this->loadSettingsFromFile(loadPieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::loadSettingsFromFile() {
|
bool Settings::loadPieces(int maximumPiecesSizeRequest) {
|
||||||
|
if (maximumPiecesSizeRequest < MINIMUM_PIECES_SIZE) {
|
||||||
|
maximumPiecesSizeRequest = MINIMUM_PIECES_SIZE;
|
||||||
|
}
|
||||||
|
else if (maximumPiecesSizeRequest > LOADED_PIECES_SIZE || maximumPiecesSizeRequest > MAXIMUM_PIECES_SIZE) {
|
||||||
|
maximumPiecesSizeRequest = LOADED_PIECES_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool succeeded = true;
|
||||||
|
int i = 1;
|
||||||
|
while (succeeded && (i <= maximumPiecesSizeRequest)) {
|
||||||
|
succeeded = this->menu.getPiecesList().loadPieces(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->maximumPiecesSize = (succeeded) ? maximumPiecesSizeRequest : 0;
|
||||||
|
return succeeded;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::loadSettingsFromFile(bool loadPieces) {
|
||||||
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
|
// file format version
|
||||||
|
settingsFile.get(byte);
|
||||||
|
|
||||||
|
// maximum pieces size
|
||||||
|
settingsFile.get(byte);
|
||||||
|
if (loadPieces) {
|
||||||
|
this->loadedPieces = this->loadPieces(byte);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->loadedPieces = false;
|
||||||
|
}
|
||||||
|
|
||||||
// keybind layout
|
// keybind layout
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->chosenKeybinds = byte;
|
this->chosenKeybinds = byte;
|
||||||
@@ -68,55 +97,71 @@ void Settings::loadSettingsFromFile() {
|
|||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->menu.setBoardHeight(byte);
|
this->menu.setBoardHeight(byte);
|
||||||
|
|
||||||
// piece distribution
|
if (this->loadedPieces) {
|
||||||
settingsFile.get(byte);
|
// piece distribution
|
||||||
this->menu.getPiecesList().setDistributionMode(DistributionMode(byte));
|
|
||||||
|
|
||||||
this->distributions.clear();
|
|
||||||
this->distributions.push_back(0);
|
|
||||||
for (int i = 1; i <= 15; i++) {
|
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->distributions.push_back(byte);
|
this->menu.getPiecesList().setDistributionMode(DistributionMode(byte));
|
||||||
}
|
|
||||||
this->confirmDistribution();
|
|
||||||
|
|
||||||
// selected pieces
|
this->distributions.clear();
|
||||||
char pieceType;
|
this->distributions.push_back(0);
|
||||||
char pieceSize;
|
for (int i = 1; i <= 15; i++) {
|
||||||
char lowByte;
|
settingsFile.get(byte);
|
||||||
char midByte;
|
this->distributions.push_back(byte);
|
||||||
char highByte;
|
}
|
||||||
|
this->confirmDistribution();
|
||||||
|
|
||||||
this->selectedPieces.clear();
|
// selected pieces
|
||||||
while (settingsFile.get(pieceType)) {
|
char pieceType;
|
||||||
if (settingsFile.eof()) break;
|
char pieceSize;
|
||||||
|
char lowByte;
|
||||||
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
char midByte;
|
||||||
settingsFile.get(pieceSize);
|
char highByte;
|
||||||
|
|
||||||
if (!(pieceSize > this->maximumPiecesSize)) {
|
this->selectedPieces.clear();
|
||||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
while (settingsFile.get(pieceType)) {
|
||||||
}
|
if (settingsFile.eof()) break;
|
||||||
}
|
|
||||||
else {
|
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
||||||
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
|
settingsFile.get(pieceSize);
|
||||||
settingsFile.get(lowByte);
|
|
||||||
settingsFile.get(midByte);
|
if (!(pieceSize > this->maximumPiecesSize)) {
|
||||||
settingsFile.get(highByte);
|
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
||||||
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
}
|
||||||
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
}
|
||||||
|
else {
|
||||||
|
if (!(getSizeOfPieces(PiecesType(pieceType)) > this->maximumPiecesSize)) {
|
||||||
|
settingsFile.get(lowByte);
|
||||||
|
settingsFile.get(midByte);
|
||||||
|
settingsFile.get(highByte);
|
||||||
|
int pieceNumber = ((unsigned char) lowByte) + ((unsigned char) midByte << 8) + ((unsigned char) highByte << 16);
|
||||||
|
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->confirmSelectedPieces();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->distributions.clear();
|
||||||
|
this->selectedPieces.clear();
|
||||||
}
|
}
|
||||||
this->confirmSelectedPieces();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::saveSettingsToFile() const {
|
void Settings::saveSettingsToFile() const {
|
||||||
|
if (!this->loadedPieces) return;
|
||||||
|
|
||||||
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
this->keybinds.at(CUSTOMIZABLE_KEYBINDS).saveKeybindsToFile();
|
||||||
|
|
||||||
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary);
|
std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary);
|
||||||
char byte;
|
char byte;
|
||||||
|
|
||||||
|
// file format version
|
||||||
|
byte = CURRENT_FILE_FORMAT_VERSION;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
|
// maximum pieces size
|
||||||
|
byte = this->maximumPiecesSize;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// keybind layout
|
// keybind layout
|
||||||
byte = this->chosenKeybinds;
|
byte = this->chosenKeybinds;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
@@ -247,16 +292,21 @@ void Settings::setGamemode(Gamemode gamemode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Settings::selectPieces(PiecesType type, int value) {
|
void Settings::selectPieces(PiecesType type, int value) {
|
||||||
|
if (!this->loadedPieces) return;
|
||||||
|
|
||||||
this->selectedPieces.emplace_back(type, value);
|
this->selectedPieces.emplace_back(type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::unselectPieces(int index) {
|
void Settings::unselectPieces(int index) {
|
||||||
|
if (!this->loadedPieces) return;
|
||||||
if (index >= this->selectedPieces.size()) return;
|
if (index >= this->selectedPieces.size()) return;
|
||||||
|
|
||||||
this->selectedPieces.erase(this->selectedPieces.begin() + index);
|
this->selectedPieces.erase(this->selectedPieces.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::confirmSelectedPieces() {
|
void Settings::confirmSelectedPieces() {
|
||||||
|
if (!this->loadedPieces) return;
|
||||||
|
|
||||||
this->menu.getPiecesList().unselectAll();
|
this->menu.getPiecesList().unselectAll();
|
||||||
|
|
||||||
if (this->getSelectedPieces().size() == 0) {
|
if (this->getSelectedPieces().size() == 0) {
|
||||||
@@ -281,6 +331,7 @@ void Settings::confirmSelectedPieces() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::increaseDistribution(int size) {
|
bool Settings::increaseDistribution(int size) {
|
||||||
|
if (!this->loadedPieces) return false;
|
||||||
if (size < 1 || size > this->maximumPiecesSize) return false;
|
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||||
|
|
||||||
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
||||||
@@ -291,6 +342,7 @@ bool Settings::increaseDistribution(int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::decreaseDistribution(int size) {
|
bool Settings::decreaseDistribution(int size) {
|
||||||
|
if (!this->loadedPieces) return false;
|
||||||
if (size < 1 || size > this->maximumPiecesSize) return false;
|
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||||
|
|
||||||
if (this->distributions.at(size) > 0) {
|
if (this->distributions.at(size) > 0) {
|
||||||
@@ -301,6 +353,8 @@ bool Settings::decreaseDistribution(int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Settings::confirmDistribution() {
|
void Settings::confirmDistribution() {
|
||||||
|
if (!this->loadedPieces) return;
|
||||||
|
|
||||||
for (int i = 1; i <= 15; i++) {
|
for (int i = 1; i <= 15; i++) {
|
||||||
this->menu.getPiecesList().changeCustomDistribution(i, (double) 1 / (this->distributions.at(i) + 0.001));
|
this->menu.getPiecesList().changeCustomDistribution(i, (double) 1 / (this->distributions.at(i) + 0.001));
|
||||||
}
|
}
|
||||||
@@ -318,6 +372,10 @@ int Settings::getMaximumPiecesSize() const {
|
|||||||
return this->maximumPiecesSize;
|
return this->maximumPiecesSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Settings::hasLoadedPieces() const {
|
||||||
|
return this->loadedPieces;
|
||||||
|
}
|
||||||
|
|
||||||
int Settings::getKeybindsLayout() const {
|
int Settings::getKeybindsLayout() const {
|
||||||
return this->chosenKeybinds;
|
return this->chosenKeybinds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Core/Menu.h"
|
#include "../Core/Menu.h"
|
||||||
#include "StartUpMenu.h"
|
|
||||||
#include "Keybinds.h"
|
#include "Keybinds.h"
|
||||||
#include "PiecesType.h"
|
#include "PiecesType.h"
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
static const int CURRENT_FILE_FORMAT_VERSION = 10;
|
||||||
|
|
||||||
static const int MAXIMUM_BOARD_WIDTH = 40;
|
static const int MAXIMUM_BOARD_WIDTH = 40;
|
||||||
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
static const int MAXIMUM_BOARD_HEIGHT = 40;
|
||||||
|
|
||||||
|
static const int MINIMUM_PIECES_SIZE = 4;
|
||||||
|
static const int MAXIMUM_PIECES_SIZE = 15;
|
||||||
|
|
||||||
|
//#define __JMINOS_RELEASE__
|
||||||
|
#ifdef __JMINOS_RELEASE__
|
||||||
|
static const int LOADED_PIECES_SIZE = 15;
|
||||||
|
#else
|
||||||
|
static const int LOADED_PIECES_SIZE = 10;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
private:
|
private:
|
||||||
Menu menu;
|
Menu menu;
|
||||||
int maximumPiecesSize;
|
int maximumPiecesSize;
|
||||||
|
bool loadedPieces;
|
||||||
std::vector<Keybinds> keybinds;
|
std::vector<Keybinds> keybinds;
|
||||||
int chosenKeybinds;
|
int chosenKeybinds;
|
||||||
int windowSizeMode;
|
int windowSizeMode;
|
||||||
@@ -25,9 +39,13 @@ class Settings {
|
|||||||
std::vector<int> distributions;
|
std::vector<int> distributions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Settings(int maximumPiecesSize);
|
Settings(bool loadPieces);
|
||||||
|
|
||||||
void loadSettingsFromFile();
|
private:
|
||||||
|
bool loadPieces(int maximumPiecesSizeRequest);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void loadSettingsFromFile(bool loadPieces = true);
|
||||||
|
|
||||||
void saveSettingsToFile() const;
|
void saveSettingsToFile() const;
|
||||||
|
|
||||||
@@ -67,6 +85,8 @@ class Settings {
|
|||||||
|
|
||||||
int getMaximumPiecesSize() const;
|
int getMaximumPiecesSize() const;
|
||||||
|
|
||||||
|
bool hasLoadedPieces() const;
|
||||||
|
|
||||||
int getKeybindsLayout() const;
|
int getKeybindsLayout() const;
|
||||||
|
|
||||||
Gamemode getGamemode() const;
|
Gamemode getGamemode() const;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
#include "StartUpMenu.h"
|
|
||||||
|
|
||||||
#include "PlayerCursor.h"
|
|
||||||
|
|
||||||
|
|
||||||
StartUpMenu::StartUpMenu() :
|
|
||||||
playerCursor({LOADED_PIECES_SIZE}) {
|
|
||||||
|
|
||||||
this->playerCursor.goToPosition({MINIMUM_PIECES_SIZE, 0});
|
|
||||||
}
|
|
||||||
|
|
||||||
int StartUpMenu::getMaximumPiecesSize() {
|
|
||||||
return LOADED_PIECES_SIZE;
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "PiecesType.h"
|
|
||||||
#include "PlayerCursor.h"
|
|
||||||
|
|
||||||
|
|
||||||
static const int MINIMUM_PIECES_SIZE = 4;
|
|
||||||
static const int MAXIMUM_PIECES_SIZE = 15;
|
|
||||||
|
|
||||||
//#define __JMINOS_RELEASE__
|
|
||||||
#ifdef __JMINOS_RELEASE__
|
|
||||||
static const int LOADED_PIECES_SIZE = 15;
|
|
||||||
#else
|
|
||||||
static const int LOADED_PIECES_SIZE = 10;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const std::pair<PiecesType, int> DEFAULT_SELECTION = {ALL_PIECES, MINIMUM_PIECES_SIZE};
|
|
||||||
|
|
||||||
|
|
||||||
class StartUpMenu {
|
|
||||||
private:
|
|
||||||
PlayerCursor playerCursor;
|
|
||||||
|
|
||||||
public:
|
|
||||||
StartUpMenu();
|
|
||||||
|
|
||||||
int getMaximumPiecesSize();
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#include "StartUpMenu.h"
|
|
||||||
#include "GraphApp.h"
|
#include "GraphApp.h"
|
||||||
#include "../Pieces/PiecesFiles.h"
|
#include "../Pieces/PiecesFiles.h"
|
||||||
|
|
||||||
@@ -20,10 +19,21 @@ int main() {
|
|||||||
pf.savePieces(i);
|
pf.savePieces(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists("data/config/settings.bin")) {
|
if (!std::filesystem::exists("data/config/settings.bin")) {
|
||||||
std::cout << "settings file not found, generating..." << std::endl;
|
std::cout << "settings file not found, generating..." << std::endl;
|
||||||
resetSettingsFile();
|
resetSettingsFile();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
std::ifstream settingsFile("data/config/settings.bin", std::ios::binary);
|
||||||
|
char byte;
|
||||||
|
|
||||||
|
settingsFile.get(byte);
|
||||||
|
if ((unsigned char) byte < CURRENT_FILE_FORMAT_VERSION) {
|
||||||
|
resetSettingsFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
|
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
|
||||||
std::cout << "keybind file n°" << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
std::cout << "keybind file n°" << (i + 1) << "/" << NUMBER_OF_KEYBINDS << " not found, generating..." << std::endl;
|
||||||
@@ -31,10 +41,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StartUpMenu startUp;
|
GraphApp UI;
|
||||||
int maximumPiecesSize = startUp.getMaximumPiecesSize();
|
|
||||||
|
|
||||||
GraphApp UI(maximumPiecesSize);
|
|
||||||
UI.run();
|
UI.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -47,6 +54,14 @@ void resetSettingsFile() {
|
|||||||
|
|
||||||
Menu menu;
|
Menu menu;
|
||||||
|
|
||||||
|
// file format version
|
||||||
|
byte = CURRENT_FILE_FORMAT_VERSION;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
|
// maximum pieces size
|
||||||
|
byte = MINIMUM_PIECES_SIZE;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// keybind layout
|
// keybind layout
|
||||||
byte = 0;
|
byte = 0;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user