ajout board menu

This commit is contained in:
2025-03-28 21:31:24 +01:00
parent 0f026635f6
commit f883bd5bab
8 changed files with 102 additions and 8 deletions

View File

@@ -0,0 +1,67 @@
#include "GameBoardAppMenu.h"
#include "AppMenu.h"
#include "../PlayerCursor.h"
#include <stack>
#include <memory>
#include <vector>
#include <SFML/Graphics.hpp>
GameBoardAppMenu::GameBoardAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow),
playerCursor({1, 1}) {
}
void GameBoardAppMenu::computeFrame() {
this->updateMetaBinds();
this->playerCursor.updatePosition();
Menu& menu = this->settings->getMenu();
switch (this->playerCursor.getPosition().y) {
case 0 : {
if (this->playerCursor.movedLeft()) {
menu.setBoardWidth(std::max(1, menu.getBoardWidth() - 1));
}
if (this->playerCursor.movedRight()) {
menu.setBoardWidth(std::min(MAXIMUM_BOARD_WIDTH, menu.getBoardWidth() + 1));
}
break;
}
case 1 : {
if (this->playerCursor.movedLeft()) {
menu.setBoardHeight(std::max(1, menu.getBoardHeight() - 1));
}
if (this->playerCursor.movedRight()) {
menu.setBoardHeight(std::min(MAXIMUM_BOARD_HEIGHT, menu.getBoardHeight() + 1));
}
break;
}
}
if (this->escReleased) {
this->menuStack->pop();
}
}
void GameBoardAppMenu::drawFrame() const {
this->renderWindow->clear(sf::Color(200, 200, 200));
const Menu& menu = this->settings->getMenu();
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, {}, "BOARD SETTINGS", 5.f, {});
sf::Vector2u windowSize = this->renderWindow->getSize();
this->placeText(text, this->playerCursor, "< BOARD WIDTH: " + std::to_string(menu.getBoardWidth()) + " >", 5.f, 15.f, sf::Vector2u{0, 0});
this->placeText(text, this->playerCursor, "< BOARD HEIGHT: " + std::to_string(menu.getBoardHeight()) + " >", 5.f, 25.f, sf::Vector2u{0, 1});
this->renderWindow->display();
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "AppMenu.h"
#include "../PlayerCursor.h"
#include <stack>
#include <memory>
#include <SFML/Graphics.hpp>
class GameBoardAppMenu : public AppMenu {
private:
PlayerCursor playerCursor;
public:
GameBoardAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
void computeFrame() override;
void drawFrame() const override;
};

View File

@@ -1,6 +1,7 @@
#include "GameSettingsAppMenu.h" #include "GameSettingsAppMenu.h"
#include "AppMenu.h" #include "AppMenu.h"
#include "GameBoardAppMenu.h"
#include "GamePlayingAppMenu.h" #include "GamePlayingAppMenu.h"
#include "../PlayerCursor.h" #include "../PlayerCursor.h"
@@ -12,7 +13,7 @@
GameSettingsAppMenu::GameSettingsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : GameSettingsAppMenu::GameSettingsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>({2, 3, 2})) { playerCursor({2, 3, 3}) {
} }
@@ -41,7 +42,12 @@ void GameSettingsAppMenu::computeFrame() {
if (this->enterReleased) { if (this->enterReleased) {
if (this->playerCursor.getPosition().y == 0) { if (this->playerCursor.getPosition().y == 0) {
//TODO if (this->playerCursor.getPosition().x == 0) {
//TODO
}
if (this->playerCursor.getPosition().x == 1) {
this->menuStack->push(std::make_shared<GameBoardAppMenu>(this->menuStack, this->settings, this->renderWindow));
}
} }
if (this->playerCursor.getPosition().y > 0) { if (this->playerCursor.getPosition().y > 0) {
this->menuStack->push(std::make_shared<GamePlayingAppMenu>(this->menuStack, this->settings, this->renderWindow)); this->menuStack->push(std::make_shared<GamePlayingAppMenu>(this->menuStack, this->settings, this->renderWindow));
@@ -62,7 +68,7 @@ void GameSettingsAppMenu::drawFrame() const {
this->placeTitle(text, {}, "GAME SETTINGS", 5.f, {}); this->placeTitle(text, {}, "GAME SETTINGS", 5.f, {});
this->placeText(text, this->playerCursor, "PIECES SELECT (TODO)", 5.f, 15.f, sf::Vector2u{0, 0}); this->placeText(text, this->playerCursor, "PIECES SELECT (TODO)", 5.f, 15.f, sf::Vector2u{0, 0});
this->placeText(text, this->playerCursor, "BOARD SELECT (TODO)", 40.f, 15.f, sf::Vector2u{1, 0}); this->placeText(text, this->playerCursor, "BOARD SELECT", 40.f, 15.f, sf::Vector2u{1, 0});
this->placeText(text, this->playerCursor, "SPRINT", 5.f, 25.f, sf::Vector2u{0, 1}); this->placeText(text, this->playerCursor, "SPRINT", 5.f, 25.f, sf::Vector2u{0, 1});
this->placeText(text, this->playerCursor, "MARATHON", 25.f, 25.f, sf::Vector2u{1, 1}); this->placeText(text, this->playerCursor, "MARATHON", 25.f, 25.f, sf::Vector2u{1, 1});

View File

@@ -11,7 +11,7 @@
InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : InfoAppMenu::InfoAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>({4})), playerCursor({4}),
sectionsName( sectionsName(
"< ABOUT >", "< ABOUT >",
"< ROTATION SYSTEM >", "< ROTATION SYSTEM >",

View File

@@ -14,7 +14,7 @@
MainAppMenu::MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : MainAppMenu::MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>({1, 1, 1})) { playerCursor({1, 1, 1}) {
} }

View File

@@ -11,7 +11,7 @@
SettingsControlsAppMenu::SettingsControlsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : SettingsControlsAppMenu::SettingsControlsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>({1, 1, 1})) { playerCursor({1, 1, 1}) {
} }

View File

@@ -15,7 +15,7 @@
SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>(12, 1)) { playerCursor({12, 1}) {
this->selectedAnAction = false; this->selectedAnAction = false;

View File

@@ -13,7 +13,7 @@
SettingsMainAppMenu::SettingsMainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : SettingsMainAppMenu::SettingsMainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor(std::vector<unsigned int>({1, 1, 1, 1})) { playerCursor({1, 1, 1, 1}) {
} }