From fefdc70af9e9ee86d908c684b7ba7c7239337d7a Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 1 Jul 2014 14:01:27 +0800 Subject: [PATCH] add default value to widget reader --- .../LoadingBarReader/LoadingBarReader.cpp | 24 +++++---- .../SliderReader/SliderReader.cpp | 23 ++++----- .../TextAtlasReader/TextAtlasReader.cpp | 51 +++++++++---------- .../cocostudio/WidgetReader/WidgetReader.cpp | 32 +++++------- 4 files changed, 61 insertions(+), 69 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 28c0828937..1c469aa32a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -117,19 +117,21 @@ namespace cocostudio bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); loadingBar->setScale9Enabled(scale9Enable); - if (scale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); - float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); - float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1); - float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1); - + + float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); + float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); + float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1); + float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1); + + if (scale9Enable) { loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); - - float width = DICTOOL->getFloatValue_json(options, P_Width); - float height = DICTOOL->getFloatValue_json(options, P_Height); - loadingBar->setSize(Size(width, height)); + } + + float width = DICTOOL->getFloatValue_json(options, P_Width); + float height = DICTOOL->getFloatValue_json(options, P_Height); + loadingBar->setSize(Size(width, height)); + /**/ loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction))); diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index 184411f2ce..0426a72dff 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -145,25 +145,24 @@ namespace cocostudio slider->setPercent(DICTOOL->getIntValue_json(options, P_Percent)); - bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName); +// bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName); float barLength = DICTOOL->getFloatValue_json(options, P_Length,290); - if (bt) - { - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BarFileNameData); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); - std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); - slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BarFileNameData); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); + std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); + slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType); - if (barTextureScale9Enable) - { - slider->setContentSize(Size(barLength, slider->getContentSize().height)); - } + + + if (barTextureScale9Enable) + { + slider->setContentSize(Size(barLength, slider->getContentSize().height)); } //loading normal slider ball texture const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_BallNormalData); int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType); - std::string imageFileName = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType); + imageFileName = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType); slider->loadSlidBallTextureNormal(imageFileName, (Widget::TextureResType)normalType); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index 730dfb2716..823ff304e0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -101,38 +101,37 @@ namespace cocostudio std::string jsonPath = GUIReader::getInstance()->getFilePath(); TextAtlas* labelAtlas = static_cast(widget); - bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue); - bool cmf = DICTOOL->checkObjectExist_json(options, P_CharMapFile); - bool iw = DICTOOL->checkObjectExist_json(options, P_ItemWidth); - bool ih = DICTOOL->checkObjectExist_json(options, P_ItemHeight); - bool scm = DICTOOL->checkObjectExist_json(options, P_StartCharMap); - if (sv && cmf && iw && ih && scm) +// bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue); +// bool cmf = DICTOOL->checkObjectExist_json(options, P_CharMapFile); +// bool iw = DICTOOL->checkObjectExist_json(options, P_ItemWidth); +// bool ih = DICTOOL->checkObjectExist_json(options, P_ItemHeight); +// bool scm = DICTOOL->checkObjectExist_json(options, P_StartCharMap); + + const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData); + int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType); + switch (cmfType) { - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData); - int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType); - switch (cmfType) + case 0: { - case 0: - { - std::string tp_c = jsonPath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); - const char* cmf_tp = tp_c.append(cmfPath).c_str(); - labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue,"12345678"), - cmf_tp, - DICTOOL->getIntValue_json(options, P_ItemWidth,24), - DICTOOL->getIntValue_json(options,P_ItemHeight,32), - DICTOOL->getStringValue_json(options, P_StartCharMap)); - break; - } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: - break; + std::string tp_c = jsonPath; + const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); + const char* cmf_tp = tp_c.append(cmfPath).c_str(); + labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue,"12345678"), + cmf_tp, + DICTOOL->getIntValue_json(options, P_ItemWidth,24), + DICTOOL->getIntValue_json(options,P_ItemHeight,32), + DICTOOL->getStringValue_json(options, P_StartCharMap)); + break; } + case 1: + CCLOG("Wrong res type of LabelAtlas!"); + break; + default: + break; } + WidgetReader::setColorPropsFromJsonDictionary(widget, options); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 1864f208e8..3c01ddc54f 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -113,11 +113,9 @@ namespace cocostudio void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { - bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); - if (ignoreSizeExsit) - { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); - } + + widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize,false)); + widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType)); @@ -151,21 +149,15 @@ namespace cocostudio float x = DICTOOL->getFloatValue_json(options, P_X); float y = DICTOOL->getFloatValue_json(options, P_Y); widget->setPosition(Vec2(x,y)); - bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX); - if (sx) - { - widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX)); - } - bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY); - if (sy) - { - widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY)); - } - bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation); - if (rt) - { - widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation)); - } + + widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX,1.0)); + + + widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY,1.0)); + + + widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation,0)); + bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile); if (vb) {