This commit is contained in:
@@ -10,15 +10,16 @@ class Client;
|
||||
namespace gui {
|
||||
class Hud : public GuiWidget {
|
||||
private:
|
||||
/* data */
|
||||
|
||||
void Draw(const char* title, bool* p_open);
|
||||
unsigned int m_GunTexture;
|
||||
unsigned int m_JP;
|
||||
unsigned int m_JPTexture;
|
||||
|
||||
public:
|
||||
Hud(GuiWidget* parent, Client* client);
|
||||
virtual void Render() override;
|
||||
|
||||
private:
|
||||
void Draw(const char* title, bool* p_open);
|
||||
void RenderTime();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace gui {
|
||||
|
||||
Hud::Hud(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {
|
||||
m_GunTexture = TextureLoader::LoadGLTexture("fingergun.png");
|
||||
m_JP = TextureLoader::LoadGLTexture("jp.png");
|
||||
m_JPTexture = TextureLoader::LoadGLTexture("jp.png");
|
||||
}
|
||||
|
||||
void Hud::Draw(const char* title, bool* p_open) {
|
||||
@@ -20,7 +20,6 @@ void Hud::Draw(const char* title, bool* p_open) {
|
||||
ImGui::Begin(title, nullptr, GetWindowFullScreenFlags() | ImGuiWindowFlags_NoInputs);
|
||||
|
||||
auto displaySize = ImGui::GetIO().DisplaySize;
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
|
||||
const static ImVec2 buttonSize = {300, 60};
|
||||
const static ImVec2 fingergunSize = {256, 134.5};
|
||||
@@ -34,17 +33,12 @@ void Hud::Draw(const char* title, bool* p_open) {
|
||||
displaySize.x - fingergunSize.x - paddingHeight, displaySize.y - fingergunSize.y + 1.0f / 2.5f * paddingHeight};
|
||||
ImVec2 spacing = ImGui::GetStyle().ItemInnerSpacing;
|
||||
|
||||
const float timetextWidth = ImGui::CalcTextSize("03 : 00").x;
|
||||
const float timetextHeight = ImGui::CalcTextSize("03 : 00").y;
|
||||
|
||||
ImGui::SetCursorPosX(center.x - timetextWidth / 2);
|
||||
ImGui::SetCursorPosY(timetextHeight / 2);
|
||||
ImGui::Text("03 : 00");
|
||||
RenderTime();
|
||||
|
||||
ImGui::SetCursorPosX(3 * paddingHeight);
|
||||
ImGui::SetCursorPosY(pvBarPos.y - 2 * paddingHeight);
|
||||
ImGui::BeginGroup();
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(m_JP), jpSize);
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(m_JPTexture), jpSize);
|
||||
|
||||
ImGui::SameLine(0.0f, paddingHeight);
|
||||
|
||||
@@ -78,6 +72,34 @@ void Hud::Draw(const char* title, bool* p_open) {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void Hud::RenderTime() {
|
||||
|
||||
std::string timeFormated;
|
||||
|
||||
std::uint64_t timeRemaining = m_Client->GetGame()->GetGameStateRemainingTime();
|
||||
|
||||
if (timeRemaining == 0) {
|
||||
timeFormated = "Waiting for players ...";
|
||||
} else {
|
||||
timeRemaining += 1000;
|
||||
|
||||
int seconds = timeRemaining / 1000 % 60;
|
||||
int minutes = timeRemaining / 1000 / 60;
|
||||
|
||||
timeFormated = (minutes < 10 ? "0" + std::to_string(minutes) : std::to_string(minutes)) + " : " +
|
||||
(seconds < 10 ? "0" + std::to_string(seconds) : std::to_string(seconds));
|
||||
}
|
||||
|
||||
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
const float timetextWidth = ImGui::CalcTextSize(timeFormated.c_str()).x;
|
||||
const float timetextHeight = ImGui::CalcTextSize(timeFormated.c_str()).y;
|
||||
|
||||
ImGui::SetCursorPosX(center.x - timetextWidth / 2);
|
||||
ImGui::SetCursorPosY(timetextHeight / 2);
|
||||
ImGui::Text("%s", timeFormated.c_str());
|
||||
}
|
||||
|
||||
void Hud::Render() {
|
||||
if (!m_Client->IsConnected())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user