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

@@ -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