2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
#ifndef __CCB_CCBANIMATION_MANAGER_H__
|
|
|
|
#define __CCB_CCBANIMATION_MANAGER_H__
|
|
|
|
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCMap.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInterval.h"
|
|
|
|
#include "2d/CCActionInstant.h"
|
|
|
|
#include "2d/CCActionEase.h"
|
2014-01-17 13:35:58 +08:00
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/ExtensionMacros.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocosbuilder/CCBSequence.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCBKeyframe.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCBSequenceProperty.h"
|
2013-10-15 18:00:03 +08:00
|
|
|
#include "extensions/GUI/CCControlExtension/CCControl.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBAnimationManagerDelegate
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-20 08:57:23 +08:00
|
|
|
virtual ~CCBAnimationManagerDelegate() {}
|
2012-09-17 14:27:17 +08:00
|
|
|
virtual void completedAnimationSequenceNamed(const char *name) = 0;
|
|
|
|
};
|
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBAnimationManager : public cocos2d::Ref
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-27 21:44:49 +08:00
|
|
|
bool _jsControlled;
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBAnimationManager();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2012-09-17 14:27:17 +08:00
|
|
|
~CCBAnimationManager();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
cocos2d::Ref *_owner;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
virtual bool init();
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::Vector<CCBSequence*>& getSequences();
|
|
|
|
void setSequences(const cocos2d::Vector<CCBSequence*>& seq);
|
2012-11-22 15:15:30 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
int getAutoPlaySequenceId();
|
|
|
|
void setAutoPlaySequenceId(int autoPlaySequenceId);
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Node* getRootNode();
|
|
|
|
void setRootNode(cocos2d::Node* pRootNode); // weak reference
|
2012-11-02 08:52:07 +08:00
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void addDocumentCallbackNode(cocos2d::Node *node);
|
2012-11-02 08:52:07 +08:00
|
|
|
void addDocumentCallbackName(std::string name);
|
2013-10-15 18:00:03 +08:00
|
|
|
void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType);
|
2013-08-12 11:18:07 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void addDocumentOutletNode(cocos2d::Node *node);
|
2012-11-02 08:52:07 +08:00
|
|
|
void addDocumentOutletName(std::string name);
|
|
|
|
|
|
|
|
void setDocumentControllerName(const std::string &name);
|
|
|
|
|
|
|
|
std::string getDocumentControllerName();
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::ValueVector& getDocumentCallbackNames();
|
|
|
|
cocos2d::Vector<cocos2d::Node*>& getDocumentCallbackNodes();
|
|
|
|
cocos2d::ValueVector& getDocumentCallbackControlEvents();
|
2013-08-12 11:18:07 +08:00
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::ValueVector& getDocumentOutletNames();
|
|
|
|
cocos2d::Vector<cocos2d::Node*>& getDocumentOutletNodes();
|
2012-11-02 08:52:07 +08:00
|
|
|
std::string getLastCompletedSequenceName();
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::ValueVector& getKeyframeCallbacks();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Size& getRootContainerSize();
|
|
|
|
void setRootContainerSize(const cocos2d::Size &rootContainerSize);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
CCBAnimationManagerDelegate* getDelegate();
|
|
|
|
void setDelegate(CCBAnimationManagerDelegate* pDelegate); // retain
|
|
|
|
|
|
|
|
const char* getRunningSequenceName();
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
const cocos2d::Size& getContainerSize(cocos2d::Node* pNode);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
void addNode(cocos2d::Node *pNode, const std::unordered_map<int, cocos2d::Map<std::string, CCBSequenceProperty*>>& seq);
|
|
|
|
void setBaseValue(const cocos2d::Value& value, cocos2d::Node *pNode, const std::string& propName);
|
2014-02-20 10:53:49 +08:00
|
|
|
void setObject(cocos2d::Ref* obj, cocos2d::Node *pNode, const std::string& propName);
|
2013-12-09 17:45:24 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
void moveAnimationsFromNode(cocos2d::Node* fromNode, cocos2d::Node* toNode);
|
2012-11-01 02:07:33 +08:00
|
|
|
|
2012-11-28 11:49:20 +08:00
|
|
|
/** @deprecated This interface will be deprecated sooner or later.*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void runAnimations(const char *pName, float fTweenDuration);
|
|
|
|
/** @deprecated This interface will be deprecated sooner or later.*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void runAnimations(const char *pName);
|
|
|
|
/** @deprecated This interface will be deprecated sooner or later.*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE void runAnimations(int nSeqId, float fTweenDuraiton);
|
|
|
|
|
|
|
|
void runAnimationsForSequenceNamedTweenDuration(const char *pName, float fTweenDuration);
|
|
|
|
void runAnimationsForSequenceNamed(const char *pName);
|
|
|
|
void runAnimationsForSequenceIdTweenDuration(int nSeqId, float fTweenDuraiton);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* when this function bound to js ,the second param are callfunc_selector
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
void setAnimationCompletedCallback(cocos2d::Ref *target, cocos2d::SEL_CallFunc callbackFunc);
|
2012-11-01 02:07:33 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
void debug();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js setCallFuncForJSCallbackNamed
|
|
|
|
*/
|
2013-10-15 18:00:03 +08:00
|
|
|
void setCallFunc(cocos2d::CallFunc *callFunc, const std::string &callbackNamed);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
cocos2d::Sequence* actionForCallbackChannel(CCBSequenceProperty* channel);
|
|
|
|
cocos2d::Sequence* actionForSoundChannel(CCBSequenceProperty* channel);
|
2013-08-05 10:23:41 +08:00
|
|
|
|
2016-02-18 15:16:36 +08:00
|
|
|
// return -1 if timeline not exist
|
2013-08-05 10:23:41 +08:00
|
|
|
int getSequenceId(const char* pSequenceName);
|
|
|
|
|
|
|
|
// get timeline duration
|
|
|
|
float getSequenceDuration(const char* pSequenceName);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
private:
|
2013-12-09 17:45:24 +08:00
|
|
|
const cocos2d::Value& getBaseValue(cocos2d::Node *pNode, const std::string& propName);
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* getObject(cocos2d::Node *pNode, const std::string& propName);
|
2013-12-09 17:45:24 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBSequence* getSequence(int nSequenceId);
|
2013-12-09 17:45:24 +08:00
|
|
|
cocos2d::ActionInterval* getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const std::string& propName, cocos2d::Node *pNode);
|
2017-01-11 21:34:57 +08:00
|
|
|
void setAnimatedProperty(const std::string& propName, cocos2d::Node *pNode, const cocos2d::Value& value, Ref* obj, float fTweenDuration);
|
2013-10-15 18:00:03 +08:00
|
|
|
void setFirstFrame(cocos2d::Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
|
|
|
cocos2d::ActionInterval* getEaseAction(cocos2d::ActionInterval *pAction, CCBKeyframe::EasingType easingType, float fEasingOpt);
|
|
|
|
void runAction(cocos2d::Node *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration);
|
2012-09-17 14:27:17 +08:00
|
|
|
void sequenceCompleted();
|
2013-07-27 22:31:57 +08:00
|
|
|
|
|
|
|
private:
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::Vector<CCBSequence*> _sequences;
|
2013-12-09 17:45:24 +08:00
|
|
|
std::unordered_map<cocos2d::Node*, std::unordered_map<int, cocos2d::Map<std::string, CCBSequenceProperty*>>> _nodeSequences;
|
|
|
|
std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Value>> _baseValues;
|
2014-02-20 10:53:49 +08:00
|
|
|
std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Ref*>> _objects;
|
2013-12-09 17:45:24 +08:00
|
|
|
|
2013-07-27 22:31:57 +08:00
|
|
|
int _autoPlaySequenceId;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Node *_rootNode;
|
2013-07-27 22:31:57 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::Size _rootContainerSize;
|
2013-07-27 22:31:57 +08:00
|
|
|
|
|
|
|
CCBAnimationManagerDelegate *_delegate;
|
|
|
|
CCBSequence *_runningSequence;
|
|
|
|
|
2013-12-09 11:45:46 +08:00
|
|
|
cocos2d::ValueVector _documentOutletNames;
|
|
|
|
cocos2d::Vector<cocos2d::Node*> _documentOutletNodes;
|
|
|
|
cocos2d::ValueVector _documentCallbackNames;
|
|
|
|
cocos2d::Vector<cocos2d::Node*> _documentCallbackNodes;
|
|
|
|
cocos2d::ValueVector _documentCallbackControlEvents;
|
|
|
|
cocos2d::ValueVector _keyframeCallbacks;
|
2013-12-09 18:17:04 +08:00
|
|
|
cocos2d::Map<std::string, cocos2d::CallFunc*> _keyframeCallFuncs;
|
2013-07-27 22:31:57 +08:00
|
|
|
|
|
|
|
std::string _documentControllerName;
|
|
|
|
std::string _lastCompletedSequenceName;
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::SEL_CallFunc _animationCompleteCallbackFunc;
|
2014-02-20 10:53:49 +08:00
|
|
|
cocos2d::Ref *_target;
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
};
|
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBSetSpriteFrame : public cocos2d::ActionInstant
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** creates a Place action with a position */
|
2013-10-15 18:00:03 +08:00
|
|
|
static CCBSetSpriteFrame* create(cocos2d::SpriteFrame *pSpriteFrame);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
~CCBSetSpriteFrame();
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
bool initWithSpriteFrame(cocos2d::SpriteFrame *pSpriteFrame);
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual CCBSetSpriteFrame* clone() const override;
|
|
|
|
virtual CCBSetSpriteFrame* reverse() const override;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
private:
|
2013-10-15 18:00:03 +08:00
|
|
|
cocos2d::SpriteFrame *_spriteFrame;
|
2013-07-18 07:56:19 +08:00
|
|
|
};
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-03-20 06:13:00 +08:00
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBSoundEffect : public cocos2d::ActionInstant
|
2013-03-15 08:43:56 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CCBSoundEffect* actionWithSoundFile(const std::string &file, float pitch, float pan, float gain);
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
~CCBSoundEffect();
|
2013-03-15 08:43:56 +08:00
|
|
|
bool initWithSoundFile(const std::string &file, float pitch, float pan, float gain);
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual CCBSoundEffect* clone() const override;
|
|
|
|
virtual CCBSoundEffect* reverse() const override;
|
|
|
|
|
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
std::string _soundFile;
|
|
|
|
float _pitch, _pan, _gain;
|
2013-03-15 08:43:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBRotateTo : public cocos2d::ActionInterval
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CCBRotateTo* create(float fDuration, float fAngle);
|
|
|
|
bool initWithDuration(float fDuration, float fAngle);
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Override
|
|
|
|
virtual void update(float time) override;
|
|
|
|
virtual CCBRotateTo* clone() const override;
|
|
|
|
virtual CCBRotateTo* reverse() const override;
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void startWithTarget(cocos2d::Node *pNode) override;
|
2013-03-20 06:13:00 +08:00
|
|
|
|
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
float _startAngle;
|
|
|
|
float _dstAngle;
|
|
|
|
float _diffAngle;
|
2013-07-18 07:56:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBRotateXTo: public cocos2d::ActionInterval
|
2013-07-18 07:56:19 +08:00
|
|
|
{
|
2013-03-20 06:13:00 +08:00
|
|
|
public:
|
2013-03-20 14:25:30 +08:00
|
|
|
static CCBRotateXTo* create(float fDuration, float fAngle);
|
|
|
|
bool initWithDuration(float fDuration, float fAngle);
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void startWithTarget(cocos2d::Node *pNode) override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual CCBRotateXTo* clone() const override;
|
|
|
|
virtual CCBRotateXTo* reverse() const override;
|
|
|
|
virtual void update(float time) override;
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-03-20 06:13:00 +08:00
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
float _startAngle;
|
|
|
|
float _dstAngle;
|
|
|
|
float _diffAngle;
|
2013-07-18 07:56:19 +08:00
|
|
|
};
|
2013-06-16 03:38:32 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBRotateYTo: public cocos2d::ActionInterval
|
2013-07-18 07:56:19 +08:00
|
|
|
{
|
2013-03-20 06:13:00 +08:00
|
|
|
public:
|
2013-03-20 14:25:30 +08:00
|
|
|
static CCBRotateYTo* create(float fDuration, float fAngle);
|
|
|
|
bool initWithDuration(float fDuration, float fAngle);
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Override
|
2013-10-15 18:00:03 +08:00
|
|
|
virtual void startWithTarget(cocos2d::Node *pNode) override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual CCBRotateYTo* clone() const override;
|
|
|
|
virtual CCBRotateYTo* reverse() const override;
|
|
|
|
virtual void update(float time) override;
|
2013-06-16 09:54:34 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
private:
|
2013-07-27 22:31:57 +08:00
|
|
|
float _startAngle;
|
|
|
|
float _dstAngle;
|
|
|
|
float _diffAngle;
|
2013-03-20 06:13:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-27 10:18:44 +08:00
|
|
|
class CC_DLL CCBEaseInstant : public cocos2d::ActionEase
|
2013-01-21 11:18:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-10-15 18:00:03 +08:00
|
|
|
static CCBEaseInstant* create(cocos2d::ActionInterval *pAction);
|
2013-06-16 03:38:32 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual CCBEaseInstant* clone() const override;
|
|
|
|
virtual CCBEaseInstant* reverse() const override;
|
|
|
|
virtual void update(float dt) override;
|
2013-01-21 11:18:06 +08:00
|
|
|
};
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
#endif // __CCB_CCBANIMATION_MANAGER_H__
|