diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 4265033bb1..58d8f03a37 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -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) { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.h b/cocos/editor-support/cocostudio/CCSGUIReader.h index 737126f85b..17b8fa16af 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.h +++ b/cocos/editor-support/cocostudio/CCSGUIReader.h @@ -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); + + }; diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 9bec809d44..ae0b63de28 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -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)); + } + } } + + + diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index 681f02224a..9fff4d903b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -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); + }; }