1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

vcmi: now obstacles can have disappearing anim

It is a reverse version of appearingAnimation.
This commit is contained in:
Konstantin
2023-03-26 19:57:21 +03:00
parent 7543fdf787
commit eff41f66ed
8 changed files with 108 additions and 13 deletions

View File

@@ -74,6 +74,37 @@ void BattleObstacleController::loadObstacleImage(const CObstacleInstance & oi)
obstacleAnimations[oi.uniqueID] = animationsCache[animationName];
}
void BattleObstacleController::obstacleRemoved(const std::vector<ObstacleChanges> & obstacles)
{
for (auto const & oi : obstacles)
{
auto & obstacle = oi.data["obstacle"];
if (!obstacle.isStruct())
{
logGlobal->error("I don't know how to animate removal of this obstacle");
continue;
}
auto animation = std::make_shared<CAnimation>(obstacle["appearAnimation"].String());
animation->preload();
auto first = animation->getImage(0, 0);
if(!first)
continue;
//we assume here that effect graphics have the same size as the usual obstacle image
// -> if we know how to blit obstacle, let's blit the effect in the same place
Point whereTo = getObstaclePosition(first, obstacle);
//AFAIK, in H3 there is no sound of obstacle removal
owner.stacksController->addNewAnim(new EffectAnimation(owner, obstacle["appearAnimation"].String(), whereTo, obstacle["position"].Integer(), 0, true));
obstacleAnimations.erase(oi.id);
//so when multiple obstacles are removed, they show up one after another
owner.waitForAnimations();
}
}
void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<const CObstacleInstance>> & obstacles)
{
for (auto const & oi : obstacles)
@@ -87,7 +118,7 @@ void BattleObstacleController::obstaclePlaced(const std::vector<std::shared_ptr<
if (!spellObstacle)
{
logGlobal->error("I don't know how to animate appearing obstacle of type %d", (int)oi->obstacleType);
logGlobal->error("I don't know how to animate removal of obstacle of type %d", (int)oi->obstacleType);
continue;
}
@@ -180,3 +211,19 @@ Point BattleObstacleController::getObstaclePosition(std::shared_ptr<IImage> imag
return r.topLeft();
}
Point BattleObstacleController::getObstaclePosition(std::shared_ptr<IImage> image, const JsonNode & obstacle)
{
auto animationYOffset = obstacle["animationYOffset"].Integer();
auto offset = image->height() % 42;
if(obstacle["needAnimationOffsetFix"].Bool() && offset > 37)
animationYOffset -= 42;
offset += animationYOffset;
Rect r = owner.fieldController->hexPositionLocal(obstacle["position"].Integer());
r.y += 42 - image->height() + offset;
return r.topLeft();
}