This commit is contained in:
@@ -14,7 +14,7 @@ class Player;
|
||||
} // namespace game
|
||||
|
||||
namespace gui {
|
||||
class Hud : public GuiWidget {
|
||||
class Hud : public GuiWidget, public game::GameListener, public client::ClientListener {
|
||||
private:
|
||||
std::uint64_t m_GunTexture;
|
||||
std::uint64_t m_JPTexture;
|
||||
@@ -22,8 +22,13 @@ class Hud : public GuiWidget {
|
||||
|
||||
public:
|
||||
Hud(GuiWidget* parent, client::Client* client);
|
||||
virtual ~Hud();
|
||||
virtual void Render() override;
|
||||
|
||||
virtual void OnGameStateUpdate(game::GameState gameState) override;
|
||||
virtual void OnGameJoin() override;
|
||||
virtual void OnGameLeave() override;
|
||||
|
||||
private:
|
||||
std::string FormatString();
|
||||
void Draw(const char* title, bool* p_open);
|
||||
|
||||
@@ -10,7 +10,7 @@ class Client;
|
||||
} // namespace client
|
||||
|
||||
namespace gui {
|
||||
class LeaderBoardGui : public GuiWidget {
|
||||
class LeaderBoardGui : public GuiWidget, public game::GameListener, public client::ClientListener {
|
||||
private:
|
||||
void Draw(const char* title, bool* p_open);
|
||||
utils::DelayTimer<float> m_Timer{5.0f};
|
||||
@@ -19,6 +19,10 @@ class LeaderBoardGui : public GuiWidget {
|
||||
LeaderBoardGui(GuiWidget* parent, client::Client* client);
|
||||
~LeaderBoardGui();
|
||||
|
||||
virtual void OnGameStateUpdate(game::GameState gameState) override;
|
||||
virtual void OnGameJoin() override;
|
||||
virtual void OnGameLeave() override;
|
||||
|
||||
virtual void Render() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,23 @@ namespace gui {
|
||||
Hud::Hud(GuiWidget* parent, client::Client* client) : GuiWidget(parent, client) {
|
||||
m_GunTexture = TextureLoader::LoadGLTexture("textures/fingergun.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) {
|
||||
@@ -148,9 +165,11 @@ void Hud::Render() {
|
||||
|
||||
switch (m_Client->GetGame()->GetGameState()) {
|
||||
case game::GameState::gsEnd: {
|
||||
game::Player* firstPlayer = m_Client->GetGame()->GetLeaderBoard().GetPlayers().front();
|
||||
if (!firstPlayer)
|
||||
const auto& players = m_Client->GetGame()->GetLeaderBoard().GetPlayers();
|
||||
if (players.empty())
|
||||
return;
|
||||
|
||||
game::Player* firstPlayer = players.front();
|
||||
DrawFinishScreen(firstPlayer->GetID() == m_Client->GetPlayerID());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -10,9 +10,20 @@
|
||||
namespace blitz {
|
||||
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) {
|
||||
static float leaderboard_width = 800.0f;
|
||||
@@ -62,6 +73,10 @@ void LeaderBoardGui::Draw(const char* title, bool* p_open) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void LeaderBoardGui::OnGameStateUpdate(game::GameState gameState) {
|
||||
m_Timer.Reset();
|
||||
}
|
||||
|
||||
void LeaderBoardGui::Render() {
|
||||
if (!m_Client->IsConnected())
|
||||
return;
|
||||
@@ -74,8 +89,6 @@ void LeaderBoardGui::Render() {
|
||||
if (m_Timer.Update(ImGui::GetIO().DeltaTime)) {
|
||||
Draw("Leaderboard", nullptr);
|
||||
}
|
||||
} else {
|
||||
m_Timer.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user