diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index 7a70a459..936b399b 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -56,4 +56,10 @@ namespace RAY { DrawTextureEx(*this, this->_position, 0, scale, this->_color); } + + void Texture::unload() + { + this->_texture = nullptr; + this->_resourcePath = ""; + } } diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 74eab4c8..43126c9d 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -44,6 +44,9 @@ namespace RAY //! @brief Load texture from file, lets one use one entity for multiple files Texture &use(const std::string &filename); + //! @brief Unload the current texture (calls to drawOn will no-op). + void unload(); + protected: private: //! @brief Texture, really, that's just it... diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index 5b7d39ad..50c98e07 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -25,7 +25,8 @@ namespace BBM GAMEPAD_0, GAMEPAD_1, GAMEPAD_2, - GAMEPAD_3 + GAMEPAD_3, + AI }; //! @brief The X and Z abscis of the movement. diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index 54e45191..52787fd6 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -44,94 +44,95 @@ namespace BBM .addComponent(1920 / 2.75, 100, 0) .addComponent("Get Ready", 120, RAY::Vector2(), ORANGE); auto &play = scene->addEntity("play button") - .addComponent(1920 / 2.5, 1080 - 180, 0) - .addComponent("assets/buttons/button_new_game.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - auto *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_new_game.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - auto *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_new_game_hovered.png"); - }) - .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - if (Runner::gameState.currentScene != GameState::LobbyScene - || !LobbySystem::playersAreReady(*wal.getScene())) - return; - LobbySystem::switchToGame(wal); - }) - .addComponent>(); + .addComponent(1920 / 2.5, 1080 - 180, 0) + .addComponent("assets/buttons/button_new_game.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); + texture->use("assets/buttons/button_new_game.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); + texture->use("assets/buttons/button_new_game_hovered.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + if (Runner::gameState.currentScene != GameState::LobbyScene + || !LobbySystem::playersAreReady(*wal.getScene())) + return; + LobbySystem::switchToGame(wal); + }) + .addComponent>(); auto &back = scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; - }) + .addComponent([](WAL::Entity &entity, WAL::Wal &wal) + { + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + wal.getSystem().unloadLobby(); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + { + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_back.png"); - }) + texture->use("assets/buttons/button_back.png"); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + { + auto *texture = dynamic_cast(entity.getComponent().drawable.get()); - texture->use("assets/buttons/button_back_hovered.png"); - }); + texture->use("assets/buttons/button_back_hovered.png"); + }); auto &lavaOption = scene->addEntity("lava option text") .addComponent(1920 / 6, 2 * 1080 / 3, 0) .addComponent("Lava: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + { + auto *text = dynamic_cast(entity.getComponent().drawable.get()); - if (text->getString().find("Off") != std::string::npos) { - text->setText("Lava: On"); - //do - } else { - text->setText("Lava: Off"); - //do - } - }) + if (text->getString().find("Off") != std::string::npos) { + text->setText("Lava: On"); + //do + } else { + text->setText("Lava: Off"); + //do + } + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) + { + entity.getComponent().drawable->setColor(BLACK); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); + { + entity.getComponent().drawable->setColor(ORANGE); + }); auto &heightOption = scene->addEntity("Height option text") .addComponent(1920 / 1.75, 2 * 1080 / 3, 0) .addComponent("2nd Level: Off", 70, RAY::Vector2(), BLACK) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) - { - RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); + { + auto *text = dynamic_cast(entity.getComponent().drawable.get()); - if (text->getString().find("Off") != std::string::npos) { - text->setText("2nd Level: On"); - //do - } else { - text->setText("2nd Level: Off"); - //do - } - }) + if (text->getString().find("Off") != std::string::npos) { + text->setText("2nd Level: On"); + //do + } else { + text->setText("2nd Level: Off"); + //do + } + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(BLACK); - }) + { + entity.getComponent().drawable->setColor(BLACK); + }) .addComponent([](WAL::Entity &entity, WAL::Wal &) - { - entity.getComponent().drawable->setColor(ORANGE); - }); + { + entity.getComponent().drawable->setColor(ORANGE); + }); for (int i = 0; i < 4; i++) { auto &playerTile = scene->addEntity("player tile") diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 9c020625..f11b9a7e 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -143,6 +143,9 @@ namespace BBM case ControllableComponent::GAMEPAD_3: player.addComponent(3); break; + case ControllableComponent::AI: + throw std::runtime_error("Not implemented error"); + break; default: throw std::runtime_error("Invalid controller for a player."); } @@ -169,5 +172,21 @@ namespace BBM } Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene; Runner::gameState.nextScene = BBM::GameState::SceneID::GameScene; + wal.getSystem().unloadLobby(); + } + + void LobbySystem::unloadLobby() + { + this->_colorTaken.fill(false); + for (auto &[_, lobby, drawable] : this->getView()) { + lobby.layout = ControllableComponent::NONE; + lobby.ready = false; + lobby.color = -1; + drawable.drawable = std::make_shared("assets/player/icons/none.png"); + lobby.coloredTile.getComponent().drawable->setColor(RAY::Color(0, 0, 0, 0)); + auto *texture = dynamic_cast(lobby.readyButton.getComponent().drawable.get()); + if (texture) + texture->unload(); + } } } \ No newline at end of file diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index b0a91bb3..d92171f9 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -42,6 +42,9 @@ namespace BBM //! @param wal The engine. static void switchToGame(WAL::Wal &wal); + //! @brief Reset the lobby scene to it's default state. + void unloadLobby(); + //! @brief A default constructor explicit LobbySystem(WAL::Wal &wal); //! @brief A Lobby system is copy constructable