mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-27 08:13:18 +00:00
Clearing the lobby on leave
This commit is contained in:
@@ -56,4 +56,10 @@ namespace RAY {
|
||||
|
||||
DrawTextureEx(*this, this->_position, 0, scale, this->_color);
|
||||
}
|
||||
|
||||
void Texture::unload()
|
||||
{
|
||||
this->_texture = nullptr;
|
||||
this->_resourcePath = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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...
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -44,94 +44,95 @@ namespace BBM
|
||||
.addComponent<PositionComponent>(1920 / 2.75, 100, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Get Ready", 120, RAY::Vector2(), ORANGE);
|
||||
auto &play = scene->addEntity("play button")
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_new_game.png")
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
texture->use("assets/buttons/button_new_game.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
texture->use("assets/buttons/button_new_game_hovered.png");
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
if (Runner::gameState.currentScene != GameState::LobbyScene
|
||||
|| !LobbySystem::playersAreReady(*wal.getScene()))
|
||||
return;
|
||||
LobbySystem::switchToGame(wal);
|
||||
})
|
||||
.addComponent<TagComponent<"PlayButton">>();
|
||||
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_new_game.png")
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
texture->use("assets/buttons/button_new_game.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
texture->use("assets/buttons/button_new_game_hovered.png");
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
if (Runner::gameState.currentScene != GameState::LobbyScene
|
||||
|| !LobbySystem::playersAreReady(*wal.getScene()))
|
||||
return;
|
||||
LobbySystem::switchToGame(wal);
|
||||
})
|
||||
.addComponent<TagComponent<"PlayButton">>();
|
||||
|
||||
|
||||
auto &back = scene->addEntity("back to menu")
|
||||
.addComponent<PositionComponent>(10, 1080 - 85, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png")
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
|
||||
wal.getSystem<LobbySystem>().unloadLobby();
|
||||
})
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_back.png");
|
||||
})
|
||||
texture->use("assets/buttons/button_back.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
{
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().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<PositionComponent>(1920 / 6, 2 * 1080 / 3, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Lava: Off", 70, RAY::Vector2(), BLACK)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
{
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().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<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
|
||||
})
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
|
||||
auto &heightOption = scene->addEntity("Height option text")
|
||||
.addComponent<PositionComponent>(1920 / 1.75, 2 * 1080 / 3, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("2nd Level: Off", 70, RAY::Vector2(), BLACK)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
{
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().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<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
|
||||
})
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
{
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
auto &playerTile = scene->addEntity("player tile")
|
||||
|
||||
@@ -143,6 +143,9 @@ namespace BBM
|
||||
case ControllableComponent::GAMEPAD_3:
|
||||
player.addComponent<GamepadComponent>(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<LobbySystem>().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<RAY::Texture>("assets/player/icons/none.png");
|
||||
lobby.coloredTile.getComponent<Drawable2DComponent>().drawable->setColor(RAY::Color(0, 0, 0, 0));
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
|
||||
if (texture)
|
||||
texture->unload();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user