Skip to content
Permalink
Browse files

update ui

  • Loading branch information
myourys committed May 20, 2014
1 parent 6e8b318 commit a2d85cc353f0eaf96c93d736c55c647802d8e66e
@@ -1,9 +1,6 @@
[submodule "tools/cocos2d-console"]
path = tools/cocos2d-console
url = git://github.com/cocos2d/cocos2d-console.git
[submodule "plugin"]
path = plugin
url = https://github.com/cocos2d-x/plugin-x.git
[submodule "tools/bindings-generator"]
path = tools/bindings-generator
url = git://github.com/cocos2d/bindings-generator.git
@@ -28,6 +28,28 @@ THE SOFTWARE.
using namespace cocos2d;

namespace cocostudio {

Action* ActionWrap::createWrap(cocos2d::Ref* node)
{
ActionWrap *ret = new ActionWrap();

if (ret )
{
ret->_node = node;
ret->autorelease();
return RepeatForever::create(ret);
}
else
{
CC_SAFE_DELETE(ret);
return nullptr;
}
}

ActionWrap::~ActionWrap()
{
ActionManagerEx::getInstance()->releaseAction(_node);
}

static ActionManagerEx* sharedActionManager = nullptr;

@@ -68,13 +90,14 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
action->initWithDictionary(actionDic,root);
actionList.pushBack(action);
}
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));
dynamic_cast<Node*>(root)->runAction(ActionWrap::createWrap(root));
_actionDic.insert(std::pair<Ref*, cocos2d::Vector<ActionObject*>>(root, actionList));
}


ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
ActionObject* ActionManagerEx::getActionByName(Ref* root,const char* actionName)
{
auto iterator = _actionDic.find(jsonName);
auto iterator = _actionDic.find(root);
if (iterator == _actionDic.end())
{
return nullptr;
@@ -91,33 +114,51 @@ ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char*
return nullptr;
}

ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName)
ActionObject* ActionManagerEx::playActionByName(Ref* root,const char* actionName)
{
ActionObject* action = getActionByName(jsonName,actionName);
ActionObject* action = getActionByName(root,actionName);
if (action)
{
action->play();
}
return action;
}

ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName, CallFunc* func)
ActionObject* ActionManagerEx::playActionByName(Ref* root,const char* actionName, CallFunc* func)
{
ActionObject* action = getActionByName(jsonName,actionName);
ActionObject* action = getActionByName(root,actionName);
if (action)
{
action->play(func);
}
return action;
}

void ActionManagerEx::releaseAction(Ref* root)
{
auto iterator = _actionDic.find(root);
if (iterator == _actionDic.end())
{
return;
}
auto actionList = iterator->second;
for (auto & action:actionList) {
action->stop();
}
actionList.clear();
_actionDic.erase(root);
}

void ActionManagerEx::releaseActions()
{
std::unordered_map<std::string, cocos2d::Vector<ActionObject*>>::iterator iter;
std::unordered_map<Ref*, cocos2d::Vector<ActionObject*>>::iterator iter;
for (iter = _actionDic.begin(); iter != _actionDic.end(); iter++)
{
cocos2d::Vector<ActionObject*> objList = iter->second;
objList.clear();
for (auto & action:objList) {
action->stop();
}
}

_actionDic.clear();
@@ -29,6 +29,22 @@ THE SOFTWARE.
#include "cocostudio/DictionaryHelper.h"

namespace cocostudio {

class ActionManagerEx;

class ActionWrap: public cocos2d::ActionInterval
{
public:
ActionWrap():_node(nullptr){};
static cocos2d::Action* createWrap(cocos2d::Ref* node);
virtual ActionWrap* reverse() const {return nullptr;};
virtual ActionWrap* clone() const {return nullptr;};

virtual void update(float t) {};
virtual ~ActionWrap();
private:
cocos2d::Ref* _node;
};

class ActionManagerEx:public cocos2d::Ref
{
@@ -70,7 +86,7 @@ class ActionManagerEx:public cocos2d::Ref
*
* @return ActionObject which named as the param name
*/
ActionObject* getActionByName(const char* jsonName,const char* actionName);
ActionObject* getActionByName(Ref* root,const char* actionName);

/**
* Play an Action with a name.
@@ -81,7 +97,7 @@ class ActionManagerEx:public cocos2d::Ref
*
* @return ActionObject which named as the param name
*/
ActionObject* playActionByName(const char* jsonName,const char* actionName);
ActionObject* playActionByName(Ref* root,const char* actionName);

/**
* Play an Action with a name.
@@ -92,18 +108,20 @@ class ActionManagerEx:public cocos2d::Ref
*
* @param func ui action call back
*/
ActionObject* playActionByName(const char* jsonName,const char* actionName, cocos2d::CallFunc* func);
ActionObject* playActionByName(Ref* root,const char* actionName, cocos2d::CallFunc* func);

/*init properties with json dictionay*/
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root);

void releaseAction(Ref* root);
/**
* Release all actions.
*
*/
void releaseActions();

protected:
std::unordered_map<std::string, cocos2d::Vector<ActionObject*>> _actionDic;
std::unordered_map<Ref*, cocos2d::Vector<ActionObject*>> _actionDic;
};

}
@@ -72,6 +72,7 @@ ActionNode::~ActionNode()
void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
{
setActionTag(DICTOOL->getIntValue_json(dic, "ActionTag"));
initActionNodeFromRoot(root);
int actionFrameCount = DICTOOL->getArrayCount_json(dic, "actionframelist");
for (int i=0; i<actionFrameCount; i++)
{
@@ -99,7 +100,14 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
actionFrame->setFrameIndex(frameInex);
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setPosition(Point(positionX, positionY));
if(this->getActionNode()->getParent())
{
actionFrame->setPosition(Point(positionX, positionY)+this->getActionNode()->getParent()->getAnchorPointInPoints());
}
else
{
actionFrame->setPosition(Point(positionX, positionY));
}
auto cActionArray = _frameArray.at((int)kKeyframeMove);
cActionArray->pushBack(actionFrame);
actionFrame->release();
@@ -165,7 +173,6 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
actionFrame->release();
}
}
initActionNodeFromRoot(root);
}

