diff --git a/src/GraphicalUI/AppMenus/AppMenu.h b/src/GraphicalUI/AppMenus/AppMenu.h index 762fd5e..5ff55b1 100644 --- a/src/GraphicalUI/AppMenus/AppMenu.h +++ b/src/GraphicalUI/AppMenus/AppMenu.h @@ -57,6 +57,33 @@ class AppMenu { } } + sf::Text createText(int fontSize = 2) const { + sf::Text newText(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * fontSize); + newText.setFillColor(sf::Color::Black); + newText.setOutlineColor(sf::Color::White); + newText.setOutlineThickness(0); + + return newText; + } + + void setTextPosition(sf::Text& text, float xPos, float yPos) const { + float sizeMultiplier = this->settings->getWindowSizeMultiplier(); + + text.setOrigin(sf::Vector2f({0, text.getLocalBounds().size.y / 2})); + text.setPosition(sf::Vector2f({sizeMultiplier * xPos, sizeMultiplier * yPos})); + } + + void setTitlePosition(sf::Text& text, float yPos) const { + float sizeMultiplier = this->settings->getWindowSizeMultiplier(); + + text.setOrigin({text.getLocalBounds().getCenter().x, text.getLocalBounds().size.y / 2}); + text.setPosition(sf::Vector2f({sizeMultiplier * 40.f, sizeMultiplier * yPos})); + } + + void setTextOutline(sf::Text& text, bool hasOutline) const { + text.setOutlineThickness(hasOutline * (this->settings->getWindowSizeMultiplier() / 2)); + } + 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(); diff --git a/src/GraphicalUI/AppMenus/InfoAppMenu.cpp b/src/GraphicalUI/AppMenus/InfoAppMenu.cpp index 97592c6..02592a3 100644 --- a/src/GraphicalUI/AppMenus/InfoAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/InfoAppMenu.cpp @@ -10,12 +10,13 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow) : AppMenu(menuStack, settings, renderWindow), - playerCursor({4}), + playerCursor({INFO_SECTIONS_COUNT}), sectionsName( "< ABOUT >", + "< PIECES TYPES >", + "< 0 DEGREES ROTATIONS >", "< ROTATION SYSTEM >", - "< SCORING >", - "< 0 DEGREES ROTATIONS >" + "< SCORING >" ), sectionsContent( "This game is written in C++,\n" @@ -27,6 +28,25 @@ InfoAppMenu::InfoAppMenu(std::shared_ptr menuStack, std::shared_ptr menuStack, std::shared_ptrcreateText()), + sectionContentText(this->createText()), + renderTexture(this->renderWindow->getSize()), + sprite(this->renderTexture.getTexture()) { - "This games introduces 0 degrees\n" - "rotations, which work by simpling\n" - "moving the piece down and kicking\n" - "it as is, allowing for new kinds\n" - "of kicks.\n" - "As a leniency mechanic, when a\n" - "piece spawns it will automatically\n" - "try a 0 degrees rotations if it\n" - "spawned inside a wall." - ) { + this->setTextOutline(this->sectionNameText, true); + + this->sectionContentText.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8); + this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]); + this->setTitlePosition(this->sectionNameText, 10.f); + + this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]); + this->setTextPosition(this->sectionContentText, 5.f, 30.f); + + this->renderTexture.clear(sf::Color(200, 200, 200)); + this->renderTexture.draw(this->sectionNameText); + this->renderTexture.draw(this->sectionContentText); + this->renderTexture.display(); + this->sprite.setTexture(this->renderTexture.getTexture()); } void InfoAppMenu::computeFrame() { this->updateMetaBinds(); this->playerCursor.updatePosition(); + if (this->playerCursor.movedLeft() || this->playerCursor.movedRight()) { + this->sectionNameText.setString(this->sectionsName[this->playerCursor.getPosition().x]); + this->setTitlePosition(this->sectionNameText, 10.f); + + this->sectionContentText.setString(this->sectionsContent[this->playerCursor.getPosition().x]); + this->setTextPosition(this->sectionContentText, 5.f, 30.f); + + this->renderTexture.clear(sf::Color(200, 200, 200)); + this->renderTexture.draw(this->sectionNameText); + this->renderTexture.draw(this->sectionContentText); + this->renderTexture.display(); + this->sprite.setTexture(this->renderTexture.getTexture()); + } + if (this->escReleased) { this->menuStack->pop(); } @@ -73,15 +116,7 @@ void InfoAppMenu::computeFrame() { void InfoAppMenu::drawFrame() const { this->renderWindow->clear(sf::Color(200, 200, 200)); - sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2); - text.setFillColor(sf::Color(0, 0, 0)); - text.setOutlineColor(sf::Color(255, 255, 255)); + this->renderWindow->draw(sprite); - this->placeTitle(text, this->playerCursor, this->sectionsName[this->playerCursor.getPosition().x], 10.f, this->playerCursor.getPosition()); - - text.setLineSpacing((float) this->settings->getWindowSizeMultiplier() / 8); - text.setOutlineThickness(0); - this->placeText(text, {}, this->sectionsContent[this->playerCursor.getPosition().x], 5.f, 30.f, {}); - this->renderWindow->display(); } diff --git a/src/GraphicalUI/AppMenus/InfoAppMenu.h b/src/GraphicalUI/AppMenus/InfoAppMenu.h index 8e3063c..bb421d6 100644 --- a/src/GraphicalUI/AppMenus/InfoAppMenu.h +++ b/src/GraphicalUI/AppMenus/InfoAppMenu.h @@ -7,12 +7,18 @@ #include #include +static const int INFO_SECTIONS_COUNT = 5; + class InfoAppMenu : public AppMenu { private: PlayerCursor playerCursor; - sf::String sectionsName[4]; - sf::String sectionsContent[4]; + sf::String sectionsName[INFO_SECTIONS_COUNT]; + sf::String sectionsContent[INFO_SECTIONS_COUNT]; + sf::Text sectionNameText; + sf::Text sectionContentText; + sf::RenderTexture renderTexture; + sf::Sprite sprite; public: InfoAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow); diff --git a/src/GraphicalUI/PlayerCursor.cpp b/src/GraphicalUI/PlayerCursor.cpp index e4dfd9c..2c0aa83 100644 --- a/src/GraphicalUI/PlayerCursor.cpp +++ b/src/GraphicalUI/PlayerCursor.cpp @@ -42,6 +42,13 @@ void PlayerCursor::updatePosition() { } } +bool PlayerCursor::moved() const { + return (this->movedLeft() + || this->movedRight() + || this->movedUp() + || this->movedDown()); +} + bool PlayerCursor::movedLeft() const { return this->shouldMove(this->leftDAS); } @@ -115,7 +122,7 @@ const sf::Vector2u& PlayerCursor::getPosition() const { bool PlayerCursor::shouldMove(int DAS) const { return (DAS == 1 || (DAS > MENU_DAS && (DAS % 5) == 0) - || (DAS > (FRAMES_PER_SECOND * 2))); + || (DAS > (MENU_DAS * 4))); } void PlayerCursor::moveLeft() { diff --git a/src/GraphicalUI/PlayerCursor.h b/src/GraphicalUI/PlayerCursor.h index 860cb04..76b12e3 100644 --- a/src/GraphicalUI/PlayerCursor.h +++ b/src/GraphicalUI/PlayerCursor.h @@ -18,6 +18,8 @@ class PlayerCursor { void updatePosition(); + bool moved() const; + bool movedLeft() const; bool movedRight() const;