ADD: Visualize Upgradeable Buildings
This commit is contained in:
parent
041f423b4f
commit
ca526e0253
BIN
assets/worldIcons/down-arrow.png
Normal file
BIN
assets/worldIcons/down-arrow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/worldIcons/up-arrow.png
Normal file
BIN
assets/worldIcons/up-arrow.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
@ -66,6 +66,7 @@ void GameLayer::onAttach()
|
||||
|
||||
auto modelTexture = AssetManager::loadTexture("warning", "assets/worldIcons/warning.png", loader);
|
||||
AssetManager::loadTexture("error", "assets/worldIcons/error.png", loader);
|
||||
AssetManager::loadTexture("upgrade", "assets/worldIcons/up-arrow.png", loader);
|
||||
|
||||
|
||||
events.subscribe<TurnChangedEvent>([this](const TurnChangedEvent& event) {
|
||||
@ -108,7 +109,15 @@ void GameLayer::onUpdate()
|
||||
|
||||
if (gameInputUser->isKeyboardEnabled()) {
|
||||
if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_U)) {
|
||||
gameMode->setUpgradeMode(!gameMode->isUpgradeMode());
|
||||
if (gameMode->isUpgradeMode()) {
|
||||
// Disable upgrade mode in upgrade system
|
||||
UpgradeSystem::disableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode);
|
||||
gameMode->setUpgradeMode(false);
|
||||
} else {
|
||||
UpgradeSystem::enableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode, *turnState);
|
||||
gameMode->setUpgradeMode(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,13 @@
|
||||
#include "../../../../engine/core/ECS/TileRenderComponent.h"
|
||||
#include "../../../../engine/core/ECS/ModelComponent.h"
|
||||
#include "../../../../engine/core/ECS/ModelStateComponent.h"
|
||||
#include "../../../../engine/renderer/loader/AssetManager.h"
|
||||
#include "../components/TileGameplayComponent.h"
|
||||
#include "../../../../engine/core/ECS/WorldSpriteComponent.h"
|
||||
#include "../../../../engine/core/animations/AnimationComponent.h"
|
||||
|
||||
class AnimationComponent;
|
||||
class WorldSpriteComponent;
|
||||
|
||||
void UpgradeSystem::tryUpdate(EntityManager &em, GameMode &gm, PlayerID player, const TurnState &turnState) {
|
||||
EntityID tileEntityID = SelectionSystem::selectedEntity;
|
||||
@ -55,6 +61,34 @@ void UpgradeSystem::tryUpdate(EntityManager &em, GameMode &gm, PlayerID player,
|
||||
|
||||
}
|
||||
|
||||
void UpgradeSystem::enableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode, const TurnState &turnState) {
|
||||
for (EntityID entityID : em.getAllEntities()) {
|
||||
auto buildingComponent = em.getComponent<BuildingComponent>(entityID);
|
||||
auto ownerComponent = em.getComponent<OwnerComponent>(entityID);
|
||||
|
||||
if (buildingComponent && ownerComponent && ownerComponent->playerID == player) {
|
||||
const auto upgradeResult = canUpgrade(em, player, gameMode, entityID, turnState);
|
||||
if (upgradeResult == UpgradeResult::Ok || upgradeResult == UpgradeResult::NotPlayersTurn) {
|
||||
createWorldSprite(em, entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpgradeSystem::disableUpgradeMode(EntityManager &em, PlayerID player, GameMode &gameMode) {
|
||||
for (EntityID entityID : em.getAllEntities()) {
|
||||
const auto buildingComponent = em.getComponent<BuildingComponent>(entityID);
|
||||
const auto ownerComponent = em.getComponent<OwnerComponent>(entityID);
|
||||
const auto worldSpriteComponent = em.getComponent<WorldSpriteComponent>(entityID);
|
||||
const auto animComponent = em.getComponent<AnimationComponent>(entityID);
|
||||
|
||||
if (buildingComponent && ownerComponent && ownerComponent->playerID == player && worldSpriteComponent) {
|
||||
em.removeComponent<WorldSpriteComponent>(entityID);
|
||||
em.removeComponent<AnimationComponent>(entityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeResult UpgradeSystem::canUpgrade(EntityManager &em, PlayerID player, GameMode& gameMode, EntityID buildingEntity, const TurnState &turnState) {
|
||||
if (!gameMode.hasTurn(player, turnState.currentTurn)) return UpgradeResult::NotPlayersTurn;
|
||||
|
||||
@ -78,3 +112,34 @@ UpgradeResult UpgradeSystem::canUpgrade(EntityManager &em, PlayerID player, Game
|
||||
|
||||
return UpgradeResult::Ok;
|
||||
}
|
||||
|
||||
void UpgradeSystem::createWorldSprite(EntityManager &em, EntityID e) {
|
||||
auto iconTexture = AssetManager::getTexture("upgrade");
|
||||
|
||||
auto worldSpritePtr = std::make_shared<WorldSpriteComponent>();
|
||||
std::weak_ptr<WorldSpriteComponent> weakSprite = worldSpritePtr;
|
||||
worldSpritePtr->texture = iconTexture;
|
||||
worldSpritePtr->iconName = "upgrade";
|
||||
|
||||
auto anim = std::make_shared<AnimationComponent>();
|
||||
|
||||
float baseY = worldSpritePtr->offset.y;
|
||||
|
||||
anim->tracks.push_back({
|
||||
AnimationCurve{CurveType::Sine, 0.3f, 5.f},
|
||||
[weakSprite, baseY](float v) {
|
||||
if (auto sprite = weakSprite.lock()) {
|
||||
sprite->offset.y = baseY + v;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!em.getComponent<WorldSpriteComponent>(e)) {
|
||||
em.addComponent(e, worldSpritePtr);
|
||||
}
|
||||
|
||||
if (!em.getComponent<AnimationComponent>(e)) {
|
||||
em.addComponent(e, anim);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,11 @@ class EntityManager;
|
||||
class UpgradeSystem {
|
||||
public:
|
||||
static void tryUpdate(EntityManager &em, GameMode &gm, PlayerID player, const TurnState &turnState);
|
||||
static void enableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode, const TurnState &turnState);
|
||||
static void disableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode);
|
||||
|
||||
private:
|
||||
static void createWorldSprite(EntityManager &em, EntityID e);
|
||||
static UpgradeResult canUpgrade(EntityManager &em, PlayerID player, GameMode &gameMode, EntityID buildingEntity, const TurnState &turnState);
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user