123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- /****************************************************************************
- 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.
- ****************************************************************************/
- #ifndef __CCB_CCBANIMATION_MANAGER_H__
- #define __CCB_CCBANIMATION_MANAGER_H__
- #include "base/CCMap.h"
- #include "2d/CCActionInterval.h"
- #include "2d/CCActionInstant.h"
- #include "2d/CCActionEase.h"
- #include "extensions/ExtensionMacros.h"
- #include "editor-support/cocosbuilder/CCBSequence.h"
- #include "editor-support/cocosbuilder/CCBKeyframe.h"
- #include "editor-support/cocosbuilder/CCBSequenceProperty.h"
- #include "extensions/GUI/CCControlExtension/CCControl.h"
- namespace cocosbuilder {
- class CC_DLL CCBAnimationManagerDelegate
- {
- public:
- virtual ~CCBAnimationManagerDelegate() {}
- virtual void completedAnimationSequenceNamed(const char *name) = 0;
- };
- class CC_DLL CCBAnimationManager : public cocos2d::Ref
- {
- public:
- bool _jsControlled;
- /**
- * @js ctor
- */
- CCBAnimationManager();
- /**
- * @js NA
- * @lua NA
- */
- ~CCBAnimationManager();
- cocos2d::Ref *_owner;
-
- virtual bool init();
-
- cocos2d::Vector<CCBSequence*>& getSequences();
- void setSequences(const cocos2d::Vector<CCBSequence*>& seq);
-
- int getAutoPlaySequenceId();
- void setAutoPlaySequenceId(int autoPlaySequenceId);
-
- cocos2d::Node* getRootNode();
- void setRootNode(cocos2d::Node* pRootNode); // weak reference
-
- void addDocumentCallbackNode(cocos2d::Node *node);
- void addDocumentCallbackName(std::string name);
- void addDocumentCallbackControlEvents(cocos2d::extension::Control::EventType eventType);
-
- void addDocumentOutletNode(cocos2d::Node *node);
- void addDocumentOutletName(std::string name);
- void setDocumentControllerName(const std::string &name);
-
- std::string getDocumentControllerName();
- cocos2d::ValueVector& getDocumentCallbackNames();
- cocos2d::Vector<cocos2d::Node*>& getDocumentCallbackNodes();
- cocos2d::ValueVector& getDocumentCallbackControlEvents();
-
- cocos2d::ValueVector& getDocumentOutletNames();
- cocos2d::Vector<cocos2d::Node*>& getDocumentOutletNodes();
- std::string getLastCompletedSequenceName();
-
- cocos2d::ValueVector& getKeyframeCallbacks();
-
- const cocos2d::Size& getRootContainerSize();
- void setRootContainerSize(const cocos2d::Size &rootContainerSize);
-
- CCBAnimationManagerDelegate* getDelegate();
- void setDelegate(CCBAnimationManagerDelegate* pDelegate); // retain
-
- const char* getRunningSequenceName();
-
- const cocos2d::Size& getContainerSize(cocos2d::Node* pNode);
-
- 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);
- void setObject(cocos2d::Ref* obj, cocos2d::Node *pNode, const std::string& propName);
-
- void moveAnimationsFromNode(cocos2d::Node* fromNode, cocos2d::Node* toNode);
- /** @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);
- /**
- * when this function bound to js ,the second param are callfunc_selector
- * @lua NA
- */
- void setAnimationCompletedCallback(cocos2d::Ref *target, cocos2d::SEL_CallFunc callbackFunc);
- void debug();
- /**
- * @js setCallFuncForJSCallbackNamed
- */
- void setCallFunc(cocos2d::CallFunc *callFunc, const std::string &callbackNamed);
- cocos2d::Sequence* actionForCallbackChannel(CCBSequenceProperty* channel);
- cocos2d::Sequence* actionForSoundChannel(CCBSequenceProperty* channel);
- // return -1 if timeline not exist
- int getSequenceId(const char* pSequenceName);
-
- // get timeline duration
- float getSequenceDuration(const char* pSequenceName);
-
- private:
- const cocos2d::Value& getBaseValue(cocos2d::Node *pNode, const std::string& propName);
- Ref* getObject(cocos2d::Node *pNode, const std::string& propName);
-
- CCBSequence* getSequence(int nSequenceId);
- cocos2d::ActionInterval* getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const std::string& propName, cocos2d::Node *pNode);
- void setAnimatedProperty(const std::string& propName, cocos2d::Node *pNode, const cocos2d::Value& value, Ref* obj, float fTweenDuration);
- 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);
- void sequenceCompleted();
-
- private:
- cocos2d::Vector<CCBSequence*> _sequences;
- 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;
- std::unordered_map<cocos2d::Node*, std::unordered_map<std::string, cocos2d::Ref*>> _objects;
-
- int _autoPlaySequenceId;
-
- cocos2d::Node *_rootNode;
-
- cocos2d::Size _rootContainerSize;
-
- CCBAnimationManagerDelegate *_delegate;
- CCBSequence *_runningSequence;
-
- cocos2d::ValueVector _documentOutletNames;
- cocos2d::Vector<cocos2d::Node*> _documentOutletNodes;
- cocos2d::ValueVector _documentCallbackNames;
- cocos2d::Vector<cocos2d::Node*> _documentCallbackNodes;
- cocos2d::ValueVector _documentCallbackControlEvents;
- cocos2d::ValueVector _keyframeCallbacks;
- cocos2d::Map<std::string, cocos2d::CallFunc*> _keyframeCallFuncs;
-
- std::string _documentControllerName;
- std::string _lastCompletedSequenceName;
-
- cocos2d::SEL_CallFunc _animationCompleteCallbackFunc;
- cocos2d::Ref *_target;
-
- };
- class CC_DLL CCBSetSpriteFrame : public cocos2d::ActionInstant
- {
- public:
- /** creates a Place action with a position */
- static CCBSetSpriteFrame* create(cocos2d::SpriteFrame *pSpriteFrame);
- /**
- * @js NA
- * @lua NA
- */
- ~CCBSetSpriteFrame();
-
- bool initWithSpriteFrame(cocos2d::SpriteFrame *pSpriteFrame);
- // Overrides
- virtual void update(float time) override;
- virtual CCBSetSpriteFrame* clone() const override;
- virtual CCBSetSpriteFrame* reverse() const override;
- private:
- cocos2d::SpriteFrame *_spriteFrame;
- };
- class CC_DLL CCBSoundEffect : public cocos2d::ActionInstant
- {
- public:
- static CCBSoundEffect* actionWithSoundFile(const std::string &file, float pitch, float pan, float gain);
- /**
- * @js NA
- * @lua NA
- */
- ~CCBSoundEffect();
- bool initWithSoundFile(const std::string &file, float pitch, float pan, float gain);
- // Overrides
- virtual void update(float time) override;
- virtual CCBSoundEffect* clone() const override;
- virtual CCBSoundEffect* reverse() const override;
- private:
- std::string _soundFile;
- float _pitch, _pan, _gain;
- };
- class CC_DLL CCBRotateTo : public cocos2d::ActionInterval
- {
- public:
- static CCBRotateTo* create(float fDuration, float fAngle);
- bool initWithDuration(float fDuration, float fAngle);
- // Override
- virtual void update(float time) override;
- virtual CCBRotateTo* clone() const override;
- virtual CCBRotateTo* reverse() const override;
- virtual void startWithTarget(cocos2d::Node *pNode) override;
- private:
- float _startAngle;
- float _dstAngle;
- float _diffAngle;
- };
- class CC_DLL CCBRotateXTo: public cocos2d::ActionInterval
- {
- public:
- static CCBRotateXTo* create(float fDuration, float fAngle);
- bool initWithDuration(float fDuration, float fAngle);
- // Overrides
- virtual void startWithTarget(cocos2d::Node *pNode) override;
- virtual CCBRotateXTo* clone() const override;
- virtual CCBRotateXTo* reverse() const override;
- virtual void update(float time) override;
- private:
- float _startAngle;
- float _dstAngle;
- float _diffAngle;
- };
- class CC_DLL CCBRotateYTo: public cocos2d::ActionInterval
- {
- public:
- static CCBRotateYTo* create(float fDuration, float fAngle);
- bool initWithDuration(float fDuration, float fAngle);
- // Override
- virtual void startWithTarget(cocos2d::Node *pNode) override;
- virtual CCBRotateYTo* clone() const override;
- virtual CCBRotateYTo* reverse() const override;
- virtual void update(float time) override;
- private:
- float _startAngle;
- float _dstAngle;
- float _diffAngle;
- };
- class CC_DLL CCBEaseInstant : public cocos2d::ActionEase
- {
- public:
- static CCBEaseInstant* create(cocos2d::ActionInterval *pAction);
- virtual CCBEaseInstant* clone() const override;
- virtual CCBEaseInstant* reverse() const override;
- virtual void update(float dt) override;
- };
- }
- #endif // __CCB_CCBANIMATION_MANAGER_H__
|