refactor Loader

This commit is contained in:
andyque 2014-06-18 14:44:00 +08:00
parent 615995af54
commit 63475a6f81
13 changed files with 203 additions and 339 deletions

View File

@ -62,21 +62,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -87,9 +87,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -148,28 +148,23 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "scale9Enable") { else if (key == "scale9Enable") {
button->setScale9Enabled(valueToBool(value)); button->setScale9Enabled(valueToBool(value));
} }

View File

@ -42,7 +42,7 @@ namespace cocostudio
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader); std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue(); std::string value = stChildArray[i].GetValue();
CCLOG("key = %s, index : %d", key.c_str(), i); // CCLOG("key = %s, index : %d", key.c_str(), i);
if (key == "ignoreSize") { if (key == "ignoreSize") {
widget->ignoreContentAdaptWithSize(valueToBool(value)); widget->ignoreContentAdaptWithSize(valueToBool(value));
}else if(key == "sizeType"){ }else if(key == "sizeType"){
@ -50,21 +50,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -75,9 +75,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -136,25 +136,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "backGroundBoxData"){ else if (key == "backGroundBoxData"){

View File

@ -45,7 +45,7 @@ namespace cocostudio
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader); std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue(); std::string value = stChildArray[i].GetValue();
CCLOG("ImageView: key = %s, value = %d", key.c_str(), i); // CCLOG("ImageView: key = %s, value = %d", key.c_str(), i);
if (key == "ignoreSize") { if (key == "ignoreSize") {
widget->ignoreContentAdaptWithSize(valueToBool(value)); widget->ignoreContentAdaptWithSize(valueToBool(value));
@ -54,21 +54,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -79,9 +79,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -140,25 +140,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "scale9Enable") { else if (key == "scale9Enable") {
imageView->setScale9Enabled(valueToBool(value)); imageView->setScale9Enabled(valueToBool(value));

View File

@ -48,8 +48,8 @@ namespace cocostudio
int ecr=0, ecg=0, ecb= 0; int ecr=0, ecg=0, ecb= 0;
float bgcv1 = 0.0f, bgcv2= 0.0f; float bgcv1 = 0.0f, bgcv2= 0.0f;
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
bool isAdaptScreen = false;
Layout::Type layoutType; Layout::Type layoutType;
int bgColorOpacity = panel->getBackGroundColorOpacity();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader); std::string key = stChildArray[i].GetName(pCocoLoader);
@ -62,21 +62,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -87,9 +87,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -148,28 +148,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
}
else if (key == "adaptScreen") {
isAdaptScreen = valueToBool(value);
} }
else if(key == "width"){ else if(key == "width"){
w = valueToFloat(value); w = valueToFloat(value);
@ -208,7 +202,7 @@ namespace cocostudio
}else if(key == "vectorY"){ }else if(key == "vectorY"){
bgcv2 = valueToFloat(value); bgcv2 = valueToFloat(value);
}else if(key == "bgColorOpacity"){ }else if(key == "bgColorOpacity"){
panel->setBackGroundColorOpacity(valueToInt(value)); bgColorOpacity = valueToInt(value);
}else if( key == "colorType"){ }else if( key == "colorType"){
panel->setBackGroundColorType(Layout::BackGroundColorType(valueToInt(value))); panel->setBackGroundColorType(Layout::BackGroundColorType(valueToInt(value)));
}else if (key == "backGroundImageData"){ }else if (key == "backGroundImageData"){
@ -239,17 +233,19 @@ namespace cocostudio
} }
Size screenSize = Director::getInstance()->getWinSize();
if (isAdaptScreen) {
w = screenSize.width;
h = screenSize.height;
}
panel->setSize(Size(w,h));
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
panel->setBackGroundColor(Color3B(cr, cg, cb)); panel->setBackGroundColor(Color3B(cr, cg, cb));
panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2)); panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2));
panel->setBackGroundColorOpacity(bgColorOpacity);
panel->setBackGroundImageColor(Color3B(_color.r, _color.g, _color.b));
panel->setBackGroundImageOpacity(_opacity);
if (panel->isBackGroundImageScale9Enabled()) { if (panel->isBackGroundImageScale9Enabled()) {
panel->setBackGroundImageCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); panel->setBackGroundImageCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
} }

View File

