on peut changer les settings wtf

This commit is contained in:
2025-03-24 16:20:37 +01:00
parent 8a4c4201fe
commit fd9fd4586a
15 changed files with 200 additions and 40 deletions

View 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);
}