feat: add working upgrade popup
This commit is contained in:
@@ -34,6 +34,7 @@ public:
|
|||||||
std::uint32_t getLobbyTime() const { return m_LobbyTime; }
|
std::uint32_t getLobbyTime() const { return m_LobbyTime; }
|
||||||
const game::Player* getPlayer() const { return m_Player; }
|
const game::Player* getPlayer() const { return m_Player; }
|
||||||
const WorldClient& getWorld() const { return m_WorldClient; }
|
const WorldClient& getWorld() const { return m_WorldClient; }
|
||||||
|
Client* getClient() const { return m_Client; }
|
||||||
|
|
||||||
render::Renderer* getRenderer() const { return m_Renderer; }
|
render::Renderer* getRenderer() const { return m_Renderer; }
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ WorldClient::WorldClient(ClientGame* game) : game::World(game), protocol::Packet
|
|||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::WorldBeginData, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::WorldBeginData, this);
|
||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::WorldData, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::WorldData, this);
|
||||||
GetDispatcher()->RegisterHandler(protocol::PacketType::SpawnMob, this);
|
GetDispatcher()->RegisterHandler(protocol::PacketType::SpawnMob, this);
|
||||||
|
GetDispatcher()->RegisterHandler(protocol::PacketType::UpgradeTower, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
void WorldClient::HandlePacket(const protocol::WorldBeginDataPacket* packet) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "gui/imgui/imgui_internal.h"
|
#include "gui/imgui/imgui_internal.h"
|
||||||
#include "window/Display.h"
|
#include "window/Display.h"
|
||||||
#include "game/client/ClientGame.h"
|
#include "game/client/ClientGame.h"
|
||||||
|
#include "game/client/Client.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -183,21 +184,44 @@ void WorldRenderer::renderTowerUpgradePopup() {
|
|||||||
if (x > 0)
|
if (x > 0)
|
||||||
ImGui::SameLine();
|
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;
|
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);
|
ImGui::PushID(x * 4 + y);
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
ImGui::BeginDisabled();
|
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::Button("", ImVec2(100, 100));
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
ImGui::EndDisabled();
|
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))) {
|
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();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user