axmol/extensions/cocostudio/ActionNode.h

193 lines
4.8 KiB
C
Raw Normal View History

/****************************************************************************
2019-11-24 23:15:56 +08:00
Copyright (c) 2013-2017 Chukong Technologies Inc.
2019-11-23 20:27:39 +08:00
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
2019-11-23 20:27:39 +08:00
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 __ActionNODE_H__
#define __ActionNODE_H__
#include "ActionFrame.h"
#include "DictionaryHelper.h"
#include "CocosStudioExport.h"
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
namespace cocostudio
{
2019-11-23 20:27:39 +08:00
class CocoLoader;
struct stExpCocoNode;
/**
2021-12-25 10:04:45 +08:00
* @js NA
* @lua NA
*/
2022-08-08 18:02:17 +08:00
class CCS_DLL ActionNode : public ax::Ref
2019-11-23 20:27:39 +08:00
{
public:
/**
2021-12-25 10:04:45 +08:00
* Default constructor
*/
2019-11-23 20:27:39 +08:00
ActionNode();
/**
2021-12-25 10:04:45 +08:00
* Default destructor
*/
2019-11-23 20:27:39 +08:00
virtual ~ActionNode();
/**
2021-12-25 10:04:45 +08:00
* Sets the time interval of frame.
*
* @param fTime the time interval of frame
*/
2019-11-23 20:27:39 +08:00
void setUnitTime(float fTime);
/**
2021-12-25 10:04:45 +08:00
* Gets the time interval of frame.
*
* @return fTime the time interval of frame
*/
2019-11-23 20:27:39 +08:00
float getUnitTime();
/**
2021-12-25 10:04:45 +08:00
* Sets tag for ActionNode
*
* @param tag tag of ActionNode
*/
2019-11-23 20:27:39 +08:00
void setActionTag(int tag);
/**
2021-12-25 10:04:45 +08:00
* Gets tag for ActionNode
*
* @return tag tag of ActionNode
*/
2019-11-23 20:27:39 +08:00
int getActionTag();
/**
2021-12-25 10:04:45 +08:00
* Sets node which will run a action.
*
* @param node which will run a action
*/
2022-08-08 18:02:17 +08:00
void setObject(ax::Ref* node);
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* Gets node which will run a action.
*
* @return node which will run a action
*/
2022-08-08 18:02:17 +08:00
ax::Ref* getObject();
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* Insets a ActionFrame to ActionNode.
*
* @param index the index of ActionFrame
*
* @param frame the ActionFrame which will be inserted
*/
2019-11-23 20:27:39 +08:00
void insertFrame(int index, ActionFrame* frame);
/**
2021-12-25 10:04:45 +08:00
* Pushes back a ActionFrame to ActionNode.
*
* @param frame the ActionFrame which will be added
*/
2019-11-23 20:27:39 +08:00
void addFrame(ActionFrame* frame);
/**
2021-12-25 10:04:45 +08:00
* Remove a ActionFrame from ActionNode.
*
* @param frame the ActionFrame which will be removed
*/
void deleteFrame(ActionFrame* frame);
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* Remove all ActionFrames from ActionNode.
*/
2019-11-23 20:27:39 +08:00
void clearAllFrame();
/**
2021-12-25 10:04:45 +08:00
* Gets index of first ActionFrame.
*
* @return index of first ActionFrame
*/
2019-11-23 20:27:39 +08:00
int getFirstFrameIndex();
/**
2021-12-25 10:04:45 +08:00
* Gets index of last ActionFrame.
*
* @return index of last ActionFrame
*/
2019-11-23 20:27:39 +08:00
int getLastFrameIndex();
/**
2021-12-25 10:04:45 +08:00
* Updates action states to some time.
*
* @param fTime the time when need to update
*/
2019-11-23 20:27:39 +08:00
virtual bool updateActionToTimeLine(float fTime);
/**
2021-12-25 10:04:45 +08:00
* Play the action.
*/
2019-11-23 20:27:39 +08:00
virtual void playAction();
/**
2021-12-25 10:04:45 +08:00
* Stop the action.
*/
2019-11-23 20:27:39 +08:00
virtual void stopAction();
/*init properties with a json dictionary*/
2022-08-08 18:02:17 +08:00
virtual void initWithDictionary(const rapidjson::Value& dic, ax::Ref* root);
2021-12-25 10:04:45 +08:00
virtual void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, Ref* root);
2019-11-23 20:27:39 +08:00
/**
2021-12-25 10:04:45 +08:00
* Gets if the action is done once time.
*
* @return that if the action is done once time
*/
2019-11-23 20:27:39 +08:00
virtual bool isActionDoneOnce();
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
protected:
int valueToInt(std::string_view value);
bool valueToBool(std::string_view value);
float valueToFloat(std::string_view value);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
int _currentFrameIndex;
int _destFrameIndex;
float _fUnitTime;
int _actionTag;
2022-08-08 18:02:17 +08:00
ax::Spawn* _actionSpawn;
ax::Action* _action;
ax::Ref* _object;
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
std::vector<ax::Vector<ActionFrame*>*> _frameArray;
2019-11-23 20:27:39 +08:00
int _frameArrayNum;
protected:
2022-08-08 18:02:17 +08:00
virtual ax::Node* getActionNode();
virtual ax::Spawn* refreshActionProperty();
2019-11-23 20:27:39 +08:00
virtual void runAction();
2022-08-08 18:02:17 +08:00
virtual void initActionNodeFromRoot(ax::Ref* root);
2021-12-25 10:04:45 +08:00
virtual void easingToFrame(float duration, float delayTime, ActionFrame* srcFrame, ActionFrame* destFrame);
2019-11-23 20:27:39 +08:00
};
2021-12-25 10:04:45 +08:00
} // namespace cocostudio
2019-11-23 20:27:39 +08:00
#endif