void ActionNode::initActionNodeFromRoot(Ref* root)
@@ -50,6 +50,8 @@ ActionObject::ActionObject()

ActionObject::~ActionObject()
{
this->stop();
CC_SAFE_RELEASE(_CallBack);
_actionNodeList.clear();
CC_SAFE_RELEASE(_pScheduler);
}
@@ -135,6 +137,7 @@ void ActionObject::addActionNode(ActionNode* node)
_actionNodeList.pushBack(node);
node->setUnitTime(_fUnitTime);
}

void ActionObject::removeActionNode(ActionNode* node)
{
if (node == nullptr)
@@ -146,25 +149,21 @@ void ActionObject::removeActionNode(ActionNode* node)

void ActionObject::play()
{
stop();
if(_bPlaying)
return;
this->updateToFrameByTime(0.0f);
for(const auto &e : _actionNodeList)
{
e->playAction();
}
if (_loop)
{
_pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f , kRepeatForever, 0.0f, false);
}
else
{
_pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f, false);
}
_pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f , kRepeatForever, 0.0f, false);
_bPlaying = true;
}

void ActionObject::play(CallFunc* func)
{
this->play();
func->retain();
this->_CallBack = func;
}
void ActionObject::pause()
@@ -174,12 +173,17 @@ void ActionObject::pause()

void ActionObject::stop()
{
if (!_bPlaying) {
return;
}
for(const auto &e : _actionNodeList)
{
e->stopAction();
if (!e->isActionDoneOnce())
e->stopAction();
}
_pScheduler->unschedule(schedule_selector(ActionObject::simulationActionUpdate), this);
_bPause = false;
_bPlaying = false;
}

void ActionObject::updateToFrameByTime(float fTime)
@@ -212,8 +216,16 @@ void ActionObject::simulationActionUpdate(float dt)
}
if (_loop)
{
this->play();
this->updateToFrameByTime(0.0f);
for(const auto &e : _actionNodeList)
{
e->playAction();
}
}
else
{
this->stop();
}
}
}
}
@@ -1113,9 +1113,11 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va
{
if (child->getPositionType() == cocos2d::ui::POSITION_PERCENT)
{
child->setPositionPercent(Point(child->getPositionPercent().x + 0.5f, child->getPositionPercent().y + 0.5f));
//child->setPositionPercent(Point(child->getPositionPercent().x + 0.5f, child->getPositionPercent().y + 0.5f));
child->setPositionPercent(Point(child->getPositionPercent().x + widget->getAnchorPoint().x, child->getPositionPercent().y + widget->getAnchorPoint().y));
}
child->setPosition(Point(child->getPositionX() + widget->getSize().width / 2.0f, child->getPositionY() + widget->getSize().height / 2.0f));
//child->setPosition(Point(child->getPositionX() + widget->getSize().width / 2.0f, child->getPositionY() + widget->getSize().height / 2.0f));
child->setPosition(Point(child->getPositionX() + widget->getAnchorPointInPoints().x, child->getPositionY() + widget->getAnchorPointInPoints().y));
}
widget->addChild(child);
}
1 plugin
Submodule plugin deleted from 56dc58
Submodule cocos2d-console updated 203 files

0 comments on commit a2d85cc

Please sign in to comment.
You can’t perform that action at this time.