refactoring
This commit is contained in:
@@ -38,6 +38,9 @@ _Repeat for every avaible actions._
|
|||||||
The settings file has the following format:
|
The settings file has the following format:
|
||||||
|
|
||||||
- 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 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 window size mode, stored with 1 byte
|
||||||
- The master volume, 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
|
- The number of the last selected gamemode (converted from an Enum), stored with 1 byte
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ Player& Menu::getPlayerControls() {
|
|||||||
return this->playerControls;
|
return this->playerControls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Player& Menu::readPlayerControls() const {
|
||||||
|
return this->playerControls;
|
||||||
|
}
|
||||||
|
|
||||||
PiecesList& Menu::getPiecesList() {
|
PiecesList& Menu::getPiecesList() {
|
||||||
return *this->piecesList;
|
return *this->piecesList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PiecesList& Menu::readPiecesList() const {
|
||||||
|
return *this->piecesList;
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,8 +56,18 @@ class Menu {
|
|||||||
*/
|
*/
|
||||||
Player& getPlayerControls();
|
Player& getPlayerControls();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A reference to the player's controls
|
||||||
|
*/
|
||||||
|
const Player& readPlayerControls() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A reference to the pieces list
|
* @return A reference to the pieces list
|
||||||
*/
|
*/
|
||||||
PiecesList& getPiecesList();
|
PiecesList& getPiecesList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A reference to the pieces list
|
||||||
|
*/
|
||||||
|
const PiecesList& readPiecesList() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Settings.h"
|
#include "../Settings.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
class AppMenu;
|
class AppMenu;
|
||||||
@@ -19,6 +21,7 @@ class AppMenu {
|
|||||||
bool enterReleased = false;
|
bool enterReleased = false;
|
||||||
bool escPressed = false;
|
bool escPressed = false;
|
||||||
bool escReleased = false;
|
bool escReleased = false;
|
||||||
|
sf::Font pressStartFont = sf::Font("data/fonts/pressstart/prstartk.ttf");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
@@ -29,6 +32,11 @@ class AppMenu {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void computeFrame() = 0;
|
||||||
|
|
||||||
|
virtual void drawFrame() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
void updateMetaBinds() {
|
void updateMetaBinds() {
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter)) {
|
||||||
enterPressed = true;
|
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>& playerCursor, const sf::String& string, float yPos, const std::optional<sf::Vector2u>& 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)));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "GamePlayingAppMenu.h"
|
#include "GamePlayingAppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -55,37 +56,21 @@ void GameSettingsAppMenu::computeFrame() {
|
|||||||
void GameSettingsAppMenu::drawFrame() const {
|
void GameSettingsAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color(200, 200, 200));
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||||
sf::Font font("data/fonts/pressstart/prstartk.ttf");
|
|
||||||
sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2);
|
|
||||||
text.setFillColor(sf::Color(0, 0, 0));
|
text.setFillColor(sf::Color(0, 0, 0));
|
||||||
text.setOutlineColor(sf::Color(255, 255, 255));
|
text.setOutlineColor(sf::Color(255, 255, 255));
|
||||||
|
|
||||||
text.setString("GAME SETTINGS");
|
this->placeTitle(text, std::optional<PlayerCursor>(), "GAME SETTINGS", 5.f, std::optional<sf::Vector2u>());
|
||||||
text.setOrigin(text.getLocalBounds().getCenter());
|
|
||||||
text.setPosition(sf::Vector2f({(float) this->settings->getWindowSizeMultiplier() * 40, (float) this->settings->getWindowSizeMultiplier() * 5}));
|
|
||||||
this->renderWindow->draw(text);
|
|
||||||
|
|
||||||
this->placeText(text, "PIECES SELECT", 5.f, 15.f, 0, 0);
|
this->placeText(text, this->playerCursor, "PIECES SELECT (TODO)", 5.f, 15.f, {0, 0});
|
||||||
this->placeText(text, "BOARD SELECT", 40.f, 15.f, 1, 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, this->playerCursor, "SPRINT", 5.f, 25.f, {0, 1});
|
||||||
this->placeText(text, "MARATHON", 25.f, 25.f, 1, 1);
|
this->placeText(text, this->playerCursor, "MARATHON", 25.f, 25.f, {1, 1});
|
||||||
this->placeText(text, "ULTRA", 50.f, 25.f, 2, 1);
|
this->placeText(text, this->playerCursor, "ULTRA", 50.f, 25.f, {2, 1});
|
||||||
this->placeText(text, "MASTER", 5.f, 35.f, 0, 2);
|
this->placeText(text, this->playerCursor, "MASTER", 5.f, 35.f, {0, 2});
|
||||||
this->placeText(text, "TODO", 25.f, 35.f, 1, 2);
|
this->placeText(text, this->playerCursor, "??? (TODO)", 25.f, 35.f, {1, 2});
|
||||||
this->placeText(text, "TODO", 50.f, 35.f, 2, 2);
|
this->placeText(text, this->playerCursor, "??? (TODO)", 50.f, 35.f, {2, 2});
|
||||||
|
|
||||||
this->renderWindow->display();
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -18,6 +18,4 @@ class GameSettingsAppMenu : public AppMenu {
|
|||||||
void computeFrame() override;
|
void computeFrame() override;
|
||||||
|
|
||||||
void drawFrame() const 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;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "GameSettingsAppMenu.h"
|
#include "GameSettingsAppMenu.h"
|
||||||
#include "SettingsMainAppMenu.h"
|
#include "SettingsMainAppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <optional>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -42,33 +43,15 @@ void MainAppMenu::drawFrame() const {
|
|||||||
|
|
||||||
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
float sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
||||||
|
|
||||||
sf::Font font("data/fonts/pressstart/prstartk.ttf");
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||||
sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2);
|
|
||||||
text.setFillColor(sf::Color(0, 0, 0));
|
text.setFillColor(sf::Color(0, 0, 0));
|
||||||
text.setOutlineColor(sf::Color(255, 255, 255));
|
text.setOutlineColor(sf::Color(255, 255, 255));
|
||||||
|
|
||||||
text.setString("JMINOS");
|
this->placeTitle(text, std::optional<PlayerCursor>(), "JMINOS", 10.f, std::optional<sf::Vector2u>());
|
||||||
text.setOrigin(text.getLocalBounds().getCenter());
|
|
||||||
text.setPosition(sf::Vector2f({sizeMultiplier * 40, sizeMultiplier * 10}));
|
|
||||||
this->renderWindow->draw(text);
|
|
||||||
|
|
||||||
text.setString("PLAY");
|
this->placeTitle(text, this->playerCursor, "PLAY", 20.f, sf::Vector2u({0, 0}));
|
||||||
text.setOutlineThickness((this->playerCursor.getPosition().y == 0) ? (sizeMultiplier / 2) : 0);
|
this->placeTitle(text, this->playerCursor, "SETTINGS", 30.f, sf::Vector2u({0, 1}));
|
||||||
text.setOrigin(text.getLocalBounds().getCenter());
|
this->placeTitle(text, this->playerCursor, "INFO (TODO)", 40.f, sf::Vector2u({0, 2}));
|
||||||
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->renderWindow->display();
|
this->renderWindow->display();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
77
src/GraphicalUI/AppMenus/SettingsControlsAppMenu.cpp
Normal file
77
src/GraphicalUI/AppMenus/SettingsControlsAppMenu.cpp
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#include "SettingsControlsAppMenu.h"
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
SettingsControlsAppMenu::SettingsControlsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
|
||||||
|
AppMenu(menuStack, settings, renderWindow),
|
||||||
|
playerCursor(std::vector<unsigned int>({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<PlayerCursor>(), "CONTROLS SETTINGS", 5.f, std::optional<sf::Vector2u>());
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
21
src/GraphicalUI/AppMenus/SettingsControlsAppMenu.h
Normal file
21
src/GraphicalUI/AppMenus/SettingsControlsAppMenu.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsControlsAppMenu : public AppMenu {
|
||||||
|
private:
|
||||||
|
PlayerCursor playerCursor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SettingsControlsAppMenu(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,8 @@
|
|||||||
#include "SettingsMainAppMenu.h"
|
#include "SettingsMainAppMenu.h"
|
||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "SettingsControlsAppMenu.h"
|
||||||
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -23,12 +24,12 @@ void SettingsMainAppMenu::computeFrame() {
|
|||||||
case 2 : {
|
case 2 : {
|
||||||
if (this->playerCursor.movedLeft()) {
|
if (this->playerCursor.movedLeft()) {
|
||||||
if (this->settings->shortenWindow()) {
|
if (this->settings->shortenWindow()) {
|
||||||
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
this->settings->changeVideoMode(*this->renderWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->playerCursor.movedRight()) {
|
if (this->playerCursor.movedRight()) {
|
||||||
if (this->settings->widenWindow()) {
|
if (this->settings->widenWindow()) {
|
||||||
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
this->settings->changeVideoMode(*this->renderWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -49,7 +50,7 @@ void SettingsMainAppMenu::computeFrame() {
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
if (this->playerCursor.getPosition().y == 1) {
|
if (this->playerCursor.getPosition().y == 1) {
|
||||||
//TODO
|
this->menuStack->push(std::make_shared<SettingsControlsAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->escReleased) {
|
if (this->escReleased) {
|
||||||
@@ -60,33 +61,18 @@ void SettingsMainAppMenu::computeFrame() {
|
|||||||
void SettingsMainAppMenu::drawFrame() const {
|
void SettingsMainAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color(200, 200, 200));
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
sf::Font font("data/fonts/pressstart/prstartk.ttf");
|
sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
|
||||||
sf::Text text(font, "", this->settings->getWindowSizeMultiplier() * 2);
|
|
||||||
text.setFillColor(sf::Color(0, 0, 0));
|
text.setFillColor(sf::Color(0, 0, 0));
|
||||||
text.setOutlineColor(sf::Color(255, 255, 255));
|
text.setOutlineColor(sf::Color(255, 255, 255));
|
||||||
|
|
||||||
text.setString("SETTINGS");
|
this->placeTitle(text, std::optional<PlayerCursor>(), "SETTINGS", 5.f, std::optional<sf::Vector2u>());
|
||||||
text.setOrigin(text.getLocalBounds().getCenter());
|
|
||||||
text.setPosition(sf::Vector2f({(float) this->settings->getWindowSizeMultiplier() * 40, (float) this->settings->getWindowSizeMultiplier() * 5}));
|
|
||||||
this->renderWindow->draw(text);
|
|
||||||
|
|
||||||
sf::Vector2u windowSize = this->renderWindow->getSize();
|
sf::Vector2u windowSize = this->renderWindow->getSize();
|
||||||
|
|
||||||
this->placeText(text, "CHANGE KEYBINDS", 5.f, 15.f, 0, 0);
|
this->placeText(text, this->playerCursor, "CHANGE KEYBINDS (TODO)", 5.f, 15.f, {0, 0});
|
||||||
this->placeText(text, "CHANGE CONTROLS", 5.f, 25.f, 0, 1);
|
this->placeText(text, this->playerCursor, "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, this->playerCursor, "< 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, "< VOLUME: " + std::to_string(this->settings->getMasterVolume()) + "% >", 5.f, 45.f, {0, 3});
|
||||||
|
|
||||||
this->renderWindow->display();
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "../PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -18,6 +18,4 @@ class SettingsMainAppMenu : public AppMenu {
|
|||||||
void computeFrame() override;
|
void computeFrame() override;
|
||||||
|
|
||||||
void drawFrame() const 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;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ GraphApp::GraphApp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphApp::run() {
|
void GraphApp::run() {
|
||||||
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
this->settings->changeVideoMode(*this->renderWindow);
|
||||||
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<MainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "PlayerCursor.h"
|
#include "PlayerCursor.h"
|
||||||
|
|
||||||
#include "../Keybinds.h"
|
#include "Keybinds.h"
|
||||||
#include "../Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -33,6 +33,18 @@ void Settings::loadSettingsFromFile() {
|
|||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->chosenKeybinds = 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
|
// window size mode
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->windowSizeMode = byte;
|
this->windowSizeMode = byte;
|
||||||
@@ -56,6 +68,12 @@ void Settings::loadSettingsFromFile() {
|
|||||||
// piece distribution
|
// piece distribution
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
//TODO
|
//TODO
|
||||||
|
if (byte == 2) {
|
||||||
|
for (int i = 1; i <= 15; i++) {
|
||||||
|
settingsFile.get(byte);
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// selected pieces
|
// selected pieces
|
||||||
char pieceType;
|
char pieceType;
|
||||||
@@ -78,6 +96,18 @@ void Settings::saveSettingsToFile() const {
|
|||||||
byte = this->chosenKeybinds;
|
byte = this->chosenKeybinds;
|
||||||
settingsFile.write(&byte, 1);
|
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
|
// window size mode
|
||||||
byte = this->windowSizeMode;
|
byte = this->windowSizeMode;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
@@ -131,10 +161,6 @@ bool Settings::canModifyCurrentKeybinds() const {
|
|||||||
return (this->chosenKeybinds == CUSTOMIZABLE_KEYBINDS);
|
return (this->chosenKeybinds == CUSTOMIZABLE_KEYBINDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::setGamemode(Gamemode gamemode) {
|
|
||||||
this->gamemode = gamemode;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Settings::widenWindow() {
|
bool Settings::widenWindow() {
|
||||||
if (this->windowSizeMode < WINDOW_SIZE_LAST_MODE) {
|
if (this->windowSizeMode < WINDOW_SIZE_LAST_MODE) {
|
||||||
this->windowSizeMode++;
|
this->windowSizeMode++;
|
||||||
@@ -151,6 +177,15 @@ bool Settings::shortenWindow() {
|
|||||||
return false;
|
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() {
|
bool Settings::raiseMasterVolume() {
|
||||||
if (this->masterVolume < 100) {
|
if (this->masterVolume < 100) {
|
||||||
this->masterVolume = std::min(this->masterVolume + 5, 100);
|
this->masterVolume = std::min(this->masterVolume + 5, 100);
|
||||||
@@ -167,6 +202,10 @@ bool Settings::lowerMasterVolume() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::setGamemode(Gamemode gamemode) {
|
||||||
|
this->gamemode = gamemode;
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::selectPieces(PiecesType type, int value) {
|
void Settings::selectPieces(PiecesType type, int value) {
|
||||||
this->selectedPieces.emplace_back(type, value);
|
this->selectedPieces.emplace_back(type, value);
|
||||||
}
|
}
|
||||||
@@ -219,10 +258,6 @@ int Settings::getMasterVolume() const {
|
|||||||
return this->masterVolume;
|
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<std::pair<PiecesType, int>>& Settings::getSelectedPieces() const {
|
const std::vector<std::pair<PiecesType, int>>& Settings::getSelectedPieces() const {
|
||||||
return this->selectedPieces;
|
return this->selectedPieces;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ class Settings {
|
|||||||
Menu menu;
|
Menu menu;
|
||||||
std::vector<Keybinds> keybinds;
|
std::vector<Keybinds> keybinds;
|
||||||
int chosenKeybinds;
|
int chosenKeybinds;
|
||||||
Gamemode gamemode;
|
|
||||||
int windowSizeMode;
|
int windowSizeMode;
|
||||||
int masterVolume;
|
int masterVolume;
|
||||||
|
Gamemode gamemode;
|
||||||
std::vector<std::pair<PiecesType, int>> selectedPieces;
|
std::vector<std::pair<PiecesType, int>> selectedPieces;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -41,16 +41,18 @@ class Settings {
|
|||||||
|
|
||||||
bool canModifyCurrentKeybinds() const;
|
bool canModifyCurrentKeybinds() const;
|
||||||
|
|
||||||
void setGamemode(Gamemode gamemode);
|
|
||||||
|
|
||||||
bool widenWindow();
|
bool widenWindow();
|
||||||
|
|
||||||
bool shortenWindow();
|
bool shortenWindow();
|
||||||
|
|
||||||
|
void changeVideoMode(sf::RenderWindow& window) const;
|
||||||
|
|
||||||
bool raiseMasterVolume();
|
bool raiseMasterVolume();
|
||||||
|
|
||||||
bool lowerMasterVolume();
|
bool lowerMasterVolume();
|
||||||
|
|
||||||
|
void setGamemode(Gamemode gamemode);
|
||||||
|
|
||||||
void selectPieces(PiecesType type, int value);
|
void selectPieces(PiecesType type, int value);
|
||||||
|
|
||||||
void unselectPieces(int index);
|
void unselectPieces(int index);
|
||||||
@@ -67,7 +69,5 @@ class Settings {
|
|||||||
|
|
||||||
int getMasterVolume() const;
|
int getMasterVolume() const;
|
||||||
|
|
||||||
const sf::VideoMode getVideoMode() const;
|
|
||||||
|
|
||||||
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
|
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,10 +33,12 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
resetSettingsFile();
|
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")) {
|
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);
|
resetKeybindFile(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +55,7 @@ int main() {
|
|||||||
|
|
||||||
void resetConfigFiles() {
|
void resetConfigFiles() {
|
||||||
resetSettingsFile;
|
resetSettingsFile;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < NUMBER_OF_KEYBINDS; i++) {
|
||||||
resetKeybindFile(i);
|
resetKeybindFile(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,10 +64,24 @@ void resetSettingsFile() {
|
|||||||
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;
|
||||||
|
|
||||||
|
Menu menu;
|
||||||
|
|
||||||
// keybind layout
|
// keybind layout
|
||||||
byte = 0;
|
byte = 0;
|
||||||
settingsFile.write(&byte, 1);
|
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
|
// window size mode
|
||||||
byte = 2;
|
byte = 2;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
@@ -75,15 +91,15 @@ void resetSettingsFile() {
|
|||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// gamemode
|
// gamemode
|
||||||
byte = SPRINT;
|
byte = Gamemode(0);
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// board width
|
// board width
|
||||||
byte = 10;
|
byte = menu.getBoardWidth();
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// board height
|
// board height
|
||||||
byte = 20;
|
byte = menu.getBoardHeight();
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// piece distribution
|
// piece distribution
|
||||||
|
|||||||
Reference in New Issue
Block a user