2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2019-11-25 01:35:26 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2019-2020 simdsoft, @HALX99
|
2013-09-20 22:23:13 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/CCActionNode.h"
|
|
|
|
#include "editor-support/cocostudio/CCActionFrameEasing.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UIWidget.h"
|
|
|
|
#include "ui/UIHelper.h"
|
2015-11-09 19:45:17 +08:00
|
|
|
#include "ui/UILayout.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/CocoLoader.h"
|
2014-07-14 20:45:24 +08:00
|
|
|
#include "base/ccUtils.h"
|
2016-05-26 17:25:03 +08:00
|
|
|
#include "editor-support/cocostudio/CCActionManagerEx.h"
|
2016-05-26 17:20:51 +08:00
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
2014-02-24 18:56:45 +08:00
|
|
|
using namespace ui;
|
2013-10-15 18:00:03 +08:00
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-11-08 14:34:24 +08:00
|
|
|
ActionNode::ActionNode()
|
2013-12-26 16:36:21 +08:00
|
|
|
: _currentFrameIndex(0)
|
|
|
|
, _destFrameIndex(0)
|
|
|
|
, _fUnitTime(0.1f)
|
|
|
|
, _actionTag(0)
|
2013-12-26 23:40:50 +08:00
|
|
|
, _actionSpawn(nullptr)
|
|
|
|
, _action(nullptr)
|
|
|
|
, _object(nullptr)
|
2013-12-26 16:36:21 +08:00
|
|
|
, _frameArrayNum(0)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
_frameArrayNum = (int)kKeyframeMax;
|
|
|
|
for(int i = 0; i < _frameArrayNum; i++)
|
|
|
|
{
|
|
|
|
_frameArray.push_back( new cocos2d::Vector<ActionFrame*>());
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionNode::~ActionNode()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if (_action == nullptr)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(_actionSpawn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(_action);
|
2015-06-09 14:38:48 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_actionSpawn);
|
2014-03-10 15:08:42 +08:00
|
|
|
}
|
2015-12-07 15:06:50 +08:00
|
|
|
|
|
|
|
CC_SAFE_RELEASE(_object);
|
2013-12-26 16:29:59 +08:00
|
|
|
|
2013-12-27 12:45:05 +08:00
|
|
|
for (auto object : _frameArray)
|
|
|
|
{
|
|
|
|
object->clear();
|
2014-01-06 10:42:17 +08:00
|
|
|
CC_SAFE_DELETE(object);
|
2013-12-27 12:45:05 +08:00
|
|
|
}
|
2014-03-10 15:08:42 +08:00
|
|
|
_frameArray.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2015-11-09 19:45:17 +08:00
|
|
|
Widget * rw = dynamic_cast<Widget *>(root);
|
|
|
|
if (nullptr == rw)
|
|
|
|
return;
|
|
|
|
|
2014-03-10 15:08:42 +08:00
|
|
|
setActionTag(DICTOOL->getIntValue_json(dic, "ActionTag"));
|
2015-11-09 19:45:17 +08:00
|
|
|
Widget* node = Helper::seekActionWidgetByActionTag(rw, getActionTag());
|
|
|
|
bool positionOffset = node && (nullptr == (dynamic_cast<Layout *>(node)));
|
|
|
|
|
2014-03-10 15:08:42 +08:00
|
|
|
int actionFrameCount = DICTOOL->getArrayCount_json(dic, "actionframelist");
|
|
|
|
for (int i=0; i<actionFrameCount; i++)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& actionFrameDic = DICTOOL->getDictionaryFromArray_json(dic, "actionframelist", i);
|
|
|
|
int frameInex = DICTOOL->getIntValue_json(actionFrameDic,"frameid");
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-03-07 21:49:24 +08:00
|
|
|
int frameTweenType = DICTOOL->getIntValue_json(actionFrameDic,"tweenType");
|
2014-03-10 15:08:42 +08:00
|
|
|
|
2014-03-07 21:49:24 +08:00
|
|
|
std::vector<float> frameTweenParameter;
|
|
|
|
int frameTweenParameterNum = DICTOOL->getArrayCount_json(actionFrameDic, "tweenParameter");
|
2014-03-10 15:08:42 +08:00
|
|
|
|
2014-03-07 21:49:24 +08:00
|
|
|
for (int j = 0; j < frameTweenParameterNum; j++)
|
|
|
|
{
|
|
|
|
float value = DICTOOL->getFloatValueFromArray_json(actionFrameDic, "tweenParameter", j);
|
|
|
|
frameTweenParameter.push_back(value);
|
|
|
|
}
|
2014-03-10 15:08:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
bool existPosition = DICTOOL->checkObjectExist_json(actionFrameDic,"positionx");
|
|
|
|
if (existPosition)
|
|
|
|
{
|
|
|
|
float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx");
|
|
|
|
float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony");
|
2016-05-26 17:20:51 +08:00
|
|
|
if (positionOffset && (nullptr != node->getParent()) && ActionManagerEx::getInstance()->getStudioVersionNumber() < 1600)
|
2015-11-09 19:45:17 +08:00
|
|
|
{
|
|
|
|
Vec2 AnchorPointIn = node->getParent()->getAnchorPointInPoints();
|
|
|
|
positionX += AnchorPointIn.x;
|
|
|
|
positionY += AnchorPointIn.y;
|
|
|
|
}
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionMoveFrame* actionFrame = new (std::nothrow) ActionMoveFrame();
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setFrameIndex(frameInex);
|
2014-03-07 21:49:24 +08:00
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
2014-05-15 01:07:09 +08:00
|
|
|
actionFrame->setPosition(Vec2(positionX, positionY));
|
2014-03-10 15:08:42 +08:00
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeMove);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
actionFrame->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool existScale = DICTOOL->checkObjectExist_json(actionFrameDic,"scalex");
|
|
|
|
if (existScale)
|
|
|
|
{
|
|
|
|
float scaleX = DICTOOL->getFloatValue_json(actionFrameDic, "scalex");
|
|
|
|
float scaleY = DICTOOL->getFloatValue_json(actionFrameDic, "scaley");
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionScaleFrame* actionFrame = new (std::nothrow) ActionScaleFrame();
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setFrameIndex(frameInex);
|
2014-03-07 21:49:24 +08:00
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setScaleX(scaleX);
|
|
|
|
actionFrame->setScaleY(scaleY);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeScale);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
2016-05-26 17:20:51 +08:00
|
|
|
actionFrame->release();
|
2014-03-10 15:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool existRotation = DICTOOL->checkObjectExist_json(actionFrameDic,"rotation");
|
|
|
|
if (existRotation)
|
|
|
|
{
|
|
|
|
float rotation = DICTOOL->getFloatValue_json(actionFrameDic, "rotation");
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionRotationFrame* actionFrame = new (std::nothrow) ActionRotationFrame();
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setFrameIndex(frameInex);
|
2014-03-07 21:49:24 +08:00
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setRotation(rotation);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeRotate);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
actionFrame->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool existOpacity = DICTOOL->checkObjectExist_json(actionFrameDic,"opacity");
|
|
|
|
if (existOpacity)
|
|
|
|
{
|
|
|
|
int opacity = DICTOOL->getIntValue_json(actionFrameDic, "opacity");
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionFadeFrame* actionFrame = new (std::nothrow) ActionFadeFrame();
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setFrameIndex(frameInex);
|
2014-03-07 21:49:24 +08:00
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setOpacity(opacity);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeTint);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
actionFrame->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool existColor = DICTOOL->checkObjectExist_json(actionFrameDic,"colorr");
|
|
|
|
if (existColor)
|
|
|
|
{
|
|
|
|
int colorR = DICTOOL->getIntValue_json(actionFrameDic, "colorr");
|
|
|
|
int colorG = DICTOOL->getIntValue_json(actionFrameDic, "colorg");
|
|
|
|
int colorB = DICTOOL->getIntValue_json(actionFrameDic, "colorb");
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionTintFrame* actionFrame = new (std::nothrow) ActionTintFrame();
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setFrameIndex(frameInex);
|
2014-03-07 21:49:24 +08:00
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
2014-03-10 15:08:42 +08:00
|
|
|
actionFrame->setColor(Color3B(colorR,colorG,colorB));
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeFade);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
actionFrame->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initActionNodeFromRoot(root);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2014-06-18 15:55:01 +08:00
|
|
|
|
2014-06-23 10:12:54 +08:00
|
|
|
int ActionNode::valueToInt(const std::string& value)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
|
|
|
return atoi(value.c_str());
|
|
|
|
}
|
2014-06-23 10:12:54 +08:00
|
|
|
bool ActionNode::valueToBool(const std::string& value)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
|
|
|
int intValue = valueToInt(value);
|
|
|
|
if (1 == intValue) {
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-06-23 10:12:54 +08:00
|
|
|
float ActionNode::valueToFloat(const std::string& value)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
2014-07-14 20:45:24 +08:00
|
|
|
return utils::atof(value.c_str());
|
2014-06-18 15:55:01 +08:00
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void ActionNode::initWithBinary(CocoLoader *cocoLoader,
|
|
|
|
stExpCocoNode *cocoNode,
|
2014-06-18 15:55:01 +08:00
|
|
|
cocos2d::Ref *root)
|
|
|
|
{
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
stExpCocoNode *stChildNode = cocoNode;
|
2014-06-18 15:55:01 +08:00
|
|
|
|
|
|
|
int actionNodeCount = stChildNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stChildNode = stChildNode[0].GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
stExpCocoNode *frameListNode = nullptr;
|
2014-06-18 15:55:01 +08:00
|
|
|
for (int i = 0; i < actionNodeCount; ++i) {
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = stChildNode[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string value = stChildNode[i].GetValue(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
if (key == "ActionTag") {
|
|
|
|
setActionTag(valueToInt(value));
|
|
|
|
}else if (key == "actionframelist"){
|
|
|
|
frameListNode = &stChildNode[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int actionFrameCount = frameListNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
for (int i=0; i<actionFrameCount; i++) {
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
int frameIndex = 0;
|
|
|
|
int frameTweenType = 0;
|
|
|
|
float positionX = 0;
|
|
|
|
float positionY = 0;
|
|
|
|
float scaleX = 1;
|
|
|
|
float scaleY = 1;
|
|
|
|
float rotation = 0;
|
|
|
|
int opacity = 255;
|
2014-06-18 15:55:01 +08:00
|
|
|
int colorR = -1;
|
|
|
|
int colorG = -1;
|
|
|
|
int colorB = -1;
|
|
|
|
std::vector<float> frameTweenParameter;
|
|
|
|
|
|
|
|
int framesCount = stFrameChildNode[i].GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
for (int j = 0; j < framesCount; j++) {
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = innerFrameNode[j].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string value = innerFrameNode[j].GetValue(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
|
|
|
|
if (key == "frameid") {
|
|
|
|
frameIndex = valueToInt(value);
|
|
|
|
}else if(key == "tweenType"){
|
|
|
|
frameTweenType = valueToInt(value);
|
|
|
|
}else if (key == "tweenParameter"){
|
|
|
|
// There are no tweenParameter args in the json file
|
|
|
|
int tweenParameterCount = innerFrameNode[j].GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
for (int k = 0; k < tweenParameterCount; ++k) {
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string t_key = tweenParameterArray[j].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string t_value = tweenParameterArray[j].GetValue(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
frameTweenParameter.push_back(valueToFloat(t_value));
|
|
|
|
}
|
|
|
|
}else if (key == "positionx"){
|
|
|
|
positionX = valueToFloat(value);
|
|
|
|
}else if (key == "positiony"){
|
|
|
|
positionY = valueToFloat(value);
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionMoveFrame* actionFrame = new (std::nothrow) ActionMoveFrame();
|
2014-06-18 15:55:01 +08:00
|
|
|
actionFrame->autorelease();
|
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
|
|
|
actionFrame->setFrameIndex(frameIndex);
|
|
|
|
actionFrame->setPosition(Vec2(positionX, positionY));
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeMove);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
}else if(key == "scalex"){
|
|
|
|
scaleX = valueToFloat(value);
|
|
|
|
}else if(key == "scaley"){
|
|
|
|
scaleY = valueToFloat(value);
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionScaleFrame* actionFrame = new (std::nothrow) ActionScaleFrame();
|
2014-06-18 15:55:01 +08:00
|
|
|
actionFrame->autorelease();
|
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
|
|
|
actionFrame->setFrameIndex(frameIndex);
|
|
|
|
actionFrame->setScaleX(scaleX);
|
|
|
|
actionFrame->setScaleY(scaleY);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeScale);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
}else if (key == "rotation"){
|
|
|
|
rotation = valueToFloat(value);
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionRotationFrame* actionFrame = new (std::nothrow) ActionRotationFrame();
|
2014-06-18 15:55:01 +08:00
|
|
|
actionFrame->autorelease();
|
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
|
|
|
actionFrame->setFrameIndex(frameIndex);
|
|
|
|
actionFrame->setRotation(rotation);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeRotate);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
}else if (key == "opacity"){
|
|
|
|
opacity = valueToInt(value);
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionFadeFrame* actionFrame = new (std::nothrow) ActionFadeFrame();
|
2014-06-18 15:55:01 +08:00
|
|
|
actionFrame->autorelease();
|
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
|
|
|
actionFrame->setFrameIndex(frameIndex);
|
|
|
|
actionFrame->setOpacity(opacity);
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeFade);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
}else if (key == "colorb"){
|
|
|
|
colorB = valueToInt(value);
|
|
|
|
}else if(key == "colorg"){
|
|
|
|
colorG = valueToInt(value);
|
|
|
|
}else if(key == "colorr"){
|
|
|
|
colorR = valueToInt(value);
|
|
|
|
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionTintFrame* actionFrame = new (std::nothrow) ActionTintFrame();
|
2014-06-18 15:55:01 +08:00
|
|
|
actionFrame->autorelease();
|
|
|
|
actionFrame->setEasingType(frameTweenType);
|
|
|
|
actionFrame->setEasingParameter(frameTweenParameter);
|
|
|
|
actionFrame->setFrameIndex(frameIndex);
|
|
|
|
actionFrame->setColor(Color3B(colorR,colorG,colorB));
|
|
|
|
auto cActionArray = _frameArray.at((int)kKeyframeTint);
|
|
|
|
cActionArray->pushBack(actionFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
initActionNodeFromRoot(root);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionNode::initActionNodeFromRoot(Ref* root)
|
2014-09-04 10:07:46 +08:00
|
|
|
{
|
|
|
|
Widget* rootWidget = dynamic_cast<Widget*>(root);
|
|
|
|
if (rootWidget != nullptr)
|
2014-03-10 15:08:42 +08:00
|
|
|
{
|
2014-09-04 10:07:46 +08:00
|
|
|
Widget* widget = Helper::seekActionWidgetByActionTag(rootWidget, getActionTag());
|
|
|
|
if (widget != nullptr)
|
2014-03-10 15:08:42 +08:00
|
|
|
{
|
2014-09-04 10:07:46 +08:00
|
|
|
setObject(widget);
|
2014-03-10 15:08:42 +08:00
|
|
|
}
|
2013-12-26 17:01:31 +08:00
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::setUnitTime(float fTime)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
_fUnitTime = fTime;
|
|
|
|
this->refreshActionProperty();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float ActionNode::getUnitTime()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
return _fUnitTime;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::setActionTag(int tag)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
_actionTag = tag;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ActionNode::getActionTag()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
return _actionTag;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionNode::setObject(Ref* node)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2015-12-07 15:06:50 +08:00
|
|
|
CC_SAFE_RELEASE(_object);
|
2014-03-10 15:08:42 +08:00
|
|
|
_object = node;
|
2015-12-07 15:06:50 +08:00
|
|
|
CC_SAFE_RETAIN(_object);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* ActionNode::getObject()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
return _object;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* ActionNode::getActionNode()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
Node* cNode = dynamic_cast<Node*>(_object);
|
|
|
|
if (cNode != nullptr)
|
|
|
|
{
|
|
|
|
return cNode;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::insertFrame(int index, ActionFrame* frame)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if (frame == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int frameType = frame->getFrameType();
|
2014-03-24 10:12:40 +08:00
|
|
|
if(frameType < (int)_frameArray.size())
|
2014-03-10 15:08:42 +08:00
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(frameType);
|
|
|
|
cArray->insert(index, frame);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::addFrame(ActionFrame* frame)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if (frame == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int frameType = frame->getFrameType();
|
|
|
|
|
2014-03-24 10:12:40 +08:00
|
|
|
if(frameType < (int)_frameArray.size())
|
2014-03-10 15:08:42 +08:00
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(frameType);
|
|
|
|
cArray->pushBack(frame);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::deleteFrame(ActionFrame* frame)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if (frame == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int frameType = frame->getFrameType();
|
2014-03-24 10:12:40 +08:00
|
|
|
if(frameType < (int)_frameArray.size())
|
2014-03-10 15:08:42 +08:00
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(frameType);
|
|
|
|
cArray->eraseObject(frame);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::clearAllFrame()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
for(auto array : _frameArray)
|
|
|
|
{
|
|
|
|
array->clear();
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Spawn * ActionNode::refreshActionProperty()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if ( _object == nullptr )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Vector<FiniteTimeAction*> cSpawnArray;
|
|
|
|
|
|
|
|
for (int n = 0; n < _frameArrayNum; n++)
|
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(n);
|
|
|
|
if (cArray->size() <= 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<FiniteTimeAction*> cSequenceArray;
|
|
|
|
auto frameCount = cArray->size();
|
2016-06-06 09:32:33 +08:00
|
|
|
if(frameCount > 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < frameCount; i++)
|
|
|
|
{
|
|
|
|
auto frame = cArray->at(i);
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
// #11173 Fixed every node of UI animation(json) is starting at frame 0.
|
|
|
|
// if (frame->getFrameIndex() > 0)
|
|
|
|
// {
|
|
|
|
// DelayTime* cDelayTime = DelayTime::create(frame->getFrameIndex() * getUnitTime());
|
|
|
|
// if (cDelayTime != nullptr)
|
|
|
|
// cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cDelayTime));
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto srcFrame = cArray->at(i-1);
|
|
|
|
float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex()) * getUnitTime();
|
|
|
|
Action* cAction = frame->getAction(duration);
|
|
|
|
if(cAction != nullptr)
|
|
|
|
cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cAction));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (frameCount == 1)
|
|
|
|
{
|
|
|
|
auto frame = cArray->at(0);
|
|
|
|
float duration = 0.0f;
|
|
|
|
Action* cAction = frame->getAction(duration);
|
|
|
|
if (cAction != nullptr)
|
|
|
|
cSequenceArray.pushBack(static_cast<FiniteTimeAction*>(cAction));
|
|
|
|
}
|
|
|
|
Sequence* cSequence = Sequence::create(cSequenceArray);
|
|
|
|
if (cSequence != nullptr)
|
|
|
|
{
|
|
|
|
cSpawnArray.pushBack(cSequence);
|
|
|
|
}
|
2014-03-10 15:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_action == nullptr)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(_actionSpawn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(_action);
|
2015-06-09 14:38:48 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_actionSpawn);
|
2014-03-10 15:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_actionSpawn = Spawn::create(cSpawnArray);
|
|
|
|
CC_SAFE_RETAIN(_actionSpawn);
|
|
|
|
return _actionSpawn;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 14:34:24 +08:00
|
|
|
void ActionNode::playAction()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if ( _object == nullptr || _actionSpawn == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-03-10 15:08:42 +08:00
|
|
|
if (_action!=nullptr)
|
|
|
|
{
|
|
|
|
_action->release();
|
|
|
|
}
|
2013-11-08 14:34:24 +08:00
|
|
|
|
2014-03-10 15:08:42 +08:00
|
|
|
_action = Sequence::create(_actionSpawn, nullptr);
|
|
|
|
_action->retain();
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-03-10 15:08:42 +08:00
|
|
|
this->runAction();
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::runAction()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
Node* cNode = this->getActionNode();
|
|
|
|
if (cNode != nullptr && _action != nullptr)
|
|
|
|
{
|
|
|
|
cNode->runAction(_action);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionNode::stopAction()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
Node* cNode = this->getActionNode();
|
|
|
|
if (cNode != nullptr && _action != nullptr)
|
|
|
|
{
|
|
|
|
cNode->stopAction(_action);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ActionNode::getFirstFrameIndex()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
int frameindex = 99999;
|
|
|
|
bool bFindFrame = false;
|
|
|
|
for (int n = 0; n < _frameArrayNum; n++)
|
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(n);
|
|
|
|
if (cArray->empty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bFindFrame = true;
|
|
|
|
auto frame = cArray->at(0);
|
|
|
|
int iFrameIndex = frame->getFrameIndex();
|
|
|
|
|
|
|
|
if (frameindex > iFrameIndex)
|
|
|
|
{
|
|
|
|
frameindex = iFrameIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bFindFrame)
|
|
|
|
{
|
|
|
|
frameindex = 0;
|
|
|
|
}
|
|
|
|
return frameindex;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int ActionNode::getLastFrameIndex()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
int frameindex = -1;
|
|
|
|
bool bFindFrame = false;
|
|
|
|
for (int n = 0; n < _frameArrayNum; n++)
|
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(n);
|
|
|
|
if (cArray->empty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bFindFrame = true;
|
|
|
|
ssize_t lastInex = cArray->size() - 1;
|
|
|
|
auto frame = cArray->at(lastInex);
|
|
|
|
int iFrameIndex = frame->getFrameIndex();
|
|
|
|
|
|
|
|
if (frameindex < iFrameIndex)
|
|
|
|
{
|
|
|
|
frameindex = iFrameIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!bFindFrame)
|
|
|
|
{
|
|
|
|
frameindex = 0;
|
|
|
|
}
|
|
|
|
return frameindex;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2014-03-10 15:08:42 +08:00
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
bool ActionNode::updateActionToTimeLine(float fTime)
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
bool bFindFrame = false;
|
|
|
|
|
|
|
|
ActionFrame* srcFrame = nullptr;
|
|
|
|
for (int n = 0; n < _frameArrayNum; n++)
|
|
|
|
{
|
|
|
|
auto cArray = _frameArray.at(n);
|
|
|
|
if (cArray->empty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ssize_t frameCount = cArray->size();
|
|
|
|
for (int i = 0; i < frameCount; i++)
|
|
|
|
{
|
|
|
|
auto frame = cArray->at(i);
|
|
|
|
|
|
|
|
if (frame->getFrameIndex()*getUnitTime() == fTime)
|
|
|
|
{
|
|
|
|
this->easingToFrame(1.0f,1.0f,nullptr,frame);
|
|
|
|
bFindFrame = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (frame->getFrameIndex()*getUnitTime() > fTime)
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
this->easingToFrame(1.0f,1.0f,nullptr,frame);
|
|
|
|
bFindFrame = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
srcFrame = cArray->at(i-1);
|
|
|
|
float duration = (frame->getFrameIndex() - srcFrame->getFrameIndex())*getUnitTime();
|
|
|
|
float delaytime = fTime - srcFrame->getFrameIndex()*getUnitTime();
|
|
|
|
this->easingToFrame(duration,1.0f,nullptr,srcFrame);
|
|
|
|
//float easingTime = ActionFrameEasing::bounceTime(delaytime);
|
|
|
|
this->easingToFrame(duration,delaytime/duration,srcFrame,frame);
|
|
|
|
bFindFrame = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bFindFrame;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
void ActionNode::easingToFrame(float duration,float delayTime,ActionFrame* srcFrame,ActionFrame* destFrame)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
Action* cAction = destFrame->getAction(duration,srcFrame);
|
|
|
|
Node* cNode = this->getActionNode();
|
|
|
|
if (cAction == nullptr || cNode == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
2016-05-26 17:20:51 +08:00
|
|
|
}
|
2014-03-10 15:08:42 +08:00
|
|
|
cAction->startWithTarget(cNode);
|
|
|
|
cAction->update(delayTime);
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 14:34:24 +08:00
|
|
|
|
|
|
|
bool ActionNode::isActionDoneOnce()
|
|
|
|
{
|
2014-03-10 15:08:42 +08:00
|
|
|
if (_action == nullptr)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return _action->isDone();
|
2013-11-08 14:34:24 +08:00
|
|
|
}
|
|
|
|
|
2014-02-13 16:39:53 +08:00
|
|
|
}
|