2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CCreatureAnimation.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/FunctionList.h"
|
|
|
|
#include "../widgets/Images.h"
|
2017-09-05 17:59:26 +02:00
|
|
|
#include "../gui/CAnimation.h"
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-12-17 21:59:59 +03:00
|
|
|
class CIntObject;
|
2013-07-06 19:10:20 +03:00
|
|
|
class CCreatureAnimation;
|
2022-11-26 23:12:20 +02:00
|
|
|
class CCanvas;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
/// Namespace for some common controls of animations
|
|
|
|
namespace AnimationControls
|
|
|
|
{
|
|
|
|
/// get SDL_Color for creature selection borders
|
|
|
|
SDL_Color getBlueBorder();
|
|
|
|
SDL_Color getGoldBorder();
|
|
|
|
SDL_Color getNoBorder();
|
|
|
|
|
|
|
|
/// creates animation object with preset speed control
|
2018-07-25 00:36:48 +02:00
|
|
|
std::shared_ptr<CCreatureAnimation> getAnimation(const CCreature * creature);
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2013-07-16 21:12:47 +03:00
|
|
|
/// returns animation speed of specific group, taking in mind game setting (in frames per second)
|
2013-07-06 19:10:20 +03:00
|
|
|
float getCreatureAnimationSpeed(const CCreature * creature, const CCreatureAnimation * anim, size_t groupID);
|
|
|
|
|
|
|
|
/// returns how far projectile should move each frame
|
|
|
|
/// TODO: make it time-based
|
|
|
|
float getProjectileSpeed();
|
|
|
|
|
2013-07-16 21:12:47 +03:00
|
|
|
/// returns speed of any spell effects, including any special effects like morale (in frames per second)
|
|
|
|
float getSpellEffectSpeed();
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
/// returns duration of full movement animation, in seconds. Needed to move animation on screen
|
|
|
|
float getMovementDuration(const CCreature * creature);
|
|
|
|
|
|
|
|
/// Returns distance on which flying creatures should during one animation loop
|
|
|
|
float getFlightDistance(const CCreature * creature);
|
|
|
|
}
|
2010-08-17 17:58:13 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Class which manages animations of creatures/units inside battles
|
2013-07-06 19:10:20 +03:00
|
|
|
/// TODO: split into constant image container and class that does *control* of animation
|
2009-04-16 14:14:13 +03:00
|
|
|
class CCreatureAnimation : public CIntObject
|
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
public:
|
2014-08-04 21:33:59 +03:00
|
|
|
typedef std::function<float(CCreatureAnimation *, size_t)> TSpeedController;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
private:
|
2017-09-05 19:45:29 +02:00
|
|
|
std::string name;
|
2017-09-05 17:59:26 +02:00
|
|
|
std::shared_ptr<CAnimation> forward;
|
|
|
|
std::shared_ptr<CAnimation> reverse;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
2017-09-05 17:59:26 +02:00
|
|
|
int fullWidth;
|
|
|
|
int fullHeight;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
// speed of animation, measure in frames per second
|
|
|
|
float speed;
|
|
|
|
|
|
|
|
// currently displayed frame. Float to allow H3-style animations where frames
|
|
|
|
// don't display for integer number of frames
|
|
|
|
float currentFrame;
|
|
|
|
// cumulative, real-time duration of animation. Used for effects like selection border
|
|
|
|
float elapsedTime;
|
|
|
|
CCreatureAnim::EAnimType type; //type of animation being displayed
|
|
|
|
|
|
|
|
// border color, disabled if alpha = 0
|
|
|
|
SDL_Color border;
|
|
|
|
|
|
|
|
TSpeedController speedController;
|
|
|
|
|
|
|
|
bool once; // animation will be played once and the reset to idling
|
|
|
|
|
|
|
|
void endAnimation();
|
2011-03-22 15:19:07 +02:00
|
|
|
|
2017-09-05 17:59:26 +02:00
|
|
|
|
|
|
|
void genBorderPalette(IImage::BorderPallete & target);
|
2011-03-22 15:19:07 +02:00
|
|
|
public:
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
// function(s) that will be called when animation ends, after reset to 1st frame
|
|
|
|
// NOTE that these function will be fired only once
|
|
|
|
CFunctionList<void()> onAnimationReset;
|
|
|
|
|
|
|
|
int getWidth() const;
|
|
|
|
int getHeight() const;
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
/// name - path to .def file, relative to SPRITES/ directory
|
|
|
|
/// controller - function that will return for how long *each* frame
|
|
|
|
/// in specified group of animation should be played, measured in seconds
|
2017-09-05 19:45:29 +02:00
|
|
|
CCreatureAnimation(const std::string & name_, TSpeedController speedController);
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-02-09 15:56:30 +02:00
|
|
|
void setType(CCreatureAnim::EAnimType type); //sets type of animation and cleares framecount
|
|
|
|
CCreatureAnim::EAnimType getType() const; //returns type of animation
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2022-11-27 17:24:45 +02:00
|
|
|
void nextFrame(std::shared_ptr<CCanvas> canvas, bool facingRight);
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
// should be called every frame, return true when animation was reset to beginning
|
|
|
|
bool incrementFrame(float timePassed);
|
|
|
|
void setBorderColor(SDL_Color palette);
|
|
|
|
|
2020-01-25 11:21:26 +02:00
|
|
|
// tint color effect
|
2020-01-26 10:01:48 +02:00
|
|
|
void shiftColor(const ColorShifter * shifter);
|
2020-01-25 11:21:26 +02:00
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
float getCurrentFrame() const; // Gets the current frame ID relative to frame group.
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-02-09 15:56:30 +02:00
|
|
|
void playOnce(CCreatureAnim::EAnimType type); //plays once given stage of animation, then resets to 2
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2017-09-08 13:25:12 +02:00
|
|
|
int framesInGroup(CCreatureAnim::EAnimType group) const;
|
2013-07-06 19:10:20 +03:00
|
|
|
|
|
|
|
void pause();
|
|
|
|
void play();
|
|
|
|
|
|
|
|
//helpers. TODO: move them somewhere else
|
|
|
|
bool isDead() const;
|
2022-11-28 22:35:38 +02:00
|
|
|
bool isDying() const;
|
|
|
|
bool isDeadOrDying() const;
|
2013-07-06 19:10:20 +03:00
|
|
|
bool isIdle() const;
|
2013-07-21 13:10:38 +03:00
|
|
|
bool isMoving() const;
|
|
|
|
bool isShooting() const;
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|