refactor: create gui widget classes

This commit is contained in:
2021-11-12 19:55:58 +01:00
parent 4ad7015f72
commit 830cb061e2
11 changed files with 166 additions and 67 deletions

View File

@@ -1,24 +1,14 @@
#include "render/gui/GameMenu.h"
#include "render/gui/imgui/imgui.h"
#include "render/WorldRenderer.h"
#include "game/client/Client.h"
#include "game/server/Lobby.h"
namespace td {
namespace gui {
ImVec4 getImGuiTeamColor(td::game::TeamColor color) {
switch (color) {
case td::game::TeamColor::None:
break;
case td::game::TeamColor::Red:
return ImVec4(1, 0, 0, 1);
case td::game::TeamColor::Blue:
return ImVec4(0, 0, 1, 1);
}
return ImVec4(1, 1, 1, 1);
}
GameMenu::GameMenu(client::Client* client) : GuiWidget(client), m_SummonMenu(std::make_unique<SummonMenu>(client)) {
}
@@ -51,7 +41,7 @@ void GameMenu::showPlayers() {
if (ImGui::TreeNode(std::string("Players (" + std::to_string(getClient()->getGame().getPlayers().size()) + ")##player_list").c_str())) {
for (auto pair : getClient()->getGame().getPlayers()) {
const td::game::Player& player = pair.second;
ImGui::PushStyleColor(ImGuiCol_Text, getImGuiTeamColor(player.getTeamColor()));
ImGui::PushStyleColor(ImGuiCol_Text, render::WorldRenderer::getImGuiTeamColor(player.getTeamColor()));
ImGui::Text("%s", player.getName().c_str());
ImGui::PopStyleColor();
}