#pragma once #include "../Settings.h" #include "../PlayerCursor.h" #include #include #include #include class AppMenu; using MenuStack = std::stack>; class AppMenu { protected: std::shared_ptr menuStack; std::shared_ptr settings; std::shared_ptr renderWindow; bool enterPressed = false; bool enterReleased = false; bool escPressed = false; bool escReleased = false; sf::Font pressStartFont; public: AppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow); virtual void computeFrame() = 0; virtual void drawFrame() const = 0; protected: void updateMetaBinds() { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter)) { enterPressed = true; enterReleased = false; } else { enterReleased = enterPressed; enterPressed = false; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) { escPressed = true; escReleased = false; } else { escReleased = escPressed; escPressed = false; } } void placeText(sf::Text& text, const std::optional& playerCursor, const sf::String& string, float xPos, 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); } 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); } text.setOrigin({text.getLocalBounds().getCenter().x, text.getLocalBounds().size.y / 2}); text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos})); this->renderWindow->draw(text); } sf::Color getColorOfBlock(Block block, int luminosityShift) const { Color rgbColor = BLOCKS_COLOR[block]; return sf::Color(std::clamp(rgbColor.red + luminosityShift, 0, 255), std::clamp(rgbColor.green + luminosityShift, 0, 255), std::clamp(rgbColor.blue + luminosityShift, 0, 255)); } };