axmol/extensions/DragonBones/animation/Animation.h

476 lines
18 KiB
C
Raw Normal View History

2021-12-26 23:26:34 +08:00
/**
* The MIT License (MIT)
*
* Copyright (c) 2012-2018 DragonBones team and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
2021-12-25 10:04:45 +08:00
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef DRAGONBONES_ANIMATION_H
#define DRAGONBONES_ANIMATION_H
#include "../core/BaseObject.h"
DRAGONBONES_NAMESPACE_BEGIN
/**
* - The animation player is used to play the animation data and manage the animation states.
* @see dragonBones.AnimationData
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see dragonBones.AnimationData
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
class Animation final : public BaseObject
{
BIND_CLASS_TYPE_B(Animation);
public:
/**
* - The play speed of all animations. [0: Stop, (0~1): Slow, 1: Normal, (1~N): Fast]
* @default 1.0
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* - [0: , (0~1): , 1: , (1~N): ]
* @default 1.0
* @version DragonBones 3.0
* @language zh_CN
*/
float timeScale;
2021-12-25 10:04:45 +08:00
private:
bool _animationDirty;
float _inheritTimeScale;
std::vector<std::string> _animationNames;
std::vector<AnimationState*> _animationStates;
2021-12-27 13:52:08 +08:00
hlookup::string_map<AnimationData*> _animations;
Armature* _armature;
AnimationConfig* _animationConfig;
AnimationState* _lastAnimationState;
public:
2021-12-25 10:04:45 +08:00
Animation() : _animationConfig(nullptr) { _onClear(); }
~Animation() { _onClear(); }
private:
void _fadeOut(AnimationConfig* animationConfig);
protected:
virtual void _onClear() override;
public:
/**
* @internal
*/
void init(Armature* armature);
/**
* @internal
*/
void advanceTime(float passedTime);
/**
* - Clear all animations states.
* @see dragonBones.AnimationState
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see dragonBones.AnimationState
* @version DragonBones 4.5
* @language zh_CN
*/
void reset();
/**
* - Pause a specific animation state.
* @param animationName - The name of animation state. (If not set, it will pause all animations)
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
void stop(std::string_view animationName);
/**
* - Play animation with a specific animation config.
* The API is still in the experimental phase and may encounter bugs or stability or compatibility issues when used.
* @param animationConfig - The animation config.
* @returns The playing animation state.
* @see dragonBones.AnimationConfig
* @beta
* @version DragonBones 5.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* API 使 bug
* @param animationConfig -
* @returns
* @see dragonBones.AnimationConfig
* @beta
* @version DragonBones 5.0
* @language zh_CN
*/
AnimationState* playConfig(AnimationConfig* animationConfig);
/**
* - Play a specific animation.
2021-12-25 10:04:45 +08:00
* @param animationName - The name of animation data. (If not set, The default animation will be played, or resume
* the animation playing from pause status, or replay the last playing animation)
* @param playTimes - Playing repeat times. [-1: Use default value of the animation data, 0: No end loop playing,
* [1~N]: Repeat N times] (default: -1)
* @returns The playing animation state.
* @example
* TypeScript style, for reference only.
* <pre>
* armature.animation.play("walk");
* </pre>
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
2021-12-25 10:04:45 +08:00
* @param animationName -
*
2021-12-24 21:11:44 +08:00
* @param playTimes - [-1: 使, 0: , [1~N]: N ] : -1
* @returns
* @example
2021-12-24 21:11:44 +08:00
* TypeScript
* <pre>
* armature.animation.play("walk");
* </pre>
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* play(std::string_view animationName = "", int playTimes = -1);
/**
* - Fade in a specific animation.
* @param animationName - The name of animation data.
2021-12-25 10:04:45 +08:00
* @param fadeInTime - The fade in time. [-1: Use the default value of animation data, [0~N]: The fade in time (In
* seconds)] (Default: -1)
* @param playTimes - playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing,
* [1~N]: Repeat N times] (Default: -1)
* @param layer - The blending layer, the animation states in high level layer will get the blending weights with
* high priority, when the total blending weights are more than 1.0, there will be no more weights can be allocated
* to the other animation states. (Default: 0)
* @param group - The blending group name, it is typically used to specify the substitution of multiple animation
* states blending. (Default: null)
* @param fadeOutMode - The fade out mode, which is typically used to specify alternate mode of multiple animation
* states blending. (Default: AnimationFadeOutMode.SameLayerAndGroup)
* @returns The playing animation state.
* @example
* TypeScript style, for reference only.
* <pre>
* armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
* armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;
* </pre>
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param fadeInTime - [-1: 使, [0~N]: ()] : -1
* @param playTimes - [-1: 使, 0: , [1~N]: N ] : -1
2021-12-25 10:04:45 +08:00
* @param layer - 1.0
* : 0
2021-12-24 21:11:44 +08:00
* @param group - : null
2021-12-25 10:04:45 +08:00
* @param fadeOutMode - :
* AnimationFadeOutMode.SameLayerAndGroup
2021-12-24 21:11:44 +08:00
* @returns
* @example
2021-12-24 21:11:44 +08:00
* TypeScript
* <pre>
* armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
* armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;
* </pre>
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* fadeIn(std::string_view animationName,
2021-12-25 10:04:45 +08:00
float fadeInTime = -1.f,
int playTimes = -1,
int layer = 0,
2021-12-28 11:00:34 +08:00
std::string_view group = "",
2021-12-25 10:04:45 +08:00
AnimationFadeOutMode fadeOutMode = AnimationFadeOutMode::SameLayerAndGroup);
/**
* - Play a specific animation from the specific time.
* @param animationName - The name of animation data.
* @param time - The start time point of playing. (In seconds)
2021-12-25 10:04:45 +08:00
* @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing,
* [1~N]: Repeat N times] (Default: -1)
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param time - ()
* @param playTimes - [-1: 使, 0: , [1~N]: N ] : -1
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndPlayByTime(std::string_view animationName, float time = 0.f, int playTimes = -1);
/**
* - Play a specific animation from the specific frame.
* @param animationName - The name of animation data.
* @param frame - The start frame of playing.
2021-12-25 10:04:45 +08:00
* @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing,
* [1~N]: Repeat N times] (Default: -1)
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param frame -
* @param playTimes - [-1: 使, 0: , [1~N]: N ] : -1
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndPlayByFrame(std::string_view animationName, unsigned frame = 0, int playTimes = -1);
/**
* - Play a specific animation from the specific progress.
* @param animationName - The name of animation data.
* @param progress - The start progress value of playing.
2021-12-25 10:04:45 +08:00
* @param playTimes - Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing,
* [1~N]: Repeat N times] (Default: -1)
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param progress -
* @param playTimes - [-1: 使, 0: , [1~N]: N ] : -1
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndPlayByProgress(std::string_view animationName, float progress = 0.f, int playTimes = -1);
/**
* - Stop a specific animation at the specific time.
* @param animationName - The name of animation data.
* @param time - The stop time. (In seconds)
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param time - ()
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndStopByTime(std::string_view animationName, float time = 0.f);
/**
* - Stop a specific animation at the specific frame.
* @param animationName - The name of animation data.
* @param frame - The stop frame.
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param frame -
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndStopByFrame(std::string_view animationName, unsigned frame = 0);
/**
* - Stop a specific animation at the specific progress.
* @param animationName - The name of animation data.
* @param progress - The stop progress value.
* @returns The played animation state.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @param progress -
* @returns
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* gotoAndStopByProgress(std::string_view animationName, float progress = 0.f);
/**
* - Get a specific animation state.
* @param animationName - The name of animation state.
* @example
* TypeScript style, for reference only.
* <pre>
* armature.animation.play("walk");
* let walkState = armature.animation.getState("walk");
* walkState.timeScale = 0.5;
* </pre>
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @example
2021-12-24 21:11:44 +08:00
* TypeScript
* <pre>
* armature.animation.play("walk");
* let walkState = armature.animation.getState("walk");
* walkState.timeScale = 0.5;
* </pre>
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
AnimationState* getState(std::string_view animationName) const;
/**
* - Check whether a specific animation data is included.
* @param animationName - The name of animation data.
* @see dragonBones.AnimationData
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @param animationName -
* @see dragonBones.AnimationData
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
bool hasAnimation(std::string_view animationName) const;
/**
* - Get all the animation states.
* @version DragonBones 5.1
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 5.1
* @language zh_CN
*/
2021-12-25 10:04:45 +08:00
inline const std::vector<AnimationState*>& getStates() const { return _animationStates; }
/**
* - Check whether there is an animation state is playing
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
bool isPlaying() const;
/**
* - Check whether all the animation states' playing were finished.
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
bool isCompleted() const;
/**
* - The name of the last playing animation state.
* @see #lastAnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see #lastAnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-26 23:26:34 +08:00
std::string_view getLastAnimationName() const;
/**
* - The name of all animation data
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-25 10:04:45 +08:00
inline const std::vector<std::string>& getAnimationNames() const { return _animationNames; }
/**
* - All animation data.
* @version DragonBones 4.5
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @version DragonBones 4.5
* @language zh_CN
*/
2021-12-27 13:52:08 +08:00
inline const hlookup::string_map<AnimationData*>& getAnimations() const { return _animations; }
void setAnimations(const hlookup::string_map<AnimationData*>& value);
/**
* - An AnimationConfig instance that can be used quickly.
* @see dragonBones.AnimationConfig
* @version DragonBones 5.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* - 使
* @see dragonBones.AnimationConfig
* @version DragonBones 5.0
* @language zh_CN
*/
AnimationConfig* getAnimationConfig() const;
/**
* - The last playing animation state
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language en_US
*/
/**
2021-12-24 21:11:44 +08:00
* -
* @see dragonBones.AnimationState
* @version DragonBones 3.0
* @language zh_CN
*/
2021-12-25 10:04:45 +08:00
inline AnimationState* getLastAnimationState() const { return _lastAnimationState; }
};
DRAGONBONES_NAMESPACE_END
#endif // DRAGONBONES_ANIMATION_H