From c5289cb1b062c9e31255280f924fc5802108d12a Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sat, 6 Nov 2021 16:11:13 +0100 Subject: [PATCH] feat: add working upgrade popup --- include/game/client/ClientGame.h | 1 + src/game/client/WorldClient.cpp | 1 + src/render/WorldRenderer.cpp | 32 ++++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/game/client/ClientGame.h b/include/game/client/ClientGame.h index 9663e06..e58965d 100644 --- a/include/game/client/ClientGame.h +++ b/include/game/client/ClientGame.h @@ -34,6 +34,7 @@ public: std::uint32_t getLobbyTime() const { return m_LobbyTime; } const game::Player* getPlayer() const { return m_Player; } const WorldClient& getWorld() const { return m_WorldClient; } + Client* getClient() const { return m_Client; } render::Renderer* getRenderer() const { return m_Renderer; } diff --git a/src/game/client/WorldClient.cpp b/src/game/client/WorldClient.cpp index 44f4fda..660c775 100644 --- a/src/game/client/WorldClient.cpp +++ b/src/game/client/WorldClient.cpp @@ -10,6 +10,7 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet GetDispatcher()->RegisterHandler(protocol::PacketType::WorldBeginData, this); GetDispatcher()->RegisterHandler(protocol::PacketType::WorldData, this); GetDispatcher()->RegisterHandler(protocol::PacketType::SpawnMob, this); + GetDispatcher()->RegisterHandler(protocol::PacketType::UpgradeTower, this); } void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) { diff --git a/src/render/WorldRenderer.cpp b/src/render/WorldRenderer.cpp index 58f7c94..7d8cf6d 100644 --- a/src/render/WorldRenderer.cpp +++ b/src/render/WorldRenderer.cpp @@ -5,6 +5,7 @@ #include "gui/imgui/imgui_internal.h" #include "window/Display.h" #include "game/client/ClientGame.h" +#include "game/client/Client.h" #include @@ -183,21 +184,44 @@ void WorldRenderer::renderTowerUpgradePopup() { if (x > 0) ImGui::SameLine(); - const game::TowerStats* towerStats = game::getTowerStats(tower->getType(), { x + 1, game::TowerPath(y) }); + int currentLevel = x + 1; + game::TowerPath currentPath = game::TowerPath(y); + + const game::TowerStats* towerStats = game::getTowerStats(tower->getType(), { currentLevel, currentPath }); + game::TowerPath towerPath = tower->getLevel().getPath(); bool disabled = towerStats == nullptr; + int towerLevel = tower->getLevel().getLevel(); + + bool alreadyUpgraded = currentLevel <= towerLevel; + bool canUpgrade = (towerLevel + 1) == currentLevel; + + if(canUpgrade && towerPath != game::TowerPath::Base){ + if(currentPath != towerPath){ + canUpgrade = false; + } + } + ImGui::PushID(x * 4 + y); if (disabled) { ImGui::BeginDisabled(); - ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_PopupBg)); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); ImGui::Button("", ImVec2(100, 100)); ImGui::PopStyleColor(); ImGui::EndDisabled(); - } else { + } else if (alreadyUpgraded) { + ImGui::BeginDisabled(); + ImGui::Button("Already", ImVec2(100, 100)); + ImGui::EndDisabled(); + } else if (canUpgrade) { if (ImGui::Button("Upgrade", ImVec2(100, 100))) { - std::cout << "Clicked !\n"; + m_Client->getClient()->upgradeTower(tower->getID(), {currentLevel, currentPath}); } + } else { + ImGui::BeginDisabled(); + ImGui::Button("Locked", ImVec2(100, 100)); + ImGui::EndDisabled(); } ImGui::PopID(); }