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