mirror of https://github.com/axmolengine/axmol.git
add base property parser for WidgetReader
This commit is contained in:
parent
95f1bd7e72
commit
615995af54
|
@ -292,6 +292,106 @@ namespace cocostudio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WidgetReader::setPropsFromBinary(cocos2d::ui::Widget *widget, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
|
||||||
|
{
|
||||||
|
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
|
||||||
|
std::string key = stChildArray[i].GetName(pCocoLoader);
|
||||||
|
std::string value = stChildArray[i].GetValue();
|
||||||
|
|
||||||
|
if (key == "ignoreSize") {
|
||||||
|
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"){
|
||||||
|
widget->setSizePercent(Vec2(valueToFloat(value), widget->getSizePercent().y));
|
||||||
|
}else if(key == "sizePercentY"){
|
||||||
|
widget->setSizePercent(Vec2(widget->getSizePercent().x, valueToFloat(value)));
|
||||||
|
}else if(key == "positionPercentX"){
|
||||||
|
widget->setPositionPercent(Vec2(valueToFloat(value), widget->getPositionPercent().y));
|
||||||
|
}else if(key == "positionPercentY"){
|
||||||
|
widget->setPositionPercent(Vec2(widget->getPositionPercent().x, valueToFloat(value)));
|
||||||
|
}else if (key == "width"){
|
||||||
|
widget->setSize(Size(valueToFloat(value), widget->getSize().height));
|
||||||
|
}else if(key == "height"){
|
||||||
|
widget->setSize(Size(widget->getSize().width, 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"){
|
||||||
|
widget->setPosition(Vec2(valueToFloat(value), widget->getPosition().y));
|
||||||
|
}else if(key == "y"){
|
||||||
|
widget->setPosition(Vec2(widget->getPosition().x, 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();
|
||||||
|
|
||||||
|
ui::LinearLayoutParameter *linearParameter = ui::LinearLayoutParameter::create();
|
||||||
|
ui::RelativeLayoutParameter *relativeParameter = ui::RelativeLayoutParameter::create();
|
||||||
|
ui::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,7 @@ namespace cocostudio
|
||||||
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
|
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
|
||||||
const rapidjson::Value& options);
|
const rapidjson::Value& options);
|
||||||
|
|
||||||
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode)
|
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
protected:
|
protected:
|
||||||
std::string getResourcePath(const rapidjson::Value& dict,
|
std::string getResourcePath(const rapidjson::Value& dict,
|
||||||
const std::string& key,
|
const std::string& key,
|
||||||
|
|
Loading…
Reference in New Issue