@ -40,6 +40,7 @@ namespace cocostudio
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget); LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
this->beginSetBasicProperties(widget); this->beginSetBasicProperties(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
int percent = loadingBar->getPercent();
stExpCocoNode *stChildArray = pCocoNode->GetChildArray(); stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
@ -54,21 +55,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -79,9 +80,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -140,25 +141,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "scale9Enable") { else if (key == "scale9Enable") {
loadingBar->setScale9Enabled(valueToBool(value)); loadingBar->setScale9Enabled(valueToBool(value));
@ -186,7 +184,7 @@ namespace cocostudio
}else if(key == "direction"){ }else if(key == "direction"){
loadingBar->setDirection((LoadingBar::Direction)valueToInt(value)); loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
}else if(key == "percent"){ }else if(key == "percent"){
loadingBar->setPercent(valueToInt(value)); percent = valueToInt(value);
} }
} //end of for loop } //end of for loop
@ -194,7 +192,7 @@ namespace cocostudio
if (loadingBar->isScale9Enabled()) { if (loadingBar->isScale9Enabled()) {
loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
} }
loadingBar->setPercent(percent);
this->endSetBasicProperties(widget); this->endSetBasicProperties(widget);
} }

View File

@ -45,120 +45,7 @@ namespace cocostudio
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader); std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue(); std::string value = stChildArray[i].GetValue();
if (key == "ignoreSize") { if (key == "innerWidth") {
widget->ignoreContentAdaptWithSize(valueToBool(value));
}else if(key == "sizeType"){
widget->setSizeType((Widget::SizeType)valueToInt(value));
}else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value);
}
else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value);
}
else if (key == "width"){
width = valueToFloat(value);
}else if(key == "height"){
height = valueToFloat(value);
}else if(key == "tag"){
widget->setTag(valueToInt(value));
}else if(key == "actiontag"){
widget->setActionTag(valueToInt(value));
}else if(key == "touchAble"){
widget->setTouchEnabled(valueToBool(value));
}else if(key == "name"){
std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName);
}else if(key == "x"){
position.x = valueToFloat(value);
}else if(key == "y"){
position.y = valueToFloat(value);
}else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){
widget->setScaleY(valueToFloat(value));
}else if(key == "rotation"){
widget->setRotation(valueToFloat(value));
}else if(key == "visible"){
widget->setVisible(valueToBool(value));
}else if(key == "ZOrder"){
widget->setZOrder(valueToInt(value));
}else if(key == "layoutParameter"){
stExpCocoNode *layoutCocosNode = stChildArray[i].GetChildArray();
LinearLayoutParameter *linearParameter = LinearLayoutParameter::create();
RelativeLayoutParameter *relativeParameter = RelativeLayoutParameter::create();
Margin mg;
int paramType = -1;
for (int j = 0; j < stChildArray[i].GetChildNum(); ++j) {
std::string innerKey = layoutCocosNode[j].GetName(pCocoLoader);
std::string innerValue = layoutCocosNode[j].GetValue();
if (innerKey == "type") {
paramType = valueToInt(innerValue);
}else if(innerKey == "gravity"){
linearParameter->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)valueToInt(innerValue));
}else if(innerKey == "relativeName"){
relativeParameter->setRelativeName(innerValue);
}else if(innerKey == "relativeToName"){
relativeParameter->setRelativeToWidgetName(innerValue);
}else if(innerKey == "align"){
relativeParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)valueToInt(innerValue));
}else if(innerKey == "marginLeft"){
mg.left = valueToFloat(innerValue);
}else if(innerKey == "marginTop"){
mg.top = valueToFloat(innerValue);
}else if(innerKey == "marginRight"){
mg.right = valueToFloat(innerValue);
}else if(innerKey == "marginDown"){
mg.bottom = valueToFloat(innerValue);
}
}
linearParameter->setMargin(mg);
relativeParameter->setMargin(mg);
switch (paramType) {
case 1:
widget->setLayoutParameter(linearParameter);
break;
case 2:
widget->setLayoutParameter(relativeParameter);
default:
break;
}
}
else if (key == "opacity") {
widget->setOpacity(valueToInt(value));
}else if(key == "colorR"){
Color3B color = widget->getColor();
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){
Color3B color = widget->getColor();
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB")
{
Color3B color = widget->getColor();
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){
widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){
widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value);
}
else if (key == "innerWidth") {
innerWidth = valueToFloat(value); innerWidth = valueToFloat(value);
} }
else if(key == "innerHeight"){ else if(key == "innerHeight"){

View File

@ -39,6 +39,7 @@ namespace cocostudio
Slider* slider = static_cast<Slider*>(widget); Slider* slider = static_cast<Slider*>(widget);
float barLength = 0.0f; float barLength = 0.0f;
int percent = slider->getPercent();
stExpCocoNode *stChildArray = pCocoNode->GetChildArray(); stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
@ -52,21 +53,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -77,9 +78,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -138,32 +139,29 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
//control custom properties //control custom properties
else if (key == "scale9Enable") { else if (key == "scale9Enable") {
slider->setScale9Enabled(valueToBool(value)); slider->setScale9Enabled(valueToBool(value));
} }
else if(key == "percent"){ else if(key == "percent"){
slider->setPercent(valueToInt(value)); percent = valueToInt(value);
}else if(key == "barFileNameData"){ }else if(key == "barFileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();; std::string resType = backGroundChildren[2].GetValue();;
@ -223,6 +221,7 @@ namespace cocostudio
if (slider->isScale9Enabled()) { if (slider->isScale9Enabled()) {
slider->setSize(Size(barLength, slider->getContentSize().height)); slider->setSize(Size(barLength, slider->getContentSize().height));
} }
slider->setPercent(percent);
this->endSetBasicProperties(widget); this->endSetBasicProperties(widget);
} }

View File

@ -58,21 +58,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -83,9 +83,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -144,25 +144,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "stringValue") { else if (key == "stringValue") {
stringValue = value; stringValue = value;

View File

@ -52,21 +52,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -77,9 +77,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -138,25 +138,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if(key == "fileNameData"){ else if(key == "fileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();

View File

@ -51,21 +51,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -76,9 +76,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -137,25 +137,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if(key == "placeHolder"){ else if(key == "placeHolder"){
textField->setPlaceHolder(value); textField->setPlaceHolder(value);

View File

@ -53,21 +53,21 @@ namespace cocostudio
}else if(key == "positionType"){ }else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value)); widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){ }else if(key == "sizePercentX"){
sizePercentX = valueToFloat(value); _sizePercentX = valueToFloat(value);
}else if(key == "sizePercentY"){ }else if(key == "sizePercentY"){
sizePercentY = valueToFloat(value); _sizePercentY = valueToFloat(value);
}else if(key == "positionPercentX"){ }else if(key == "positionPercentX"){
positionPercentX = valueToFloat(value); _positionPercentX = valueToFloat(value);
}else if(key == "positionPercentY"){ }else if(key == "positionPercentY"){
positionPercentY = valueToFloat(value); _positionPercentY = valueToFloat(value);
} }
else if(key == "adaptScreen"){ else if(key == "adaptScreen"){
isAdaptScreen = valueToBool(value); _isAdaptScreen = valueToBool(value);
} }
else if (key == "width"){ else if (key == "width"){
width = valueToFloat(value); _width = valueToFloat(value);
}else if(key == "height"){ }else if(key == "height"){
height = valueToFloat(value); _height = valueToFloat(value);
}else if(key == "tag"){ }else if(key == "tag"){
widget->setTag(valueToInt(value)); widget->setTag(valueToInt(value));
}else if(key == "actiontag"){ }else if(key == "actiontag"){
@ -78,9 +78,9 @@ namespace cocostudio
std::string widgetName = value.empty() ? "default" : value; std::string widgetName = value.empty() ? "default" : value;
widget->setName(widgetName); widget->setName(widgetName);
}else if(key == "x"){ }else if(key == "x"){
position.x = valueToFloat(value); _position.x = valueToFloat(value);
}else if(key == "y"){ }else if(key == "y"){
position.y = valueToFloat(value); _position.y = valueToFloat(value);
}else if(key == "scaleX"){ }else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value)); widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){ }else if(key == "scaleY"){
@ -139,25 +139,22 @@ namespace cocostudio
} }
else if (key == "opacity") { else if (key == "opacity") {
widget->setOpacity(valueToInt(value)); _opacity = valueToInt(value);
}else if(key == "colorR"){ }else if(key == "colorR"){
Color3B color = widget->getColor(); _color.r = valueToInt(value);
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){ }else if(key == "colorG"){
Color3B color = widget->getColor(); _color.g = valueToInt(value);
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB") }else if(key == "colorB")
{ {
Color3B color = widget->getColor(); _color.b = valueToInt(value);
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){ }else if(key == "flipX"){
widget->setFlippedX(valueToBool(value)); widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){ }else if(key == "flipY"){
widget->setFlippedY(valueToBool(value)); widget->setFlippedY(valueToBool(value));
}else if(key == "anchorPointX"){ }else if(key == "anchorPointX"){
originalAnchorPoint.x = valueToFloat(value); _originalAnchorPoint.x = valueToFloat(value);
}else if(key == "anchorPointY"){ }else if(key == "anchorPointY"){
originalAnchorPoint.y = valueToFloat(value); _originalAnchorPoint.y = valueToFloat(value);
} }
else if (key == "touchScaleEnable") { else if (key == "touchScaleEnable") {
label->setTouchScaleChangeEnabled(valueToBool(value)); label->setTouchScaleChangeEnabled(valueToBool(value));

View File

@ -14,13 +14,14 @@ namespace cocostudio
IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader) IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader)
WidgetReader::WidgetReader() WidgetReader::WidgetReader()
:sizePercentX(0.0f), :_sizePercentX(0.0f),
sizePercentY(0.0f), _sizePercentY(0.0f),
isAdaptScreen(false), _isAdaptScreen(false),
width(0.0f), _width(0.0f),
height(0.0f), _height(0.0f),
positionPercentX(0.0f), _positionPercentX(0.0f),
positionPercentY(0.0f) _positionPercentY(0.0f),
_opacity(255)
{ {
valueToInt = [=](std::string str) -> int{ valueToInt = [=](std::string str) -> int{
return atoi(str.c_str()); return atoi(str.c_str());
@ -198,25 +199,29 @@ namespace cocostudio
void WidgetReader::beginSetBasicProperties(cocos2d::ui::Widget *widget) void WidgetReader::beginSetBasicProperties(cocos2d::ui::Widget *widget)
{ {
position = widget->getPosition(); _position = widget->getPosition();
//set default color //set default color
widget->setColor(Color3B(255,255,255)); _color = Color3B(255,255,255);
originalAnchorPoint = widget->getAnchorPoint(); widget->setColor(_color);
_opacity = widget->getOpacity();
_originalAnchorPoint = widget->getAnchorPoint();
} }
void WidgetReader::endSetBasicProperties(Widget *widget) void WidgetReader::endSetBasicProperties(Widget *widget)
{ {
Size screenSize = Director::getInstance()->getWinSize(); Size screenSize = Director::getInstance()->getWinSize();
widget->setPositionPercent(Vec2(positionPercentX, positionPercentY)); widget->setPositionPercent(Vec2(_positionPercentX, _positionPercentY));
widget->setSizePercent(Vec2(sizePercentX, sizePercentY)); widget->setSizePercent(Vec2(_sizePercentX, _sizePercentY));
if (isAdaptScreen) { if (_isAdaptScreen) {
width = screenSize.width; _width = screenSize.width;
height = screenSize.height; _height = screenSize.height;
} }
widget->setSize(Size(width, height)); widget->setColor(_color);
widget->setPosition(position); widget->setOpacity(_opacity);
widget->setAnchorPoint(originalAnchorPoint); widget->setSize(Size(_width, _height));
widget->setPosition(_position);
widget->setAnchorPoint(_originalAnchorPoint);
} }
std::string WidgetReader::getResourcePath(const rapidjson::Value &dict, std::string WidgetReader::getResourcePath(const rapidjson::Value &dict,

View File

@ -74,15 +74,17 @@ namespace cocostudio
std::function<bool(std::string)> valueToBool; std::function<bool(std::string)> valueToBool;
std::function<float(std::string)> valueToFloat; std::function<float(std::string)> valueToFloat;
float sizePercentX; float _sizePercentX;
float sizePercentY; float _sizePercentY;
float positionPercentX; float _positionPercentX;
float positionPercentY; float _positionPercentY;
float width ; float _width ;
float height; float _height;
cocos2d::Vec2 position; cocos2d::Color3B _color;
bool isAdaptScreen; int _opacity;
cocos2d::Vec2 originalAnchorPoint; cocos2d::Vec2 _position;
bool _isAdaptScreen;
cocos2d::Vec2 _originalAnchorPoint;
}; };
} }