From 2f6f1b715115a4eb54387008fd7d599fb9f6ff7d Mon Sep 17 00:00:00 2001 From: andyque Date: Wed, 11 Jun 2014 14:45:35 +0800 Subject: [PATCH] improve binary format --- .../cocostudio/CCSGUIReader.cpp | 151 +++++++++--------- .../editor-support/cocostudio/CCSGUIReader.h | 2 +- .../UIButtonTest/UIButtonTest_Editor.cpp | 28 ++-- 3 files changed, 91 insertions(+), 90 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index a9ea05e010..46dc01ca1b 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -218,6 +218,70 @@ Widget* GUIReader::widgetFromJsonFile(const char *fileName) return widget; } +std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget) +{ + std::string readerName; + + // 1st., custom widget parse properties of parent widget with parent widget reader + if (dynamic_cast(widget)) + { + readerName = "ButtonReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "CheckBoxReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "ImageViewReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "TextAtlasReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "TextBMFontReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "TextReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "LoadingBarReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "SliderReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "TextFieldReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "LayoutReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "ScrollViewReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "ListViewReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "PageViewReader"; + } + else if (dynamic_cast(widget)) + { + readerName = "WidgetReader"; + } + + return readerName; +} std::string WidgetPropertiesReader::getGUIClassName(const std::string &name) @@ -297,12 +361,14 @@ Widget* GUIReader::widgetFromBinaryFile(const char *fileName) { stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(); - //rapidjson::Type tType = tpChildArray[i].GetType(pCocoLoader); - - std::string strValue = tpChildArray[7].GetValue(); - - fileVersion = strValue.c_str(); + for (int i = 0; i < tpRootCocoNode->GetChildNum(); ++i) { + std::string key = tpChildArray[i].GetName(&tCocoLoader); + if (key == "version") { + fileVersion = tpChildArray[i].GetValue(); + break; + } + } WidgetPropertiesReader * pReader = nullptr; if (fileVersion) @@ -310,6 +376,7 @@ Widget* GUIReader::widgetFromBinaryFile(const char *fileName) int versionInteger = getVersionInteger(fileVersion); if (versionInteger < 250) { + CCASSERT(0, "You current studio doesn't support binary format, please upgrade to the latest version!"); pReader = new WidgetPropertiesReader0250(); widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName); } @@ -439,11 +506,6 @@ Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, c ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget); return widget; } - -cocos2d::ui::Widget* WidgetPropertiesReader0250::createWidgetFromBinary(CocoLoader* pCocoLoader,stExpCocoNode* pCocoNode, const char* fileName) -{ - return nullptr; -} Widget* WidgetPropertiesReader0250::widgetFromJsonDictionary(const rapidjson::Value&data) @@ -1159,7 +1221,10 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c { stExpCocoNode *tpChildArray = pCocoNode->GetChildArray(); - + for (int i = 0; i < pCocoNode->GetChildNum(); ++i) { + const char* value = tpChildArray[i].GetName(pCocoLoader); + CCLOG("%s", value); + } int texturesCount = tpChildArray[6].GetChildNum(); for (int i=0; isetPropsFromBinary(widget, pCocoLoader, pCocoNode); } -std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget) -{ - std::string readerName; - - // 1st., custom widget parse properties of parent widget with parent widget reader - if (dynamic_cast(widget)) - { - readerName = "ButtonReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "CheckBoxReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "ImageViewReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "TextAtlasReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "TextBMFontReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "TextReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "LoadingBarReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "SliderReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "TextFieldReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "LayoutReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "ScrollViewReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "ListViewReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "PageViewReader"; - } - else if (dynamic_cast(widget)) - { - readerName = "WidgetReader"; - } - - return readerName; -} Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data) { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.h b/cocos/editor-support/cocostudio/CCSGUIReader.h index 967593cd7c..ae14590fcc 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.h +++ b/cocos/editor-support/cocostudio/CCSGUIReader.h @@ -143,7 +143,7 @@ public: //added for binary parsing virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode, - const char* fileName)override; + const char* fileName)override{return nullptr;} virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode){return nullptr;} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp index dfa7066e6a..6cc6e7316f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp @@ -20,23 +20,23 @@ bool UIButtonTest_Editor::init() { if (UIScene_Editor::init()) { - auto _layout2 = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); +// auto _layout2 = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/uibutton_editor_2(1).json")); -// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.csb")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/uibutton_editor_2(1).json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.csb")); - Vector firstLayouts = _layout2->getAllLayouts(_layout2); - Vector secondLayouts = _layout->getAllLayouts(_layout); - - - CCASSERT(firstLayouts.size() == secondLayouts.size(), "can't compare"); - - for (int i=0 ; i < firstLayouts.size(); ++i) { - Layout *l1 = firstLayouts.at(i); - Layout *l2 = secondLayouts.at(i); - l1->compareLayout(l2); - } +// Vector firstLayouts = _layout2->getAllLayouts(_layout2); +// Vector secondLayouts = _layout->getAllLayouts(_layout); +// +// +// CCASSERT(firstLayouts.size() == secondLayouts.size(), "can't compare"); +// +// for (int i=0 ; i < firstLayouts.size(); ++i) { +// Layout *l1 = firstLayouts.at(i); +// Layout *l2 = secondLayouts.at(i); +// l1->compareLayout(l2); +// }