on peut changer les settings wtf
This commit is contained in:
Binary file not shown.
@@ -39,6 +39,7 @@ 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 window size mode, 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
|
- The number of the last selected gamemode (converted from an Enum), stored with 1 byte
|
||||||
- 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
|
||||||
|
|||||||
@@ -136,42 +136,6 @@ void GamePlayingAppMenu::drawFrame() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (this->game.getNextPieces().size() > 0) {
|
|
||||||
for (int y = 10; y >= 0; y--) {
|
|
||||||
for (int x = 0; x <= 10; x++) {
|
|
||||||
Block block = this->game.getNextPieces().at(0).getBlockType();
|
|
||||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
|
||||||
cell.setPosition(sf::Vector2f((x + 2 + this->game.getBoard().getWidth())*20, (this->game.getBoard().getBaseHeight() - y)*20));
|
|
||||||
if (this->game.getNextPieces().at(0).getPositions().contains(Position({x, y}))) {
|
|
||||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cell.setFillColor(sf::Color(0, 0, 0));
|
|
||||||
}
|
|
||||||
this->renderWindow->draw(cell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->game.getHeldPiece() != nullptr) {
|
|
||||||
for (int y = 10; y >= 0; y--) {
|
|
||||||
for (int x = 0; x <= 10; x++) {
|
|
||||||
Block block = this->game.getHeldPiece()->getBlockType();
|
|
||||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
|
||||||
cell.setPosition(sf::Vector2f((x + 12 + this->game.getBoard().getWidth())*20, (this->game.getBoard().getBaseHeight() - y)*20));
|
|
||||||
if (this->game.getHeldPiece()->getPositions().contains(Position({x, y}))) {
|
|
||||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cell.setFillColor(sf::Color(0, 0, 0));
|
|
||||||
}
|
|
||||||
this->renderWindow->draw(cell);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
this->renderWindow->display();
|
this->renderWindow->display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "AppMenu.h"
|
#include "AppMenu.h"
|
||||||
#include "GameSettingsAppMenu.h"
|
#include "GameSettingsAppMenu.h"
|
||||||
|
#include "SettingsMainAppMenu.h"
|
||||||
#include "PlayerCursor.h"
|
#include "PlayerCursor.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@@ -25,7 +26,7 @@ void MainAppMenu::computeFrame() {
|
|||||||
this->menuStack->push(std::make_shared<GameSettingsAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
this->menuStack->push(std::make_shared<GameSettingsAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
if (this->playerCursor.getPosition().y == 1) {
|
if (this->playerCursor.getPosition().y == 1) {
|
||||||
//TODO
|
this->menuStack->push(std::make_shared<SettingsMainAppMenu>(this->menuStack, this->settings, this->renderWindow));
|
||||||
}
|
}
|
||||||
if (this->playerCursor.getPosition().y == 2) {
|
if (this->playerCursor.getPosition().y == 2) {
|
||||||
//TODO
|
//TODO
|
||||||
|
|||||||
@@ -42,6 +42,22 @@ void PlayerCursor::updatePosition() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerCursor::movedLeft() const {
|
||||||
|
return this->shouldMove(this->leftDAS);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerCursor::movedRight() const {
|
||||||
|
return this->shouldMove(this->rightDAS);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerCursor::movedUp() const {
|
||||||
|
return this->shouldMove(this->upDAS);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlayerCursor::movedDown() const {
|
||||||
|
return this->shouldMove(this->downDAS);
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerCursor::goToPosition(const sf::Vector2u& newPosition) {
|
void PlayerCursor::goToPosition(const sf::Vector2u& newPosition) {
|
||||||
if (this->rows.size() > newPosition.y) {
|
if (this->rows.size() > newPosition.y) {
|
||||||
if (this->rows.at(newPosition.y) > newPosition.x) {
|
if (this->rows.at(newPosition.y) > newPosition.x) {
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ class PlayerCursor {
|
|||||||
|
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
|
|
||||||
|
bool movedLeft() const;
|
||||||
|
|
||||||
|
bool movedRight() const;
|
||||||
|
|
||||||
|
bool movedUp() const;
|
||||||
|
|
||||||
|
bool movedDown() const;
|
||||||
|
|
||||||
void goToPosition(const sf::Vector2u& newPosition);
|
void goToPosition(const sf::Vector2u& newPosition);
|
||||||
|
|
||||||
const sf::Vector2u& getPosition() const;
|
const sf::Vector2u& getPosition() const;
|
||||||
|
|||||||
92
src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp
Normal file
92
src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#include "SettingsMainAppMenu.h"
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
SettingsMainAppMenu::SettingsMainAppMenu(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, 1})) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsMainAppMenu::computeFrame() {
|
||||||
|
this->updateMetaBinds();
|
||||||
|
this->playerCursor.updatePosition();
|
||||||
|
|
||||||
|
switch (this->playerCursor.getPosition().y) {
|
||||||
|
case 2 : {
|
||||||
|
if (this->playerCursor.movedLeft()) {
|
||||||
|
if (this->settings->shortenWindow()) {
|
||||||
|
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this->playerCursor.movedRight()) {
|
||||||
|
if (this->settings->widenWindow()) {
|
||||||
|
changeVideoMode(*this->renderWindow, this->settings->getVideoMode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3 : {
|
||||||
|
if (this->playerCursor.movedLeft()) {
|
||||||
|
this->settings->lowerMasterVolume();
|
||||||
|
}
|
||||||
|
if (this->playerCursor.movedRight()) {
|
||||||
|
this->settings->raiseMasterVolume();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->enterReleased) {
|
||||||
|
if (this->playerCursor.getPosition().y == 0) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
if (this->playerCursor.getPosition().y == 1) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this->escReleased) {
|
||||||
|
this->menuStack->pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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->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);
|
||||||
|
}
|
||||||
23
src/GraphicalUI/AppMenus/SettingsMainAppMenu.h
Normal file
23
src/GraphicalUI/AppMenus/SettingsMainAppMenu.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AppMenu.h"
|
||||||
|
#include "PlayerCursor.h"
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
#include <memory>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsMainAppMenu : public AppMenu {
|
||||||
|
private:
|
||||||
|
PlayerCursor playerCursor;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SettingsMainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
@@ -48,5 +48,6 @@ void GraphApp::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->settings->saveSettingsToFile();
|
||||||
renderWindow->close();
|
renderWindow->close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ Keybinds::Keybinds(int layoutNumber) :
|
|||||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||||
this->keybinds.insert({action, std::set<sfKey>()});
|
this->keybinds.insert({action, std::set<sfKey>()});
|
||||||
}
|
}
|
||||||
|
this->modifiable = (layoutNumber == CUSTOMIZABLE_KEYBINDS);
|
||||||
|
|
||||||
this->loadKeybindsFromFile();
|
this->loadKeybindsFromFile();
|
||||||
}
|
}
|
||||||
@@ -44,6 +45,8 @@ void Keybinds::loadKeybindsFromFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Keybinds::saveKeybindsToFile() const {
|
void Keybinds::saveKeybindsToFile() const {
|
||||||
|
if (!this->modifiable) return;
|
||||||
|
|
||||||
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::trunc | std::ios::binary);
|
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(this->layoutNumber) + ".bin", std::ios::trunc | std::ios::binary);
|
||||||
|
|
||||||
char byte;
|
char byte;
|
||||||
@@ -62,13 +65,21 @@ void Keybinds::saveKeybindsToFile() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Keybinds::addKey(Action action, sfKey key) {
|
void Keybinds::addKey(Action action, sfKey key) {
|
||||||
|
if (!this->modifiable) return;
|
||||||
|
|
||||||
this->keybinds.at(action).insert(key);
|
this->keybinds.at(action).insert(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keybinds::clearKeys(Action action) {
|
void Keybinds::clearKeys(Action action) {
|
||||||
|
if (!this->modifiable) return;
|
||||||
|
|
||||||
this->keybinds.at(action).clear();
|
this->keybinds.at(action).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Keybinds::isModifiable() const {
|
||||||
|
return this->modifiable;
|
||||||
|
}
|
||||||
|
|
||||||
const std::set<Action> Keybinds::getActions(sfKey key) const {
|
const std::set<Action> Keybinds::getActions(sfKey key) const {
|
||||||
std::set<Action> actions;
|
std::set<Action> actions;
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class Keybinds {
|
|||||||
private:
|
private:
|
||||||
std::map<Action, std::set<sfKey>> keybinds;
|
std::map<Action, std::set<sfKey>> keybinds;
|
||||||
int layoutNumber;
|
int layoutNumber;
|
||||||
|
bool modifiable;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Keybinds(int layoutNumber);
|
Keybinds(int layoutNumber);
|
||||||
@@ -28,6 +29,8 @@ class Keybinds {
|
|||||||
|
|
||||||
void clearKeys(Action action);
|
void clearKeys(Action action);
|
||||||
|
|
||||||
|
bool isModifiable() const;
|
||||||
|
|
||||||
const std::set<Action> getActions(sfKey key) const;
|
const std::set<Action> getActions(sfKey key) const;
|
||||||
|
|
||||||
const std::set<sfKey>& getKeybinds(Action action) const;
|
const std::set<sfKey>& getKeybinds(Action action) const;
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
#include "../Core/Menu.h"
|
#include "../Core/Menu.h"
|
||||||
#include "Keybinds.h"
|
#include "Keybinds.h"
|
||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
static const sf::Vector2u BASE_WINDOW_SIZE = {80, 50};
|
static const sf::Vector2u BASE_WINDOW_SIZE = {80, 50};
|
||||||
static const int WINDOW_SIZE_MULTIPLIERS[] = {4, 6, 10, 14, 20};
|
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;
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +37,10 @@ void Settings::loadSettingsFromFile() {
|
|||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->windowSizeMode = byte;
|
this->windowSizeMode = byte;
|
||||||
|
|
||||||
|
// master volume
|
||||||
|
settingsFile.get(byte);
|
||||||
|
this->masterVolume = byte;
|
||||||
|
|
||||||
// gamemode
|
// gamemode
|
||||||
settingsFile.get(byte);
|
settingsFile.get(byte);
|
||||||
this->gamemode = Gamemode(byte);
|
this->gamemode = Gamemode(byte);
|
||||||
@@ -77,6 +82,10 @@ void Settings::saveSettingsToFile() const {
|
|||||||
byte = this->windowSizeMode;
|
byte = this->windowSizeMode;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
|
// master volume
|
||||||
|
byte = this->masterVolume;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// gamemode
|
// gamemode
|
||||||
byte = this->gamemode;
|
byte = this->gamemode;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
@@ -142,6 +151,22 @@ bool Settings::shortenWindow() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Settings::raiseMasterVolume() {
|
||||||
|
if (this->masterVolume < 100) {
|
||||||
|
this->masterVolume = std::min(this->masterVolume + 5, 100);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::lowerMasterVolume() {
|
||||||
|
if (this->masterVolume > 0) {
|
||||||
|
this->masterVolume = std::max(this->masterVolume - 5, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -190,6 +215,10 @@ int Settings::getWindowSizeMultiplier() const {
|
|||||||
return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode];
|
return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Settings::getMasterVolume() const {
|
||||||
|
return this->masterVolume;
|
||||||
|
}
|
||||||
|
|
||||||
const sf::VideoMode Settings::getVideoMode() const {
|
const sf::VideoMode Settings::getVideoMode() const {
|
||||||
return sf::VideoMode(BASE_WINDOW_SIZE * (unsigned int) WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]);
|
return sf::VideoMode(BASE_WINDOW_SIZE * (unsigned int) WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class Settings {
|
|||||||
int chosenKeybinds;
|
int chosenKeybinds;
|
||||||
Gamemode gamemode;
|
Gamemode gamemode;
|
||||||
int windowSizeMode;
|
int windowSizeMode;
|
||||||
|
int masterVolume;
|
||||||
std::vector<std::pair<PiecesType, int>> selectedPieces;
|
std::vector<std::pair<PiecesType, int>> selectedPieces;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -46,6 +47,10 @@ class Settings {
|
|||||||
|
|
||||||
bool shortenWindow();
|
bool shortenWindow();
|
||||||
|
|
||||||
|
bool raiseMasterVolume();
|
||||||
|
|
||||||
|
bool lowerMasterVolume();
|
||||||
|
|
||||||
void selectPieces(PiecesType type, int value);
|
void selectPieces(PiecesType type, int value);
|
||||||
|
|
||||||
void unselectPieces(int index);
|
void unselectPieces(int index);
|
||||||
@@ -60,6 +65,8 @@ class Settings {
|
|||||||
|
|
||||||
int getWindowSizeMultiplier() const;
|
int getWindowSizeMultiplier() const;
|
||||||
|
|
||||||
|
int getMasterVolume() const;
|
||||||
|
|
||||||
const sf::VideoMode getVideoMode() const;
|
const sf::VideoMode getVideoMode() const;
|
||||||
|
|
||||||
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
|
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ void resetSettingsFile() {
|
|||||||
byte = 2;
|
byte = 2;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
|
// master volume
|
||||||
|
byte = 50;
|
||||||
|
settingsFile.write(&byte, 1);
|
||||||
|
|
||||||
// gamemode
|
// gamemode
|
||||||
byte = SPRINT;
|
byte = SPRINT;
|
||||||
settingsFile.write(&byte, 1);
|
settingsFile.write(&byte, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user