simple leaderboard
All checks were successful
Linux arm64 / Build (push) Successful in 4m34s

This commit is contained in:
Morph01
2024-03-22 09:13:17 +01:00
parent bea98cbe45
commit 63c33e4bc5
4 changed files with 82 additions and 1 deletions

View File

@@ -16,9 +16,10 @@ class Player {
Vec3f m_Velocity;
float m_Yaw;
float m_Pitch;
float m_HP;
public:
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0) {}
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0), m_HP(100) {}
PlayerID GetID() const {
return m_ID;
@@ -75,6 +76,18 @@ class Player {
void AddPitch(float dPitch) {
m_Pitch += dPitch;
}
float GetHP() const {
return m_HP;
}
void SetHP(float HP) {
m_HP = HP;
}
void AddHP(float HP) {
m_HP += HP;
}
};

View File

@@ -0,0 +1,21 @@
#pragma once
#include "GuiWidget.h"
#include "client/Client.h"
namespace blitz {
namespace gui {
class LeaderBoard : public GuiWidget {
private:
void Draw(const char* title, bool* p_open);
public:
LeaderBoard(GuiWidget* parent, Client* client);
~LeaderBoard();
virtual void Render() override;
};
} // namespace gui
} // namespace blitz

View File

@@ -3,6 +3,7 @@
#include "client/gui/GameChatGui.h"
#include "client/gui/Hud.h"
#include "client/gui/MainMenu.h"
#include "client/gui/LeaderBoard.h"
#include <imgui.h>
namespace blitz {
@@ -13,6 +14,7 @@ BlitzGui::BlitzGui(Client* client) : GuiWidget(nullptr, client) {
AddWidget(std::make_unique<GameChatGui>(this, client));
AddWidget(std::make_unique<MainMenu>(client));
AddWidget(std::make_unique<Hud>(this, client));
AddWidget(std::make_unique<LeaderBoard>(this, client));
SetCustomTheme();
}

View File

@@ -0,0 +1,45 @@
#include "client/gui/LeaderBoard.h"
#include "client/game/ClientGame.h"
#include "client/gui/GuiWidget.h"
#include <client/Client.h>
#include <imgui.h>
namespace blitz {
namespace gui {
LeaderBoard::LeaderBoard(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
LeaderBoard::~LeaderBoard() {}
void LeaderBoard::Draw(const char* title, bool* p_open) {
static int leaderboard_width = 620;
static int leaderboard_height = 450;
ImGuiWindowFlags leaderboard_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize;
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(leaderboard_width, leaderboard_height));
ImGui::Begin(title, p_open, leaderboard_flags);
{
for (auto [id, player] : m_Client->GetGame()->GetPlayers()) {
ImGui::Text("%s", player.GetName().c_str());
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x * 10);
ImGui::Text("%.0f", player.GetHP());
}
}
ImGui::End();
}
void LeaderBoard::Render() {
if (!m_Client->IsConnected())
return;
if (ImGui::IsKeyDown(ImGuiKey_Tab)) {
Draw("Leaderboard", nullptr);
}
}
} // namespace gui
} // namespace blitz