mirror of https://github.com/axmolengine/axmol.git
issue #2790: Uses Vector<T> or Map<K, V> as many as possible for CCBReader.
This commit is contained in:
parent
f6dc9bf9b6
commit
d1d5659818
|
@ -21,25 +21,18 @@ CCBAnimationManager::CCBAnimationManager()
|
|||
: _jsControlled(false)
|
||||
, _owner(NULL)
|
||||
, _sequences(NULL)
|
||||
, _nodeSequences(NULL)
|
||||
, _baseValues(NULL)
|
||||
, _autoPlaySequenceId(0)
|
||||
, _rootNode(NULL)
|
||||
, _rootContainerSize(Size::ZERO)
|
||||
, _delegate(NULL)
|
||||
, _runningSequence(NULL)
|
||||
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
bool CCBAnimationManager::init()
|
||||
{
|
||||
_nodeSequences = new Dictionary();
|
||||
_nodeSequences->init();
|
||||
_baseValues = new Dictionary();
|
||||
_baseValues->init();
|
||||
|
||||
_keyframeCallFuncs = new Dictionary();
|
||||
_keyframeCallFuncs->init();
|
||||
|
||||
|
@ -64,12 +57,17 @@ CCBAnimationManager::~CCBAnimationManager()
|
|||
// node->release();
|
||||
// }
|
||||
|
||||
_nodeSequences->release();
|
||||
_baseValues->release();
|
||||
|
||||
setRootNode(NULL);
|
||||
setDelegate(NULL);
|
||||
|
||||
for (auto iter = _objects.begin(); iter != _objects.end(); ++iter)
|
||||
{
|
||||
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2)
|
||||
{
|
||||
iter2->second->release();
|
||||
}
|
||||
}
|
||||
|
||||
CC_SAFE_RELEASE(_keyframeCallFuncs);
|
||||
CC_SAFE_RELEASE(_target);
|
||||
}
|
||||
|
@ -219,31 +217,44 @@ const Size& CCBAnimationManager::getContainerSize(Node *pNode)
|
|||
}
|
||||
|
||||
// refer to CCBReader::readNodeGraph() for data structure of pSeq
|
||||
void CCBAnimationManager::addNode(Node *pNode, Dictionary *pSeq)
|
||||
void CCBAnimationManager::addNode(Node *pNode, const std::unordered_map<int, Map<std::string, CCBSequenceProperty*>>& seq)
|
||||
{
|
||||
// pNode->retain();
|
||||
|
||||
_nodeSequences->setObject(pSeq, (intptr_t)pNode);
|
||||
_nodeSequences[pNode] = seq;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setBaseValue(Object *pValue, Node *pNode, const char *propName)
|
||||
void CCBAnimationManager::setBaseValue(const Value& value, Node *pNode, const std::string& propName)
|
||||
{
|
||||
Dictionary *props = (Dictionary*)_baseValues->objectForKey((intptr_t)pNode);
|
||||
if (! props)
|
||||
{
|
||||
props = Dictionary::create();
|
||||
_baseValues->setObject(props, (intptr_t)pNode);
|
||||
// pNode->retain();
|
||||
}
|
||||
|
||||
props->setObject(pValue, propName);
|
||||
auto& props = _baseValues[pNode];
|
||||
props[propName] = value;
|
||||
}
|
||||
|
||||
Object* CCBAnimationManager::getBaseValue(Node *pNode, const char* propName)
|
||||
const Value& CCBAnimationManager::getBaseValue(Node *pNode, const std::string& propName)
|
||||
{
|
||||
Dictionary *props = (Dictionary*)_baseValues->objectForKey((intptr_t)pNode);
|
||||
auto& props = _baseValues[pNode];
|
||||
return props[propName];
|
||||
}
|
||||
|
||||
return props->objectForKey(propName);
|
||||
void CCBAnimationManager::setObject(Object* obj, Node *pNode, const std::string& propName)
|
||||
{
|
||||
auto& props = _objects[pNode];
|
||||
auto iter = props.find(propName);
|
||||
if (iter != props.end())
|
||||
iter->second->release();
|
||||
|
||||
props[propName] = obj;
|
||||
obj->retain();
|
||||
}
|
||||
|
||||
Object* CCBAnimationManager::getObject(Node *pNode, const std::string& propName)
|
||||
{
|
||||
auto& props = _objects[pNode];
|
||||
auto iter = props.find(propName);
|
||||
if (iter != props.end())
|
||||
return iter->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int CCBAnimationManager::getSequenceId(const char* pSequenceName)
|
||||
|
@ -280,23 +291,32 @@ float CCBAnimationManager::getSequenceDuration(const char *pSequenceName)
|
|||
}
|
||||
|
||||
|
||||
void CCBAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode) {
|
||||
|
||||
void CCBAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode)
|
||||
{
|
||||
// Move base values
|
||||
Object* baseValue = _baseValues->objectForKey((intptr_t)fromNode);
|
||||
if(baseValue) {
|
||||
_baseValues->setObject(baseValue, (intptr_t)toNode);
|
||||
_baseValues->removeObjectForKey((intptr_t)fromNode);
|
||||
|
||||
auto baseValueIter = _baseValues.find(fromNode);
|
||||
if(baseValueIter != _baseValues.end())
|
||||
{
|
||||
_baseValues.erase(baseValueIter);
|
||||
_baseValues[toNode] = baseValueIter->second;
|
||||
// fromNode->release();
|
||||
// toNode->retain();
|
||||
}
|
||||
|
||||
auto objIter = _objects.find(fromNode);
|
||||
if (objIter != _objects.end())
|
||||
{
|
||||
_objects.erase(objIter);
|
||||
_objects[toNode] = objIter->second;
|
||||
}
|
||||
|
||||
|
||||
// Move seqs
|
||||
Object *seqs = _nodeSequences->objectForKey((intptr_t)fromNode);
|
||||
if(seqs) {
|
||||
_nodeSequences->setObject(seqs, (intptr_t)toNode);
|
||||
_nodeSequences->removeObjectForKey((intptr_t)fromNode);
|
||||
auto seqsIter = _nodeSequences.find(fromNode);
|
||||
if (seqsIter != _nodeSequences.end())
|
||||
{
|
||||
_nodeSequences.erase(seqsIter);
|
||||
_nodeSequences[toNode] = seqsIter->second;
|
||||
|
||||
// fromNode->release();
|
||||
// toNode->retain();
|
||||
|
@ -304,41 +324,37 @@ void CCBAnimationManager::moveAnimationsFromNode(Node* fromNode, Node* toNode) {
|
|||
}
|
||||
|
||||
// Refer to CCBReader::readKeyframe() for the real type of value
|
||||
ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *propName, Node *pNode)
|
||||
ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const std::string& propName, Node *pNode)
|
||||
{
|
||||
float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0);
|
||||
|
||||
if (strcmp(propName, "rotationX") == 0)
|
||||
if (propName == "rotationX")
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return CCBRotateXTo::create(duration, value->getFloatValue());
|
||||
return CCBRotateXTo::create(duration, pKeyframe1->getValue().asFloat());
|
||||
}
|
||||
else if(strcmp(propName, "rotationY") == 0)
|
||||
else if (propName == "rotationY")
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return CCBRotateYTo::create(duration, value->getFloatValue());
|
||||
return CCBRotateYTo::create(duration, pKeyframe1->getValue().asFloat());
|
||||
}
|
||||
else if (strcmp(propName, "rotation") == 0)
|
||||
else if (propName == "rotation")
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return CCBRotateTo::create(duration, value->getFloatValue());
|
||||
return CCBRotateTo::create(duration, pKeyframe1->getValue().asFloat());
|
||||
}
|
||||
else if (strcmp(propName, "opacity") == 0)
|
||||
else if (propName == "opacity")
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
return FadeTo::create(duration, value->getByteValue());
|
||||
return FadeTo::create(duration, pKeyframe1->getValue().asByte());
|
||||
}
|
||||
else if (strcmp(propName, "color") == 0)
|
||||
else if (propName == "color")
|
||||
{
|
||||
Color3BWapper* color = (Color3BWapper*)pKeyframe1->getValue();
|
||||
Color3B c = color->getColor();
|
||||
|
||||
return TintTo::create(duration, c.r, c.g, c.b);
|
||||
auto c = pKeyframe1->getValue().asValueMap();
|
||||
unsigned char r = c["r"].asByte();
|
||||
unsigned char g = c["g"].asByte();
|
||||
unsigned char b = c["b"].asByte();
|
||||
return TintTo::create(duration, r, g, b);
|
||||
}
|
||||
else if (strcmp(propName, "visible") == 0)
|
||||
else if (propName == "visible")
|
||||
{
|
||||
CCBValue *value = (CCBValue*)pKeyframe1->getValue();
|
||||
if (value->getBoolValue())
|
||||
if (pKeyframe1->getValue().asBool())
|
||||
{
|
||||
return Sequence::createWithTwoActions(DelayTime::create(duration), Show::create());
|
||||
}
|
||||
|
@ -347,21 +363,21 @@ ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyfr
|
|||
return Sequence::createWithTwoActions(DelayTime::create(duration), Hide::create());
|
||||
}
|
||||
}
|
||||
else if (strcmp(propName, "displayFrame") == 0)
|
||||
else if (propName == "displayFrame")
|
||||
{
|
||||
return Sequence::createWithTwoActions(DelayTime::create(duration),
|
||||
CCBSetSpriteFrame::create((SpriteFrame *)pKeyframe1->getValue()));
|
||||
CCBSetSpriteFrame::create(static_cast<SpriteFrame*>(pKeyframe1->getObject())));
|
||||
}
|
||||
else if (strcmp(propName, "position") == 0)
|
||||
else if (propName == "position")
|
||||
{
|
||||
// Get position type
|
||||
Array *array = static_cast<Array*>(getBaseValue(pNode, propName));
|
||||
CCBReader::PositionType type = (CCBReader::PositionType)((CCBValue*)array->getObjectAtIndex(2))->getIntValue();
|
||||
auto& array = getBaseValue(pNode, propName).asValueVector();
|
||||
CCBReader::PositionType type = (CCBReader::PositionType)array[2].asInt();
|
||||
|
||||
// Get relative position
|
||||
Array *value = static_cast<Array*>(pKeyframe1->getValue());
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto value = pKeyframe1->getValue().asValueVector();
|
||||
float x = value[0].asFloat();
|
||||
float y = value[1].asFloat();
|
||||
|
||||
Size containerSize = getContainerSize(pNode->getParent());
|
||||
|
||||
|
@ -369,16 +385,16 @@ ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyfr
|
|||
|
||||
return MoveTo::create(duration, absPos);
|
||||
}
|
||||
else if (strcmp(propName, "scale") == 0)
|
||||
else if (propName == "scale")
|
||||
{
|
||||
// Get position type
|
||||
Array *array = (Array*)getBaseValue(pNode, propName);
|
||||
CCBReader::ScaleType type = (CCBReader::ScaleType)((CCBValue*)array->getObjectAtIndex(2))->getIntValue();
|
||||
auto& array = getBaseValue(pNode, propName).asValueVector();
|
||||
CCBReader::ScaleType type = (CCBReader::ScaleType)array[2].asInt();
|
||||
|
||||
// Get relative scale
|
||||
Array *value = (Array*)pKeyframe1->getValue();
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto value = pKeyframe1->getValue().asValueVector();
|
||||
float x = value[0].asFloat();
|
||||
float y = value[1].asFloat();
|
||||
|
||||
if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
||||
{
|
||||
|
@ -389,31 +405,33 @@ ActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyfr
|
|||
|
||||
return ScaleTo::create(duration, x, y);
|
||||
}
|
||||
else if(strcmp(propName, "skew") == 0)
|
||||
else if (propName == "skew")
|
||||
{
|
||||
// Get relative skew
|
||||
Array *value = (Array*)pKeyframe1->getValue();
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto& value = pKeyframe1->getValue().asValueVector();
|
||||
float x = value[0].asFloat();
|
||||
float y = value[1].asFloat();
|
||||
|
||||
return SkewTo::create(duration, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
log("CCBReader: Failed to create animation for property: %s", propName);
|
||||
log("CCBReader: Failed to create animation for property: %s", propName.c_str());
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CCBAnimationManager::setAnimatedProperty(const char *propName, Node *pNode, Object *pValue, float fTweenDuration)
|
||||
void CCBAnimationManager::setAnimatedProperty(const std::string& propName, Node *pNode, const Value& value, Object* obj, float fTweenDuration)
|
||||
{
|
||||
if (fTweenDuration > 0)
|
||||
{
|
||||
// Create a fake keyframe to generate the action from
|
||||
CCBKeyframe *kf1 = new CCBKeyframe();
|
||||
kf1->autorelease();
|
||||
kf1->setValue(pValue);
|
||||
|
||||
kf1->setObject(obj);
|
||||
kf1->setValue(value);
|
||||
kf1->setTime(fTweenDuration);
|
||||
kf1->setEasingType(CCBKeyframe::EasingType::LINEAR);
|
||||
|
||||
|
@ -425,38 +443,37 @@ void CCBAnimationManager::setAnimatedProperty(const char *propName, Node *pNode,
|
|||
{
|
||||
// Just set the value
|
||||
|
||||
if (strcmp(propName, "position") == 0)
|
||||
if (propName == "position")
|
||||
{
|
||||
// Get position type
|
||||
Array *array = (Array*)getBaseValue(pNode, propName);
|
||||
CCBReader::PositionType type = (CCBReader::PositionType)((CCBValue*)array->getObjectAtIndex(2))->getIntValue();
|
||||
|
||||
auto& array = getBaseValue(pNode, propName).asValueVector();
|
||||
CCBReader::PositionType type = (CCBReader::PositionType)array[2].asInt();
|
||||
// Get relative position
|
||||
Array *value = (Array*)pValue;
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto& valueVector = value.asValueVector();
|
||||
float x = valueVector[0].asFloat();
|
||||
float y = valueVector[1].asFloat();
|
||||
|
||||
pNode->setPosition(getAbsolutePosition(Point(x,y), type, getContainerSize(pNode->getParent()), propName));
|
||||
}
|
||||
else if (strcmp(propName, "scale") == 0)
|
||||
else if (propName == "scale")
|
||||
{
|
||||
// Get scale type
|
||||
Array *array = (Array*)getBaseValue(pNode, propName);
|
||||
CCBReader::ScaleType type = (CCBReader::ScaleType)((CCBValue*)array->getObjectAtIndex(2))->getIntValue();
|
||||
auto& array = getBaseValue(pNode, propName).asValueVector();
|
||||
CCBReader::ScaleType type = (CCBReader::ScaleType)array[2].asInt();
|
||||
|
||||
// Get relative scale
|
||||
Array *value = (Array*)pValue;
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto& valueVector = value.asValueVector();
|
||||
float x = valueVector[0].asFloat();
|
||||
float y = valueVector[1].asFloat();
|
||||
|
||||
setRelativeScale(pNode, x, y, type, propName);
|
||||
}
|
||||
else if(strcmp(propName, "skew") == 0)
|
||||
else if(propName == "skew")
|
||||
{
|
||||
// Get relative scale
|
||||
Array *value = (Array*)pValue;
|
||||
float x = ((CCBValue*)value->getObjectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->getObjectAtIndex(1))->getFloatValue();
|
||||
auto& valueVector = value.asValueVector();
|
||||
float x = valueVector[0].asFloat();
|
||||
float y = valueVector[1].asFloat();
|
||||
|
||||
pNode->setSkewX(x);
|
||||
pNode->setSkewY(y);
|
||||
|
@ -466,41 +483,44 @@ void CCBAnimationManager::setAnimatedProperty(const char *propName, Node *pNode,
|
|||
// [node setValue:value forKey:name];
|
||||
|
||||
// TODO only handle rotation, opacity, displayFrame, color
|
||||
if (strcmp(propName, "rotation") == 0)
|
||||
if (propName == "rotation")
|
||||
{
|
||||
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
||||
float rotate = value.asFloat();
|
||||
pNode->setRotation(rotate);
|
||||
} else if(strcmp(propName, "rotationX") == 0)
|
||||
} else if(propName == "rotationX")
|
||||
{
|
||||
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
||||
float rotate = value.asFloat();
|
||||
pNode->setRotationX(rotate);
|
||||
}else if(strcmp(propName, "rotationY") == 0)
|
||||
}else if(propName == "rotationY")
|
||||
{
|
||||
float rotate = ((CCBValue*)pValue)->getFloatValue();
|
||||
float rotate = value.asFloat();
|
||||
pNode->setRotationY(rotate);
|
||||
}
|
||||
else if (strcmp(propName, "opacity") == 0)
|
||||
else if (propName == "opacity")
|
||||
{
|
||||
int opacity = ((CCBValue*)pValue)->getByteValue();
|
||||
unsigned char opacity = value.asByte();
|
||||
(dynamic_cast<RGBAProtocol*>(pNode))->setOpacity(opacity);
|
||||
}
|
||||
else if (strcmp(propName, "displayFrame") == 0)
|
||||
else if (propName == "displayFrame")
|
||||
{
|
||||
((Sprite*)pNode)->setDisplayFrame((SpriteFrame*)pValue);
|
||||
static_cast<Sprite*>(pNode)->setDisplayFrame(static_cast<SpriteFrame*>(obj));
|
||||
}
|
||||
else if (strcmp(propName, "color") == 0)
|
||||
else if (propName == "color")
|
||||
{
|
||||
Color3BWapper *color = (Color3BWapper*)pValue;
|
||||
(dynamic_cast<RGBAProtocol*>(pNode))->setColor(color->getColor());
|
||||
auto c = value.asValueMap();
|
||||
unsigned char r = c["r"].asByte();
|
||||
unsigned char g = c["g"].asByte();
|
||||
unsigned char b = c["b"].asByte();
|
||||
(dynamic_cast<RGBAProtocol*>(pNode))->setColor(Color3B(r, g, b));
|
||||
}
|
||||
else if (strcmp(propName, "visible") == 0)
|
||||
else if (propName == "visible")
|
||||
{
|
||||
bool visible = ((CCBValue*)pValue)->getBoolValue();
|
||||
bool visible = value.asBool();
|
||||
pNode->setVisible(visible);
|
||||
}
|
||||
else
|
||||
{
|
||||
log("unsupported property name is %s", propName);
|
||||
log("unsupported property name is %s", propName.c_str());
|
||||
CCASSERT(false, "unsupported property now");
|
||||
}
|
||||
}
|
||||
|
@ -514,15 +534,16 @@ void CCBAnimationManager::setFirstFrame(Node *pNode, CCBSequenceProperty *pSeqPr
|
|||
if (keyframes.empty())
|
||||
{
|
||||
// Use base value (no animation)
|
||||
Object *baseValue = getBaseValue(pNode, pSeqProp->getName());
|
||||
CCASSERT(baseValue, "No baseValue found for property");
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, fTweenDuration);
|
||||
auto& baseValue = getBaseValue(pNode, pSeqProp->getName());
|
||||
auto obj = getObject(pNode, pSeqProp->getName());
|
||||
CCASSERT(!baseValue.isNull(), "No baseValue found for property");
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, baseValue, obj, fTweenDuration);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use first keyframe
|
||||
CCBKeyframe *keyframe = keyframes.at(0);
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), fTweenDuration);
|
||||
setAnimatedProperty(pSeqProp->getName(), pNode, keyframe->getValue(), keyframe->getObject(), fTweenDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,9 +635,9 @@ Object* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* chann
|
|||
actions.pushBack(DelayTime::create(timeSinceLastKeyframe));
|
||||
}
|
||||
|
||||
Array* keyVal = static_cast<Array *>(keyframe->getValue());
|
||||
std::string selectorName = static_cast<String *>(keyVal->getObjectAtIndex(0))->getCString();
|
||||
CCBReader::TargetType selectorTarget = (CCBReader::TargetType)atoi(static_cast<String *>(keyVal->getObjectAtIndex(1))->getCString());
|
||||
auto& keyVal = keyframe->getValue().asValueVector();
|
||||
std::string selectorName = keyVal[0].asString();
|
||||
CCBReader::TargetType selectorTarget = (CCBReader::TargetType)keyVal[1].asInt();
|
||||
|
||||
if(_jsControlled) {
|
||||
String* callbackName = String::createWithFormat("%d:%s", selectorTarget, selectorName.c_str());
|
||||
|
@ -693,19 +714,19 @@ Object* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel)
|
|||
}
|
||||
|
||||
stringstream ss (stringstream::in | stringstream::out);
|
||||
Array* keyVal = (Array*)keyframe->getValue();
|
||||
std::string soundFile = ((String *)keyVal->getObjectAtIndex(0))->getCString();
|
||||
auto& keyVal = keyframe->getValue().asValueVector();
|
||||
std::string soundFile = keyVal[0].asString();
|
||||
|
||||
float pitch, pan, gain;
|
||||
ss << ((String *)keyVal->getObjectAtIndex(1))->getCString();
|
||||
ss << keyVal[1].asString();
|
||||
ss >> pitch;
|
||||
ss.flush();
|
||||
|
||||
ss << ((String *)keyVal->getObjectAtIndex(2))->getCString();
|
||||
ss << keyVal[2].asString();
|
||||
ss >> pan;
|
||||
ss.flush();
|
||||
|
||||
ss << ((String *)keyVal->getObjectAtIndex(3))->getCString();
|
||||
ss << keyVal[3].asString();
|
||||
ss >> gain;
|
||||
ss.flush();
|
||||
|
||||
|
@ -778,26 +799,24 @@ void CCBAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, fl
|
|||
|
||||
_rootNode->stopAllActions();
|
||||
|
||||
DictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(_nodeSequences, pElement)
|
||||
for (auto nodeSeqIter = _nodeSequences.begin(); nodeSeqIter != _nodeSequences.end(); ++nodeSeqIter)
|
||||
{
|
||||
Node *node = reinterpret_cast<Node*>(pElement->getIntKey());
|
||||
Node *node = nodeSeqIter->first;
|
||||
node->stopAllActions();
|
||||
|
||||
// Refer to CCBReader::readKeyframe() for the real type of value
|
||||
Dictionary *seqs = (Dictionary*)pElement->getObject();
|
||||
Dictionary *seqNodeProps = (Dictionary*)seqs->objectForKey(nSeqId);
|
||||
auto seqs = nodeSeqIter->second;
|
||||
auto seqNodeProps = seqs[nSeqId];
|
||||
|
||||
set<string> seqNodePropNames;
|
||||
std::set<std::string> seqNodePropNames;
|
||||
|
||||
if (seqNodeProps)
|
||||
if (!seqNodeProps.empty())
|
||||
{
|
||||
// Reset nodes that have sequence node properties, and run actions on them
|
||||
DictElement* pElement1 = NULL;
|
||||
CCDICT_FOREACH(seqNodeProps, pElement1)
|
||||
for (auto iter = seqNodeProps.begin(); iter != seqNodeProps.end(); ++iter)
|
||||
{
|
||||
const char *propName = pElement1->getStrKey();
|
||||
CCBSequenceProperty *seqProp = static_cast<CCBSequenceProperty*>(seqNodeProps->objectForKey(propName));
|
||||
const std::string propName = iter->first;
|
||||
CCBSequenceProperty *seqProp = iter->second;
|
||||
seqNodePropNames.insert(propName);
|
||||
|
||||
setFirstFrame(node, seqProp, fTweenDuration);
|
||||
|
@ -806,20 +825,28 @@ void CCBAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, fl
|
|||
}
|
||||
|
||||
// Reset the nodes that may have been changed by other timelines
|
||||
Dictionary *nodeBaseValues = (Dictionary*)_baseValues->objectForKey(pElement->getIntKey());
|
||||
if (nodeBaseValues)
|
||||
{
|
||||
DictElement* pElement2 = NULL;
|
||||
CCDICT_FOREACH(nodeBaseValues, pElement2)
|
||||
{
|
||||
if (seqNodePropNames.find(pElement2->getStrKey()) == seqNodePropNames.end())
|
||||
{
|
||||
Object *value = pElement2->getObject();
|
||||
auto& nodeBaseValues = _baseValues[node];
|
||||
|
||||
if (value)
|
||||
{
|
||||
setAnimatedProperty(pElement2->getStrKey(), node, value, fTweenDuration);
|
||||
}
|
||||
if (!nodeBaseValues.empty())
|
||||
{
|
||||
for (auto iter = nodeBaseValues.begin(); iter != nodeBaseValues.end(); ++iter)
|
||||
{
|
||||
if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
|
||||
{
|
||||
setAnimatedProperty(iter->first, node, iter->second, nullptr, fTweenDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& nodeObject = _objects[node];
|
||||
|
||||
if (!nodeObject.empty())
|
||||
{
|
||||
for (auto iter = nodeObject.begin(); iter != nodeObject.end(); ++iter)
|
||||
{
|
||||
if (seqNodePropNames.find(iter->first) == seqNodePropNames.end())
|
||||
{
|
||||
setAnimatedProperty(iter->first, node, Value(), iter->second, fTweenDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,8 +77,10 @@ public:
|
|||
|
||||
const cocos2d::Size& getContainerSize(cocos2d::Node* pNode);
|
||||
|
||||
void addNode(cocos2d::Node *pNode, cocos2d::Dictionary *pSeq);
|
||||
void setBaseValue(cocos2d::Object *pValue, cocos2d::Node *pNode, const char *propName);
|
||||
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::Object* 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.*/
|
||||
|
@ -113,10 +115,12 @@ public:
|
|||
float getSequenceDuration(const char* pSequenceName);
|
||||
|
||||
private:
|
||||
cocos2d::Object* getBaseValue(cocos2d::Node *pNode, const char* propName);
|
||||
const cocos2d::Value& getBaseValue(cocos2d::Node *pNode, const std::string& propName);
|
||||
Object* getObject(cocos2d::Node *pNode, const std::string& propName);
|
||||
|
||||
CCBSequence* getSequence(int nSequenceId);
|
||||
cocos2d::ActionInterval* getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *propName, cocos2d::Node *pNode);
|
||||
void setAnimatedProperty(const char *propName,cocos2d::Node *pNode, Object *pValue, float fTweenDuraion);
|
||||
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, Object* obj, float fTweenDuraion);
|
||||
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);
|
||||
|
@ -124,8 +128,10 @@ private:
|
|||
|
||||
private:
|
||||
cocos2d::Vector<CCBSequence*> _sequences;
|
||||
cocos2d::Dictionary *_nodeSequences;
|
||||
cocos2d::Dictionary *_baseValues;
|
||||
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::Object*>> _objects;
|
||||
|
||||
int _autoPlaySequenceId;
|
||||
|
||||
cocos2d::Node *_rootNode;
|
||||
|
|
|
@ -5,27 +5,37 @@ using namespace cocos2d;
|
|||
namespace cocosbuilder {
|
||||
|
||||
CCBKeyframe::CCBKeyframe()
|
||||
: _value(NULL)
|
||||
, _time(0.0f)
|
||||
: _time(0.0f)
|
||||
, _easingType(EasingType::INSTANT)
|
||||
, _easingOpt(0.0f)
|
||||
, _object(nullptr)
|
||||
{}
|
||||
|
||||
CCBKeyframe::~CCBKeyframe()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_value);
|
||||
CC_SAFE_RELEASE(_object);
|
||||
}
|
||||
|
||||
Object* CCBKeyframe::getValue()
|
||||
const Value& CCBKeyframe::getValue() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setValue(Object *pValue)
|
||||
void CCBKeyframe::setValue(const Value& value)
|
||||
{
|
||||
CC_SAFE_RELEASE(_value);
|
||||
_value = pValue;
|
||||
CC_SAFE_RETAIN(_value);
|
||||
_value = value;
|
||||
}
|
||||
|
||||
Object* CCBKeyframe::getObject() const
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
|
||||
void CCBKeyframe::setObject(Object* obj)
|
||||
{
|
||||
CC_SAFE_RETAIN(obj);
|
||||
CC_SAFE_RELEASE(_object);
|
||||
_object = obj;
|
||||
}
|
||||
|
||||
float CCBKeyframe::getTime()
|
||||
|
|
|
@ -40,8 +40,11 @@ public:
|
|||
*/
|
||||
~CCBKeyframe();
|
||||
|
||||
cocos2d::Object* getValue();
|
||||
void setValue(cocos2d::Object *pValue); // retain
|
||||
const cocos2d::Value& getValue() const;
|
||||
void setValue(const cocos2d::Value& value);
|
||||
|
||||
cocos2d::Object* getObject() const;
|
||||
void setObject(cocos2d::Object* obj);
|
||||
|
||||
float getTime();
|
||||
void setTime(float fTime);
|
||||
|
@ -53,7 +56,8 @@ public:
|
|||
void setEasingOpt(float fEasingOpt);
|
||||
|
||||
private:
|
||||
cocos2d::Object *_value;
|
||||
cocos2d::Value _value;
|
||||
cocos2d::Object* _object;
|
||||
float _time;
|
||||
EasingType _easingType;
|
||||
float _easingOpt;
|
||||
|
|
|
@ -51,7 +51,7 @@ class CCBMemberVariableAssigner {
|
|||
* @param value The value of the property.
|
||||
* @return Whether the assignment was successful.
|
||||
*/
|
||||
virtual bool onAssignCCBCustomProperty(cocos2d::Object* target, const char* memberVariableName, CCBValue* value) { return false; };
|
||||
virtual bool onAssignCCBCustomProperty(cocos2d::Object* target, const char* memberVariableName, const cocos2d::Value& value) { return false; };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -553,14 +553,14 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
}
|
||||
|
||||
// Read animated properties
|
||||
Dictionary *seqs = Dictionary::create();
|
||||
std::unordered_map<int, Map<std::string, CCBSequenceProperty*>> seqs;
|
||||
_animatedProps = new set<string>();
|
||||
|
||||
int numSequence = readInt(false);
|
||||
for (int i = 0; i < numSequence; ++i)
|
||||
{
|
||||
int seqId = readInt(false);
|
||||
Dictionary *seqNodeProps = Dictionary::create();
|
||||
Map<std::string, CCBSequenceProperty*> seqNodeProps;
|
||||
|
||||
int numProps = readInt(false);
|
||||
|
||||
|
@ -582,13 +582,13 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
seqProp->getKeyframes().pushBack(keyframe);
|
||||
}
|
||||
|
||||
seqNodeProps->setObject(seqProp, seqProp->getName());
|
||||
seqNodeProps.insert(seqProp->getName(), seqProp);
|
||||
}
|
||||
|
||||
seqs->setObject(seqNodeProps, seqId);
|
||||
seqs[seqId] = seqNodeProps;
|
||||
}
|
||||
|
||||
if (seqs->count() > 0)
|
||||
if (!seqs.empty())
|
||||
{
|
||||
_actionManager->addNode(node, seqs);
|
||||
}
|
||||
|
@ -674,7 +674,7 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
}
|
||||
|
||||
// Assign custom properties.
|
||||
if (ccNodeLoader->getCustomProperties()->count() > 0)
|
||||
if (!ccNodeLoader->getCustomProperties().empty())
|
||||
{
|
||||
bool customAssigned = false;
|
||||
|
||||
|
@ -686,15 +686,15 @@ Node * CCBReader::readNodeGraph(Node * pParent)
|
|||
CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);
|
||||
if(targetAsCCBMemberVariableAssigner != nullptr)
|
||||
{
|
||||
Dictionary* pCustomPropeties = ccNodeLoader->getCustomProperties();
|
||||
DictElement* pElement;
|
||||
CCDICT_FOREACH(pCustomPropeties, pElement)
|
||||
auto& customPropeties = ccNodeLoader->getCustomProperties();
|
||||
|
||||
for (auto iter = customPropeties.begin(); iter != customPropeties.end(); ++iter)
|
||||
{
|
||||
customAssigned = targetAsCCBMemberVariableAssigner->onAssignCCBCustomProperty(target, pElement->getStrKey(), static_cast<CCBValue*>(pElement->getObject()));
|
||||
customAssigned = targetAsCCBMemberVariableAssigner->onAssignCCBCustomProperty(target, iter->first.c_str(), iter->second);
|
||||
|
||||
if(!customAssigned && this->_CCBMemberVariableAssigner != nullptr)
|
||||
{
|
||||
customAssigned = this->_CCBMemberVariableAssigner->onAssignCCBCustomProperty(target, pElement->getStrKey(), static_cast<CCBValue*>(pElement->getObject()));
|
||||
customAssigned = this->_CCBMemberVariableAssigner->onAssignCCBCustomProperty(target, iter->first.c_str(), iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -743,7 +743,7 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
|
|||
|
||||
CCBKeyframe::EasingType easingType = static_cast<CCBKeyframe::EasingType>(readInt(false));
|
||||
float easingOpt = 0;
|
||||
Object *value = nullptr;
|
||||
Value value;
|
||||
|
||||
if (easingType == CCBKeyframe::EasingType::CUBIC_IN
|
||||
|| easingType == CCBKeyframe::EasingType::CUBIC_OUT
|
||||
|
@ -759,24 +759,28 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
|
|||
|
||||
if (type == PropertyType::CHECK)
|
||||
{
|
||||
value = CCBValue::create(readBool());
|
||||
value = readBool();
|
||||
}
|
||||
else if (type == PropertyType::BYTE)
|
||||
{
|
||||
value = CCBValue::create(readByte());
|
||||
value = readByte();
|
||||
}
|
||||
else if (type == PropertyType::COLOR3)
|
||||
{
|
||||
int r = readByte();
|
||||
int g = readByte();
|
||||
int b = readByte();
|
||||
unsigned char r = readByte();
|
||||
unsigned char g = readByte();
|
||||
unsigned char b = readByte();
|
||||
|
||||
Color3B c = Color3B(r,g,b);
|
||||
value = Color3BWapper::create(c);
|
||||
ValueMap colorMap;
|
||||
colorMap["r"] = r;
|
||||
colorMap["g"] = g;
|
||||
colorMap["b"] = b;
|
||||
|
||||
value = colorMap;
|
||||
}
|
||||
else if (type == PropertyType::DEGREES)
|
||||
{
|
||||
value = CCBValue::create(readFloat());
|
||||
value = readFloat();
|
||||
}
|
||||
else if (type == PropertyType::SCALE_LOCK || type == PropertyType::POSITION
|
||||
|| type == PropertyType::FLOAT_XY)
|
||||
|
@ -784,9 +788,11 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
|
|||
float a = readFloat();
|
||||
float b = readFloat();
|
||||
|
||||
value = Array::create(CCBValue::create(a),
|
||||
CCBValue::create(b),
|
||||
nullptr);
|
||||
ValueVector ab;
|
||||
ab.push_back(Value(a));
|
||||
ab.push_back(Value(b));
|
||||
|
||||
value = ab;
|
||||
}
|
||||
else if (type == PropertyType::SPRITEFRAME)
|
||||
{
|
||||
|
@ -818,10 +824,13 @@ CCBKeyframe* CCBReader::readKeyframe(PropertyType type)
|
|||
|
||||
spriteFrame = frameCache->getSpriteFrameByName(spriteFile.c_str());
|
||||
}
|
||||
value = spriteFrame;
|
||||
|
||||
keyframe->setObject(spriteFrame);
|
||||
// FIXME:XXX keyframe->setValue(spriteFrame);
|
||||
}
|
||||
|
||||
keyframe->setValue(value);
|
||||
if (!value.isNull())
|
||||
keyframe->setValue(value);
|
||||
|
||||
return keyframe;
|
||||
}
|
||||
|
@ -842,15 +851,15 @@ bool CCBReader::readCallbackKeyframesForSeq(CCBSequence* seq)
|
|||
|
||||
int callbackType = readInt(false);
|
||||
|
||||
Array* value = Array::create();
|
||||
value->addObject(String::create(callbackName));
|
||||
value->addObject(String::createWithFormat("%d", callbackType));
|
||||
ValueVector valueVector;
|
||||
valueVector.push_back(Value(callbackName));
|
||||
valueVector.push_back(Value(callbackType));
|
||||
|
||||
CCBKeyframe* keyframe = new CCBKeyframe();
|
||||
keyframe->autorelease();
|
||||
|
||||
keyframe->setTime(time);
|
||||
keyframe->setValue(value);
|
||||
keyframe->setValue(Value(valueVector));
|
||||
|
||||
if(_jsControlled) {
|
||||
std::stringstream callbackIdentifier;
|
||||
|
@ -882,16 +891,15 @@ bool CCBReader::readSoundKeyframesForSeq(CCBSequence* seq) {
|
|||
float pan = readFloat();
|
||||
float gain = readFloat();
|
||||
|
||||
Array* value = Array::create();
|
||||
|
||||
value->addObject(String::create(soundFile));
|
||||
value->addObject(String::createWithFormat("%f", pitch));
|
||||
value->addObject(String::createWithFormat("%f", pan));
|
||||
value->addObject(String::createWithFormat("%f", gain));
|
||||
ValueVector vec;
|
||||
vec.push_back(Value(soundFile));
|
||||
vec.push_back(Value(pitch));
|
||||
vec.push_back(Value(pan));
|
||||
vec.push_back(Value(gain));
|
||||
|
||||
CCBKeyframe* keyframe = new CCBKeyframe();
|
||||
keyframe->setTime(time);
|
||||
keyframe->setValue(value);
|
||||
keyframe->setValue(Value(vec));
|
||||
channel->getKeyframes().pushBack(keyframe);
|
||||
keyframe->release();
|
||||
}
|
||||
|
|
|
@ -6,154 +6,24 @@ namespace cocosbuilder {
|
|||
|
||||
// Implementation of Color3BWapper
|
||||
|
||||
Color3BWapper* Color3BWapper::create(const Color3B& color)
|
||||
{
|
||||
Color3BWapper *ret = new Color3BWapper();
|
||||
if (ret)
|
||||
{
|
||||
ret->color.r = color.r;
|
||||
ret->color.g = color.g;
|
||||
ret->color.b = color.b;
|
||||
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const Color3B& Color3BWapper::getColor() const
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
// Implementation of CCBValue
|
||||
|
||||
CCBValue* CCBValue::create(int nValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_value.intValue = nValue;
|
||||
ret->_type = Type::INT;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(float fValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_value.floatValue = fValue;
|
||||
ret->_type = Type::FLOAT;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(bool vValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_value.intValue = vValue ? 1 : 0;
|
||||
ret->_type = Type::BOOL;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(unsigned char byte)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_value.intValue = byte;
|
||||
ret->_type = Type::UNSIGNED_CHAR;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CCBValue* CCBValue::create(const char *pStringValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_strValue = pStringValue;
|
||||
ret->_type = Type::STRING;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
CCBValue* CCBValue::create(Array *pArrValue)
|
||||
{
|
||||
CCBValue *ret = new CCBValue();
|
||||
if (ret)
|
||||
{
|
||||
ret->_arrValue = pArrValue;
|
||||
ret->_type = Type::ARRAY;
|
||||
ret->autorelease();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int CCBValue::getIntValue()
|
||||
{
|
||||
CCASSERT(_type == Type::INT, "The type of CCBValue isn't integer.");
|
||||
|
||||
return _value.intValue;
|
||||
}
|
||||
|
||||
float CCBValue::getFloatValue()
|
||||
{
|
||||
CCASSERT(_type == Type::FLOAT, "The type of CCBValue isn't float.");
|
||||
|
||||
return _value.floatValue;
|
||||
}
|
||||
|
||||
bool CCBValue::getBoolValue()
|
||||
{
|
||||
CCASSERT(_type == Type::BOOL, "The type of CCBValue isn't boolean.");
|
||||
|
||||
return _value.intValue == 1 ? true : false;
|
||||
}
|
||||
|
||||
unsigned char CCBValue::getByteValue()
|
||||
{
|
||||
CCASSERT(_type == Type::UNSIGNED_CHAR, "The type of CCBValue isn't unsigned char.");
|
||||
|
||||
return (unsigned char)(_value.intValue);
|
||||
}
|
||||
|
||||
Array* CCBValue::getArrayValue()
|
||||
{
|
||||
CCASSERT(_type == Type::ARRAY, "The type of CCBValue isn't array.");
|
||||
|
||||
return _arrValue;
|
||||
}
|
||||
|
||||
|
||||
const char* CCBValue::getStringValue()
|
||||
{
|
||||
CCASSERT(_type == Type::STRING, "The type of CCBValue isn't string.");
|
||||
|
||||
return _strValue.c_str();
|
||||
}
|
||||
|
||||
CCBValue::Type CCBValue::getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
//Color3BWapper* Color3BWapper::create(const Color3B& color)
|
||||
//{
|
||||
// Color3BWapper *ret = new Color3BWapper();
|
||||
// if (ret)
|
||||
// {
|
||||
// ret->color.r = color.r;
|
||||
// ret->color.g = color.g;
|
||||
// ret->color.b = color.b;
|
||||
//
|
||||
// ret->autorelease();
|
||||
// }
|
||||
//
|
||||
// return ret;
|
||||
//}
|
||||
//
|
||||
//const Color3B& Color3BWapper::getColor() const
|
||||
//{
|
||||
// return color;
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,61 +9,16 @@
|
|||
|
||||
namespace cocosbuilder {
|
||||
|
||||
class Color3BWapper : public cocos2d::Object
|
||||
{
|
||||
public:
|
||||
static Color3BWapper* create(const cocos2d::Color3B& color);
|
||||
|
||||
const cocos2d::Color3B& getColor() const;
|
||||
|
||||
private:
|
||||
cocos2d::Color3B color;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CCBValue : public cocos2d::Object
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Type
|
||||
{
|
||||
INT,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
UNSIGNED_CHAR,
|
||||
STRING,
|
||||
ARRAY
|
||||
};
|
||||
|
||||
static CCBValue* create(int nValue);
|
||||
static CCBValue* create(bool bValue);
|
||||
static CCBValue* create(float fValue);
|
||||
static CCBValue* create(unsigned char byte);
|
||||
static CCBValue* create(const char* pStr);
|
||||
static CCBValue* create(cocos2d::Array* pArr);
|
||||
|
||||
|
||||
int getIntValue();
|
||||
float getFloatValue();
|
||||
bool getBoolValue();
|
||||
unsigned char getByteValue();
|
||||
const char* getStringValue();
|
||||
cocos2d::Array *getArrayValue();
|
||||
|
||||
Type getType();
|
||||
|
||||
private:
|
||||
union
|
||||
{
|
||||
int intValue;
|
||||
float floatValue;
|
||||
} _value;
|
||||
|
||||
std::string _strValue;
|
||||
cocos2d::Array* _arrValue;
|
||||
Type _type;
|
||||
};
|
||||
//class Color3BWapper : public cocos2d::Object
|
||||
//{
|
||||
//public:
|
||||
// static Color3BWapper* create(const cocos2d::Color3B& color);
|
||||
//
|
||||
// const cocos2d::Color3B& getColor() const;
|
||||
//
|
||||
//private:
|
||||
// cocos2d::Color3B color;
|
||||
//};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using namespace cocos2d;
|
|||
|
||||
namespace cocosbuilder {
|
||||
|
||||
Point getAbsolutePosition(const Point &pt, CCBReader::PositionType type, const Size &containerSize, const char *propName)
|
||||
Point getAbsolutePosition(const Point &pt, CCBReader::PositionType type, const Size &containerSize, const std::string& propName)
|
||||
{
|
||||
Point absPt = Point(0,0);
|
||||
if (type == CCBReader::PositionType::RELATIVE_BOTTOM_LEFT)
|
||||
|
@ -43,7 +43,7 @@ Point getAbsolutePosition(const Point &pt, CCBReader::PositionType type, const S
|
|||
return absPt;
|
||||
}
|
||||
|
||||
void setRelativeScale(Node *pNode, float scaleX, float scaleY, CCBReader::ScaleType type, const char* propName)
|
||||
void setRelativeScale(Node *pNode, float scaleX, float scaleY, CCBReader::ScaleType type, const std::string& propName)
|
||||
{
|
||||
CCASSERT(pNode, "pNode should not be null");
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
namespace cocosbuilder {
|
||||
|
||||
extern cocos2d::Point getAbsolutePosition(const cocos2d::Point &pt, CCBReader::PositionType type, const cocos2d::Size &containerSize, const char *propName);
|
||||
extern cocos2d::Point getAbsolutePosition(const cocos2d::Point &pt, CCBReader::PositionType type, const cocos2d::Size &containerSize, const std::string&propName);
|
||||
|
||||
extern void setRelativeScale(cocos2d::Node *node, float scaleX, float scaleY, CCBReader::ScaleType type, const char* propName);
|
||||
extern void setRelativeScale(cocos2d::Node *node, float scaleX, float scaleY, CCBReader::ScaleType type, const std::string& propName);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,33 +12,29 @@ namespace cocosbuilder {
|
|||
|
||||
NodeLoader::NodeLoader()
|
||||
{
|
||||
_customProperties = new Dictionary();
|
||||
_customProperties->init();
|
||||
}
|
||||
|
||||
NodeLoader::~NodeLoader()
|
||||
{
|
||||
CC_SAFE_RELEASE(_customProperties);
|
||||
}
|
||||
|
||||
Dictionary* NodeLoader::getCustomProperties()
|
||||
ValueMap& NodeLoader::getCustomProperties()
|
||||
{
|
||||
return _customProperties;
|
||||
}
|
||||
|
||||
Node * NodeLoader::loadNode(Node * pParent, CCBReader * ccbReader) {
|
||||
Node * NodeLoader::loadNode(Node * pParent, CCBReader * ccbReader)
|
||||
{
|
||||
Node * ccNode = this->createNode(pParent, ccbReader);
|
||||
|
||||
//clear _customProperties, ready for load next node.
|
||||
if (_customProperties != nullptr)
|
||||
{
|
||||
_customProperties->removeAllObjects();
|
||||
}
|
||||
_customProperties.clear();
|
||||
|
||||
return ccNode;
|
||||
}
|
||||
|
||||
void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbReader) {
|
||||
void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbReader)
|
||||
{
|
||||
int numRegularProps = ccbReader->readInt(false);
|
||||
int numExturaProps = ccbReader->readInt(false);
|
||||
int propertyCount = numRegularProps + numExturaProps;
|
||||
|
@ -382,11 +378,12 @@ Point NodeLoader::parsePropTypePosition(Node * pNode, Node * pParent, CCBReader
|
|||
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
Array *baseValue = Array::create(CCBValue::create(x),
|
||||
CCBValue::create(y),
|
||||
CCBValue::create((int)type),
|
||||
NULL);
|
||||
ccbReader->getAnimationManager()->setBaseValue(baseValue, pNode, pPropertyName);
|
||||
ValueVector vec;
|
||||
vec.push_back(Value(x));
|
||||
vec.push_back(Value(y));
|
||||
vec.push_back(Value((int)type));
|
||||
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(vec), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return pt;
|
||||
|
@ -485,11 +482,12 @@ float * NodeLoader::parsePropTypeScaleLock(Node * pNode, Node * pParent, CCBRead
|
|||
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
Array *baseValue = Array::create(CCBValue::create(x),
|
||||
CCBValue::create(y),
|
||||
CCBValue::create((int)type),
|
||||
NULL);
|
||||
ccbReader->getAnimationManager()->setBaseValue(baseValue, pNode, pPropertyName);
|
||||
ValueVector baseValue;
|
||||
baseValue.push_back(Value(x));
|
||||
baseValue.push_back(Value(y));
|
||||
baseValue.push_back(Value((int)type));
|
||||
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(baseValue), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
||||
|
@ -513,8 +511,7 @@ float NodeLoader::parsePropTypeDegrees(Node * pNode, Node * pParent, CCBReader *
|
|||
float ret = ccbReader->readFloat();
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCBValue *value = CCBValue::create(ret);
|
||||
ccbReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -562,8 +559,7 @@ bool NodeLoader::parsePropTypeCheck(Node * pNode, Node * pParent, CCBReader * cc
|
|||
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
CCBValue *value = CCBValue::create(ret);
|
||||
ccbReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -603,7 +599,7 @@ SpriteFrame * NodeLoader::parsePropTypeSpriteFrame(Node * pNode, Node * pParent,
|
|||
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
ccbReader->getAnimationManager()->setBaseValue(spriteFrame, pNode, pPropertyName);
|
||||
ccbReader->getAnimationManager()->setObject(spriteFrame, pNode, pPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -653,22 +649,27 @@ unsigned char NodeLoader::parsePropTypeByte(Node * pNode, Node * pParent, CCBRea
|
|||
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
ccbReader->getAnimationManager()->setBaseValue(CCBValue::create(ret), pNode, pPropertyName);
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Color3B NodeLoader::parsePropTypeColor3(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName) {
|
||||
unsigned char red = ccbReader->readByte();
|
||||
unsigned char green = ccbReader->readByte();
|
||||
unsigned char blue = ccbReader->readByte();
|
||||
unsigned char r = ccbReader->readByte();
|
||||
unsigned char g = ccbReader->readByte();
|
||||
unsigned char b = ccbReader->readByte();
|
||||
|
||||
Color3B color(r, g, b);
|
||||
|
||||
ValueMap colorMap;
|
||||
colorMap["r"] = r;
|
||||
colorMap["g"] = g;
|
||||
colorMap["b"] = b;
|
||||
|
||||
Color3B color(red, green, blue);
|
||||
if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
|
||||
{
|
||||
Color3BWapper *value = Color3BWapper::create(color);
|
||||
ccbReader->getAnimationManager()->setBaseValue(value, pNode, pPropertyName);
|
||||
ccbReader->getAnimationManager()->setBaseValue(Value(colorMap), pNode, pPropertyName);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
@ -1047,7 +1048,7 @@ void NodeLoader::onHandlePropTypeScaleLock(Node * pNode, Node * pParent, const c
|
|||
void NodeLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const char* pPropertyName, float pFloat, CCBReader * ccbReader) {
|
||||
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
||||
// It may be a custom property, add it to custom property dictionary.
|
||||
_customProperties->setObject(CCBValue::create(pFloat), pPropertyName);
|
||||
_customProperties[pPropertyName] = Value(pFloat);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1074,7 +1075,7 @@ void NodeLoader::onHandlePropTypeInteger(Node * pNode, Node * pParent, const cha
|
|||
} else {
|
||||
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
||||
// It may be a custom property, add it to custom property dictionary.
|
||||
_customProperties->setObject(CCBValue::create(pInteger), pPropertyName);
|
||||
_customProperties[pPropertyName] = Value(pInteger);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1094,7 +1095,7 @@ void NodeLoader::onHandlePropTypeCheck(Node * pNode, Node * pParent, const char*
|
|||
} else {
|
||||
//ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
||||
// It may be a custom property, add it to custom property dictionary.
|
||||
_customProperties->setObject(CCBValue::create(pCheck), pPropertyName);
|
||||
_customProperties[pPropertyName] = Value(pCheck);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1138,7 @@ void NodeLoader::onHandlePropTypeFntFile(Node * pNode, Node * pParent, const cha
|
|||
void NodeLoader::onHandlePropTypeString(Node * pNode, Node * pParent, const char* pPropertyName, const char * pString, CCBReader * ccbReader) {
|
||||
// ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
|
||||
// It may be a custom property, add it to custom property dictionary.
|
||||
_customProperties->setObject(CCBValue::create(pString), pPropertyName);
|
||||
_customProperties[pPropertyName] = Value(pString);
|
||||
}
|
||||
|
||||
void NodeLoader::onHandlePropTypeText(Node * pNode, Node * pParent, const char* pPropertyName, const char * pText, CCBReader * ccbReader) {
|
||||
|
|
|
@ -75,7 +75,7 @@ class NodeLoader : public cocos2d::Object {
|
|||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
virtual cocos2d::Dictionary* getCustomProperties();
|
||||
virtual cocos2d::ValueMap& getCustomProperties();
|
||||
|
||||
protected:
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(cocos2d::Node);
|
||||
|
@ -141,7 +141,7 @@ class NodeLoader : public cocos2d::Object {
|
|||
virtual void onHandlePropTypeCCBFile(cocos2d::Node * pNode, cocos2d::Node * pParent, const char* pPropertyName, cocos2d::Node * pCCBFileNode, CCBReader * ccbReader);
|
||||
|
||||
protected:
|
||||
cocos2d::Dictionary* _customProperties;
|
||||
cocos2d::ValueMap _customProperties;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -92,32 +92,32 @@ bool HelloCocosBuilderLayer::onAssignCCBMemberVariable(Object * pTarget, const c
|
|||
return false;
|
||||
}
|
||||
|
||||
bool HelloCocosBuilderLayer::onAssignCCBCustomProperty(Object* pTarget, const char* pMemberVariableName, cocosbuilder::CCBValue* pCCBValue)
|
||||
bool HelloCocosBuilderLayer::onAssignCCBCustomProperty(Object* pTarget, const char* pMemberVariableName, const Value& pCCBValue)
|
||||
{
|
||||
bool bRet = false;
|
||||
if (pTarget == this)
|
||||
{
|
||||
if (0 == strcmp(pMemberVariableName, "mCustomPropertyInt"))
|
||||
{
|
||||
this->mCustomPropertyInt = pCCBValue->getIntValue();
|
||||
this->mCustomPropertyInt = pCCBValue.asInt();
|
||||
log("mCustomPropertyInt = %d", mCustomPropertyInt);
|
||||
bRet = true;
|
||||
}
|
||||
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyFloat"))
|
||||
{
|
||||
this->mCustomPropertyFloat = pCCBValue->getFloatValue();
|
||||
this->mCustomPropertyFloat = pCCBValue.asFloat();
|
||||
log("mCustomPropertyFloat = %f", mCustomPropertyFloat);
|
||||
bRet = true;
|
||||
}
|
||||
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyBoolean"))
|
||||
{
|
||||
this->mCustomPropertyBoolean = pCCBValue->getBoolValue();
|
||||
this->mCustomPropertyBoolean = pCCBValue.asBool();
|
||||
log("mCustomPropertyBoolean = %d", mCustomPropertyBoolean);
|
||||
bRet = true;
|
||||
}
|
||||
else if ( 0 == strcmp(pMemberVariableName, "mCustomPropertyString"))
|
||||
{
|
||||
this->mCustomPropertyString = pCCBValue->getStringValue();
|
||||
this->mCustomPropertyString = pCCBValue.asString();
|
||||
log("mCustomPropertyString = %s", mCustomPropertyString.c_str());
|
||||
bRet = true;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class HelloCocosBuilderLayer
|
|||
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::Object * pTarget, const char * pSelectorName);
|
||||
virtual cocos2d::extension::Control::Handler onResolveCCBCCControlSelector(cocos2d::Object * pTarget, const char * pSelectorName);
|
||||
virtual bool onAssignCCBMemberVariable(cocos2d::Object * pTarget, const char * pMemberVariableName, cocos2d::Node * node);
|
||||
virtual bool onAssignCCBCustomProperty(Object* pTarget, const char* pMemberVariableName, cocosbuilder::CCBValue* pCCBValue);
|
||||
virtual bool onAssignCCBCustomProperty(Object* pTarget, const char* pMemberVariableName, const cocos2d::Value& pCCBValue);
|
||||
virtual void onNodeLoaded(cocos2d::Node * node, cocosbuilder::NodeLoader * nodeLoader);
|
||||
|
||||
void onMenuTestClicked(cocos2d::Object * sender, cocos2d::extension::Control::EventType pControlEvent);
|
||||
|
|
Loading…
Reference in New Issue