Compare commits
2 Commits
f4b58fb67e
...
1a95765877
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a95765877 | |||
| 6bff555cbc |
@@ -48,4 +48,7 @@ The settings file has the following format:
|
|||||||
- 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 10) (15x1 byte total)
|
||||||
- Every selected pieces, using 1 byte for the type of selection (once again converted from an Enum) and 1 byte for the actual value
|
- 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 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).
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ GameDistributionAppMenu::GameDistributionAppMenu(std::shared_ptr<MenuStack> menu
|
|||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
playerCursor({1}) {
|
playerCursor({1}) {
|
||||||
|
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
|
||||||
this->playerCursor.addRow(i, 1);
|
this->playerCursor.addRow(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ void GameDistributionAppMenu::drawFrame() const {
|
|||||||
const DistributionMode distributionMode = this->settings->getMenu().readPiecesList().getDistributionMode();
|
const DistributionMode distributionMode = this->settings->getMenu().readPiecesList().getDistributionMode();
|
||||||
const std::vector<int>& distributions = this->settings->getDistributions();
|
const std::vector<int>& distributions = this->settings->getDistributions();
|
||||||
|
|
||||||
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, MAXIMUM_PIECES_SIZE - 3);
|
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 1, 0, this->settings->getMaximumPiecesSize() - 3);
|
||||||
if (firstElem == 0) {
|
if (firstElem == 0) {
|
||||||
this->placeText(text, this->playerCursor, "< DISTRIBUTION MODE: " + getPiecesDistributionName(distributionMode) + " >", 5.f, 15.f, sf::Vector2u{0, 0});
|
this->placeText(text, this->playerCursor, "< DISTRIBUTION MODE: " + getPiecesDistributionName(distributionMode) + " >", 5.f, 15.f, sf::Vector2u{0, 0});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::
|
|||||||
AppMenu(menuStack, settings, renderWindow),
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) {
|
playerCursor({1, (unsigned int) this->settings->getSelectedPieces().size() + 1u}) {
|
||||||
|
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
for (int i = 1; i <= this->settings->getMaximumPiecesSize(); i++) {
|
||||||
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
this->playerCursor.addRow(i + 1, this->settings->getMenu().readPiecesList().getNumberOfPieces(i) + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,11 +53,7 @@ void GamePiecesAppMenu::computeFrame() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this->settings->getSelectedPieces().size() == 0) {
|
|
||||||
this->settings->selectPieces(ALL_PIECES, 4);
|
|
||||||
}
|
|
||||||
this->settings->confirmSelectedPieces();
|
this->settings->confirmSelectedPieces();
|
||||||
|
|
||||||
this->menuStack->pop();
|
this->menuStack->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +78,7 @@ void GamePiecesAppMenu::drawFrame() const {
|
|||||||
this->drawSelectedPiecesRow(15.f);
|
this->drawSelectedPiecesRow(15.f);
|
||||||
|
|
||||||
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
|
bool drawFromFirstElem = (this->playerCursor.getPosition().y == 1);
|
||||||
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, MAXIMUM_PIECES_SIZE - 2);
|
int firstElem = std::clamp(((int) this->playerCursor.getPosition().y) - 2, 1, this->settings->getMaximumPiecesSize() - 2);
|
||||||
this->drawRow(firstElem, 25.f, drawFromFirstElem);
|
this->drawRow(firstElem, 25.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
|
this->drawRow(firstElem + 1, 35.f, drawFromFirstElem);
|
||||||
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
|
this->drawRow(firstElem + 2, 45.f, drawFromFirstElem);
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
static const double TIME_BETWEEN_FRAMES = (1000.f / FRAMES_PER_SECOND);
|
||||||
|
|
||||||
|
|
||||||
GraphApp::GraphApp() {
|
GraphApp::GraphApp(int maximumPiecesSize) {
|
||||||
this->settings = std::make_shared<Settings>();
|
this->settings = std::make_shared<Settings>(maximumPiecesSize);
|
||||||
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>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class GraphApp {
|
|||||||
std::shared_ptr<sf::RenderWindow> renderWindow;
|
std::shared_ptr<sf::RenderWindow> renderWindow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphApp();
|
GraphApp(int maximumPiecesSize);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ static const int START_TIMER_MAX = 4;
|
|||||||
static const int DISTRIBUTION_MAX = 10;
|
static const int DISTRIBUTION_MAX = 10;
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings() {
|
Settings::Settings(int maximumPiecesSize) {
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
this->maximumPiecesSize = maximumPiecesSize;
|
||||||
|
for (int i = 1; i <= this->maximumPiecesSize; i++) {
|
||||||
this->menu.getPiecesList().loadPieces(i);
|
this->menu.getPiecesList().loadPieces(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,13 +82,31 @@ void Settings::loadSettingsFromFile() {
|
|||||||
|
|
||||||
// selected pieces
|
// selected pieces
|
||||||
char pieceType;
|
char pieceType;
|
||||||
char pieceValue;
|
char pieceSize;
|
||||||
|
char lowByte;
|
||||||
|
char midByte;
|
||||||
|
char highByte;
|
||||||
|
|
||||||
this->selectedPieces.clear();
|
this->selectedPieces.clear();
|
||||||
while (settingsFile.get(pieceType)) {
|
while (settingsFile.get(pieceType)) {
|
||||||
if (settingsFile.eof()) break;
|
if (settingsFile.eof()) break;
|
||||||
|
|
||||||
settingsFile.get(pieceValue);
|
if (getSizeOfPieces(PiecesType(pieceType)) == 0) {
|
||||||
this->selectedPieces.push_back({PiecesType(pieceType), pieceValue});
|
settingsFile.get(pieceSize);
|
||||||
|
|
||||||
|
if (!(pieceSize > this->maximumPiecesSize)) {
|
||||||
|
this->selectedPieces.emplace_back(PiecesType(pieceType), pieceSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
this->confirmSelectedPieces();
|
||||||
}
|
}
|
||||||
@@ -147,8 +166,18 @@ void Settings::saveSettingsToFile() const {
|
|||||||
for (const auto& [type, value] : this->selectedPieces) {
|
for (const auto& [type, value] : this->selectedPieces) {
|
||||||
byte = type;
|
byte = type;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
byte = value;
|
if (getSizeOfPieces(type) == 0) {
|
||||||
settingsFile.write(&byte, 1);
|
byte = value;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int number = value;
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
byte = (number % 256);
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
number = (number >> 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,6 +259,10 @@ void Settings::unselectPieces(int index) {
|
|||||||
void Settings::confirmSelectedPieces() {
|
void Settings::confirmSelectedPieces() {
|
||||||
this->menu.getPiecesList().unselectAll();
|
this->menu.getPiecesList().unselectAll();
|
||||||
|
|
||||||
|
if (this->getSelectedPieces().size() == 0) {
|
||||||
|
this->selectedPieces.push_back(DEFAULT_SELECTION);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& [type, value] : this->selectedPieces) {
|
for (const auto& [type, value] : this->selectedPieces) {
|
||||||
int size = getSizeOfPieces(type);
|
int size = getSizeOfPieces(type);
|
||||||
|
|
||||||
@@ -242,15 +275,13 @@ void Settings::confirmSelectedPieces() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (size > MAXIMUM_PIECES_SIZE) return;
|
|
||||||
|
|
||||||
this->menu.getPiecesList().selectPiece(size, value);
|
this->menu.getPiecesList().selectPiece(size, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::increaseDistribution(int size) {
|
bool Settings::increaseDistribution(int size) {
|
||||||
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
|
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||||
|
|
||||||
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
if (this->distributions.at(size) < DISTRIBUTION_MAX) {
|
||||||
this->distributions.at(size)++;
|
this->distributions.at(size)++;
|
||||||
@@ -260,7 +291,7 @@ bool Settings::increaseDistribution(int size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::decreaseDistribution(int size) {
|
bool Settings::decreaseDistribution(int size) {
|
||||||
if (size < 1 || size > MAXIMUM_PIECES_SIZE) return false;
|
if (size < 1 || size > this->maximumPiecesSize) return false;
|
||||||
|
|
||||||
if (this->distributions.at(size) > 0) {
|
if (this->distributions.at(size) > 0) {
|
||||||
this->distributions.at(size)--;
|
this->distributions.at(size)--;
|
||||||
@@ -283,6 +314,10 @@ Keybinds& Settings::getKeybinds() {
|
|||||||
return this->keybinds.at(this->chosenKeybinds);
|
return this->keybinds.at(this->chosenKeybinds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Settings::getMaximumPiecesSize() const {
|
||||||
|
return this->maximumPiecesSize;
|
||||||
|
}
|
||||||
|
|
||||||
int Settings::getKeybindsLayout() const {
|
int Settings::getKeybindsLayout() const {
|
||||||
return this->chosenKeybinds;
|
return this->chosenKeybinds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#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"
|
||||||
|
|
||||||
@@ -10,17 +11,11 @@
|
|||||||
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;
|
||||||
|
|
||||||
//#define __JMINOS_RELEASE__
|
|
||||||
#ifdef __JMINOS_RELEASE__
|
|
||||||
static const int MAXIMUM_PIECES_SIZE = 15;
|
|
||||||
#else
|
|
||||||
static const int MAXIMUM_PIECES_SIZE = 10;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
private:
|
private:
|
||||||
Menu menu;
|
Menu menu;
|
||||||
|
int maximumPiecesSize;
|
||||||
std::vector<Keybinds> keybinds;
|
std::vector<Keybinds> keybinds;
|
||||||
int chosenKeybinds;
|
int chosenKeybinds;
|
||||||
int windowSizeMode;
|
int windowSizeMode;
|
||||||
@@ -30,7 +25,7 @@ class Settings {
|
|||||||
std::vector<int> distributions;
|
std::vector<int> distributions;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Settings();
|
Settings(int maximumPiecesSize);
|
||||||
|
|
||||||
void loadSettingsFromFile();
|
void loadSettingsFromFile();
|
||||||
|
|
||||||
@@ -70,6 +65,8 @@ class Settings {
|
|||||||
|
|
||||||
Keybinds& getKeybinds();
|
Keybinds& getKeybinds();
|
||||||
|
|
||||||
|
int getMaximumPiecesSize() const;
|
||||||
|
|
||||||
int getKeybindsLayout() const;
|
int getKeybindsLayout() const;
|
||||||
|
|
||||||
Gamemode getGamemode() const;
|
Gamemode getGamemode() const;
|
||||||
|
|||||||
15
src/GraphicalUI/StartUpMenu.cpp
Normal file
15
src/GraphicalUI/StartUpMenu.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#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
|
||||||
|
}
|
||||||
28
src/GraphicalUI/StartUpMenu.h
Normal file
28
src/GraphicalUI/StartUpMenu.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#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,3 +1,4 @@
|
|||||||
|
#include "StartUpMenu.h"
|
||||||
#include "GraphApp.h"
|
#include "GraphApp.h"
|
||||||
#include "../Pieces/PiecesFiles.h"
|
#include "../Pieces/PiecesFiles.h"
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ int main() {
|
|||||||
std::srand(std::time(NULL));
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
PiecesFiles pf;
|
PiecesFiles pf;
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
for (int i = 1; i <= LOADED_PIECES_SIZE; i++) {
|
||||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||||
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
||||||
pf.savePieces(i);
|
pf.savePieces(i);
|
||||||
@@ -30,7 +31,10 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphApp UI;
|
StartUpMenu startUp;
|
||||||
|
int maximumPiecesSize = startUp.getMaximumPiecesSize();
|
||||||
|
|
||||||
|
GraphApp UI(maximumPiecesSize);
|
||||||
UI.run();
|
UI.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user