feat: add working upgrade popup
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 <iostream>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user