mirror of https://github.com/axmolengine/axmol.git
closed #5118, refactor, improving variable name
This commit is contained in:
parent
ebffc66a83
commit
c2f7c10f1c
|
@ -218,6 +218,30 @@ Widget* GUIReader::widgetFromJsonFile(const char *fileName)
|
|||
}
|
||||
|
||||
|
||||
void WidgetPropertiesReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float anchorPointXInFile;
|
||||
if (isAnchorPointXExists) {
|
||||
anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX");
|
||||
}else{
|
||||
anchorPointXInFile = widget->getAnchorPoint().x;
|
||||
}
|
||||
|
||||
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
float anchorPointYInFile;
|
||||
if (isAnchorPointYExists) {
|
||||
anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY");
|
||||
}
|
||||
else{
|
||||
anchorPointYInFile = widget->getAnchorPoint().y;
|
||||
}
|
||||
|
||||
if (isAnchorPointXExists || isAnchorPointYExists) {
|
||||
widget->setAnchorPoint(Vector2(anchorPointXInFile, anchorPointYInFile));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName)
|
||||
{
|
||||
|
@ -411,26 +435,9 @@ void WidgetPropertiesReader0250::setColorPropsForWidgetFromJsonDictionary(Widget
|
|||
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
||||
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
||||
widget->setColor(Color3B(colorR, colorG, colorB));
|
||||
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float apxf;
|
||||
float apyf;
|
||||
if (apx) {
|
||||
apxf = DICTOOL->getFloatValue_json(options, "anchorPointX");
|
||||
}
|
||||
else{
|
||||
apxf = widget->getAnchorPoint().x;
|
||||
}
|
||||
|
||||
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
if (apy) {
|
||||
apyf = DICTOOL->getFloatValue_json(options, "anchorPointY");
|
||||
}else{
|
||||
apyf = widget->getAnchorPoint().y;
|
||||
}
|
||||
this->setAnchorPointForWidget(widget, options);
|
||||
|
||||
if (apx || apy) {
|
||||
widget->setAnchorPoint(Vector2(apxf, apyf));
|
||||
}
|
||||
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
||||
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
||||
widget->setFlippedX(flipX);
|
||||
|
@ -1248,32 +1255,16 @@ void WidgetPropertiesReader0300::setColorPropsForWidgetFromJsonDictionary(Widget
|
|||
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
||||
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
||||
widget->setColor(Color3B(colorR, colorG, colorB));
|
||||
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float apxf;
|
||||
float apyf;
|
||||
if (apx) {
|
||||
apxf = DICTOOL->getFloatValue_json(options, "anchorPointX");
|
||||
}else{
|
||||
apxf = widget->getAnchorPoint().x;
|
||||
}
|
||||
|
||||
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
if (apy) {
|
||||
apyf = DICTOOL->getFloatValue_json(options, "anchorPointY");
|
||||
}
|
||||
else{
|
||||
apyf = widget->getAnchorPoint().y;
|
||||
}
|
||||
|
||||
if (apx || apy) {
|
||||
widget->setAnchorPoint(Vector2(apxf, apyf));
|
||||
}
|
||||
|
||||
this->setAnchorPointForWidget(widget, options);
|
||||
|
||||
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
||||
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
||||
widget->setFlippedX(flipX);
|
||||
widget->setFlippedY(flipY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WidgetPropertiesReader0300::setPropsForButtonFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
||||
{
|
||||
|
|
|
@ -91,6 +91,9 @@ public:
|
|||
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
||||
cocos2d::ui::Widget* widget,
|
||||
const rapidjson::Value& customOptions) = 0;
|
||||
protected:
|
||||
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
|
||||
|
||||
protected:
|
||||
std::string m_strFilePath;
|
||||
};
|
||||
|
@ -160,6 +163,8 @@ public:
|
|||
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
||||
cocos2d::ui::Widget* widget,
|
||||
const rapidjson::Value& customOptions);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -162,29 +162,8 @@ namespace cocostudio
|
|||
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
||||
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
||||
widget->setColor(Color3B(colorR, colorG, colorB));
|
||||
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
|
||||
float apxf;
|
||||
float apyf;
|
||||
if (apx) {
|
||||
apxf = DICTOOL->getFloatValue_json(options, "anchorPointX");
|
||||
}
|
||||
else{
|
||||
apxf = widget->getAnchorPoint().x;
|
||||
}
|
||||
|
||||
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
|
||||
if (apy) {
|
||||
apyf = DICTOOL->getFloatValue_json(options, "anchorPointY");
|
||||
}
|
||||
else{
|
||||
apyf = widget->getAnchorPoint().y;
|
||||
}
|
||||
|
||||
if (apx || apy) {
|
||||
widget->setAnchorPoint(Vector2(apxf, apyf));
|
||||
}
|
||||
this->setAnchorPointForWidget(widget, options);
|
||||
|
||||
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
||||
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
||||
|
@ -213,4 +192,31 @@ namespace cocostudio
|
|||
}
|
||||
return imageFileName_tp;
|
||||
}
|
||||
|
||||
void WidgetReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
|
||||
{
|
||||
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
||||
float anchorPointXInFile;
|
||||
if (isAnchorPointXExists) {
|
||||
anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX");
|
||||
}else{
|
||||
anchorPointXInFile = widget->getAnchorPoint().x;
|
||||
}
|
||||
|
||||
bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
||||
float anchorPointYInFile;
|
||||
if (isAnchorPointYExists) {
|
||||
anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY");
|
||||
}
|
||||
else{
|
||||
anchorPointYInFile = widget->getAnchorPoint().y;
|
||||
}
|
||||
|
||||
if (isAnchorPointXExists || isAnchorPointYExists) {
|
||||
widget->setAnchorPoint(Vector2(anchorPointXInFile, anchorPointYInFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ namespace cocostudio
|
|||
std::string getResourcePath(const rapidjson::Value& dict,
|
||||
const std::string& key,
|
||||
cocos2d::ui::Widget::TextureResType texType);
|
||||
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue