fix endgame gui timers
All checks were successful
Linux arm64 / Build (push) Successful in 4m42s

This commit is contained in:
2024-04-14 19:55:51 +02:00
parent 8880056b1c
commit b917a8d1fa
4 changed files with 49 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ class Player;
} // namespace game } // namespace game
namespace gui { namespace gui {
class Hud : public GuiWidget { class Hud : public GuiWidget, public game::GameListener, public client::ClientListener {
private: private:
std::uint64_t m_GunTexture; std::uint64_t m_GunTexture;
std::uint64_t m_JPTexture; std::uint64_t m_JPTexture;
@@ -22,8 +22,13 @@ class Hud : public GuiWidget {
public: public:
Hud(GuiWidget* parent, client::Client* client); Hud(GuiWidget* parent, client::Client* client);
virtual ~Hud();
virtual void Render() override; virtual void Render() override;
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
private: private:
std::string FormatString(); std::string FormatString();
void Draw(const char* title, bool* p_open); void Draw(const char* title, bool* p_open);

View File

@@ -10,7 +10,7 @@ class Client;
} // namespace client } // namespace client
namespace gui { namespace gui {
class LeaderBoardGui : public GuiWidget { class LeaderBoardGui : public GuiWidget, public game::GameListener, public client::ClientListener {
private: private:
void Draw(const char* title, bool* p_open); void Draw(const char* title, bool* p_open);
utils::DelayTimer<float> m_Timer{5.0f}; utils::DelayTimer<float> m_Timer{5.0f};
@@ -19,6 +19,10 @@ class LeaderBoardGui : public GuiWidget {
LeaderBoardGui(GuiWidget* parent, client::Client* client); LeaderBoardGui(GuiWidget* parent, client::Client* client);
~LeaderBoardGui(); ~LeaderBoardGui();
virtual void OnGameStateUpdate(game::GameState gameState) override;
virtual void OnGameJoin() override;
virtual void OnGameLeave() override;
virtual void Render() override; virtual void Render() override;
}; };

View File

@@ -13,6 +13,23 @@ namespace gui {
Hud::Hud(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) { Hud::Hud(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {
m_GunTexture = TextureLoader::LoadGLTexture("textures/fingergun.png"); m_GunTexture = TextureLoader::LoadGLTexture("textures/fingergun.png");
m_JPTexture = TextureLoader::LoadGLTexture("textures/jp.png"); m_JPTexture = TextureLoader::LoadGLTexture("textures/jp.png");
m_Client->BindListener(this);
}
Hud::~Hud() {
m_Client->UnbindListener(this);
}
void Hud::OnGameStateUpdate(game::GameState gameState) {
m_Timer.Reset();
}
void Hud::OnGameJoin() {
m_Client->GetGame()->BindListener(this);
}
void Hud::OnGameLeave() {
m_Client->GetGame()->UnbindListener(this);
} }
void Hud::Draw(const char* title, bool* p_open) { void Hud::Draw(const char* title, bool* p_open) {
@@ -148,9 +165,11 @@ void Hud::Render() {
switch (m_Client->GetGame()->GetGameState()) { switch (m_Client->GetGame()->GetGameState()) {
case game::GameState::gsEnd: { case game::GameState::gsEnd: {
game::Player* firstPlayer = m_Client->GetGame()->GetLeaderBoard().GetPlayers().front(); const auto& players = m_Client->GetGame()->GetLeaderBoard().GetPlayers();
if (!firstPlayer) if (players.empty())
return; return;
game::Player* firstPlayer = players.front();
DrawFinishScreen(firstPlayer->GetID() == m_Client->GetPlayerID()); DrawFinishScreen(firstPlayer->GetID() == m_Client->GetPlayerID());
break; break;
} }

View File

@@ -10,9 +10,20 @@
namespace blitz { namespace blitz {
namespace gui { namespace gui {
LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {} LeaderBoardGui::LeaderBoardGui(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {
m_Client->BindListener(this);
}
LeaderBoardGui::~LeaderBoardGui() {} void LeaderBoardGui::OnGameJoin() {
m_Client->GetGame()->BindListener(this);
}
void LeaderBoardGui::OnGameLeave() {
m_Client->GetGame()->UnbindListener(this);
}
LeaderBoardGui::~LeaderBoardGui() {
m_Client->UnbindListener(this);
}
void LeaderBoardGui::Draw(const char* title, bool* p_open) { void LeaderBoardGui::Draw(const char* title, bool* p_open) {
static float leaderboard_width = 800.0f; static float leaderboard_width = 800.0f;
@@ -62,6 +73,10 @@ void LeaderBoardGui::Draw(const char* title, bool* p_open) {
ImGui::End(); ImGui::End();
} }
void LeaderBoardGui::OnGameStateUpdate(game::GameState gameState) {
m_Timer.Reset();
}
void LeaderBoardGui::Render() { void LeaderBoardGui::Render() {
if (!m_Client->IsConnected()) if (!m_Client->IsConnected())
return; return;
@@ -74,8 +89,6 @@ void LeaderBoardGui::Render() {
if (m_Timer.Update(ImGui::GetIO().DeltaTime)) { if (m_Timer.Update(ImGui::GetIO().DeltaTime)) {
Draw("Leaderboard", nullptr); Draw("Leaderboard", nullptr);
} }
} else {
m_Timer.Reset();
} }
} }