diff --git a/doc/files_format.md b/doc/files_format.md index 437b98d..bfbcb5a 100644 --- a/doc/files_format.md +++ b/doc/files_format.md @@ -38,6 +38,9 @@ _Repeat for every avaible actions._ The settings file has the following format: - The number of the chosen keybinds (from 0 to 4), stored with 1 byte +- The DAS of the player, stored with 1 byte +- The ARR of the player, stored with 1 byte +- The SDR of the player, stored with 1 byte - The window size mode, stored with 1 byte - The master volume, stored with 1 byte - The number of the last selected gamemode (converted from an Enum), stored with 1 byte diff --git a/src/Core/Menu.cpp b/src/Core/Menu.cpp index f76d05a..5302734 100644 --- a/src/Core/Menu.cpp +++ b/src/Core/Menu.cpp @@ -47,6 +47,14 @@ Player& Menu::getPlayerControls() { return this->playerControls; } +const Player& Menu::readPlayerControls() const { + return this->playerControls; +} + PiecesList& Menu::getPiecesList() { return *this->piecesList; } + +const PiecesList& Menu::readPiecesList() const { + return *this->piecesList; +} diff --git a/src/Core/Menu.h b/src/Core/Menu.h index aea2c96..74f180e 100644 --- a/src/Core/Menu.h +++ b/src/Core/Menu.h @@ -50,14 +50,24 @@ class Menu { * @return The height of the board */ int getBoardHeight() const; - + /** * @return A reference to the player's controls */ Player& getPlayerControls(); + + /** + * @return A reference to the player's controls + */ + const Player& readPlayerControls() const; /** * @return A reference to the pieces list */ PiecesList& getPiecesList(); + + /** + * @return A reference to the pieces list + */ + const PiecesList& readPiecesList() const; }; diff --git a/src/GraphicalUI/AppMenus/AppMenu.h b/src/GraphicalUI/AppMenus/AppMenu.h index fda18b2..4862cb8 100644 --- a/src/GraphicalUI/AppMenus/AppMenu.h +++ b/src/GraphicalUI/AppMenus/AppMenu.h @@ -1,9 +1,11 @@ #pragma once #include "../Settings.h" +#include "../PlayerCursor.h" #include #include +#include #include class AppMenu; @@ -19,6 +21,7 @@ class AppMenu { bool enterReleased = false; bool escPressed = false; bool escReleased = false; + sf::Font pressStartFont = sf::Font("data/fonts/pressstart/prstartk.ttf"); public: AppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow) : @@ -29,6 +32,11 @@ class AppMenu { } + virtual void computeFrame() = 0; + + virtual void drawFrame() const = 0; + + protected: void updateMetaBinds() { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter)) { enterPressed = true; @@ -49,15 +57,28 @@ class AppMenu { } } - virtual void computeFrame() = 0; + void placeText(sf::Text& text, const PlayerCursor& playerCursor, const sf::String& string, float xPos, float yPos, const sf::Vector2u& cursorPos) const { + float sizeMultiplier = this->settings->getWindowSizeMultiplier(); - virtual void drawFrame() const = 0; + text.setString(string); + text.setOutlineThickness((playerCursor.getPosition() == cursorPos) ? (sizeMultiplier / 2) : 0); + text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2})); + text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos})); + this->renderWindow->draw(text); + } + + void placeTitle(sf::Text& text, const std::optional& playerCursor, const sf::String& string, float yPos, const std::optional& cursorPos) const { + float sizeMultiplier = this->settings->getWindowSizeMultiplier(); + + text.setString(string); + if (playerCursor.has_value() && cursorPos.has_value()) { + text.setOutlineThickness((playerCursor.value().getPosition() == cursorPos.value()) ? (sizeMultiplier / 2) : 0); + } + else { + text.setOutlineThickness(0); + } + text.setOrigin(text.getLocalBounds().getCenter()); + text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos})); + this->renderWindow->draw(text); + } }; - - -inline void changeVideoMode(sf::RenderWindow& window, const sf::VideoMode& videoMode) { - window.create(videoMode, "jminos", sf::Style::Close | sf::Style::Titlebar); - sf::Vector2u desktopSize = sf::VideoMode::getDesktopMode().size; - sf::Vector2u windowSize = window.getSize(); - window.setPosition(sf::Vector2i((desktopSize.x / 2) - (windowSize.x / 2), (desktopSize.y / 2) - (windowSize.y / 2))); -} diff --git a/src/GraphicalUI/AppMenus/GameSettingsAppMenu.cpp b/src/GraphicalUI/AppMenus/GameSettingsAppMenu.cpp index 9133a5e..b4fdfb8 100644 --- a/src/GraphicalUI/AppMenus/GameSettingsAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GameSettingsAppMenu.cpp @@ -2,11 +2,12 @@ #include "AppMenu.h" #include "GamePlayingAppMenu.h" -#include "PlayerCursor.h" +#include "../PlayerCursor.h" #include #include #include +#include #include @@ -55,37 +56,21 @@ void GameSettingsAppMenu::computeFrame() { void GameSettingsAppMenu::drawFrame() const { this->renderWindow->clear(sf::Color(200, 200, 200)); - - sf::Font font("data/fonts/pressstart/prstartk.ttf"); - sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2); + sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2); text.setFillColor(sf::Color(0, 0, 0)); text.setOutlineColor(sf::Color(255, 255, 255)); - text.setString("GAME SETTINGS"); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({(float) this->settings->getWindowSizeMultiplier() * 40, (float) this->settings->getWindowSizeMultiplier() * 5})); - this->renderWindow->draw(text); + this->placeTitle(text, std::optional(), "GAME SETTINGS", 5.f, std::optional()); - this->placeText(text, "PIECES SELECT", 5.f, 15.f, 0, 0); - this->placeText(text, "BOARD SELECT", 40.f, 15.f, 1, 0); + this->placeText(text, this->playerCursor, "PIECES SELECT (TODO)", 5.f, 15.f, {0, 0}); + this->placeText(text, this->playerCursor, "BOARD SELECT (TODO)", 40.f, 15.f, {1, 0}); - this->placeText(text, "SPRINT", 5.f, 25.f, 0, 1); - this->placeText(text, "MARATHON", 25.f, 25.f, 1, 1); - this->placeText(text, "ULTRA", 50.f, 25.f, 2, 1); - this->placeText(text, "MASTER", 5.f, 35.f, 0, 2); - this->placeText(text, "TODO", 25.f, 35.f, 1, 2); - this->placeText(text, "TODO", 50.f, 35.f, 2, 2); + this->placeText(text, this->playerCursor, "SPRINT", 5.f, 25.f, {0, 1}); + this->placeText(text, this->playerCursor, "MARATHON", 25.f, 25.f, {1, 1}); + this->placeText(text, this->playerCursor, "ULTRA", 50.f, 25.f, {2, 1}); + this->placeText(text, this->playerCursor, "MASTER", 5.f, 35.f, {0, 2}); + this->placeText(text, this->playerCursor, "??? (TODO)", 25.f, 35.f, {1, 2}); + this->placeText(text, this->playerCursor, "??? (TODO)", 50.f, 35.f, {2, 2}); this->renderWindow->display(); } - -void GameSettingsAppMenu::placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const { - float sizeMultiplier = this->settings->getWindowSizeMultiplier(); - - text.setString(string); - text.setOutlineThickness((this->playerCursor.getPosition().x == xCursorOutline - && this->playerCursor.getPosition().y == yCursorOutline) ? (sizeMultiplier / 2) : 0); - text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2})); - text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos})); - this->renderWindow->draw(text); -} diff --git a/src/GraphicalUI/AppMenus/GameSettingsAppMenu.h b/src/GraphicalUI/AppMenus/GameSettingsAppMenu.h index f67002b..6dd4fb7 100644 --- a/src/GraphicalUI/AppMenus/GameSettingsAppMenu.h +++ b/src/GraphicalUI/AppMenus/GameSettingsAppMenu.h @@ -1,7 +1,7 @@ #pragma once #include "AppMenu.h" -#include "PlayerCursor.h" +#include "../PlayerCursor.h" #include #include @@ -18,6 +18,4 @@ class GameSettingsAppMenu : public AppMenu { void computeFrame() override; void drawFrame() const override; - - void placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const; }; diff --git a/src/GraphicalUI/AppMenus/MainAppMenu.cpp b/src/GraphicalUI/AppMenus/MainAppMenu.cpp index f017c75..8847ba4 100644 --- a/src/GraphicalUI/AppMenus/MainAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/MainAppMenu.cpp @@ -3,11 +3,12 @@ #include "AppMenu.h" #include "GameSettingsAppMenu.h" #include "SettingsMainAppMenu.h" -#include "PlayerCursor.h" +#include "../PlayerCursor.h" #include #include #include +#include #include @@ -42,33 +43,15 @@ void MainAppMenu::drawFrame() const { float sizeMultiplier = this->settings->getWindowSizeMultiplier(); - sf::Font font("data/fonts/pressstart/prstartk.ttf"); - sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2); + sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2); text.setFillColor(sf::Color(0, 0, 0)); text.setOutlineColor(sf::Color(255, 255, 255)); - text.setString("JMINOS"); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({sizeMultiplier * 40, sizeMultiplier * 10})); - this->renderWindow->draw(text); + this->placeTitle(text, std::optional(), "JMINOS", 10.f, std::optional()); - text.setString("PLAY"); - text.setOutlineThickness((this->playerCursor.getPosition().y == 0) ? (sizeMultiplier / 2) : 0); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({sizeMultiplier * 40, sizeMultiplier * 20})); - this->renderWindow->draw(text); - - text.setString("SETTINGS"); - text.setOutlineThickness((this->playerCursor.getPosition().y == 1) ? (sizeMultiplier / 2) : 0); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({sizeMultiplier * 40, sizeMultiplier * 30})); - this->renderWindow->draw(text); - - text.setString("INFO"); - text.setOutlineThickness((this->playerCursor.getPosition().y == 2) ? (sizeMultiplier / 2) : 0); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({sizeMultiplier * 40, sizeMultiplier * 40})); - this->renderWindow->draw(text); + this->placeTitle(text, this->playerCursor, "PLAY", 20.f, sf::Vector2u({0, 0})); + this->placeTitle(text, this->playerCursor, "SETTINGS", 30.f, sf::Vector2u({0, 1})); + this->placeTitle(text, this->playerCursor, "INFO (TODO)", 40.f, sf::Vector2u({0, 2})); this->renderWindow->display(); } diff --git a/src/GraphicalUI/AppMenus/MainAppMenu.h b/src/GraphicalUI/AppMenus/MainAppMenu.h index 6d2f925..0d90cbd 100644 --- a/src/GraphicalUI/AppMenus/MainAppMenu.h +++ b/src/GraphicalUI/AppMenus/MainAppMenu.h @@ -1,7 +1,7 @@ #pragma once #include "AppMenu.h" -#include "PlayerCursor.h" +#include "../PlayerCursor.h" #include #include diff --git a/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.cpp b/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.cpp new file mode 100644 index 0000000..2d4be51 --- /dev/null +++ b/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.cpp @@ -0,0 +1,77 @@ +#include "SettingsControlsAppMenu.h" + +#include "AppMenu.h" +#include "../PlayerCursor.h" + +#include +#include +#include +#include + + +SettingsControlsAppMenu::SettingsControlsAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow) : + AppMenu(menuStack, settings, renderWindow), + playerCursor(std::vector({1, 1, 1})) { + +} + +void SettingsControlsAppMenu::computeFrame() { + this->updateMetaBinds(); + this->playerCursor.updatePosition(); + + Player& playerControls = this->settings->getMenu().getPlayerControls(); + + switch (this->playerCursor.getPosition().y) { + case 0 : { + if (this->playerCursor.movedLeft()) { + playerControls.setDAS(playerControls.getDAS() - 1); + } + if (this->playerCursor.movedRight()) { + playerControls.setDAS(playerControls.getDAS() + 1); + } + break; + } + case 1 : { + if (this->playerCursor.movedLeft()) { + playerControls.setARR(playerControls.getARR() - 1); + } + if (this->playerCursor.movedRight()) { + playerControls.setARR(playerControls.getARR() + 1); + } + break; + } + case 2 : { + if (this->playerCursor.movedLeft()) { + playerControls.setSDR(playerControls.getSDR() - 1); + } + if (this->playerCursor.movedRight()) { + playerControls.setSDR(playerControls.getSDR() + 1); + } + break; + } + } + + if (this->escReleased) { + this->menuStack->pop(); + } +} + +void SettingsControlsAppMenu::drawFrame() const { + this->renderWindow->clear(sf::Color(200, 200, 200)); + + const Player& playerControls = this->settings->getMenu().readPlayerControls(); + + 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, std::optional(), "CONTROLS SETTINGS", 5.f, std::optional()); + + sf::Vector2u windowSize = this->renderWindow->getSize(); + + this->placeText(text, this->playerCursor, "< DAS: " + std::to_string(playerControls.getDAS()) + " >", 5.f, 15.f, {0, 0}); + this->placeText(text, this->playerCursor, "< ARR: " + std::to_string(playerControls.getARR()) + " >", 5.f, 25.f, {0, 1}); + this->placeText(text, this->playerCursor, "< SDR: " + std::to_string(playerControls.getSDR()) + " >", 5.f, 35.f, {0, 2}); + + this->renderWindow->display(); +} diff --git a/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.h b/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.h new file mode 100644 index 0000000..1973fa2 --- /dev/null +++ b/src/GraphicalUI/AppMenus/SettingsControlsAppMenu.h @@ -0,0 +1,21 @@ +#pragma once + +#include "AppMenu.h" +#include "../PlayerCursor.h" + +#include +#include +#include + + +class SettingsControlsAppMenu : public AppMenu { + private: + PlayerCursor playerCursor; + + public: + SettingsControlsAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow); + + void computeFrame() override; + + void drawFrame() const override; +}; diff --git a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp index 0822f7c..b131938 100644 --- a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp @@ -1,7 +1,8 @@ #include "SettingsMainAppMenu.h" #include "AppMenu.h" -#include "PlayerCursor.h" +#include "SettingsControlsAppMenu.h" +#include "../PlayerCursor.h" #include #include @@ -23,12 +24,12 @@ void SettingsMainAppMenu::computeFrame() { case 2 : { if (this->playerCursor.movedLeft()) { if (this->settings->shortenWindow()) { - changeVideoMode(*this->renderWindow, this->settings->getVideoMode()); + this->settings->changeVideoMode(*this->renderWindow); } } if (this->playerCursor.movedRight()) { if (this->settings->widenWindow()) { - changeVideoMode(*this->renderWindow, this->settings->getVideoMode()); + this->settings->changeVideoMode(*this->renderWindow); } } break; @@ -49,7 +50,7 @@ void SettingsMainAppMenu::computeFrame() { //TODO } if (this->playerCursor.getPosition().y == 1) { - //TODO + this->menuStack->push(std::make_shared(this->menuStack, this->settings, this->renderWindow)); } } if (this->escReleased) { @@ -60,33 +61,18 @@ void SettingsMainAppMenu::computeFrame() { void SettingsMainAppMenu::drawFrame() const { this->renderWindow->clear(sf::Color(200, 200, 200)); - sf::Font font("data/fonts/pressstart/prstartk.ttf"); - sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2); + sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2); text.setFillColor(sf::Color(0, 0, 0)); text.setOutlineColor(sf::Color(255, 255, 255)); - text.setString("SETTINGS"); - text.setOrigin(text.getLocalBounds().getCenter()); - text.setPosition(sf::Vector2f({(float) this->settings->getWindowSizeMultiplier() * 40, (float) this->settings->getWindowSizeMultiplier() * 5})); - this->renderWindow->draw(text); + this->placeTitle(text, std::optional(), "SETTINGS", 5.f, std::optional()); sf::Vector2u windowSize = this->renderWindow->getSize(); - this->placeText(text, "CHANGE KEYBINDS", 5.f, 15.f, 0, 0); - this->placeText(text, "CHANGE CONTROLS", 5.f, 25.f, 0, 1); - this->placeText(text, "WINDOW SIZE: " + std::to_string(windowSize.x) + "x" + std::to_string(windowSize.y), 5.f, 35.f, 0, 2); - this->placeText(text, "VOLUME: " + std::to_string(this->settings->getMasterVolume()) + "%", 5.f, 45.f, 0, 3); + this->placeText(text, this->playerCursor, "CHANGE KEYBINDS (TODO)", 5.f, 15.f, {0, 0}); + this->placeText(text, this->playerCursor, "CHANGE CONTROLS", 5.f, 25.f, {0, 1}); + this->placeText(text, this->playerCursor, "< WINDOW SIZE: " + std::to_string(windowSize.x) + "x" + std::to_string(windowSize.y) + " >", 5.f, 35.f, {0, 2}); + this->placeText(text, this->playerCursor, "< VOLUME: " + std::to_string(this->settings->getMasterVolume()) + "% >", 5.f, 45.f, {0, 3}); this->renderWindow->display(); } - -void SettingsMainAppMenu::placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const { - float sizeMultiplier = this->settings->getWindowSizeMultiplier(); - - text.setString(string); - text.setOutlineThickness((this->playerCursor.getPosition().x == xCursorOutline - && this->playerCursor.getPosition().y == yCursorOutline) ? (sizeMultiplier / 2) : 0); - text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2})); - text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos})); - this->renderWindow->draw(text); -} diff --git a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.h b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.h index 3ca9d22..9418730 100644 --- a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.h +++ b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.h @@ -1,7 +1,7 @@ #pragma once #include "AppMenu.h" -#include "PlayerCursor.h" +#include "../PlayerCursor.h" #include #include @@ -18,6 +18,4 @@ class SettingsMainAppMenu : public AppMenu { void computeFrame() override; void drawFrame() const override; - - void placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const; }; diff --git a/src/GraphicalUI/GraphApp.cpp b/src/GraphicalUI/GraphApp.cpp index 006d873..c802bcf 100644 --- a/src/GraphicalUI/GraphApp.cpp +++ b/src/GraphicalUI/GraphApp.cpp @@ -18,7 +18,7 @@ GraphApp::GraphApp() { } void GraphApp::run() { - changeVideoMode(*this->renderWindow, this->settings->getVideoMode()); + this->settings->changeVideoMode(*this->renderWindow); this->menuStack->push(std::make_shared(this->menuStack, this->settings, this->renderWindow)); bool quit = false; diff --git a/src/GraphicalUI/AppMenus/PlayerCursor.cpp b/src/GraphicalUI/PlayerCursor.cpp similarity index 98% rename from src/GraphicalUI/AppMenus/PlayerCursor.cpp rename to src/GraphicalUI/PlayerCursor.cpp index f145ab7..771f4f0 100644 --- a/src/GraphicalUI/AppMenus/PlayerCursor.cpp +++ b/src/GraphicalUI/PlayerCursor.cpp @@ -1,7 +1,7 @@ #include "PlayerCursor.h" -#include "../Keybinds.h" -#include "../Settings.h" +#include "Keybinds.h" +#include "Settings.h" #include #include diff --git a/src/GraphicalUI/AppMenus/PlayerCursor.h b/src/GraphicalUI/PlayerCursor.h similarity index 100% rename from src/GraphicalUI/AppMenus/PlayerCursor.h rename to src/GraphicalUI/PlayerCursor.h diff --git a/src/GraphicalUI/Settings.cpp b/src/GraphicalUI/Settings.cpp index 86b0752..b9539d7 100644 --- a/src/GraphicalUI/Settings.cpp +++ b/src/GraphicalUI/Settings.cpp @@ -33,6 +33,18 @@ void Settings::loadSettingsFromFile() { settingsFile.get(byte); this->chosenKeybinds = byte; + // DAS tuning + settingsFile.get(byte); + this->menu.getPlayerControls().setDAS(byte); + + // ARR tuning + settingsFile.get(byte); + this->menu.getPlayerControls().setARR(byte); + + // SDR tuning + settingsFile.get(byte); + this->menu.getPlayerControls().setSDR(byte); + // window size mode settingsFile.get(byte); this->windowSizeMode = byte; @@ -56,6 +68,12 @@ void Settings::loadSettingsFromFile() { // piece distribution settingsFile.get(byte); //TODO + if (byte == 2) { + for (int i = 1; i <= 15; i++) { + settingsFile.get(byte); + //TODO + } + } // selected pieces char pieceType; @@ -78,6 +96,18 @@ void Settings::saveSettingsToFile() const { byte = this->chosenKeybinds; settingsFile.write(&byte, 1); + // DAS tuning + byte = this->menu.readPlayerControls().getDAS(); + settingsFile.write(&byte, 1); + + // ARR tuning + byte = this->menu.readPlayerControls().getARR(); + settingsFile.write(&byte, 1); + + // SDR tuning + byte = this->menu.readPlayerControls().getSDR(); + settingsFile.write(&byte, 1); + // window size mode byte = this->windowSizeMode; settingsFile.write(&byte, 1); @@ -131,10 +161,6 @@ 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++; @@ -151,6 +177,15 @@ bool Settings::shortenWindow() { return false; } +void Settings::changeVideoMode(sf::RenderWindow& window) const { + sf::VideoMode videoMode(BASE_WINDOW_SIZE * (unsigned int) WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]); + window.create(videoMode, "jminos", sf::Style::Close | sf::Style::Titlebar); + + sf::Vector2u desktopSize = sf::VideoMode::getDesktopMode().size; + sf::Vector2u windowSize = window.getSize(); + window.setPosition(sf::Vector2i((desktopSize.x / 2) - (windowSize.x / 2), (desktopSize.y / 2) - (windowSize.y / 2))); +} + bool Settings::raiseMasterVolume() { if (this->masterVolume < 100) { this->masterVolume = std::min(this->masterVolume + 5, 100); @@ -167,6 +202,10 @@ bool Settings::lowerMasterVolume() { return false; } +void Settings::setGamemode(Gamemode gamemode) { + this->gamemode = gamemode; +} + void Settings::selectPieces(PiecesType type, int value) { this->selectedPieces.emplace_back(type, value); } @@ -219,10 +258,6 @@ int Settings::getMasterVolume() const { return this->masterVolume; } -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 46e22b2..082e7ca 100644 --- a/src/GraphicalUI/Settings.h +++ b/src/GraphicalUI/Settings.h @@ -23,9 +23,9 @@ class Settings { Menu menu; std::vector keybinds; int chosenKeybinds; - Gamemode gamemode; int windowSizeMode; int masterVolume; + Gamemode gamemode; std::vector> selectedPieces; public: @@ -41,16 +41,18 @@ class Settings { bool canModifyCurrentKeybinds() const; - void setGamemode(Gamemode gamemode); - bool widenWindow(); bool shortenWindow(); + void changeVideoMode(sf::RenderWindow& window) const; + bool raiseMasterVolume(); bool lowerMasterVolume(); + void setGamemode(Gamemode gamemode); + void selectPieces(PiecesType type, int value); void unselectPieces(int index); @@ -67,7 +69,5 @@ class Settings { int getMasterVolume() const; - const sf::VideoMode getVideoMode() const; - const std::vector>& getSelectedPieces() const; }; diff --git a/src/GraphicalUI/main.cpp b/src/GraphicalUI/main.cpp index 486fcaa..630c593 100644 --- a/src/GraphicalUI/main.cpp +++ b/src/GraphicalUI/main.cpp @@ -33,10 +33,12 @@ int main() { } } if (!std::filesystem::exists("data/config/settings.bin")) { + std::cout << "settings file not found, generating..." << std::endl; resetSettingsFile(); } - for (int i = 0; i < 5; i++) { + for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) { 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; resetKeybindFile(i); } } @@ -53,7 +55,7 @@ int main() { void resetConfigFiles() { resetSettingsFile; - for (int i = 0; i < 5; i++) { + for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) { resetKeybindFile(i); } } @@ -62,10 +64,24 @@ void resetSettingsFile() { std::ofstream settingsFile("data/config/settings.bin", std::ios::trunc | std::ios::binary); char byte; + Menu menu; + // keybind layout byte = 0; settingsFile.write(&byte, 1); + // DAS tuning + byte = menu.getPlayerControls().getDAS(); + settingsFile.write(&byte, 1); + + // ARR tuning + byte = menu.getPlayerControls().getARR(); + settingsFile.write(&byte, 1); + + // SDR tuning + byte = menu.getPlayerControls().getSDR(); + settingsFile.write(&byte, 1); + // window size mode byte = 2; settingsFile.write(&byte, 1); @@ -75,15 +91,15 @@ void resetSettingsFile() { settingsFile.write(&byte, 1); // gamemode - byte = SPRINT; + byte = Gamemode(0); settingsFile.write(&byte, 1); // board width - byte = 10; + byte = menu.getBoardWidth(); settingsFile.write(&byte, 1); // board height - byte = 20; + byte = menu.getBoardHeight(); settingsFile.write(&byte, 1); // piece distribution