refactor: create gui widget classes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
42
src/render/gui/MobTooltip.cpp
Normal file
42
src/render/gui/MobTooltip.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "render/gui/MobTooltip.h"
|
||||
#include "render/gui/imgui/imgui.h"
|
||||
|
||||
#include "render/WorldRenderer.h"
|
||||
|
||||
#include "game/Mobs.h"
|
||||
|
||||
#include "game/client/Client.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
MobTooltip::MobTooltip(client::Client* client) : GuiWidget(client) {
|
||||
|
||||
}
|
||||
|
||||
void MobTooltip::render() {
|
||||
if(m_Mob == nullptr) return;
|
||||
|
||||
const game::Player& sender = getClient()->getGame().getPlayerById(m_Mob->getSender());
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("Sender :");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, render::WorldRenderer::getImGuiTeamColor(sender.getTeamColor()));
|
||||
ImGui::Text("%s", sender.getName().c_str());
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::Text("Mob HP : %.1f/%i", m_Mob->getHealth(), m_Mob->getStats()->getMaxLife());
|
||||
ImGui::Text("Mob Type : %s", game::MobFactory::getMobName(m_Mob->getType()).c_str());
|
||||
ImGui::Text("Mob Level : %i", m_Mob->getLevel());
|
||||
ImGui::NewLine();
|
||||
ImGui::Text("Mob Stats :");
|
||||
ImGui::Text("\tMax health : %i", m_Mob->getStats()->getMaxLife());
|
||||
ImGui::Text("\tSpeed : %.1f", m_Mob->getStats()->getMovementSpeed());
|
||||
ImGui::Text("\tDamage : %.1f", m_Mob->getStats()->getDamage());
|
||||
ImGui::Text("\tMoney cost : %i", m_Mob->getStats()->getMoneyCost());
|
||||
ImGui::Text("\tEXP cost : %i", m_Mob->getStats()->getExpCost());
|
||||
ImGui::Text("\tEXP reward : %i", m_Mob->getStats()->getExpReward());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
41
src/render/gui/TowerPlacePopup.cpp
Normal file
41
src/render/gui/TowerPlacePopup.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "render/gui/TowerPlacePopup.h"
|
||||
|
||||
#include "render/gui/imgui/imgui.h"
|
||||
|
||||
#include "game/Towers.h"
|
||||
|
||||
#include "game/client/Client.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
TowerPlacePopup::TowerPlacePopup(client::Client* client) : GuiWidget(client) {
|
||||
|
||||
}
|
||||
|
||||
void TowerPlacePopup::render(){
|
||||
if (ImGui::BeginPopup("TowerPlace")) {
|
||||
for (int i = 0; i < (int)game::TowerType::TowerCount; i++) {
|
||||
game::TowerType towerType = game::TowerType(i);
|
||||
const game::TowerInfo& towerInfo = game::getTowerInfo(towerType);
|
||||
if (!towerInfo.isBigTower() || (towerInfo.isBigTower() && getClient()->getGame().getWorld().CanPlaceBigTower(m_ClickWorldPos, getClient()->getGame().getPlayer()->getID()))) {
|
||||
if (ImGui::Button(game::getTowerInfo(towerType).getName().c_str())) {
|
||||
getClient()->placeTower(towerType, m_ClickWorldPos);
|
||||
ImGui::CloseCurrentPopup();
|
||||
break;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip(game::getTowerInfo(towerType).getDescription().c_str(), "%s");
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void TowerPlacePopup::setClickPos(const glm::vec2& worldPos){
|
||||
m_ClickWorldPos = worldPos;
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user