feat: add working upgrade popup

This commit is contained in:
2021-11-06 16:11:13 +01:00
parent ae802b4253
commit c5289cb1b0
3 changed files with 30 additions and 4 deletions

View File

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

View File

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

View File

@@ -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();
}