axmol/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h

441 lines
12 KiB
C
Raw Normal View History

2015-06-17 13:16:06 +08:00
/****************************************************************************
2014-06-11 11:10:07 +08:00
Copyright (c) 2013 cocos2d-x.org
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2014-06-11 11:10:07 +08:00
http://www.cocos2d-x.org
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 __CCFRAME_H__
#define __CCFRAME_H__
2014-08-29 15:39:52 +08:00
#include <string>
#include "base/CCRef.h"
#include "base/CCVector.h"
#include "2d/CCNode.h"
#include "2d/CCSprite.h"
2015-04-09 18:10:37 +08:00
#include "2d/CCTweenFunction.h"
#include "editor-support/cocostudio/ActionTimeline/CCTimelineMacro.h"
#include "editor-support/cocostudio/CocosStudioExport.h"
2014-06-11 11:10:07 +08:00
NS_TIMELINE_BEGIN
2014-06-11 11:10:07 +08:00
class Timeline;
2014-12-12 18:02:03 +08:00
class ActionTimeline;
2014-06-11 11:10:07 +08:00
class CC_STUDIO_DLL Frame : public cocos2d::Ref
2014-06-11 11:10:07 +08:00
{
public:
virtual void setFrameIndex(unsigned int frameIndex) { _frameIndex = frameIndex; }
virtual unsigned int getFrameIndex() const { return _frameIndex; }
2014-06-11 11:10:07 +08:00
virtual void setTimeline(Timeline* timeline) { _timeline = timeline; }
virtual Timeline* getTimeline() const { return _timeline; }
2014-06-11 11:10:07 +08:00
virtual void setNode(cocos2d::Node* node) { _node = node; }
2014-06-18 11:22:38 +08:00
virtual cocos2d::Node* getNode() const { return _node; }
2014-06-11 11:10:07 +08:00
virtual void setTween(bool tween) { _tween = tween; }
virtual bool isTween() const { return _tween; }
2014-06-11 11:10:07 +08:00
virtual void setTweenType(const cocos2d::tweenfunc::TweenType& tweenType) { _tweenType = tweenType; }
virtual cocos2d::tweenfunc::TweenType getTweenType() const { return _tweenType; }
2015-04-09 18:10:37 +08:00
// !to make easing with params, need setTweenType(TweenType::CUSTOM_EASING)
virtual void setEasingParams(const std::vector<float>& easingParams);
virtual const std::vector<float>& getEasingParams() const;
2014-10-17 20:43:01 +08:00
virtual bool isEnterWhenPassed() { return _enterWhenPassed; }
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame* nextFrame, int currentFrameIndex) = 0;
2015-04-09 18:10:37 +08:00
virtual void apply(float percent);
2014-06-11 11:10:07 +08:00
virtual Frame* clone() = 0;
protected:
Frame();
virtual ~Frame();
2015-04-09 18:10:37 +08:00
2015-04-10 14:24:48 +08:00
virtual void onApply(float percent) {};
2015-04-09 18:10:37 +08:00
//update percent depends _tweenType, and return the Calculated percent
virtual float tweenPercent(float percent);
virtual void emitEvent();
virtual void cloneProperty(Frame* frame);
2014-06-11 11:10:07 +08:00
protected:
unsigned int _frameIndex;
bool _tween;
2014-10-17 20:43:01 +08:00
bool _enterWhenPassed;
2015-04-09 18:10:37 +08:00
cocos2d::tweenfunc::TweenType _tweenType;
2015-04-09 18:10:37 +08:00
std::vector<float> _easingParam;
2014-06-11 11:10:07 +08:00
Timeline* _timeline;
cocos2d::Node* _node;
2014-06-11 11:10:07 +08:00
};
class CC_STUDIO_DLL VisibleFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static VisibleFrame* create();
VisibleFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setVisible(bool visible) { _visible = visible;}
inline bool isVisible() const { return _visible; }
protected:
bool _visible;
};
class CC_STUDIO_DLL TextureFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static TextureFrame* create();
TextureFrame();
virtual void setNode(cocos2d::Node* node) override;
2014-06-11 11:10:07 +08:00
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
2014-06-13 19:52:53 +08:00
inline void setTextureName(std::string textureName) { _textureName = textureName;}
inline std::string getTextureName() const { return _textureName; }
2014-06-11 11:10:07 +08:00
protected:
cocos2d::Sprite* _sprite;
2014-06-13 19:52:53 +08:00
std::string _textureName;
2014-06-11 11:10:07 +08:00
};
class CC_STUDIO_DLL RotationFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static RotationFrame* create();
RotationFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setRotation(float rotation) { _rotation = rotation; }
inline float getRotation() const { return _rotation; }
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
2014-06-11 11:10:07 +08:00
float _rotation;
float _betwennRotation;
};
class CC_STUDIO_DLL SkewFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static SkewFrame* create();
SkewFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setSkewX(float skewx) { _skewX = skewx; }
inline float getSkewX() const { return _skewX; }
inline void setSkewY(float skewy) { _skewY = skewy; }
inline float getSkewY() const { return _skewY; }
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
2014-06-11 11:10:07 +08:00
float _skewX;
float _skewY;
float _betweenSkewX;
float _betweenSkewY;
};
class CC_STUDIO_DLL RotationSkewFrame : public SkewFrame
2014-06-11 11:10:07 +08:00
{
public:
static RotationSkewFrame* create();
RotationSkewFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
2015-04-09 18:10:37 +08:00
protected:
virtual void onApply(float percent) override;
2014-06-11 11:10:07 +08:00
};
class CC_STUDIO_DLL PositionFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static PositionFrame* create();
PositionFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setPosition(const cocos2d::Point& position) { _position = position; }
inline cocos2d::Point getPosition() const { return _position; }
2014-06-11 11:10:07 +08:00
inline void setX(float x) { _position.x = x; }
inline void setY(float y) { _position.y = y; }
inline float getX() const { return _position.x; }
inline float getY() const { return _position.y; }
2015-04-09 18:10:37 +08:00
2014-06-11 11:10:07 +08:00
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
cocos2d::Point _position;
2014-06-11 11:10:07 +08:00
float _betweenX;
float _betweenY;
};
class CC_STUDIO_DLL ScaleFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static ScaleFrame* create();
ScaleFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setScale(float scale) { _scaleX = scale; _scaleY = scale; }
inline void setScaleX(float scaleX) { _scaleX = scaleX; }
inline float getScaleX() const { return _scaleX; }
inline void setScaleY(float scaleY) { _scaleY = scaleY;}
inline float getScaleY() const { return _scaleY; }
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
2014-06-11 11:10:07 +08:00
float _scaleX;
float _scaleY;
float _betweenScaleX;
float _betweenScaleY;
};
class CC_STUDIO_DLL AnchorPointFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static AnchorPointFrame* create();
AnchorPointFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setAnchorPoint(const cocos2d::Point& point) { _anchorPoint = point; }
inline cocos2d::Point getAnchorPoint() const { return _anchorPoint; }
2014-06-11 11:10:07 +08:00
protected:
virtual void onApply(float percent) override;
cocos2d::Vec2 _betweenAnchorPoint;
cocos2d::Vec2 _anchorPoint;
2014-06-11 11:10:07 +08:00
};
enum InnerActionType
{
LoopAction,
NoLoopAction,
SingleFrame
};
class CC_STUDIO_DLL InnerActionFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
2015-01-12 13:54:17 +08:00
static const std::string AnimationAllName;
2014-06-11 11:10:07 +08:00
static InnerActionFrame* create();
InnerActionFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setInnerActionType(InnerActionType type) { _innerActionType = type; }
inline InnerActionType getInnerActionType() const { return _innerActionType; }
inline void setEnterWithName(bool isEnterWithName) { _enterWithName = isEnterWithName;}
void setStartFrameIndex(int frameIndex);
2014-06-11 11:10:07 +08:00
inline int getStartFrameIndex() const { return _startFrameIndex; }
void setEndFrameIndex(int frameIndex);
inline int getEndFrameIndex() const { return _endFrameIndex; }
void setAnimationName(const std::string& animationNamed);
inline void setSingleFrameIndex(int frameIndex) { _singleFrameIndex = frameIndex;}
inline int getSingleFrameIndex() const { return _singleFrameIndex;}
2014-06-11 11:10:07 +08:00
protected:
InnerActionType _innerActionType;
int _startFrameIndex;
int _endFrameIndex;
int _singleFrameIndex;
std::string _animationName;
bool _enterWithName;
2014-06-11 11:10:07 +08:00
};
class CC_STUDIO_DLL ColorFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static ColorFrame* create();
ColorFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
/** @deprecated Use method setAlpha() and getAlpha() of AlphaFrame instead */
CC_DEPRECATED_ATTRIBUTE inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
CC_DEPRECATED_ATTRIBUTE inline GLubyte getAlpha() const { return _alpha; }
inline void setColor(const cocos2d::Color3B& color) { _color = color; }
inline cocos2d::Color3B getColor() const { return _color; }
2014-06-11 11:10:07 +08:00
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
GLubyte _alpha;
cocos2d::Color3B _color;
2014-06-11 11:10:07 +08:00
int _betweenRed;
int _betweenGreen;
int _betweenBlue;
};
class CC_STUDIO_DLL AlphaFrame : public Frame
{
public:
static AlphaFrame* create();
AlphaFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual Frame* clone() override;
inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
inline GLubyte getAlpha() const { return _alpha; }
protected:
2015-04-09 18:10:37 +08:00
virtual void onApply(float percent) override;
GLubyte _alpha;
int _betweenAlpha;
};
2014-06-11 11:10:07 +08:00
class CC_STUDIO_DLL EventFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static EventFrame* create();
2014-10-17 20:43:01 +08:00
void init();
2014-06-11 11:10:07 +08:00
EventFrame();
virtual void setNode(cocos2d::Node* node) override;
2014-12-12 18:02:03 +08:00
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setEvent(std::string event) { _event = event;}
inline std::string getEvent() const { return _event; }
protected:
std::string _event;
2014-12-12 18:02:03 +08:00
ActionTimeline* _action;
2014-06-11 11:10:07 +08:00
};
class CC_STUDIO_DLL ZOrderFrame : public Frame
2014-06-11 11:10:07 +08:00
{
public:
static ZOrderFrame* create();
ZOrderFrame();
2014-10-23 17:37:18 +08:00
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
2014-06-11 11:10:07 +08:00
virtual Frame* clone() override;
inline void setZOrder(int zorder) { _zorder = zorder;}
inline int getZOrder() const { return _zorder; }
protected:
int _zorder;
};
2015-04-10 13:34:39 +08:00
class CC_STUDIO_DLL BlendFuncFrame : public Frame
{
public:
static BlendFuncFrame* create();
BlendFuncFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual Frame* clone() override;
inline cocos2d::BlendFunc getBlendFunc() const { return _blendFunc; }
inline void setBlendFunc(cocos2d::BlendFunc blendFunc) { _blendFunc = blendFunc; }
2015-04-10 13:34:39 +08:00
protected:
cocos2d::BlendFunc _blendFunc;
2015-04-10 13:34:39 +08:00
};
2014-06-11 11:10:07 +08:00
2016-01-12 17:21:01 +08:00
class CC_STUDIO_DLL PlayableFrame : public Frame
{
public:
static PlayableFrame* create();
PlayableFrame();
virtual void onEnter(Frame* nextFrame, int currentFrameINdex) override;
virtual Frame* clone() override;
inline std::string getPlayableAct() const { return _playableAct; }
// @param playact, express the interface in PlayableProtocol, should be "start" or "stop"
inline void setPlayableAct(std::string playact) { _playableAct = playact; }
static const std::string PLAYABLE_EXTENTION;
private:
std::string _playableAct; // express the interface in PlayableProtocol
static const std::string START_ACT;
static const std::string STOP_ACT;
};
NS_TIMELINE_END
2014-06-11 11:10:07 +08:00
#endif /*__CCFRAME_H__*/