diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 6e14825c2980..b217e523e15d 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -999,6 +999,10 @@ 29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */; }; 29CB8F4E1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; }; 29CB8F4F1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; }; + 29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; }; + 29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; }; + 29E99D201957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; }; + 29E99D211957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; }; 2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; }; 2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; }; 2AC795DD1862870F005EC8E1 /* EventData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D71862867D005EC8E1 /* EventData.cpp */; }; @@ -2309,6 +2313,8 @@ 299754F3193EC95400A54AC3 /* ObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectFactory.h; path = ../base/ObjectFactory.h; sourceTree = ""; }; 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutManager.cpp; sourceTree = ""; }; 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutManager.h; sourceTree = ""; }; + 29E99D1C1957BA7000046604 /* CocoLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoLoader.cpp; sourceTree = ""; }; + 29E99D1D1957BA7000046604 /* CocoLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoLoader.h; sourceTree = ""; }; 2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = ""; }; 2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = ""; }; 2AC795D51862867D005EC8E1 /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = ""; }; @@ -3641,6 +3647,8 @@ 1A8C5946180E930E00EF57C3 /* cocostudio */ = { isa = PBXGroup; children = ( + 29E99D1C1957BA7000046604 /* CocoLoader.cpp */, + 29E99D1D1957BA7000046604 /* CocoLoader.h */, 0634A4C4194B19E400E608AF /* ActionTimeline */, 50FCEB6818C72017004AD434 /* WidgetReader */, 06CAAAC1186AD63B0012A414 /* TriggerObj.h */, @@ -5162,6 +5170,7 @@ 1AD71E0D180E26E600808F54 /* CocosBuilder.h in Headers */, 1AD71E97180E26E600808F54 /* Animation.h in Headers */, 1AD71E9B180E26E600808F54 /* AnimationState.h in Headers */, + 29E99D201957BA7000046604 /* CocoLoader.h in Headers */, 1A01C69218F57BE800EFE3A6 /* CCDouble.h in Headers */, 50ABBE251925AB6F00A911A9 /* base64.h in Headers */, 50ABBEC91925AB6F00A911A9 /* firePngData.h in Headers */, @@ -5469,6 +5478,7 @@ 06CAAACE186AD7FA0012A414 /* TriggerBase.h in Headers */, 503DD8EC1926736A00CD74DD /* CCGLView.h in Headers */, 50FCEBC218C72017004AD434 /* TextFieldReader.h in Headers */, + 29E99D211957BA7000046604 /* CocoLoader.h in Headers */, 50ABBEBA1925AB6F00A911A9 /* ccUTF8.h in Headers */, 1A570068180BC5A10088DEC7 /* CCActionCamera.h in Headers */, 1A57006C180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */, @@ -6173,6 +6183,7 @@ ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */, 06CAAACB186AD7F20012A414 /* TriggerMng.cpp in Sources */, 46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */, + 29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */, 50ABBDA71925AB4100A911A9 /* CCRenderCommand.cpp in Sources */, 50ABBD501925AB0000A911A9 /* Quaternion.cpp in Sources */, 50ABBEBB1925AB6F00A911A9 /* ccUtils.cpp in Sources */, @@ -6633,6 +6644,7 @@ 50ABBE621925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */, B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */, 2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */, + 29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */, B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */, 0634A4D5194B19E400E608AF /* CCActionTimelineCache.cpp in Sources */, 50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 7b1632cc5930..2ea769f34b8d 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -5476,6 +5476,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", CC_TARGET_OS_IPHONE, @@ -5492,6 +5493,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", CC_TARGET_OS_IPHONE, diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index 442d23e50158..0ad232ea06fe 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -332,7 +332,7 @@ Frame* ActionTimelineCache::loadTextureFrame(const rapidjson::Value& json) const char* texture = DICTOOL->getStringValue_json(json, Value); - if(texture != NULL) + if(texture != nullptr) { std::string path = texture; @@ -354,7 +354,7 @@ Frame* ActionTimelineCache::loadEventFrame(const rapidjson::Value& json) const char* evnt = DICTOOL->getStringValue_json(json, Value); - if(evnt != NULL) + if(evnt != nullptr) frame->setEvent(evnt); return frame; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp index 9991baff0b9a..6f8d82afc871 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.cpp @@ -26,7 +26,7 @@ THE SOFTWARE. #include "CCActionTimelineCache.h" #include "CCActionTimeline.h" -#include "../CCSGUIReader.h" +#include "cocostudio/CCSGUIReader.h" using namespace cocos2d; using namespace ui; @@ -150,7 +150,6 @@ void NodeReader::init() _funcs.insert(Pair(ClassName_Widget, std::bind(&NodeReader::loadWidget, this, _1))); _funcs.insert(Pair(ClassName_Label, std::bind(&NodeReader::loadWidget, this, _1))); - _guiReader = new WidgetPropertiesReader0300(); } Node* NodeReader::createNode(const std::string& filename) @@ -445,7 +444,9 @@ Node* NodeReader::loadWidget(const rapidjson::Value& json) WidgetReaderProtocol* reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); - _guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json); + WidgetPropertiesReader0300* guiReader = new WidgetPropertiesReader0300(); + guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json); + CC_SAFE_DELETE(guiReader); int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG); widget->setUserObject(ActionTimelineData::create(actionTag)); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h index 80a8a671ac5e..669a3123edda 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h @@ -30,7 +30,6 @@ THE SOFTWARE. namespace cocostudio { -class WidgetPropertiesReader0300; namespace timeline{ @@ -78,7 +77,6 @@ class NodeReader std::unordered_map _funcs; - WidgetPropertiesReader0300* _guiReader; bool _recordJsonPath; std::string _jsonPath; diff --git a/cocos/editor-support/cocostudio/Android.mk b/cocos/editor-support/cocostudio/Android.mk index 07bb09ceb26b..de25e273e2a4 100644 --- a/cocos/editor-support/cocostudio/Android.mk +++ b/cocos/editor-support/cocostudio/Android.mk @@ -39,6 +39,7 @@ CCSSceneReader.cpp \ TriggerBase.cpp \ TriggerMng.cpp \ TriggerObj.cpp \ +CocoLoader.cpp \ WidgetReader/WidgetReader.cpp \ WidgetReader/ButtonReader/ButtonReader.cpp \ WidgetReader/CheckBoxReader/CheckBoxReader.cpp \ diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp index a439f843cb93..21dc78b04b2e 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.cpp +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. #include "cocostudio/CCActionManagerEx.h" #include "cocostudio/DictionaryHelper.h" +#include "cocostudio/CocoLoader.h" using namespace cocos2d; @@ -70,6 +71,42 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V } _actionDic.insert(std::pair>(fileName, actionList)); } + + void ActionManagerEx::initWithBinary(const char* file, + cocos2d::Ref *root, + CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode) + { + std::string path = file; + ssize_t pos = path.find_last_of("/"); + std::string fileName = path.substr(pos+1,path.length()); + CCLOG("filename == %s",fileName.c_str()); + cocos2d::Vector actionList; + + stExpCocoNode *stChildArray = pCocoNode->GetChildArray(); + stExpCocoNode *actionNode = nullptr; + for (int i=0; i < pCocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + if (key == "actionlist") { + actionNode = &stChildArray[i]; + break; + } + } + if (nullptr != actionNode) + { + int actionCount = actionNode->GetChildNum(); + for (int i = 0; i < actionCount; ++i) { + ActionObject* action = new ActionObject(); + action->autorelease(); + + action->initWithBinary(cocoLoader, actionNode->GetChildArray(), root); + + actionList.pushBack(action); + } + } + _actionDic.insert(std::pair>(fileName, actionList)); + + } ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName) diff --git a/cocos/editor-support/cocostudio/CCActionManagerEx.h b/cocos/editor-support/cocostudio/CCActionManagerEx.h index b33b0993423c..ebea43482514 100644 --- a/cocos/editor-support/cocostudio/CCActionManagerEx.h +++ b/cocos/editor-support/cocostudio/CCActionManagerEx.h @@ -29,6 +29,9 @@ THE SOFTWARE. #include "cocostudio/DictionaryHelper.h" namespace cocostudio { + +class CocoLoader; +struct stExpCocoNode; class ActionManagerEx:public cocos2d::Ref { @@ -96,6 +99,8 @@ class ActionManagerEx:public cocos2d::Ref /*init properties with json dictionay*/ void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root); + void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); + /** * Release all actions. * diff --git a/cocos/editor-support/cocostudio/CCActionNode.cpp b/cocos/editor-support/cocostudio/CCActionNode.cpp index f610c0e15f53..eb68c98019cf 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.cpp +++ b/cocos/editor-support/cocostudio/CCActionNode.cpp @@ -27,6 +27,7 @@ THE SOFTWARE. #include "cocostudio/DictionaryHelper.h" #include "ui/UIWidget.h" #include "ui/UIHelper.h" +#include "cocostudio/CocoLoader.h" using namespace cocos2d; using namespace ui; @@ -167,6 +168,149 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) } initActionNodeFromRoot(root); } + + int ActionNode::valueToInt(const std::string& value) + { + return atoi(value.c_str()); + } + bool ActionNode::valueToBool(const std::string& value) + { + int intValue = valueToInt(value); + if (1 == intValue) { + return true; + }else{ + return false; + } + } + float ActionNode::valueToFloat(const std::string& value) + { + return atof(value.c_str()); + } + + void ActionNode::initWithBinary(CocoLoader *cocoLoader, + stExpCocoNode *cocoNode, + cocos2d::Ref *root) + { + + stExpCocoNode *stChildNode = cocoNode; + + int actionNodeCount = stChildNode->GetChildNum(); + stChildNode = stChildNode[0].GetChildArray(); + stExpCocoNode *frameListNode = nullptr; + for (int i = 0; i < actionNodeCount; ++i) { + std::string key = stChildNode[i].GetName(cocoLoader); + std::string value = stChildNode[i].GetValue(); + if (key == "ActionTag") { + setActionTag(valueToInt(value)); + }else if (key == "actionframelist"){ + frameListNode = &stChildNode[i]; + } + } + + int actionFrameCount = frameListNode->GetChildNum(); + stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray(); + for (int i=0; i frameTweenParameter; + + int framesCount = stFrameChildNode[i].GetChildNum(); + stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray(); + for (int j = 0; j < framesCount; j++) { + std::string key = innerFrameNode[j].GetName(cocoLoader); + std::string value = innerFrameNode[j].GetValue(); + + if (key == "frameid") { + frameIndex = valueToInt(value); + }else if(key == "tweenType"){ + frameTweenType = valueToInt(value); + }else if (key == "tweenParameter"){ + // There are no tweenParameter args in the json file + int tweenParameterCount = innerFrameNode[j].GetChildNum(); + stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray(); + for (int k = 0; k < tweenParameterCount; ++k) { + std::string t_key = tweenParameterArray[j].GetName(cocoLoader); + std::string t_value = tweenParameterArray[j].GetValue(); + frameTweenParameter.push_back(valueToFloat(t_value)); + } + }else if (key == "positionx"){ + positionX = valueToFloat(value); + }else if (key == "positiony"){ + positionY = valueToFloat(value); + ActionMoveFrame* actionFrame = new ActionMoveFrame(); + actionFrame->autorelease(); + actionFrame->setEasingType(frameTweenType); + actionFrame->setEasingParameter(frameTweenParameter); + actionFrame->setFrameIndex(frameIndex); + actionFrame->setPosition(Vec2(positionX, positionY)); + auto cActionArray = _frameArray.at((int)kKeyframeMove); + cActionArray->pushBack(actionFrame); + }else if(key == "scalex"){ + scaleX = valueToFloat(value); + }else if(key == "scaley"){ + scaleY = valueToFloat(value); + ActionScaleFrame* actionFrame = new ActionScaleFrame(); + actionFrame->autorelease(); + actionFrame->setEasingType(frameTweenType); + actionFrame->setEasingParameter(frameTweenParameter); + actionFrame->setFrameIndex(frameIndex); + actionFrame->setScaleX(scaleX); + actionFrame->setScaleY(scaleY); + auto cActionArray = _frameArray.at((int)kKeyframeScale); + cActionArray->pushBack(actionFrame); + }else if (key == "rotation"){ + rotation = valueToFloat(value); + ActionRotationFrame* actionFrame = new ActionRotationFrame(); + actionFrame->autorelease(); + actionFrame->setEasingType(frameTweenType); + actionFrame->setEasingParameter(frameTweenParameter); + actionFrame->setFrameIndex(frameIndex); + actionFrame->setRotation(rotation); + auto cActionArray = _frameArray.at((int)kKeyframeRotate); + cActionArray->pushBack(actionFrame); + }else if (key == "opacity"){ + opacity = valueToInt(value); + ActionFadeFrame* actionFrame = new ActionFadeFrame(); + actionFrame->autorelease(); + actionFrame->setEasingType(frameTweenType); + actionFrame->setEasingParameter(frameTweenParameter); + actionFrame->setFrameIndex(frameIndex); + actionFrame->setOpacity(opacity); + auto cActionArray = _frameArray.at((int)kKeyframeFade); + cActionArray->pushBack(actionFrame); + }else if (key == "colorb"){ + colorB = valueToInt(value); + }else if(key == "colorg"){ + colorG = valueToInt(value); + }else if(key == "colorr"){ + colorR = valueToInt(value); + + ActionTintFrame* actionFrame = new ActionTintFrame(); + actionFrame->autorelease(); + actionFrame->setEasingType(frameTweenType); + actionFrame->setEasingParameter(frameTweenParameter); + actionFrame->setFrameIndex(frameIndex); + actionFrame->setColor(Color3B(colorR,colorG,colorB)); + auto cActionArray = _frameArray.at((int)kKeyframeTint); + cActionArray->pushBack(actionFrame); + } + + + } + + } + initActionNodeFromRoot(root); + } void ActionNode::initActionNodeFromRoot(Ref* root) { diff --git a/cocos/editor-support/cocostudio/CCActionNode.h b/cocos/editor-support/cocostudio/CCActionNode.h index f0043cb26490..5b6da7962094 100644 --- a/cocos/editor-support/cocostudio/CCActionNode.h +++ b/cocos/editor-support/cocostudio/CCActionNode.h @@ -29,7 +29,9 @@ THE SOFTWARE. #include "cocostudio/DictionaryHelper.h" namespace cocostudio { - + +class CocoLoader; +struct stExpCocoNode; /** * @js NA * @lua NA @@ -149,6 +151,7 @@ class ActionNode : public cocos2d::Ref /*init properties with a json dictionary*/ virtual void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root); + virtual void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, Ref* root); /** * Gets if the action is done once time. @@ -157,6 +160,10 @@ class ActionNode : public cocos2d::Ref */ virtual bool isActionDoneOnce(); protected: + int valueToInt(const std::string& value); + bool valueToBool(const std::string& value); + float valueToFloat(const std::string& value); + int _currentFrameIndex; int _destFrameIndex; diff --git a/cocos/editor-support/cocostudio/CCActionObject.cpp b/cocos/editor-support/cocostudio/CCActionObject.cpp index 121979d98398..0ab3dbdef84b 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.cpp +++ b/cocos/editor-support/cocostudio/CCActionObject.cpp @@ -24,6 +24,7 @@ THE SOFTWARE. #include "cocostudio/CCActionObject.h" #include "cocostudio/DictionaryHelper.h" +#include "cocostudio/CocoLoader.h" #include "base/CCDirector.h" #include "base/CCScheduler.h" @@ -44,128 +45,192 @@ ActionObject::ActionObject() , _CallBack(nullptr) , _fTotalTime(0.0f) { - _pScheduler = Director::getInstance()->getScheduler(); - CC_SAFE_RETAIN(_pScheduler); + _pScheduler = Director::getInstance()->getScheduler(); + CC_SAFE_RETAIN(_pScheduler); } ActionObject::~ActionObject() { - _actionNodeList.clear(); - CC_SAFE_RELEASE(_pScheduler); - CC_SAFE_RELEASE(_CallBack); + _actionNodeList.clear(); + CC_SAFE_RELEASE(_pScheduler); + CC_SAFE_RELEASE(_CallBack); } void ActionObject::setName(const char* name) { - _name.assign(name); + _name.assign(name); } const char* ActionObject::getName() { - return _name.c_str(); + return _name.c_str(); } void ActionObject::setLoop(bool bLoop) { - _loop = bLoop; + _loop = bLoop; } bool ActionObject::getLoop() { - return _loop; + return _loop; } void ActionObject::setUnitTime(float fTime) { - _fUnitTime = fTime; + _fUnitTime = fTime; for(const auto &e : _actionNodeList) - { + { e->setUnitTime(_fUnitTime); - } + } } float ActionObject::getUnitTime() { - return _fUnitTime; + return _fUnitTime; } float ActionObject::getCurrentTime() { - return _currentTime; + return _currentTime; } void ActionObject::setCurrentTime(float fTime) { - _currentTime = fTime; + _currentTime = fTime; } float ActionObject::getTotalTime() { - return _fTotalTime; + return _fTotalTime; } bool ActionObject::isPlaying() { - return _bPlaying; + return _bPlaying; } void ActionObject::initWithDictionary(const rapidjson::Value& dic, Ref* root) { - setName(DICTOOL->getStringValue_json(dic, "name")); - setLoop(DICTOOL->getBooleanValue_json(dic, "loop")); - setUnitTime(DICTOOL->getFloatValue_json(dic, "unittime")); - int actionNodeCount = DICTOOL->getArrayCount_json(dic, "actionnodelist"); - int maxLength = 0; - for (int i=0; iautorelease(); - const rapidjson::Value& actionNodeDic = DICTOOL->getDictionaryFromArray_json(dic, "actionnodelist", i); - actionNode->initWithDictionary(actionNodeDic,root); - actionNode->setUnitTime(getUnitTime()); - _actionNodeList.pushBack(actionNode); - - int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex(); - if(length > maxLength) - maxLength = length; - } - _fTotalTime = maxLength*_fUnitTime; + setName(DICTOOL->getStringValue_json(dic, "name")); + setLoop(DICTOOL->getBooleanValue_json(dic, "loop")); + setUnitTime(DICTOOL->getFloatValue_json(dic, "unittime")); + int actionNodeCount = DICTOOL->getArrayCount_json(dic, "actionnodelist"); + int maxLength = 0; + for (int i=0; iautorelease(); + const rapidjson::Value& actionNodeDic = DICTOOL->getDictionaryFromArray_json(dic, "actionnodelist", i); + actionNode->initWithDictionary(actionNodeDic,root); + actionNode->setUnitTime(getUnitTime()); + _actionNodeList.pushBack(actionNode); + + int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex(); + if(length > maxLength) + maxLength = length; + } + _fTotalTime = maxLength*_fUnitTime; +} + +void ActionObject::initWithBinary(CocoLoader *cocoLoader, + stExpCocoNode *cocoNode, + cocos2d::Ref *root) +{ + stExpCocoNode *stChildNode = cocoNode->GetChildArray(); + stExpCocoNode *actionNodeList = nullptr; + int count = cocoNode->GetChildNum(); + for (int i = 0; i < count; ++i) { + std::string key = stChildNode[i].GetName(cocoLoader); + std::string value = stChildNode[i].GetValue(); + if (key == "name") { + setName(value.c_str()); + }else if (key == "loop"){ + setLoop(valueToBool(value)); + }else if(key == "unittime"){ + setUnitTime(valueToFloat(value)); + }else if (key == "actionnodelist"){ + actionNodeList = &stChildNode[i]; + } + } + + if(nullptr != actionNodeList) + { + int actionNodeCount = actionNodeList->GetChildNum(); + stExpCocoNode *actionNodeArray = actionNodeList->GetChildArray(); + int maxLength = 0; + for (int i=0; iautorelease(); + + actionNode->initWithBinary(cocoLoader, &actionNodeArray[i] , root); + + actionNode->setUnitTime(getUnitTime()); + + _actionNodeList.pushBack(actionNode); + + int length = actionNode->getLastFrameIndex() - actionNode->getFirstFrameIndex(); + if(length > maxLength) + maxLength = length; + } + + + _fTotalTime = maxLength* _fUnitTime; + } +} + +int ActionObject::valueToInt(const std::string& value) +{ + return atoi(value.c_str()); +} +bool ActionObject::valueToBool(const std::string& value) +{ + int intValue = valueToInt(value); + if (1 == intValue) { + return true; + }else{ + return false; + } +} +float ActionObject::valueToFloat(const std::string& value) +{ + return atof(value.c_str()); } void ActionObject::addActionNode(ActionNode* node) { - if (node == nullptr) - { - return; - } - _actionNodeList.pushBack(node); - node->setUnitTime(_fUnitTime); + if (node == nullptr) + { + return; + } + _actionNodeList.pushBack(node); + node->setUnitTime(_fUnitTime); } void ActionObject::removeActionNode(ActionNode* node) { - if (node == nullptr) - { - return; - } - _actionNodeList.eraseObject(node); + if (node == nullptr) + { + return; + } + _actionNodeList.eraseObject(node); } void ActionObject::play() { - stop(); - this->updateToFrameByTime(0.0f); + stop(); + this->updateToFrameByTime(0.0f); for(const auto &e : _actionNodeList) - { - e->playAction(); - } - if (_loop) - { - _pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f , kRepeatForever, 0.0f, false); - } - else - { - _pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f, false); - } + { + e->playAction(); + } + if (_loop) + { + _pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f , kRepeatForever, 0.0f, false); + } + else + { + _pScheduler->schedule(schedule_selector(ActionObject::simulationActionUpdate), this, 0.0f, false); + } } void ActionObject::play(CallFunc* func) { - this->play(); + this->play(); this->_CallBack = func; CC_SAFE_RETAIN(_CallBack); } diff --git a/cocos/editor-support/cocostudio/CCActionObject.h b/cocos/editor-support/cocostudio/CCActionObject.h index dcc8008dda9a..401a18431d06 100644 --- a/cocos/editor-support/cocostudio/CCActionObject.h +++ b/cocos/editor-support/cocostudio/CCActionObject.h @@ -31,6 +31,9 @@ THE SOFTWARE. namespace cocostudio { +class CocoLoader; +struct stExpCocoNode; + /** * @js NA * @lua NA @@ -160,10 +163,17 @@ class ActionObject : public cocos2d::Ref /*init properties with a json dictionary*/ void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root); + + void initWithBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode, cocos2d::Ref* root); + /*scheduler update function*/ void simulationActionUpdate(float dt); protected: + int valueToInt(const std::string& value); + bool valueToBool(const std::string& value); + float valueToFloat(const std::string& value); + cocos2d::Vector _actionNodeList; std::string _name; bool _loop; diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index f3a37a41d6be..24d5147f4716 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -35,6 +35,9 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCDatas.h" +#include "cocostudio/CocoLoader.h" + + using namespace cocos2d; @@ -192,6 +195,10 @@ void DataReaderHelper::loadData() { DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo); } + else if(pAsyncStruct->configType == CocoStudio_Binary) + { + DataReaderHelper::addDataFromBinaryCache(pAsyncStruct->fileContent.c_str(),pDataInfo); + } // put the image info into the queue _dataInfoMutex.lock(); @@ -294,8 +301,17 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) // Read content from file std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); - std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath); - + bool isbinarysrc = str==".csb"; + std::string filemode("r"); + if(isbinarysrc) + filemode += "b"; + ssize_t filesize; + + _dataReaderHelper->_getFileMutex.lock(); + unsigned char *pBytes = FileUtils::getInstance()->getFileData(filePath, filemode.c_str(), &filesize); + std::string contentStr((const char*)pBytes,filesize); + _dataReaderHelper->_getFileMutex.unlock(); + DataInfo dataInfo; dataInfo.filename = filePathStr; dataInfo.asyncStruct = nullptr; @@ -308,6 +324,12 @@ void DataReaderHelper::addDataFromFile(const std::string& filePath) { DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo); } + else if(str == ".csb") + { + DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo); + } + + CC_SAFE_DELETE_ARRAY(pBytes); } void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Ref *target, SEL_SCHEDULE selector) @@ -391,9 +413,23 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath); + bool isbinaryfilesrc = str==".csb"; + std::string filereadmode("r"); + if (isbinaryfilesrc) { + filereadmode += "b"; + } + ssize_t size; // XXX fileContent is being leaked - data->fileContent = FileUtils::getInstance()->getStringFromFile(fullPath); - + + _dataReaderHelper->_getFileMutex.lock(); + unsigned char *pBytes = FileUtils::getInstance()->getFileData(fullPath.c_str() , filereadmode.c_str(), &size); + _dataReaderHelper->_getFileMutex.unlock(); + + Data bytecpy; + bytecpy.copy(pBytes, size); + data->fileContent = std::string((const char*)bytecpy.getBytes(), size); + CC_SAFE_DELETE_ARRAY(pBytes); + if (str == ".xml") { data->configType = DragonBone_XML; @@ -402,6 +438,10 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const { data->configType = CocoStudio_JSON; } + else if(str == ".csb") + { + data->configType = CocoStudio_Binary; + } // add async struct into queue @@ -1368,7 +1408,7 @@ DisplayData *DataReaderHelper::decodeBoneDisplay(const rapidjson::Value& json, D displayData = new SpriteDisplayData(); const char *name = DICTOOL->getStringValue_json(json, A_NAME); - if(name != NULL) + if(name != nullptr) { ((SpriteDisplayData *)displayData)->displayName = name; } @@ -1700,5 +1740,844 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, } } + + void DataReaderHelper::addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo) + { + CocoLoader tCocoLoader; + if (tCocoLoader.ReadCocoBinBuff((char*)fileContent)) + { + stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode(); + rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader); + if (rapidjson::kObjectType == tType) + { + stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(); + int nCount = tpRootCocoNode->GetChildNum(); + + dataInfo->contentScale = 1.0f; + int length = 0; + std::string key; + stExpCocoNode* pDataArray; + for (int i = 0; i < nCount; ++i) + { + key = tpChildArray[i].GetName(&tCocoLoader); + if (key.compare(CONTENT_SCALE) == 0) + { + std::string value = tpChildArray[i].GetValue(); + dataInfo->contentScale = atof(value.c_str()); + } + else if ( 0 == key.compare(ARMATURE_DATA)) + { + pDataArray = tpChildArray[i].GetChildArray(); + length = tpChildArray[i].GetChildNum(); + ArmatureData * armatureData; + for (int ii = 0; ii < length; ++ii) + { + armatureData = decodeArmature(&tCocoLoader, &pDataArray[ii], dataInfo); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.lock(); + } + ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str()); + armatureData->release(); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.unlock(); + } + } + } + else if ( 0 == key.compare(ANIMATION_DATA)) + { + pDataArray = tpChildArray[i].GetChildArray(); + length = tpChildArray[i].GetChildNum(); + AnimationData *animationData; + for (int ii = 0; ii < length; ++ii) + { + animationData = decodeAnimation(&tCocoLoader, &pDataArray[ii], dataInfo); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.lock(); + } + ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str()); + animationData->release(); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.unlock(); + } + } + } + else if (key.compare(TEXTURE_DATA) == 0) + { + pDataArray = tpChildArray[i].GetChildArray(); + length = tpChildArray[i].GetChildNum(); + for (int ii = 0; ii < length; ++ii) + { + TextureData *textureData = decodeTexture(&tCocoLoader, &pDataArray[ii]); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.lock(); + } + ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str()); + textureData->release(); + if (dataInfo->asyncStruct) + { + _dataReaderHelper->_addDataMutex.unlock(); + } + } + } + } + // Auto losprite file + bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile; + if (autoLoad) + { + for (int i = 0; i < nCount; ++i) + { + key = tpChildArray[i].GetName(&tCocoLoader); + if( 0 != key.compare(CONFIG_FILE_PATH)) + { + continue; + } + length = tpChildArray[i].GetChildNum(); + stExpCocoNode *pConfigFilePath = tpChildArray[i].GetChildArray(); + for (int ii = 0; ii < length; ii++) + { + const char *path = pConfigFilePath[ii].GetValue(); + if (path == nullptr) + { + CCLOG("load CONFIG_FILE_PATH error."); + return; + } + + std::string filePath = path; + filePath = filePath.erase(filePath.find_last_of(".")); + + if (dataInfo->asyncStruct) + { + dataInfo->configFileQueue.push(filePath); + } + else + { + std::string plistPath = filePath + ".plist"; + std::string pngPath = filePath + ".png"; + + ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str()); + } + } + } + } + } + } + } + + ArmatureData* DataReaderHelper::decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + ArmatureData *armatureData = new ArmatureData(); + armatureData->init(); + stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray(); + const char *name = pAramtureDataArray[2].GetValue(); //DICTOOL->getStringValue_json(json, A_NAME); + if(name != nullptr) + { + armatureData->name = name; + } + + float version = atof(pAramtureDataArray[1].GetValue()); + dataInfo->cocoStudioVersion = armatureData->dataVersion = version; //DICTOOL->getFloatValue_json(json, VERSION, 0.1f); + + int length = pAramtureDataArray[3].GetChildNum(); //DICTOOL->getArrayCount_json(json, BONE_DATA, 0); + stExpCocoNode *pBoneChildren = pAramtureDataArray[3].GetChildArray(); + stExpCocoNode* child; + for (int i = 0; i < length; i++) + { + //const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, BONE_DATA, i); //json[BONE_DATA][i]; + child = &pBoneChildren[i]; + BoneData *boneData = decodeBone(cocoLoader, child, dataInfo); + armatureData->addBoneData(boneData); + boneData->release(); + } + + return armatureData; + } + + BoneData* DataReaderHelper::decodeBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + BoneData *boneData = new BoneData(); + boneData->init(); + + decodeNode(boneData, cocoLoader, cocoNode, dataInfo); + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pBoneChildren = cocoNode->GetChildArray(); + stExpCocoNode* child; + const char *str = nullptr; + std::string key; + for (int i = 0; i < length; ++i) + { + child = &pBoneChildren[i]; + key = child->GetName(cocoLoader); + str = child->GetValue(); + if (key.compare(A_NAME) == 0) + { + //DICTOOL->getStringValue_json(json, A_NAME); + if(str != nullptr) + { + boneData->name = str; + } + } + else if (key.compare(A_PARENT) == 0) + { + //DICTOOL->getStringValue_json(json, A_PARENT); + if(str != nullptr) + { + boneData->parentName = str; + } + } + else if (key.compare(DISPLAY_DATA) == 0) + { + int count = child->GetChildNum(); + stExpCocoNode *pDisplayData = child->GetChildArray(); + for (int ii = 0; ii < count; ++ii) + { + DisplayData *displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo); + if(displayData == nullptr) + continue; + boneData->addDisplayData(displayData); + displayData->release(); + } + } + } + + return boneData; + } + + DisplayData* DataReaderHelper::decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + stExpCocoNode* children = cocoNode->GetChildArray(); + stExpCocoNode* child = &children[1]; + const char *str = nullptr; + + std::string key = child->GetName(cocoLoader); + str = child->GetValue(); + DisplayData *displayData = nullptr; + if (key.compare(A_DISPLAY_TYPE) == 0) + { + str = child->GetValue(); + DisplayType displayType = (DisplayType)(atoi(str)); + + int length = 0; + switch (displayType) + { + case CS_DISPLAY_SPRITE: + { + displayData = new SpriteDisplayData(); + + const char *name = children[0].GetValue(); + if(name != nullptr) + { + ((SpriteDisplayData *)displayData)->displayName = name; + } + stExpCocoNode *pSkinDataArray = children[2].GetChildArray(); + if (pSkinDataArray != nullptr) + { + stExpCocoNode *pSkinData = &pSkinDataArray[0]; + if (pSkinData != nullptr) + { + SpriteDisplayData *sdd = (SpriteDisplayData *)displayData; + length = pSkinData->GetChildNum(); + stExpCocoNode *SkinDataValue = pSkinData->GetChildArray(); + for (int i = 0; i < length; ++i) + { + key = SkinDataValue[i].GetName(cocoLoader); + str = SkinDataValue[i].GetValue(); + if (key.compare(A_X) == 0) + { + sdd->skinData.x = atof(str) * s_PositionReadScale; + } + else if (key.compare(A_Y) == 0) + { + sdd->skinData.y = atof(str) * s_PositionReadScale; + } + else if (key.compare(A_SCALE_X) == 0) + { + sdd->skinData.scaleX = atof(str); + } + else if (key.compare(A_SCALE_Y) == 0) + { + sdd->skinData.scaleY = atof(str); + } + else if (key.compare(A_SKEW_X) == 0) + { + sdd->skinData.skewX = atof(str); + } + else if (key.compare(A_SKEW_Y) == 0) + { + sdd->skinData.skewY = atof(str); + } + } + + sdd->skinData.x *= dataInfo->contentScale; + sdd->skinData.y *= dataInfo->contentScale; + } + } + } + + break; + case CS_DISPLAY_ARMATURE: + { + displayData = new ArmatureDisplayData(); + + const char *name = cocoNode[0].GetValue(); + if(name != nullptr) + { + ((ArmatureDisplayData *)displayData)->displayName = name; + } + } + break; + case CS_DISPLAY_PARTICLE: + { + displayData = new ParticleDisplayData(); + length = cocoNode->GetChildNum(); + stExpCocoNode *pDisplayData = cocoNode->GetChildArray(); + for (int i = 0; i < length; ++i) + { + key = pDisplayData[i].GetName(cocoLoader); + str = pDisplayData[i].GetValue(); + if (key.compare(A_PLIST) == 0) + { + const char *plist = str; + if(plist != nullptr) + { + if (dataInfo->asyncStruct) + { + ((ParticleDisplayData *)displayData)->displayName = dataInfo->asyncStruct->baseFilePath + plist; + } + else + { + ((ParticleDisplayData *)displayData)->displayName = dataInfo->baseFilePath + plist; + } + } + } + } + } + break; + default: + displayData = new SpriteDisplayData(); + + break; + } + displayData->displayType = displayType; + } + return displayData; + } + + AnimationData* DataReaderHelper::decodeAnimation(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + AnimationData *aniData = new AnimationData(); + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pAnimationData = cocoNode->GetChildArray(); + const char *str = nullptr; + std::string key; + stExpCocoNode* child; + MovementData *movementData; + for (int i = 0; i < length; ++i) + { + child = &pAnimationData[i]; + key = child->GetName(cocoLoader); + str = child->GetValue(); + if (key.compare(A_NAME) == 0) + { + if(str != nullptr) + { + aniData->name = str; + } + } + else if (key.compare(MOVEMENT_DATA) == 0) + { + int movcount = child->GetChildNum(); + stExpCocoNode* movArray = child->GetChildArray(); + for( int movnum =0; movnum addMovement(movementData); + movementData->release(); + } + } + } + return aniData; + } + + MovementData* DataReaderHelper::decodeMovement(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + MovementData *movementData = new MovementData(); + movementData->scale = 1.0f; + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray(); + + const char *str = nullptr; + std::string key; + stExpCocoNode* child; + for (int i = 0; i < length; ++i) + { + child = &pMoveDataArray[i]; + key = child->GetName(cocoLoader); + str = child->GetValue(); + if (key.compare(A_NAME) == 0) + { + if(str != nullptr) + { + movementData->name = str; + } + } + else if (key.compare(A_LOOP) == 0) + { + movementData->loop = true; + if(str != nullptr) + { + if (strcmp("1", str) != 0) + { + movementData->loop = false; + } + } + } + else if (key.compare(A_DURATION_TWEEN) == 0) + { + movementData->durationTween = 0; + if(str != nullptr) + { + movementData->durationTween = atoi(str); + } + } + else if (key.compare(A_DURATION_TO) == 0) + { + movementData->durationTo = 0; + if(str != nullptr) + { + movementData->durationTo = atoi(str); + } + } + else if (key.compare(A_DURATION) == 0) + { + movementData->duration = 0; + if(str != nullptr) + { + movementData->duration = atoi(str); + } + } + else if (key.compare(A_MOVEMENT_SCALE) == 0) + { + movementData->scale = 1.0; + if(str != nullptr) + { + movementData->scale = atof(str); + } + } + else if (key.compare(A_TWEEN_EASING) == 0) + { + movementData->tweenEasing = cocos2d::tweenfunc::Linear; + if(str != nullptr) + { + movementData->tweenEasing = (TweenType)(atoi(str)); + } + } + else if (key.compare(MOVEMENT_BONE_DATA) == 0) + { + int count = child->GetChildNum(); + stExpCocoNode *pMoveBoneData = child->GetChildArray(); + MovementBoneData *movementBoneData; + for (int ii = 0; ii < count; ++ii) + { + movementBoneData = decodeMovementBone(cocoLoader, &pMoveBoneData[ii],dataInfo); + movementData->addMovementBoneData(movementBoneData); + movementBoneData->release(); + } + } + } + return movementData; + } + + MovementBoneData* DataReaderHelper::decodeMovementBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + MovementBoneData *movementBoneData = new MovementBoneData(); + movementBoneData->init(); + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray(); + stExpCocoNode* movebonechild; + const char *str = nullptr; + for (int i = 0; i < length; ++i) + { + movebonechild = &pMovementBoneDataArray[i]; + std::string key = movebonechild->GetName(cocoLoader); + str = movebonechild->GetValue(); + if (key.compare(A_NAME) == 0) + { + if(str != nullptr) + { + movementBoneData->name = str; + } + } + else if (key.compare(A_MOVEMENT_DELAY) == 0) + { + if(str != nullptr) + { + movementBoneData->delay = atof(str); + } + } + else if (key.compare(FRAME_DATA) == 0) + { + int count =movebonechild->GetChildNum(); + stExpCocoNode *pFrameDataArray = movebonechild->GetChildArray(); + for (int ii = 0; ii < count; ++ii) + { + FrameData *frameData = decodeFrame(cocoLoader, &pFrameDataArray[ii], dataInfo); + movementBoneData->addFrameData(frameData); + frameData->release(); + + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) + { + frameData->frameID = movementBoneData->duration; + movementBoneData->duration += frameData->duration; + } + } + } + } + + + + const ssize_t framesizemusone = movementBoneData->frameList.size()-1; + if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) + { + //! Change rotation range from (-180 -- 180) to (-infinity -- infinity) + cocos2d::Vector frames =movementBoneData->frameList; + + ssize_t imusone =0; + ssize_t i =0; + for (i = framesizemusone; i >= 0; i--) + { + if (i > 0) + { + imusone = i-1; + float difSkewX = frames.at(i)->skewX - frames.at(imusone)->skewX; + float difSkewY = frames.at(i)->skewY - frames.at(imusone)->skewY; + + if (difSkewX < -M_PI || difSkewX > M_PI) + { + frames.at(imusone)->skewX = difSkewX < 0 ? frames.at(imusone)->skewX - 2 * M_PI : frames.at(imusone)->skewX + 2 * M_PI; + } + + if (difSkewY < -M_PI || difSkewY > M_PI) + { + frames.at(imusone)->skewY = difSkewY < 0 ? frames.at(imusone)->skewY - 2 * M_PI : frames.at(imusone)->skewY + 2 * M_PI; + } + } + } + } + + + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) + { + if (movementBoneData->frameList.size() > 0) + { + FrameData *frameData = new FrameData(); + frameData = movementBoneData->frameList.at(framesizemusone); + movementBoneData->addFrameData(frameData); + frameData->release(); + frameData->frameID = movementBoneData->duration; + } + } + + return movementBoneData; + } + + FrameData* DataReaderHelper::decodeFrame(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo) + { + FrameData *frameData = new FrameData(); + + decodeNode(frameData, cocoLoader, cocoNode, dataInfo); + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray(); + const char *str = nullptr; + for (int i = 0; i < length; ++i) + { + std::string key = pFrameDataArray[i].GetName(cocoLoader); + str = pFrameDataArray[i].GetValue(); + if (key.compare(A_TWEEN_EASING) == 0) + { + frameData->tweenEasing = cocos2d::tweenfunc::Linear; + if(str != nullptr) + { + frameData->tweenEasing = (TweenType)(atoi(str)); + } + } + else if (key.compare(A_DISPLAY_INDEX) == 0) + { + if(str != nullptr) + { + frameData->displayIndex = atoi(str); + } + } + else if (key.compare(A_BLEND_SRC) == 0) + { + if(str != nullptr) + { + frameData->blendFunc.src = (GLenum)(atoi(str)); + } + } + else if (key.compare(A_BLEND_DST) == 0) + { + if(str != nullptr) + { + frameData->blendFunc.dst = (GLenum)(atoi(str)); + } + } + else if (key.compare(A_TWEEN_FRAME) == 0) + { + frameData->isTween = true; + if(str != nullptr) + { + if (strcmp("1", str) != 0) + { + frameData->isTween = false; + } + } + } + else if (key.compare(A_EVENT) == 0) + { + if(str != nullptr) + { + frameData->strEvent = str; + } + } + else if (key.compare(A_DURATION) == 0) + { + if (dataInfo->cocoStudioVersion < VERSION_COMBINED) + { + frameData->duration = 1; + if(str != nullptr) + { + frameData->duration = atoi(str); + } + } + } + else if (key.compare(A_FRAME_INDEX) == 0) + { + if (dataInfo->cocoStudioVersion >= VERSION_COMBINED) + { + if(str != nullptr) + { + frameData->frameID = atoi(str); + } + } + } + else if (key.compare(A_EASING_PARAM) == 0) + { + int count = pFrameDataArray[i].GetChildNum(); + if (count != 0 ) + { + frameData->easingParams = new float[count]; + stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray(); + for (int ii = 0; ii < count; ++ii) + { + str = pFrameData[ii].GetValue(); + if (str != nullptr) + { + frameData->easingParams[ii] = atof(str); + } + } + } + + } + } + + return frameData; + } + + TextureData* DataReaderHelper::decodeTexture(CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + TextureData *textureData = new TextureData(); + textureData->init(); + + if(cocoNode == nullptr) + { + return textureData; + } + + int length = cocoNode->GetChildNum(); + stExpCocoNode *pTextureDataArray = cocoNode->GetChildArray(); + const char *str = nullptr; + for (int i = 0; i < length; ++i) + { + std::string key = pTextureDataArray[i].GetName(cocoLoader); + str = pTextureDataArray[i].GetValue(); + if (key.compare(A_NAME) == 0) + { + if(str != nullptr) + { + textureData->name = str; + } + } + else if (key.compare(A_WIDTH) == 0) + { + if(str != nullptr) + { + textureData->width = atof(str); + } + } + else if (key.compare(A_HEIGHT) == 0) + { + if(str != NULL) + { + textureData->height = atof(str); + } + } + else if (key.compare(A_PIVOT_X) == 0) + { + if(str != NULL) + { + textureData->pivotX = atof(str); + } + } + else if (key.compare(A_PIVOT_Y) == 0) + { + if(str != NULL) + { + textureData->pivotY = atof(str); + } + } + else if (key.compare(CONTOUR_DATA) == 0) + { + int count = pTextureDataArray[i].GetChildNum(); + stExpCocoNode *pContourArray = pTextureDataArray[i].GetChildArray(); + for (int ii = 0; ii < count; ++ii) + { + ContourData *contourData = decodeContour(cocoLoader, &pContourArray[ii]); + textureData->contourDataList.pushBack(contourData); + contourData->release(); + } + } + } + return textureData; + } + + ContourData* DataReaderHelper::decodeContour(CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + ContourData *contourData = new ContourData(); + contourData->init(); + + int length = cocoNode->GetChildNum(); + stExpCocoNode *verTexPointArray = cocoNode->GetChildArray(); + const char *str = nullptr; + for (int i = 0; i < length; ++i) + { + std::string key = verTexPointArray[i].GetName(cocoLoader); + str = verTexPointArray[i].GetValue(); + if (key.compare(VERTEX_POINT) == 0) + { + int count = verTexPointArray[i].GetChildNum(); + stExpCocoNode *pVerTexPointArray = verTexPointArray[i].GetChildArray(); + stExpCocoNode *pVerTexPoint; + for (int ii = count - 1; ii >= 0; --ii) + { + pVerTexPoint = pVerTexPointArray[ii].GetChildArray(); + Vec2 vertex; + vertex.x = atof(pVerTexPoint[0].GetValue()); + vertex.y = atof(pVerTexPoint[1].GetValue()); + contourData->vertexList.push_back(vertex); } + break; + } + } + return contourData; + } + + void DataReaderHelper::decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode* cocoNode, DataInfo *dataInfo) + { + int length = cocoNode->GetChildNum(); + stExpCocoNode *NodeArray = cocoNode->GetChildArray(); + const char *str = nullptr; + + bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING; + stExpCocoNode* child; + for (int i = 0; i < length; ++i) + { + child = &NodeArray[i]; + std::string key = child->GetName(cocoLoader); + str = child->GetValue(); + if (key.compare(A_X) == 0) + { + node->x = atof(str) * dataInfo->contentScale; + } + else if (key.compare(A_Y) == 0) + { + node->y = atof(str) * dataInfo->contentScale; + } + else if (key.compare(A_Z) == 0) + { + node->zOrder = atoi(str); + } + else if (key.compare(A_SKEW_X) == 0) + { + node->skewX = atof(str); + } + else if (key.compare(A_SKEW_Y) == 0) + { + node->skewY = atof(str); + } + else if (key.compare(A_SCALE_X) == 0) + { + node->scaleX = atof(str); + } + else if (key.compare(A_SCALE_Y) == 0) + { + node->scaleY = atof(str); + } + else if (key.compare(COLOR_INFO) == 0) + { + if (!isVersionL) + { + if (child->GetType(cocoLoader) == rapidjson::kObjectType) + { + if(child->GetChildNum() == 4) + { + stExpCocoNode *ChildArray = child->GetChildArray(); + + node->a = atoi(ChildArray[0].GetValue()); + node->r = atoi(ChildArray[1].GetValue()); + node->g = atoi(ChildArray[2].GetValue()); + node->b = atoi(ChildArray[3].GetValue()); + } + + } + + + + node->isUseColorInfo = true; + } + } + } + + if (isVersionL) + { + int colorcoount = NodeArray[0].GetChildNum(); + if(colorcoount>0) + { + + if (NodeArray[0].GetType(cocoLoader) == rapidjson::kObjectType) + { + if(NodeArray[0].GetChildNum() == 4) + { + stExpCocoNode *ChildArray = NodeArray[0].GetChildArray(); + + node->a = atoi(ChildArray[0].GetValue()); + node->r = atoi(ChildArray[1].GetValue()); + node->g = atoi(ChildArray[2].GetValue()); + node->b = atoi(ChildArray[3].GetValue()); + } + } + + node->isUseColorInfo = true; + } + } + } } diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.h b/cocos/editor-support/cocostudio/CCDataReaderHelper.h index 26d3c25d350a..2401d710d0f2 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.h +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.h @@ -30,6 +30,9 @@ THE SOFTWARE. #include "cocostudio/CCArmature.h" #include "cocostudio/DictionaryHelper.h" +#include "json/document.h" +#include "DictionaryHelper.h" + #include #include #include @@ -43,7 +46,8 @@ namespace tinyxml2 } namespace cocostudio { - + class CocoLoader; + struct stExpCocoNode; /** * @js NA * @lua NA @@ -55,7 +59,8 @@ class DataReaderHelper : cocos2d::Ref enum ConfigType { DragonBone_XML, - CocoStudio_JSON + CocoStudio_JSON, + CocoStudio_Binary }; typedef struct _AsyncStruct @@ -171,7 +176,24 @@ class DataReaderHelper : cocos2d::Ref static ContourData *decodeContour(const rapidjson::Value& json); static void decodeNode(BaseData *node, const rapidjson::Value& json, DataInfo *dataInfo); - + +// for binary decode +public: + static void addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo = nullptr); + static ArmatureData *decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + static BoneData *decodeBone(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + static DisplayData *decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + static AnimationData *decodeAnimation(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + static MovementData *decodeMovement(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + + static MovementBoneData *decodeMovementBone(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + static FrameData *decodeFrame(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + + static TextureData *decodeTexture(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode); + static ContourData *decodeContour(CocoLoader *cocoLoader, stExpCocoNode *pCocoNode); + + static void decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode *pCocoNode, DataInfo *dataInfo); + protected: void loadData(); diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index f21f84af8eaa..639253409ca1 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -39,10 +39,11 @@ THE SOFTWARE. #include "WidgetReader/PageViewReader/PageViewReader.h" #include "WidgetReader/ScrollViewReader/ScrollViewReader.h" #include "WidgetReader/ListViewReader/ListViewReader.h" +#include "cocostudio/CocoLoader.h" +#include "ui/CocosGUI.h" -using namespace cocos2d::ui; using namespace cocos2d; - +using namespace cocos2d::ui; namespace cocostudio { @@ -129,7 +130,7 @@ int GUIReader::getVersionInteger(const char *str) int is = atoi(s.c_str()); int iVersion = it*1000+ih*100+ite*10+is; - CCLOG("iversion %d",iVersion); +// CCLOG("iversion %d",iVersion); return iVersion; /************************/ } @@ -140,8 +141,8 @@ void GUIReader::storeFileDesignSize(const char *fileName, const cocos2d::Size &s keyWidth.append("width"); std::string keyHeight = fileName; keyHeight.append("height"); - _fileDesignSizes[keyWidth] = Value(size.width); - _fileDesignSizes[keyHeight] = Value(size.height); + _fileDesignSizes[keyWidth] = cocos2d::Value(size.width); + _fileDesignSizes[keyHeight] = cocos2d::Value(size.height); } const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const @@ -218,6 +219,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) @@ -270,6 +335,107 @@ WidgetReaderProtocol* WidgetPropertiesReader::createWidgetReaderProtocol(const s + +Widget* GUIReader::widgetFromBinaryFile(const char *fileName) +{ + std::string jsonpath; + rapidjson::Document jsonDict; + jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName); + size_t pos = jsonpath.find_last_of('/'); + m_strFilePath = jsonpath.substr(0,pos+1); + ssize_t nSize = 0; + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); + unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath, "rb", &nSize); + + const char* fileVersion = ""; + ui::Widget* widget = nullptr; + + if (pBuffer != NULL && nSize > 0) + { + CocoLoader tCocoLoader; + if(true == tCocoLoader.ReadCocoBinBuff((char*)pBuffer)) + { + stExpCocoNode* tpRootCocoNode = tCocoLoader.GetRootCocoNode(); + + rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader); + if (rapidjson::kObjectType == tType || rapidjson::kArrayType == tType) + { + stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(); + + + 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) + { + 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); + } + else + { + pReader = new WidgetPropertiesReader0300(); + widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName); + } + } + else + { + pReader = new WidgetPropertiesReader0250(); + widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName); + } + + CC_SAFE_DELETE(pReader); + + } + } + } + + CC_SAFE_DELETE_ARRAY(pBuffer); + + return widget; + +} + +std::string WidgetPropertiesReader::getWidgetReaderClassName(const std::string& classname) +{ + // create widget reader to parse properties of widget + std::string readerName = classname; + if (readerName == "Panel") + { + readerName = "Layout"; + } + else if (readerName == "TextArea") + { + readerName = "Text"; + } + else if (readerName == "TextButton") + { + readerName = "Button"; + } + else if (readerName == "Label") + { + readerName = "Text"; + } + else if (readerName == "LabelAtlas") + { + readerName = "TextAtlas"; + } + else if (readerName == "LabelBMFont") + { + readerName = "TextBMFont"; + } + readerName.append("Reader"); + return readerName; +} void WidgetPropertiesReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options) { @@ -295,6 +461,7 @@ void WidgetPropertiesReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget } } + Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName) { @@ -335,12 +502,13 @@ Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, c /* *********temp********* */ // ActionManager::getInstance()->releaseActions(); /* ********************** */ - CCLOG("file name == [%s]",fileName); +// CCLOG("file name == [%s]",fileName); Ref* rootWidget = (Ref*) widget; ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget); return widget; } + Widget* WidgetPropertiesReader0250::widgetFromJsonDictionary(const rapidjson::Value&data) { Widget* widget = nullptr; @@ -1044,45 +1212,225 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c /* *********temp********* */ // ActionManager::getInstance()->releaseActions(); /* ********************** */ - CCLOG("file name == [%s]",fileName); +// CCLOG("file name == [%s]",fileName); Ref* rootWidget = (Ref*) widget; ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget); return widget; } -Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data) + cocos2d::ui::Widget* WidgetPropertiesReader0300::createWidgetFromBinary(CocoLoader* cocoLoader,stExpCocoNode* cocoNode, const char* fileName) { - const char* classname = DICTOOL->getStringValue_json(data, "classname"); - const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options"); - Widget* widget = this->createGUI(classname); - // create widget reader to parse properties of widget - std::string readerName = classname; - if (readerName == "Panel") - { - readerName = "Layout"; + stExpCocoNode *tpChildArray = cocoNode->GetChildArray(); + float fileDesignWidth; + float fileDesignHeight; + + Widget* widget = nullptr; + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = tpChildArray[i].GetName(cocoLoader); + + if (key == "textures") { + int texturesCount = tpChildArray[i].GetChildNum(); + for (int j=0; jaddSpriteFramesWithFile(file); + } + }else if (key == "designWidth"){ + fileDesignWidth = atof(tpChildArray[i].GetValue()); + }else if (key == "designHeight"){ + fileDesignHeight = atof(tpChildArray[i].GetValue()); + }else if (key == "widgetTree"){ + + if (fileDesignWidth <= 0 || fileDesignHeight <= 0) { + CCLOGERROR("Read design size error!\n"); + Size winSize = Director::getInstance()->getWinSize(); + GUIReader::getInstance()->storeFileDesignSize(fileName, winSize); + } + else + { + GUIReader::getInstance()->storeFileDesignSize(fileName, Size(fileDesignWidth, fileDesignHeight)); + } + + + stExpCocoNode *widgetTreeNode = &tpChildArray[i]; + rapidjson::Type tType = tpChildArray[i].GetType(cocoLoader); + + if (rapidjson::kObjectType == tType) + { + widget = widgetFromBinary(cocoLoader, widgetTreeNode); + } + + if (widget->getContentSize().equals(Size::ZERO)) + { + Layout* rootWidget = dynamic_cast(widget); + rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight)); + } + } } - else if (readerName == "TextArea") - { - readerName = "Text"; + + /* ********************** */ + /* ********************** */ + stExpCocoNode *optionChildNode = cocoNode->GetChildArray(); + for (int k = 0; k < cocoNode->GetChildNum(); ++k) { + std::string key = optionChildNode[k].GetName(cocoLoader); + if (key == "animation") { + Ref* rootWidget = (Ref*) widget; + ActionManagerEx::getInstance()->initWithBinary(fileName,rootWidget,cocoLoader, &optionChildNode[k]); + break; + } } - else if (readerName == "TextButton") - { - readerName = "Button"; + + return widget; +} + +Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* cocoNode) +{ + Widget* widget = nullptr; + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + stExpCocoNode *optionsNode = nullptr; + stExpCocoNode *childrenNode = nullptr; + int elementCount = cocoNode->GetChildNum(); + std::string classname; + + for (int i = 0; i < elementCount; ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + if (key == "classname" ) + { + if (!value.empty()) + { + classname = value; + widget = this->createGUI(classname); + } + else + { + CCLOG("Warning!!! classname not found!"); + } + }else if(key == "children"){ + childrenNode = &stChildArray[i]; + }else if(key == "options"){ + optionsNode = &stChildArray[i]; + } + } - else if (readerName == "Label") + + std::string readerName = this->getWidgetReaderClassName(classname); + + WidgetReaderProtocol* reader = this->createWidgetReaderProtocol(readerName); + + if (reader) { - readerName = "Text"; + // widget parse with widget reader + setPropsForAllWidgetFromBinary(reader, widget, cocoLoader,optionsNode); } - else if (readerName == "LabelAtlas") + else { - readerName = "TextAtlas"; + // 1st., custom widget parse properties of parent widget with parent widget reader + readerName = this->getWidgetReaderClassName(widget); + reader = this->createWidgetReaderProtocol(readerName); + + + if (reader && widget) { + setPropsForAllWidgetFromBinary(reader, widget, cocoLoader, optionsNode); + // 2nd., custom widget parse with custom reader + //2nd. parse custom property + const char* customProperty = NULL; + stExpCocoNode *optionChildNode = optionsNode->GetChildArray(); + for (int k = 0; k < optionsNode->GetChildNum(); ++k) { + std::string key = optionChildNode[k].GetName(cocoLoader); + if (key == "customProperty") { + customProperty = optionChildNode[k].GetValue(); + break; + } + } + + rapidjson::Document customJsonDict; + customJsonDict.Parse<0>(customProperty); + if (customJsonDict.HasParseError()) + { + CCLOG("GetParseError %s\n", customJsonDict.GetParseError()); + } + setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict); + }else{ + CCLOG("Widget or WidgetReader doesn't exists!!! Please check your csb file."); + } + } - else if (readerName == "LabelBMFont") - { - readerName = "TextBMFont"; + + //parse children + if (nullptr != childrenNode) { + rapidjson::Type tType22 = childrenNode->GetType(cocoLoader); + if (tType22 == rapidjson::kArrayType) { + + int childrenCount = childrenNode->GetChildNum(); + stExpCocoNode* innerChildArray = childrenNode->GetChildArray(); + for (int i=0; i < childrenCount; ++i) { + rapidjson::Type tType = innerChildArray[i].GetType(cocoLoader); + + if (tType == rapidjson::kObjectType) { + + Widget *child = widgetFromBinary(cocoLoader, &innerChildArray[i]); + + if (child) + { + PageView* pageView = dynamic_cast(widget); + if (pageView) + { + pageView->addPage(static_cast(child)); + } + else + { + ListView* listView = dynamic_cast(widget); + if (listView) + { + listView->pushBackCustomItem(child); + } + else + { + if (!dynamic_cast(widget)) + { + if (child->getPositionType() == ui::Widget::PositionType::PERCENT) + { + child->setPositionPercent(Vec2(child->getPositionPercent().x + widget->getAnchorPoint().x, + child->getPositionPercent().y + widget->getAnchorPoint().y)); + } + child->setPosition(Vec2(child->getPositionX() + widget->getAnchorPointInPoints().x, + child->getPositionY() + widget->getAnchorPointInPoints().y)); + } + widget->addChild(child); + } + } + } + + } + } + } } - readerName.append("Reader"); + + return widget; +} + +void WidgetPropertiesReader0300::setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, + cocos2d::ui::Widget* widget, + CocoLoader* cocoLoader, + stExpCocoNode* cocoNode) +{ + reader->setPropsFromBinary(widget, cocoLoader, cocoNode); +} + + +Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data) +{ + const char* classname = DICTOOL->getStringValue_json(data, "classname"); + const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options"); + Widget* widget = this->createGUI(classname); +// CCLOG("classname = %s", classname); + std::string readerName = this->getWidgetReaderClassName(classname); WidgetReaderProtocol* reader = this->createWidgetReaderProtocol(readerName); @@ -1093,77 +1441,26 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va } else { - // 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"; - } + readerName = this->getWidgetReaderClassName(widget); reader = dynamic_cast(ObjectFactory::getInstance()->createObject(readerName)); - setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions); - - // 2nd., custom widget parse with custom reader - const char* customProperty = DICTOOL->getStringValue_json(uiOptions, "customProperty"); - rapidjson::Document customJsonDict; - customJsonDict.Parse<0>(customProperty); - if (customJsonDict.HasParseError()) - { - CCLOG("GetParseError %s\n", customJsonDict.GetParseError()); + if (reader && widget) { + setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions); + + // 2nd., custom widget parse with custom reader + const char* customProperty = DICTOOL->getStringValue_json(uiOptions, "customProperty"); + rapidjson::Document customJsonDict; + customJsonDict.Parse<0>(customProperty); + if (customJsonDict.HasParseError()) + { + CCLOG("GetParseError %s\n", customJsonDict.GetParseError()); + } + setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict); + }else{ + CCLOG("Widget or WidgetReader doesn't exists!!! Please check your csb file."); } - setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict); + } int childrenCount = DICTOOL->getArrayCount_json(data, "children"); @@ -1202,908 +1499,6 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va } return widget; } - -void WidgetPropertiesReader0300::setPropsForWidgetFromJsonDictionary(Widget*widget,const rapidjson::Value&options) -{ - bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); - if (ignoreSizeExsit) - { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); - } - - widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, "sizeType")); - widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, "positionType")); - - widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY"))); - widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY"))); - - float w = DICTOOL->getFloatValue_json(options, "width"); - float h = DICTOOL->getFloatValue_json(options, "height"); - widget->setSize(Size(w, h)); - - widget->setTag(DICTOOL->getIntValue_json(options, "tag")); - widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag")); - widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble")); - const char* name = DICTOOL->getStringValue_json(options, "name"); - const char* widgetName = name?name:"default"; - widget->setName(widgetName); - float x = DICTOOL->getFloatValue_json(options, "x"); - float y = DICTOOL->getFloatValue_json(options, "y"); - widget->setPosition(Vec2(x,y)); - bool sx = DICTOOL->checkObjectExist_json(options, "scaleX"); - if (sx) - { - widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX")); - } - bool sy = DICTOOL->checkObjectExist_json(options, "scaleY"); - if (sy) - { - widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY")); - } - bool rt = DICTOOL->checkObjectExist_json(options, "rotation"); - if (rt) - { - widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation")); - } - bool vb = DICTOOL->checkObjectExist_json(options, "visible"); - if (vb) - { - widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); - } - int z = DICTOOL->getIntValue_json(options, "ZOrder"); - widget->setLocalZOrder(z); - - bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); - if (layout) - { - const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter"); - int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type"); - LayoutParameter* parameter = nullptr; - switch (paramType) - { - case 0: - break; - case 1: - { - parameter = LinearLayoutParameter::create(); - int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity"); - ((LinearLayoutParameter*)parameter)->setGravity((LinearLayoutParameter::LinearGravity)gravity); - break; - } - case 2: - { - parameter = RelativeLayoutParameter::create(); - RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter; - const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName"); - rParameter->setRelativeName(relativeName); - const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName"); - rParameter->setRelativeToWidgetName(relativeToName); - int align = DICTOOL->getIntValue_json(layoutParameterDic, "align"); - rParameter->setAlign((RelativeLayoutParameter::RelativeAlign)align); - break; - } - default: - break; - } - if (parameter) - { - float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft"); - float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop"); - float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight"); - float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown"); - parameter->setMargin(Margin(mgl, mgt, mgr, mgb)); - widget->setLayoutParameter(parameter); - } - } -} - -void WidgetPropertiesReader0300::setColorPropsForWidgetFromJsonDictionary(Widget *widget, const rapidjson::Value&options) -{ - bool op = DICTOOL->checkObjectExist_json(options, "opacity"); - if (op) - { - widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity")); - } - bool cr = DICTOOL->checkObjectExist_json(options, "colorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "colorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "colorB"); - int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255; - int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; - int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; - widget->setColor(Color3B(colorR, colorG, colorB)); - - 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) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::Button* button = static_cast(widget); - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - button->setScale9Enabled(scale9Enable); - - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - std::string tp_n = m_strFilePath; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; - button->loadTextureNormal(normalFileName_tp); - break; - } - case 1: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - button->loadTextureNormal(normalFileName,TextureResType::PLIST); - break; - } - default: - break; - } - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - std::string tp_p = m_strFilePath; - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; - button->loadTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - button->loadTexturePressed(pressedFileName,TextureResType::PLIST); - break; - } - default: - break; - } - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - std::string tp_d = m_strFilePath; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; - button->loadTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - button->loadTextureDisabled(disabledFileName,TextureResType::PLIST); - break; - } - default: - break; - } - if (scale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - button->setCapInsets(Rect(cx, cy, cw, ch)); - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); - if (sw && sh) - { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); - button->setSize(Size(swf, shf)); - } - } - bool tt = DICTOOL->checkObjectExist_json(options, "text"); - if (tt) - { - const char* text = DICTOOL->getStringValue_json(options, "text"); - if (text) - { - button->setTitleText(text); - } - } - - bool cr = DICTOOL->checkObjectExist_json(options, "textColorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "textColorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "textColorB"); - int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255; - int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255; - int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255; - button->setTitleColor(Color3B(cri,cgi,cbi)); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForCheckBoxFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - CheckBox* checkBox = static_cast(widget); - - const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData"); - int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType"); - switch (backGroundType) - { - case 0: - { - std::string tp_b = m_strFilePath; - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr; - checkBox->loadTextureBackGround(backGroundFileName_tp); - break; - } - case 1: - { - const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path"); - checkBox->loadTextureBackGround(backGroundFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData"); - int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType"); - switch (backGroundSelectedType) - { - case 0: - { - std::string tp_bs = m_strFilePath; - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr; - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp); - break; - } - case 1: - { - const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path"); - checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData"); - int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType"); - switch (frontCrossType) - { - case 0: - { - std::string tp_c = m_strFilePath; - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr; - checkBox->loadTextureFrontCross(frontCrossFileName_tp); - break; - } - case 1: - { - const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path"); - checkBox->loadTextureFrontCross(frontCrossFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData"); - int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType"); - switch (backGroundDisabledType) - { - case 0: - { - std::string tp_bd = m_strFilePath; - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr; - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp); - break; - } - case 1: - { - const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path"); - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData"); - int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType"); - switch (frontCrossDisabledType) - { - case 0: - { - std::string tp_cd = m_strFilePath; - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr; - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp); - break; - } - case 1: - { - const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path"); - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,TextureResType::PLIST); - break; - } - default: - break; - } - checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState")); - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForImageViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - - cocos2d::ui::ImageView* imageView = static_cast(widget); - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_i = m_strFilePath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) - { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - imageView->loadTexture(imageFileName_tp); - } - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - imageView->loadTexture(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable"); - bool scale9Enable = false; - if (scale9EnableExist) - { - scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - } - imageView->setScale9Enabled(scale9Enable); - - - if (scale9Enable) - { - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); - if (sw && sh) - { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); - imageView->setSize(Size(swf, shf)); - } - - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - imageView->setCapInsets(Rect(cx, cy, cw, ch)); - - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForLabelFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::Text* label = static_cast(widget); - bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable"); - label->setTouchScaleChangeEnabled(touchScaleChangeAble); - const char* text = DICTOOL->getStringValue_json(options, "text"); - label->setString(text); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - label->setFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); - if (aw && ah) - { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); - label->setTextAreaSize(size); - } - bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); - if (ha) - { - label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment")); - } - bool va = DICTOOL->checkObjectExist_json(options, "vAlignment"); - if (va) - { - label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment")); - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForLabelAtlasFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::TextAtlas* labelAtlas = static_cast(widget); - bool sv = DICTOOL->checkObjectExist_json(options, "stringValue"); - bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile"); - bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth"); - bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight"); - bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap"); - if (sv && cmf && iw && ih && scm) - { - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); - switch (cmfType) - { - case 0: - { - std::string tp_c = m_strFilePath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); - const char* cmf_tp = tp_c.append(cmfPath).c_str(); - labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap")); - break; - } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: - break; - } - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForLayoutFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - - float w = 0, h = 0; - bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); - if (adaptScrenn) - { - Size screenSize = CCDirector::getInstance()->getWinSize(); - w = screenSize.width; - h = screenSize.height; - } - else - { - w = DICTOOL->getFloatValue_json(options, "width"); - h = DICTOOL->getFloatValue_json(options, "height"); - } - - Layout* panel = static_cast(widget); - if (!dynamic_cast(widget) - && !dynamic_cast(widget)) - { - panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble")); - } - bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable"); - panel->setBackGroundImageScale9Enabled(backGroundScale9Enable); - int cr = DICTOOL->getIntValue_json(options, "bgColorR"); - int cg = DICTOOL->getIntValue_json(options, "bgColorG"); - int cb = DICTOOL->getIntValue_json(options, "bgColorB"); - - int scr = DICTOOL->getIntValue_json(options, "bgStartColorR"); - int scg = DICTOOL->getIntValue_json(options, "bgStartColorG"); - int scb = DICTOOL->getIntValue_json(options, "bgStartColorB"); - - int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR"); - int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG"); - int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB"); - - float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX"); - float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY"); - panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2)); - - int co = DICTOOL->getIntValue_json(options, "bgColorOpacity"); - - int colorType = DICTOOL->getIntValue_json(options, "colorType"); - panel->setBackGroundColorType(Layout::BackGroundColorType(colorType)); - panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); - panel->setBackGroundColor(Color3B(cr, cg, cb)); - panel->setBackGroundColorOpacity(co); - - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_b = m_strFilePath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - panel->setBackGroundImage(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - panel->setBackGroundImage(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - if (backGroundScale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); - } - panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, "layoutType")); - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForScrollViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForLayoutFromJsonDictionary(widget, options); - cocos2d::ui::ScrollView* scrollView = static_cast(widget); - float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth"); - float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight"); - scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); - int direction = DICTOOL->getFloatValue_json(options, "direction"); - scrollView->setDirection((ScrollView::Direction)direction); - scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable")); - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForSliderFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::Slider* slider = static_cast(widget); - - bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable"); - slider->setScale9Enabled(barTextureScale9Enable); - bool bt = DICTOOL->checkObjectExist_json(options, "barFileName"); - float barLength = DICTOOL->getFloatValue_json(options, "length"); - if (bt) - { - if (barTextureScale9Enable) - { - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = m_strFilePath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - slider->setSize(Size(barLength, slider->getContentSize().height)); - } - else - { - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileType) - { - case 0: - { - std::string tp_b = m_strFilePath; - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - slider->loadBarTexture(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - } - } - - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - switch (normalType) - { - case 0: - { - std::string tp_n = m_strFilePath; - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr; - slider->loadSlidBallTextureNormal(normalFileName_tp); - break; - } - case 1: - { - const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path"); - slider->loadSlidBallTextureNormal(normalFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - switch (pressedType) - { - case 0: - { - std::string tp_p = m_strFilePath; - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr; - slider->loadSlidBallTexturePressed(pressedFileName_tp); - break; - } - case 1: - { - const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path"); - slider->loadSlidBallTexturePressed(pressedFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - switch (disabledType) - { - case 0: - { - std::string tp_d = m_strFilePath; - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr; - slider->loadSlidBallTextureDisabled(disabledFileName_tp); - break; - } - case 1: - { - const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path"); - slider->loadSlidBallTextureDisabled(disabledFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); - - const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData"); - int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType"); - switch (progressBarType) - { - case 0: - { - std::string tp_b = m_strFilePath; - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr; - slider->loadProgressBarTexture(imageFileName_tp); - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path"); - slider->loadProgressBarTexture(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForTextFieldFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::TextField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder"); - if (ph) - { - textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder")); - } - textField->setText(DICTOOL->getStringValue_json(options, "text")); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); - if (fs) - { - textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); - } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); - if (fn) - { - textField->setFontName(DICTOOL->getStringValue_json(options, "fontName")); - } - bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth"); - bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight"); - if (tsw && tsh) - { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight"))); - } - - float dw = DICTOOL->getFloatValue_json(options, "width"); - float dh = DICTOOL->getFloatValue_json(options, "height"); - if (dw > 0.0f || dh > 0.0f) - { - //textField->setSize(Size(dw, dh)); - } - bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable"); - textField->setMaxLengthEnabled(maxLengthEnable); - - if (maxLengthEnable) - { - int maxLength = DICTOOL->getIntValue_json(options, "maxLength"); - textField->setMaxLength(maxLength); - } - bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable"); - textField->setPasswordEnabled(passwordEnable); - if (passwordEnable) - { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText")); - } - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForLoadingBarFromJsonDictionary(Widget *widget, const rapidjson::Value&options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - cocos2d::ui::LoadingBar* loadingBar = static_cast(widget); - - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - switch (imageFileNameType) - { - case 0: - { - std::string tp_i = m_strFilePath; - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - const char* imageFileName_tp = nullptr; - if (imageFileName && (strcmp(imageFileName, "") != 0)) - { - imageFileName_tp = tp_i.append(imageFileName).c_str(); - loadingBar->loadTexture(imageFileName_tp); - } - break; - } - case 1: - { - const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path"); - loadingBar->loadTexture(imageFileName,TextureResType::PLIST); - break; - } - default: - break; - } - - /* ui mark add load bar scale9 parse */ - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); - loadingBar->setScale9Enabled(scale9Enable); - - if (scale9Enable) - { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); - - loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); - - float width = DICTOOL->getFloatValue_json(options, "width"); - float height = DICTOOL->getFloatValue_json(options, "height"); - loadingBar->setSize(Size(width, height)); - } - /**/ - - loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, "direction"))); - loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent")); - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForLabelBMFontFromJsonDictionary(Widget *widget, const rapidjson::Value&options) -{ - setPropsForWidgetFromJsonDictionary(widget, options); - - cocos2d::ui::TextBMFont* labelBMFont = static_cast(widget); - - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); - switch (cmfType) - { - case 0: - { - std::string tp_c = m_strFilePath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); - const char* cmf_tp = tp_c.append(cmfPath).c_str(); - labelBMFont->setFntFile(cmf_tp); - break; - } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: - break; - } - - const char* text = DICTOOL->getStringValue_json(options, "text"); - labelBMFont->setString(text); - - setColorPropsForWidgetFromJsonDictionary(widget,options); -} - -void WidgetPropertiesReader0300::setPropsForPageViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options) -{ - setPropsForLayoutFromJsonDictionary(widget, options); -} - -void WidgetPropertiesReader0300::setPropsForListViewFromJsonDictionary(Widget* widget, const rapidjson::Value& options) -{ - setPropsForLayoutFromJsonDictionary(widget, options); - - ListView* listView = static_cast(widget); - - float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth"); - float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight"); - listView->setInnerContainerSize(Size(innerWidth, innerHeight)); - int direction = DICTOOL->getFloatValue_json(options, "direction"); - listView->setDirection((ScrollView::Direction)direction); - - ListView::Gravity gravity = (ListView::Gravity)DICTOOL->getIntValue_json(options, "gravity"); - listView->setGravity(gravity); - - float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin"); - listView->setItemsMargin(itemMargin); -} void WidgetPropertiesReader0300::setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol *reader, Widget *widget, const rapidjson::Value &options) { diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.h b/cocos/editor-support/cocostudio/CCSGUIReader.h index 5c794c5e58e3..c5a798a8783a 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.h +++ b/cocos/editor-support/cocostudio/CCSGUIReader.h @@ -30,8 +30,10 @@ THE SOFTWARE. #include "WidgetReader/WidgetReaderProtocol.h" #include "base/ObjectFactory.h" - namespace cocostudio { + + class CocoLoader; + struct stExpCocoNode; #define kCCSVersion 1.0 @@ -49,6 +51,9 @@ class GUIReader : public cocos2d::Ref static void destroyInstance(); cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName); + + cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName); + int getVersionInteger(const char* str); /** * @js NA @@ -66,7 +71,6 @@ class GUIReader : public cocos2d::Ref cocos2d::ObjectFactory::Instance ins, Ref* object, SEL_ParseEvent callBack); - protected: GUIReader(); ~GUIReader(); @@ -89,13 +93,27 @@ class WidgetPropertiesReader : public cocos2d::Ref { public: virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName)=0; + virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0; virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0; + + virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType, cocos2d::ui::Widget* widget, const rapidjson::Value& customOptions) = 0; + + //add binary parsing + virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,stExpCocoNode* pCocoNode, const char* fileName)=0; + virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0; + virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, + cocos2d::ui::Widget* widget, + CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode) = 0; + protected: void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options); + std::string getWidgetReaderClassName(const std::string& classname); + std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget); std::string getGUIClassName(const std::string& name); cocos2d::ui::Widget *createGUI(const std::string& classname); @@ -115,7 +133,22 @@ class WidgetPropertiesReader0250 : public WidgetPropertiesReader virtual ~WidgetPropertiesReader0250(){}; virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName); + virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic); + + //added for binary parsing + virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode, + const char* fileName)override{return nullptr;} + + virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode){return nullptr;} + + virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, + cocos2d::ui::Widget* widget, + CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode) {} + virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); @@ -137,7 +170,7 @@ class WidgetPropertiesReader0250 : public WidgetPropertiesReader cocos2d::ui::Widget* widget, const rapidjson::Value& customOptions); }; - + class WidgetPropertiesReader0300 : public WidgetPropertiesReader { @@ -146,32 +179,40 @@ class WidgetPropertiesReader0300 : public WidgetPropertiesReader WidgetPropertiesReader0300(){}; virtual ~WidgetPropertiesReader0300(){}; - virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName); - virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic); - virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget*,const rapidjson::Value& options); + virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, + const char* fullPath, + const char* fileName); - virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForButtonFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForCheckBoxFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForImageViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForLabelFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForLabelAtlasFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForLabelBMFontFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForLoadingBarFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForSliderFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForTextFieldFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForLayoutFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForPageViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options); - virtual void setPropsForListViewFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + //add bin parse support + virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode, + const char* fileName)override; + + virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode); + + virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, + cocos2d::ui::Widget* widget, + CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode); + + virtual void setPropsForAllCustomWidgetFromBinary(const std::string& classType, + cocos2d::ui::Widget* widget, + CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode) { + //TODO: custom property + } + + virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic); + + virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, + cocos2d::ui::Widget* widget, + const rapidjson::Value& options); - virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options); virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType, cocos2d::ui::Widget* widget, const rapidjson::Value& customOptions); - - }; diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 02c2b210205d..894d4aa39b4b 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -25,7 +25,7 @@ THE SOFTWARE. #include "cocostudio/CocoStudio.h" #include "ui/CocosGUI.h" #include "audio/include/SimpleAudioEngine.h" -#include "ObjectFactory.h" +#include "base/ObjectFactory.h" using namespace cocos2d; using namespace ui; diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 0b4d610faa7c..aa662393ef7a 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -33,6 +33,7 @@ set(CS_SRC TriggerBase.cpp TriggerMng.cpp TriggerObj.cpp + CocoLoader.cpp WidgetReader/WidgetReader.cpp WidgetReader/ButtonReader/ButtonReader.cpp WidgetReader/CheckBoxReader/CheckBoxReader.cpp diff --git a/cocos/editor-support/cocostudio/CocoLoader.cpp b/cocos/editor-support/cocostudio/CocoLoader.cpp new file mode 100644 index 000000000000..90dfd12ecf91 --- /dev/null +++ b/cocos/editor-support/cocostudio/CocoLoader.cpp @@ -0,0 +1,196 @@ +#include "CocoLoader.h" + + +using namespace std; +using namespace rapidjson; + +namespace cocostudio{ + + +const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" }; +const char* kObjKeyName[] = { "__type" , "classname" }; +char g_Buff[2048]; + +Type stExpCocoNode::GetType(CocoLoader* pCoco) +{ + Type tType = kObjectType; + if(m_ObjIndex >= 0) + { + stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray(); + if( m_AttribIndex >= 0 ) + { + stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray; + tType = tpAttribDescArray[m_AttribIndex].m_Type; + + if(kFalseType == tType || kTrueType == tType) + { + char* szValue = (char*)m_szValue; + if(szValue[0] == '0') + { + return kFalseType; + } + else + { + return kTrueType; + } + } + + } + else + { + tType = kObjectType; + } + } + else + { + if(m_AttribIndex >= 0) + { + tType = (Type)m_ChildNum; + + if(kFalseType == tType || kTrueType == tType) + { + char* szValue = (char*)m_szValue; + if(szValue[0] == '0') + { + return kFalseType; + } + else + { + return kTrueType; + } + } + } + else + { + tType = kArrayType; + } + } + return tType; +} + +char* stExpCocoNode::GetName(CocoLoader* pCoco) +{ + char* szName = NULL ; + if(m_ObjIndex >= 0) + { + stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDescArray(); + if( m_AttribIndex >= 0 ) + { + stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray; + szName = (char*)tpAttribDescArray[m_AttribIndex].m_szName; + } + else + { + char* szValue = (char*)m_szValue; + if(szValue[0]) + { + szName = (char*)m_szValue; + } + else + { + szName = (char*)tpCocoObjectDesc[m_ObjIndex].m_szName; + } + } + } + else + { + if(m_AttribIndex >= 0) + { + char* pStringAddr = (char*)pCoco->GetCocoObjectDescArray() + pCoco->GetFileHeader()->m_lStringMemAddr ; + szName = m_ChildArray + pStringAddr; + } + else + { + szName = (char*)m_szValue; + } + } + return szName ; +} + +char* stExpCocoNode::GetValue() +{ + return (char*)m_szValue; +} + +int stExpCocoNode::GetChildNum() +{ + return m_ChildNum; +} + +stExpCocoNode* stExpCocoNode::GetChildArray() +{ + return (stExpCocoNode*)m_ChildArray; +} + +void stExpCocoNode::ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr) +{ + m_szValue = m_szValue + (uint64_t)pStringMemoryAddr; + if( -1 == m_AttribIndex ) + { + if(m_ChildNum > 0) + { + m_ChildArray = m_ChildArray + (uint64_t)cocoNodeAddr; + + stExpCocoNode* tpChildArray = (stExpCocoNode*)m_ChildArray; + for(int i = 0 ; i < m_ChildNum ; i++) + { + tpChildArray[i].ReBuild(cocoNodeAddr,pStringMemoryAddr); + } + } + } + +} + +CocoLoader::CocoLoader() +{ + m_pRootNode = NULL; + m_pObjectDescArray = NULL; +} + +CocoLoader::~CocoLoader() +{ + +} + +bool CocoLoader::ReadCocoBinBuff(char* pBinBuff) +{ + char* pTempBuff = pBinBuff; + + m_pFileHeader = (stCocoFileHeader*)pTempBuff; + pTempBuff += sizeof(stCocoFileHeader); + + char* pStartAddr = pTempBuff; + m_pObjectDescArray = (stExpCocoObjectDesc*)pStartAddr; + + char* pAttrAddr = pStartAddr + m_pFileHeader->m_lAttribMemAddr ; + char* pCocoMemAddr = pStartAddr + m_pFileHeader->m_CocoNodeMemAddr; + char* pStringAddr = pStartAddr + m_pFileHeader->m_lStringMemAddr ; + + m_pRootNode = (stExpCocoNode*)pCocoMemAddr; + + if(1 == m_pFileHeader->m_nFirstUsed) + { + for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++) + { + m_pObjectDescArray[i].ReBuild(pAttrAddr,pStringAddr) ; + } + m_pRootNode->ReBuild(pCocoMemAddr,pStringAddr); + + m_pFileHeader->m_nFirstUsed = 0; + } + + return true; +} + +stExpCocoObjectDesc* CocoLoader::GetCocoObjectDesc(const char* szObjDesc) +{ + for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++) + { + if(0 == strcmp((char*)m_pObjectDescArray[i].m_szName,szObjDesc)) + { + return &m_pObjectDescArray[i]; + } + } + return NULL; +} +} diff --git a/cocos/editor-support/cocostudio/CocoLoader.h b/cocos/editor-support/cocostudio/CocoLoader.h new file mode 100644 index 000000000000..5f59b496ee9a --- /dev/null +++ b/cocos/editor-support/cocostudio/CocoLoader.h @@ -0,0 +1,139 @@ +/**************************************************************************** + Copyright (c) 2013 cocos2d-x.org + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef _COCOLOADER_H +#define _COCOLOADER_H + +#include +#include +#include +#include +#include "json/rapidjson.h" +#include "json/document.h" + +#pragma pack (4) + +namespace cocostudio{ + + +struct stExpCocoAttribDesc +{ + rapidjson::Type m_Type; + uint64_t m_szName; + uint64_t m_szDefaultValue; +public: + + void ReBuild(char* pStringMemoryAddr) + { + m_szName = m_szName + (uint64_t)pStringMemoryAddr; + m_szDefaultValue = m_szDefaultValue + (uint64_t)pStringMemoryAddr; + } +}; + +struct stExpCocoObjectDesc +{ + uint32_t m_nAttribNum; + uint64_t m_szName; + uint64_t m_pAttribDescArray; + +public: + stExpCocoObjectDesc() + { + m_nAttribNum = 0; + m_szName = 0; + m_pAttribDescArray = 0; + } + void ReBuild(char* pAttribMemoryAddr,char* pStringMemoryAddr) + { + m_szName = m_szName + (uint64_t)pStringMemoryAddr; + m_pAttribDescArray = m_pAttribDescArray + (uint64_t)pAttribMemoryAddr; + stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*)m_pAttribDescArray; + for(uint32_t i = 0 ; i < m_nAttribNum ; i++) + { + tpAttribDescArray[i].ReBuild(pStringMemoryAddr); + } + } + +}; + +class CocoLoader; + +struct stExpCocoNode +{ +protected: + int32_t m_ObjIndex; + int32_t m_AttribIndex; + uint32_t m_ChildNum; + uint64_t m_szValue; + uint64_t m_ChildArray; + +public: + rapidjson::Type GetType(CocoLoader* pCoco); + char* GetName(CocoLoader* pCoco); + char* GetValue(); + int GetChildNum(); + stExpCocoNode* GetChildArray(); + +public: + inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr); + void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false); +}; + + +struct stCocoFileHeader +{ + char m_FileDesc[32]; + char m_Version[32]; + uint32_t m_nFirstUsed; + uint32_t m_ObjectCount; + uint64_t m_lAttribMemAddr; + uint64_t m_CocoNodeMemAddr; + uint64_t m_lStringMemAddr; + +}; + + +class CocoLoader +{ +private: + stCocoFileHeader* m_pFileHeader; + stExpCocoNode* m_pRootNode; + stExpCocoObjectDesc* m_pObjectDescArray; + +public: + CocoLoader(); + ~CocoLoader(); + +public: + bool ReadCocoBinBuff(char* pBinBuff); + stCocoFileHeader* GetFileHeader(){return m_pFileHeader;} + stExpCocoNode* GetRootCocoNode(){return m_pRootNode;} + stExpCocoObjectDesc* GetCocoObjectDescArray(){return m_pObjectDescArray;} + stExpCocoObjectDesc* GetCocoObjectDesc(const char* szObjDesc); +}; + +} + +#pragma pack () +#endif diff --git a/cocos/editor-support/cocostudio/ObjectFactory.cpp b/cocos/editor-support/cocostudio/ObjectFactory.cpp deleted file mode 100644 index 26bb4d7c359c..000000000000 --- a/cocos/editor-support/cocostudio/ObjectFactory.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013-2014 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "ObjectFactory.h" -#include "ui/UIWidget.h" -#include "cocostudio/WidgetReader/WidgetReaderProtocol.h" - -using namespace cocos2d; - -namespace cocostudio { - -ObjectFactory::TInfo::TInfo(void) -:_class("") -,_fun(nullptr) -{ -} - -ObjectFactory::TInfo::TInfo(const std::string& type, Instance ins) -:_class(type) -,_fun(ins) -{ - ObjectFactory::getInstance()->registerType(*this); -} - -ObjectFactory::TInfo::TInfo(const TInfo &t) -{ - _class = t._class; - _fun = t._fun; -} - -ObjectFactory::TInfo::~TInfo(void) -{ - _class = ""; - _fun = nullptr; -} - -ObjectFactory::TInfo& ObjectFactory::TInfo::operator= (const TInfo &t) -{ - _class = t._class; - _fun = t._fun; - return *this; -} - - -ObjectFactory* ObjectFactory::_sharedFactory = nullptr; - -ObjectFactory::ObjectFactory(void) -{ - -} - -ObjectFactory::~ObjectFactory(void) -{ - _typeMap.clear(); -} - -ObjectFactory* ObjectFactory::getInstance() -{ - if ( nullptr == _sharedFactory) - { - _sharedFactory = new ObjectFactory(); - } - return _sharedFactory; -} - -void ObjectFactory::destroyInstance() -{ - CC_SAFE_DELETE(_sharedFactory); -} - -Ref* ObjectFactory::createObject(const std::string &name) -{ - Ref *o = nullptr; - do - { - const TInfo t = _typeMap[name]; - CC_BREAK_IF(t._fun == nullptr); - o = t._fun(); - } while (0); - - return o; -} - -Component* ObjectFactory::createComponent(const std::string &name) -{ - std::string comName; - if (name == "CCSprite" || name == "CCTMXTiledMap" || name == "CCParticleSystemQuad" || name == "CCArmature" || name == "GUIComponent") - { - comName = "ComRender"; - } - else if (name == "CCComAudio" || name == "CCBackgroundAudio") - { - comName = "ComAudio"; - } - else if (name == "CCComController") - { - comName = "ComController"; - } - else if (name == "CCComAttribute") - { - comName = "ComAttribute"; - } - else if (name == "CCScene") - { - comName = "Scene"; - } - else - { - CCASSERT(false, "Unregistered Component!"); - } - Ref *o = NULL; - do - { - const TInfo t = _typeMap[comName]; - CC_BREAK_IF(t._fun == NULL); - o = t._fun(); - } while (0); - - return (Component*)o; - -} - -ui::Widget* ObjectFactory::createGUI(std::string name) -{ - Ref* object = nullptr; - - if (name == "Panel") - { - name = "Layout"; - } - else if (name == "TextArea") - { - name = "Text"; - } - else if (name == "TextButton") - { - name = "Button"; - } - else if (name == "Label") - { - name = "Text"; - } - else if (name == "LabelAtlas") - { - name = "TextAtlas"; - } - else if (name == "LabelBMFont") - { - name = "TextBMFont"; - } - - do - { - const TInfo t = _typeMap[name]; - CC_BREAK_IF(t._fun == NULL); - object = t._fun(); - } while (0); - - return static_cast(object); -} - -WidgetReaderProtocol* ObjectFactory::createWidgetReaderProtocol(std::string name) -{ - Ref* object = NULL; - - do - { - const TInfo t = _typeMap[name]; - CC_BREAK_IF(t._fun == NULL); - object = t._fun(); - } while (0); - - return dynamic_cast(object); -} - -void ObjectFactory::registerType(const TInfo &t) -{ - _typeMap.insert(std::make_pair(t._class, t)); -} - -} diff --git a/cocos/editor-support/cocostudio/ObjectFactory.h b/cocos/editor-support/cocostudio/ObjectFactory.h deleted file mode 100644 index 3d6c675ec710..000000000000 --- a/cocos/editor-support/cocostudio/ObjectFactory.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013-2014 Chukong Technologies Inc. - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __TRIGGERFACTORY_H__ -#define __TRIGGERFACTORY_H__ - -#include "cocos2d.h" -#include -#include - -namespace cocos2d -{ - namespace ui - { - class Widget; - } -} -namespace cocostudio -{ - class WidgetReaderProtocol; -} - -namespace cocostudio { - -class ObjectFactory -{ -public: - typedef cocos2d::Ref* (*Instance)(void); - struct TInfo - { - TInfo(void); - TInfo(const std::string& type, Instance ins = NULL); - TInfo(const TInfo &t); - ~TInfo(void); - TInfo& operator= (const TInfo &t); - std::string _class; - Instance _fun; - }; - typedef std::unordered_map FactoryMap; - - static ObjectFactory* getInstance(); - static void destroyInstance(); - cocos2d::Ref* createObject(const std::string &name); - cocos2d::Component* createComponent(const std::string &name); - cocos2d::ui::Widget* createGUI(std::string name); - WidgetReaderProtocol* createWidgetReaderProtocol(std::string name); - void registerType(const TInfo &t); - void removeAll(); - -protected: - ObjectFactory(void); - virtual ~ObjectFactory(void); -private: - static ObjectFactory *_sharedFactory; - FactoryMap _typeMap; -}; - -} - -#endif diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index b26507dbe503..7fc1ea8177a6 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -2,13 +2,34 @@ #include "ButtonReader.h" #include "ui/UIButton.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { - static ButtonReader* instanceButtonReader = NULL; + + static const char* P_Scale9Enable = "scale9Enable"; + static const char* P_NormalData = "normalData"; + static const char* P_PressedData = "pressedData"; + static const char* P_DisabledData = "disabledData"; + static const char* P_Text = "text"; + static const char* P_CapInsetsX = "capInsetsX"; + static const char* P_CapInsetsY = "capInsetsY"; + static const char* P_CapInsetsWidth = "capInsetsWidth"; + static const char* P_CapInsetsHeight = "capInsetsHeight"; + static const char* P_Scale9Width = "scale9Width"; + static const char* P_Scale9Height = "scale9Height"; + static const char* P_TextColorR = "textColorR"; + static const char* P_TextColorG = "textColorG"; + static const char* P_TextColorB = "textColorB"; + static const char* P_FontSize = "fontSize"; + static const char* P_FontName = "fontName"; + + + + static ButtonReader* instanceButtonReader = nullptr; IMPLEMENT_CLASS_WIDGET_READER_INFO(ButtonReader) @@ -36,78 +57,181 @@ namespace cocostudio CC_SAFE_DELETE(instanceButtonReader); } + void ButtonReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + Button *button = static_cast(widget); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + this->beginSetBasicProperties(widget); + + float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; + int cri = 255, cgi = 255, cbi = 255; + float scale9Width = 0.0f, scale9Height = 0.0f; + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); +// CCLOG("Button: key = %s, value = %d", key.c_str(), i); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + + else if (key == P_Scale9Enable) { + button->setScale9Enabled(valueToBool(value)); + } + else if (key == P_NormalData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + button->loadTextureNormal(backgroundValue, imageFileNameType); + + } + else if (key == P_PressedData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + button->loadTexturePressed(backgroundValue, imageFileNameType); + + } + else if (key == P_DisabledData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + button->loadTextureDisabled(backgroundValue, imageFileNameType); + + }else if (key == P_Text){ + button->setTitleText(value); + } + else if(key == P_CapInsetsX){ + capsx = valueToFloat(value); + }else if(key == P_CapInsetsY){ + capsy = valueToFloat(value); + }else if(key == P_CapInsetsWidth){ + capsWidth = valueToFloat(value); + }else if(key == P_CapInsetsHeight){ + capsHeight = valueToFloat(value); + }else if(key == P_Scale9Width){ + scale9Width = valueToFloat(value); + }else if(key == P_Scale9Height){ + scale9Height = valueToFloat(value); + }else if(key == P_TextColorR){ + cri = valueToInt(value); + }else if(key == P_TextColorG){ + cgi = valueToInt(value); + }else if(key == P_TextColorB){ + cbi = valueToInt(value); + }else if(key == P_FontSize){ + button->setTitleFontSize(valueToFloat(value)); + }else if(key == P_FontName){ + button->setTitleFontName(value); + } + + } //end of for loop + + this->endSetBasicProperties(widget); + + if (button->isScale9Enabled()) { + button->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); + button->setSize(Size(scale9Width, scale9Height)); + } + + button->setTitleColor(Color3B(cri, cgi, cbi)); + + + } + void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); Button* button = static_cast(widget); - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); button->setScale9Enabled(scale9Enable); - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - std::string normalTexturePath = this->getResourcePath(normalDic, "path", (Widget::TextureResType)normalType); + const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_NormalData); + int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType); + std::string normalTexturePath = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType); button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType); - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); + const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_PressedData); + int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType); - std::string pressedTexturePath = this->getResourcePath(pressedDic, "path", (Widget::TextureResType)pressedType); + std::string pressedTexturePath = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType); button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType); - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); + const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_DisabledData); + int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType); - std::string disabledTexturePath = this->getResourcePath(disabledDic, "path", (Widget::TextureResType)disabledType); + std::string disabledTexturePath = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType); button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType); if (scale9Enable) { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); + float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); + float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth); + float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight); button->setCapInsets(Rect(cx, cy, cw, ch)); - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); + bool sw = DICTOOL->checkObjectExist_json(options, P_Scale9Width); + bool sh = DICTOOL->checkObjectExist_json(options, P_Scale9Height); if (sw && sh) { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); + float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width); + float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height); button->setSize(Size(swf, shf)); } } - bool tt = DICTOOL->checkObjectExist_json(options, "text"); + bool tt = DICTOOL->checkObjectExist_json(options, P_Text); if (tt) { - const char* text = DICTOOL->getStringValue_json(options, "text"); + const char* text = DICTOOL->getStringValue_json(options, P_Text); if (text) { button->setTitleText(text); } } - bool cr = DICTOOL->checkObjectExist_json(options, "textColorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "textColorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "textColorB"); - int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255; - int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255; - int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255; + bool cr = DICTOOL->checkObjectExist_json(options, P_TextColorR); + bool cg = DICTOOL->checkObjectExist_json(options, P_TextColorG); + bool cb = DICTOOL->checkObjectExist_json(options, P_TextColorB); + int cri = cr?DICTOOL->getIntValue_json(options, P_TextColorR):255; + int cgi = cg?DICTOOL->getIntValue_json(options, P_TextColorG):255; + int cbi = cb?DICTOOL->getIntValue_json(options, P_TextColorB):255; button->setTitleColor(Color3B(cri,cgi,cbi)); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize); if (fs) { - button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + button->setTitleFontSize(DICTOOL->getIntValue_json(options, P_FontSize)); } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + bool fn = DICTOOL->checkObjectExist_json(options, P_FontName); if (fn) { - button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName")); + button->setTitleFontName(DICTOOL->getStringValue_json(options, P_FontName)); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h index 379897676ab9..d2ba76cbde31 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h @@ -42,6 +42,7 @@ namespace cocostudio virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 0d24ac68b2d5..6cf60f4f8409 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -2,12 +2,19 @@ #include "CheckBoxReader.h" #include "ui/UICheckBox.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_BackGroundBoxData = "backGroundBoxData"; + static const char* P_BackGroundBoxSelectedData = "backGroundBoxSelectedData"; + static const char* P_FrontCrossData = "frontCrossData"; + static const char* P_BackGroundBoxDisabledData = "backGroundBoxDisabledData"; + static const char* P_FrontCrossDisabledData = "frontCrossDisabledData"; + static CheckBoxReader* instanceCheckBoxReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader) @@ -31,41 +38,113 @@ namespace cocostudio return instanceCheckBoxReader; } + void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + + CheckBox *checkBox = static_cast(widget); + this->beginSetBasicProperties(widget); + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); +// CCLOG("key = %s, index : %d", key.c_str(), i); + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if (key == P_BackGroundBoxData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + checkBox->loadTextureBackGround(backgroundValue, imageFileNameType); + }else if(key == P_BackGroundBoxSelectedData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType); + }else if(key == P_FrontCrossData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType); + }else if(key == P_BackGroundBoxDisabledData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType); + }else if (key == P_FrontCrossDisabledData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType); + } +// else if (key == "selectedState"){ +// checkBox->setSelectedState(valueToBool(value)); +// } + } + + this->endSetBasicProperties(widget); + + + } + void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); CheckBox* checkBox = static_cast(widget); - //load background image - const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData"); - int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType"); - std::string backGroundTexturePath = this->getResourcePath(backGroundDic, "path", (Widget::TextureResType)backGroundType); + const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxData); + int backGroundType = DICTOOL->getIntValue_json(backGroundDic,P_ResourceType); + std::string backGroundTexturePath = this->getResourcePath(backGroundDic, P_Path, (Widget::TextureResType)backGroundType); checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType); //load background selected image - const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData"); - int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType"); - std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, "path", (Widget::TextureResType)backGroundSelectedType); + const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxSelectedData); + int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, P_ResourceType); + std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, P_Path, (Widget::TextureResType)backGroundSelectedType); checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType); //load frontCross image - const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData"); - int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType"); - std::string frontCrossFileName = this->getResourcePath(frontCrossDic, "path", (Widget::TextureResType)frontCrossType); + const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossData); + int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, P_ResourceType); + std::string frontCrossFileName = this->getResourcePath(frontCrossDic, P_Path, (Widget::TextureResType)frontCrossType); checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType); //load backGroundBoxDisabledData - const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData"); - int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType"); - std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, "path", (Widget::TextureResType)backGroundDisabledType); + const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxDisabledData); + int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, P_ResourceType); + std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, P_Path, (Widget::TextureResType)backGroundDisabledType); checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType); ///load frontCrossDisabledData - const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData"); - int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType"); - std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, "path", (Widget::TextureResType)frontCrossDisabledType); + const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossDisabledData); + int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, P_ResourceType); + std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, P_Path, (Widget::TextureResType)frontCrossDisabledType); checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType); diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h index 1f9aa3b89e75..1c934dfb991e 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h @@ -41,6 +41,7 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index 7518098731fe..537fdeebfbb5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -2,12 +2,23 @@ #include "ImageViewReader.h" #include "ui/UIImageView.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_Scale9Enable = "scale9Enable"; + static const char* P_FileNameData = "fileNameData"; + static const char* P_CapInsetsX = "capInsetsX"; + static const char* P_CapInsetsY = "capInsetsY"; + static const char* P_CapInsetsWidth = "capInsetsWidth"; + static const char* P_CapInsetsHeight = "capInsetsHeight"; + static const char* P_Scale9Width = "scale9Width"; + static const char* P_Scale9Height = "scale9Height"; + + static ImageViewReader* instanceImageViewReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(ImageViewReader) @@ -31,6 +42,64 @@ namespace cocostudio return instanceImageViewReader; } + void ImageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + ImageView* imageView = static_cast(widget); + this->beginSetBasicProperties(widget); + float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if (key == P_Scale9Enable) { + imageView->setScale9Enabled(valueToBool(value)); + } + else if (key == P_FileNameData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + imageView->loadTexture(backgroundValue, imageFileNameType); + + } + else if(key == P_Scale9Width){ + imageView->setSize(Size(valueToFloat(value), imageView->getSize().height)); + }else if(key == P_Scale9Height){ + imageView->setSize(Size(imageView->getSize().width, valueToFloat(value))); + } + else if(key == P_CapInsetsX){ + capsx = valueToFloat(value); + }else if(key == P_CapInsetsY){ + capsy = valueToFloat(value); + }else if(key == P_CapInsetsWidth){ + capsWidth = valueToFloat(value); + }else if(key == P_CapInsetsHeight){ + capsHeight = valueToFloat(value); + } + + } //end of for loop + + if (imageView->isScale9Enabled()) { + imageView->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); + } + + this->endSetBasicProperties(widget); + + } + void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -39,36 +108,36 @@ namespace cocostudio ImageView* imageView = static_cast(widget); - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType); + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_FileNameData); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); + std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); - bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable"); + bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, P_Scale9Enable); bool scale9Enable = false; if (scale9EnableExist) { - scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); } imageView->setScale9Enabled(scale9Enable); if (scale9Enable) { - bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width"); - bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height"); + bool sw = DICTOOL->checkObjectExist_json(options, P_Scale9Width); + bool sh = DICTOOL->checkObjectExist_json(options, P_Scale9Height); if (sw && sh) { - float swf = DICTOOL->getFloatValue_json(options, "scale9Width"); - float shf = DICTOOL->getFloatValue_json(options, "scale9Height"); + float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width); + float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height); imageView->setSize(Size(swf, shf)); } - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); + float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); + float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth); + float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight); imageView->setCapInsets(Rect(cx, cy, cw, ch)); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h index 4b633e6e8fa0..27dd31eab502 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.h @@ -41,6 +41,7 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 926083f0b5f1..7c381ea5f5cf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -2,12 +2,35 @@ #include "LayoutReader.h" #include "ui/UILayout.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_CapInsetsX = "capInsetsX"; + static const char* P_CapInsetsY = "capInsetsY"; + static const char* P_CapInsetsWidth = "capInsetsWidth"; + static const char* P_CapInsetsHeight = "capInsetsHeight"; + static const char* P_ClipAble = "clipAble"; + static const char* P_BackGroundScale9Enable = "backGroundScale9Enable"; + static const char* P_BgColorR = "bgColorR"; + static const char* P_BgColorG = "bgColorG"; + static const char* P_BgColorB = "bgColorB"; + static const char* P_BgStartColorR = "bgStartColorR"; + static const char* P_BgStartColorG = "bgStartColorG"; + static const char* P_BgStartColorB = "bgStartColorB"; + static const char* P_BgEndColorR = "bgEndColorR"; + static const char* P_BgEndColorG = "bgEndColorG"; + static const char* P_BgEndColorB = "bgEndColorB"; + static const char* P_VectorX = "vectorX"; + static const char* P_VectorY = "vectorY"; + static const char* P_BgColorOpacity = "bgColorOpacity"; + static const char* P_ColorType = "colorType"; + static const char* P_BackGroundImageData = "backGroundImageData"; + static const char* P_LayoutType = "layoutType"; + static LayoutReader* instanceLayoutReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(LayoutReader) @@ -31,6 +54,119 @@ namespace cocostudio return instanceLayoutReader; } + void LayoutReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + Layout* panel = static_cast(widget); + + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + this->beginSetBasicProperties(widget); + + int cr=0, cg = 0, cb = 0; + int scr=0, scg=0, scb=0; + int ecr=0, ecg=0, ecb= 0; + float bgcv1 = 0.0f, bgcv2= 0.0f; + float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; + Layout::Type layoutType; + int bgColorOpacity = panel->getBackGroundColorOpacity(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if(key == P_AdaptScreen){ + _isAdaptScreen = valueToBool(value); + } + else if( key == P_ClipAble){ + panel->setClippingEnabled(valueToBool(value)); + }else if(key == P_BackGroundScale9Enable){ + panel->setBackGroundImageScale9Enabled(valueToBool(value)); + }else if(key == P_BgColorR){ + cr = valueToInt(value); + }else if(key == P_BgColorG){ + cg = valueToInt(value); + }else if(key == P_BgColorB) + { + cb = valueToInt(value); + }else if(key == P_BgStartColorR){ + scr = valueToInt(value); + }else if(key == P_BgStartColorG){ + scg = valueToInt(value); + }else if(key == P_BgStartColorB) + { + scb = valueToInt(value); + } + else if(key == P_BgEndColorR){ + ecr = valueToInt(value); + }else if(key == P_BgEndColorG){ + ecg = valueToInt(value); + }else if(key == P_BgEndColorB) + { + ecb = valueToInt(value); + }else if (key == P_VectorX){ + bgcv1 = valueToFloat(value); + }else if(key == P_VectorY){ + bgcv2 = valueToFloat(value); + }else if(key == P_BgColorOpacity){ + bgColorOpacity = valueToInt(value); + }else if( key == P_ColorType){ + panel->setBackGroundColorType(Layout::BackGroundColorType(valueToInt(value))); + }else if (key == P_BackGroundImageData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + if (backGroundChildren) { + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + panel->setBackGroundImage(backgroundValue, imageFileNameType); + } + + }else if(key == P_CapInsetsX){ + capsx = valueToFloat(value); + }else if(key == P_CapInsetsY){ + capsy = valueToFloat(value); + }else if(key == P_CapInsetsWidth){ + capsWidth = valueToFloat(value); + }else if(key == P_CapInsetsHeight){ + capsHeight = valueToFloat(value); + }else if (key == P_LayoutType){ + layoutType = (Layout::Type)valueToInt(value); + } + + } + + + panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); + panel->setBackGroundColor(Color3B(cr, cg, cb)); + panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2)); + + + panel->setBackGroundColorOpacity(bgColorOpacity); + + + panel->setBackGroundImageColor(Color3B(_color.r, _color.g, _color.b)); + + panel->setBackGroundImageOpacity(_opacity); + + if (panel->isBackGroundImageScale9Enabled()) { + panel->setBackGroundImageCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); + } + + panel->setLayoutType(layoutType); + this->endSetBasicProperties(widget); + + } + void LayoutReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -39,7 +175,7 @@ namespace cocostudio /* adapt screen gui */ float w = 0, h = 0; - bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); + bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen); if (adaptScrenn) { Size screenSize = CCDirector::getInstance()->getWinSize(); @@ -48,60 +184,61 @@ namespace cocostudio } else { - w = DICTOOL->getFloatValue_json(options, "width"); - h = DICTOOL->getFloatValue_json(options, "height"); + w = DICTOOL->getFloatValue_json(options, P_Width); + h = DICTOOL->getFloatValue_json(options, P_Height); } panel->setSize(Size(w, h)); /**/ - panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble")); + panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, P_ClipAble)); - bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable"); + bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, P_BackGroundScale9Enable); panel->setBackGroundImageScale9Enabled(backGroundScale9Enable); - int cr = DICTOOL->getIntValue_json(options, "bgColorR"); - int cg = DICTOOL->getIntValue_json(options, "bgColorG"); - int cb = DICTOOL->getIntValue_json(options, "bgColorB"); + int cr = DICTOOL->getIntValue_json(options, P_BgColorR); + int cg = DICTOOL->getIntValue_json(options, P_BgColorG); + int cb = DICTOOL->getIntValue_json(options, P_BgColorB); - int scr = DICTOOL->getIntValue_json(options, "bgStartColorR"); - int scg = DICTOOL->getIntValue_json(options, "bgStartColorG"); - int scb = DICTOOL->getIntValue_json(options, "bgStartColorB"); + int scr = DICTOOL->getIntValue_json(options, P_BgStartColorR); + int scg = DICTOOL->getIntValue_json(options, P_BgStartColorG); + int scb = DICTOOL->getIntValue_json(options, P_BgStartColorB); - int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR"); - int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG"); - int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB"); + int ecr = DICTOOL->getIntValue_json(options, P_BgEndColorR); + int ecg = DICTOOL->getIntValue_json(options, P_BgEndColorG); + int ecb = DICTOOL->getIntValue_json(options, P_BgEndColorB); - float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX"); - float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY"); + float bgcv1 = DICTOOL->getFloatValue_json(options, P_VectorX); + float bgcv2 = DICTOOL->getFloatValue_json(options, P_VectorY); panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2)); - int co = DICTOOL->getIntValue_json(options, "bgColorOpacity"); + int co = DICTOOL->getIntValue_json(options, P_BgColorOpacity); - int colorType = DICTOOL->getIntValue_json(options, "colorType"); + int colorType = DICTOOL->getIntValue_json(options, P_ColorType); panel->setBackGroundColorType(Layout::BackGroundColorType(colorType)); panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb)); panel->setBackGroundColor(Color3B(cr, cg, cb)); panel->setBackGroundColorOpacity(co); - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType); + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BackGroundImageData); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); + std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); panel->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); - + if (backGroundScale9Enable) { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); + float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); + float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth); + float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight); panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch)); } - panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, "layoutType")); - int bgimgcr = DICTOOL->getIntValue_json(options, "colorR"); - int bgimgcg = DICTOOL->getIntValue_json(options, "colorG"); - int bgimgcb = DICTOOL->getIntValue_json(options, "colorB"); + panel->setLayoutType((Layout::Type)DICTOOL->getIntValue_json(options, P_LayoutType)); + + int bgimgcr = DICTOOL->getIntValue_json(options, P_ColorR); + int bgimgcg = DICTOOL->getIntValue_json(options, P_ColorG); + int bgimgcb = DICTOOL->getIntValue_json(options, P_ColorB); panel->setBackGroundImageColor(Color3B(bgimgcr, bgimgcg, bgimgcb)); diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h index 8d7387d39529..77518df73860 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.h @@ -41,6 +41,7 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index b9a936b2dcaf..cf1bdbee4e61 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -2,12 +2,16 @@ #include "ListViewReader.h" #include "ui/UIListView.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_Direction = "direction"; + static const char* P_ItemMargin = "itemMargin"; + static ListViewReader* instanceListViewReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(ListViewReader) @@ -31,6 +35,30 @@ namespace cocostudio return instanceListViewReader; } + void ListViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode) + { + ScrollViewReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + ListView* listView = static_cast(widget); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + if (key == P_Direction) { + listView->setDirection((ScrollView::Direction)valueToInt(value)); + } + else if(key == P_Gravity){ + listView->setGravity((ListView::Gravity)valueToInt(value)); + }else if(key == P_ItemMargin){ + listView->setItemsMargin(valueToFloat(value)); + } + + } //end of for loop + } + void ListViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { ScrollViewReader::setPropsFromJsonDictionary(widget, options); @@ -38,13 +66,13 @@ namespace cocostudio ListView* listView = static_cast(widget); - int direction = DICTOOL->getFloatValue_json(options, "direction"); + int direction = DICTOOL->getFloatValue_json(options, P_Direction); listView->setDirection((ScrollView::Direction)direction); - ListView::Gravity gravity = (ListView::Gravity)DICTOOL->getIntValue_json(options, "gravity"); + ListView::Gravity gravity = (ListView::Gravity)DICTOOL->getIntValue_json(options, P_Gravity); listView->setGravity(gravity); - float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin"); + float itemMargin = DICTOOL->getFloatValue_json(options, P_ItemMargin); listView->setItemsMargin(itemMargin); } } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h index 83bb88d79c03..226ac4fac8a9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.h @@ -41,6 +41,7 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index c5452a908bcb..92c23aa86d70 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -2,12 +2,23 @@ #include "LoadingBarReader.h" #include "ui/UILoadingBar.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; +using namespace cocostudio; namespace cocostudio { + static const char* P_Scale9Enable = "scale9Enable"; + static const char* P_CapInsetsX = "capInsetsX"; + static const char* P_CapInsetsY = "capInsetsY"; + static const char* P_CapInsetsWidth = "capInsetsWidth"; + static const char* P_CapInsetsHeight = "capInsetsHeight"; + static const char* P_TextureData = "textureData"; + static const char* P_Direction = "direction"; + static const char* P_Percent = "percent"; + static LoadingBarReader* instanceLoadingBar = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader) @@ -31,6 +42,64 @@ namespace cocostudio return instanceLoadingBar; } + void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + LoadingBar* loadingBar = static_cast(widget); + this->beginSetBasicProperties(widget); + float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f; + int percent = loadingBar->getPercent(); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if (key == P_Scale9Enable) { + loadingBar->setScale9Enabled(valueToBool(value)); + } + else if (key == P_TextureData){ + + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + loadingBar->loadTexture(backgroundValue, imageFileNameType); + + } + else if(key == P_CapInsetsX){ + capsx = valueToFloat(value); + }else if(key == P_CapInsetsY){ + capsy = valueToFloat(value); + }else if(key == P_CapInsetsWidth){ + capsWidth = valueToFloat(value); + }else if(key == P_CapInsetsHeight){ + capsHeight = valueToFloat(value); + }else if(key == P_Direction){ + loadingBar->setDirection((LoadingBar::Direction)valueToInt(value)); + }else if(key == P_Percent){ + percent = valueToInt(value); + } + + } //end of for loop + + if (loadingBar->isScale9Enabled()) { + loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight)); + } + loadingBar->setPercent(percent); + this->endSetBasicProperties(widget); + } + void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -38,33 +107,33 @@ namespace cocostudio LoadingBar* loadingBar = static_cast(widget); - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType); + const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_TextureData); + int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); + std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); /* gui mark add load bar scale9 parse */ - bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); loadingBar->setScale9Enabled(scale9Enable); if (scale9Enable) { - float cx = DICTOOL->getFloatValue_json(options, "capInsetsX"); - float cy = DICTOOL->getFloatValue_json(options, "capInsetsY"); - float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth"); - float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight"); + float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); + float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); + float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth); + float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight); loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); - float width = DICTOOL->getFloatValue_json(options, "width"); - float height = DICTOOL->getFloatValue_json(options, "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, "direction"))); - loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent")); + loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction))); + loadingBar->setPercent(DICTOOL->getIntValue_json(options, P_Percent)); WidgetReader::setColorPropsFromJsonDictionary(widget, options); diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h index 0138cad6cddc..7a08aa7e04bd 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.h @@ -41,6 +41,7 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index a5111906bece..048985cac12f 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -2,13 +2,15 @@ #include "PageViewReader.h" #include "ui/UIPageView.h" +#include "ui/UILayout.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { - static PageViewReader* instancePageViewReader = NULL; + static PageViewReader* instancePageViewReader = nullptr; IMPLEMENT_CLASS_WIDGET_READER_INFO(PageViewReader) @@ -31,6 +33,11 @@ namespace cocostudio return instancePageViewReader; } + void PageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + } + void PageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { LayoutReader::setPropsFromJsonDictionary(widget, options); diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h index 1fa59db3e51f..63f6f446abd2 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* cocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index 956b0e113a3f..b2ab36cf4736 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -2,13 +2,19 @@ #include "ScrollViewReader.h" #include "ui/UIScrollView.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { - static ScrollViewReader* instanceScrollViewReader = NULL; + static const char* P_InnerWidth = "innerWidth"; + static const char* P_InnerHeight = "innerHeight"; + static const char* P_Direction = "direction"; + static const char* P_BounceEnable = "bounceEnable"; + + static ScrollViewReader* instanceScrollViewReader = nullptr; IMPLEMENT_CLASS_WIDGET_READER_INFO(ScrollViewReader) @@ -31,18 +37,47 @@ namespace cocostudio return instanceScrollViewReader; } + void ScrollViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode) + { + //TODO::need to refactor... + LayoutReader::setPropsFromBinary(widget, cocoLoader, cocoNode); + + ScrollView* scrollView = static_cast(widget); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + float innerWidth; + float innerHeight; + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + if (key == P_InnerWidth) { + innerWidth = valueToFloat(value); + } + else if(key == P_InnerHeight){ + innerHeight = valueToFloat(value); + }else if(key == P_Direction){ + scrollView->setDirection((ScrollView::Direction)valueToInt(value)); + }else if(key == P_BounceEnable){ + scrollView->setBounceEnabled(valueToBool(value)); + } + + } //end of for loop + scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); + + } + void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { LayoutReader::setPropsFromJsonDictionary(widget, options); ScrollView* scrollView = static_cast(widget); - float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth"); - float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight"); + float innerWidth = DICTOOL->getFloatValue_json(options, P_InnerWidth); + float innerHeight = DICTOOL->getFloatValue_json(options, P_InnerHeight); scrollView->setInnerContainerSize(Size(innerWidth, innerHeight)); - int direction = DICTOOL->getFloatValue_json(options, "direction"); + int direction = DICTOOL->getFloatValue_json(options, P_Direction); scrollView->setDirection((ScrollView::Direction)direction); - scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable")); + scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, P_BounceEnable)); LayoutReader::setColorPropsFromJsonDictionary(widget, options); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h index 0e3d6e7124f7..ce95c3b5f76c 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index ca92886ef672..e117f61e24a1 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -2,12 +2,24 @@ #include "SliderReader.h" #include "ui/UISlider.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_Scale9Enable = "scale9Enable"; + static const char* P_Percent = "percent"; + static const char* P_BarFileNameData = "barFileNameData"; + static const char* P_Length = "length"; + static const char* P_BallNormalData = "ballNormalData"; + static const char* P_BallPressedData = "ballPressedData"; + static const char* P_BallDisabledData = "ballDisabledData"; + static const char* P_ProgressBarData = "progressBarData"; + + static const char* P_BarFileName = "barFileName"; + static SliderReader* instanceSliderReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader) @@ -31,6 +43,95 @@ namespace cocostudio return instanceSliderReader; } + void SliderReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode) + { + this->beginSetBasicProperties(widget); + + Slider* slider = static_cast(widget); + + float barLength = 0.0f; + int percent = slider->getPercent(); + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + //control custom properties + else if (key == P_Scale9Enable) { + slider->setScale9Enabled(valueToBool(value)); + } + else if(key == P_Percent){ + percent = valueToInt(value); + }else if(key == P_BarFileNameData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + slider->loadBarTexture(backgroundValue, imageFileNameType); + + }else if(key == P_Length){ + barLength = valueToFloat(value); + }else if(key == P_BallNormalData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + slider->loadSlidBallTextureNormal(backgroundValue, imageFileNameType); + + }else if(key == P_BallPressedData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + slider->loadSlidBallTexturePressed(backgroundValue, imageFileNameType); + + }else if(key == P_BallDisabledData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + slider->loadSlidBallTextureDisabled(backgroundValue, imageFileNameType); + + }else if(key == P_ProgressBarData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + slider->loadProgressBarTexture(backgroundValue, imageFileNameType); + + } + + } //end of for loop + + if (slider->isScale9Enabled()) { + slider->setSize(Size(barLength, slider->getContentSize().height)); + } + slider->setPercent(percent); + + this->endSetBasicProperties(widget); + } + void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -38,19 +139,19 @@ namespace cocostudio Slider* slider = static_cast(widget); - bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable"); + bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); slider->setScale9Enabled(barTextureScale9Enable); - slider->setPercent(DICTOOL->getIntValue_json(options, "percent")); + slider->setPercent(DICTOOL->getIntValue_json(options, P_Percent)); - bool bt = DICTOOL->checkObjectExist_json(options, "barFileName"); - float barLength = DICTOOL->getFloatValue_json(options, "length"); + bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName); + float barLength = DICTOOL->getFloatValue_json(options, P_Length); if (bt) { - const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData"); - int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType"); - std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (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) @@ -60,28 +161,28 @@ namespace cocostudio } //loading normal slider ball texture - const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData"); - int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType"); - std::string imageFileName = this->getResourcePath(normalDic, "path", (Widget::TextureResType)normalType); + 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); slider->loadSlidBallTextureNormal(imageFileName, (Widget::TextureResType)normalType); //loading slider ball press texture - const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData"); - int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType"); - std::string pressedFileName = this->getResourcePath(pressedDic, "path", (Widget::TextureResType)pressedType); + const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_BallPressedData); + int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType); + std::string pressedFileName = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType); slider->loadSlidBallTexturePressed(pressedFileName, (Widget::TextureResType)pressedType); //loading silder ball disable texture - const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData"); - int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType"); - std::string disabledFileName = this->getResourcePath(disabledDic, "path", (Widget::TextureResType)disabledType); + const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_BallDisabledData); + int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType); + std::string disabledFileName = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType); slider->loadSlidBallTextureDisabled(disabledFileName, (Widget::TextureResType)disabledType); //load slider progress texture - const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData"); - int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType"); - std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (Widget::TextureResType)progressBarType); + const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, P_ProgressBarData); + int progressBarType = DICTOOL->getIntValue_json(progressBarDic, P_ResourceType); + std::string progressBarFileName = this->getResourcePath(progressBarDic, P_Path, (Widget::TextureResType)progressBarType); slider->loadProgressBarTexture(progressBarFileName, (Widget::TextureResType)progressBarType); diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h index 6f972b7c63c1..2ea5f002ffa3 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index c7ef7ebcd2cf..d634c5cd39f5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -2,12 +2,22 @@ #include "TextAtlasReader.h" #include "ui/UITextAtlas.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_StringValue = "stringValue"; + static const char* P_CharMapFileData = "charMapFileData"; + static const char* P_ItemWidth = "itemWidth"; + static const char* P_ItemHeight = "itemHeight"; + static const char* P_StartCharMap = "startCharMap"; + + + static const char* P_CharMapFile = "charMapFile"; + static TextAtlasReader* instanceTextAtalsReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader) @@ -31,6 +41,58 @@ namespace cocostudio return instanceTextAtalsReader; } + void TextAtlasReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + this->beginSetBasicProperties(widget); + + TextAtlas* labelAtlas = static_cast(widget); + + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + Widget::TextureResType type; + std::string charMapFileName; + std::string stringValue; + std::string startCharMap; + float itemWidth; + float itemHeight; + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if (key == P_StringValue) { + stringValue = value; + } + else if(key == P_CharMapFileData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + + charMapFileName = backgroundValue; + type = imageFileNameType; + + }else if(key == P_ItemWidth){ + itemWidth = valueToFloat(value); + }else if(key == P_ItemHeight){ + itemHeight = valueToFloat(value); + }else if(key == P_StartCharMap){ + startCharMap = value; + } + } //end of for loop + + if (type == (Widget::TextureResType)0) { + labelAtlas->setProperty(stringValue, charMapFileName, itemWidth, itemHeight, startCharMap); + } + this->endSetBasicProperties(widget); + } + void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -39,23 +101,23 @@ namespace cocostudio std::string jsonPath = GUIReader::getInstance()->getFilePath(); TextAtlas* labelAtlas = static_cast(widget); - bool sv = DICTOOL->checkObjectExist_json(options, "stringValue"); - bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile"); - bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth"); - bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight"); - bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap"); + 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) { - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); + const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData); + int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType); switch (cmfType) { case 0: { std::string tp_c = jsonPath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); + 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, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap")); + labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue),cmf_tp,DICTOOL->getIntValue_json(options, P_ItemWidth),DICTOOL->getIntValue_json(options,P_ItemHeight), DICTOOL->getStringValue_json(options, P_StartCharMap)); break; } case 1: diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.h b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.h index ec1af5913283..99a00444c140 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.h @@ -40,6 +40,8 @@ namespace cocostudio static TextAtlasReader* getInstance(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 0558c1b072a2..f20326ba9b4f 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -2,12 +2,16 @@ #include "TextBMFontReader.h" #include "ui/UITextBMFont.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_FileNameData = "fileNameData"; + static const char* P_Text = "text"; + static TextBMFontReader* instanceTextBMFontReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader) @@ -31,6 +35,41 @@ namespace cocostudio return instanceTextBMFontReader; } + void TextBMFontReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + this->beginSetBasicProperties(widget); + + TextBMFont* labelBMFont = static_cast(widget); + + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if(key == P_FileNameData){ + stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(); + std::string resType = backGroundChildren[2].GetValue();; + + Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType); + + std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType); + if (imageFileNameType == (Widget::TextureResType)0) { + labelBMFont->setFntFile(backgroundValue); + } + + }else if(key == P_Text){ + labelBMFont->setString(value); + } + } //end of for loop + this->endSetBasicProperties(widget); + } + void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -40,14 +79,14 @@ namespace cocostudio TextBMFont* labelBMFont = static_cast(widget); - const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData"); - int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType"); + const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_FileNameData); + int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType); switch (cmfType) { case 0: { std::string tp_c = jsonPath; - const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path"); + const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path); const char* cmf_tp = tp_c.append(cmfPath).c_str(); labelBMFont->setFntFile(cmf_tp); break; @@ -59,7 +98,7 @@ namespace cocostudio break; } - const char* text = DICTOOL->getStringValue_json(options, "text"); + const char* text = DICTOOL->getStringValue_json(options, P_Text); labelBMFont->setString(text); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.h b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.h index 491feb52f15b..4fdc193a40df 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 634c34c1c817..5f56526e0307 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -2,6 +2,7 @@ #include "TextFieldReader.h" #include "ui/UITextField.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; @@ -10,6 +11,17 @@ namespace cocostudio { static TextFieldReader* instanceTextFieldReader = NULL; + static const char* P_PlaceHolder = "placeHolder"; + static const char* P_Text = "text"; + static const char* P_FontSize = "fontSize"; + static const char* P_FontName = "fontName"; + static const char* P_TouchSizeWidth = "touchSizeWidth"; + static const char* P_TouchSizeHeight = "touchSizeHeight"; + static const char* P_MaxLengthEnable = "maxLengthEnable"; + static const char* P_MaxLength = "maxLength"; + static const char* P_PasswordEnable = "passwordEnable"; + static const char* P_PasswordStyleText = "passwordStyleText"; + IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader) TextFieldReader::TextFieldReader() @@ -31,54 +43,96 @@ namespace cocostudio return instanceTextFieldReader; } + void TextFieldReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode) + { + this->beginSetBasicProperties(widget); + + TextField* textField = static_cast(widget); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if(key == P_PlaceHolder){ + textField->setPlaceHolder(value); + }else if(key == P_Text){ + textField->setText(value); + }else if(key == P_FontSize){ + textField->setFontSize(valueToInt(value)); + }else if(key == P_FontName){ + textField->setFontName(value); + }else if(key == P_TouchSizeWidth){ + textField->setTouchSize(Size(valueToFloat(value), textField->getTouchSize().height)); + }else if(key == P_TouchSizeHeight){ + textField->setTouchSize(Size(textField->getTouchSize().width, valueToFloat(value))); + }else if (key == P_MaxLengthEnable){ + textField->setMaxLengthEnabled(valueToBool(value)); + }else if(key == P_MaxLength){ + textField->setMaxLength(valueToInt(value)); + }else if(key == P_PasswordEnable){ + textField->setPasswordEnabled(valueToBool(value)); + }else if(key == P_PasswordStyleText){ + textField->setPasswordStyleText(value.c_str()); + } + } //end of for loop + this->endSetBasicProperties(widget); + } + void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); TextField* textField = static_cast(widget); - bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder"); + bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder); if (ph) { - textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder")); + textField->setPlaceHolder(DICTOOL->getStringValue_json(options, P_PlaceHolder)); } - textField->setText(DICTOOL->getStringValue_json(options, "text")); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + textField->setText(DICTOOL->getStringValue_json(options, P_Text)); + bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize); if (fs) { - textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize)); } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + bool fn = DICTOOL->checkObjectExist_json(options, P_FontName); if (fn) { - textField->setFontName(DICTOOL->getStringValue_json(options, "fontName")); + textField->setFontName(DICTOOL->getStringValue_json(options, P_FontName)); } - bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth"); - bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight"); + bool tsw = DICTOOL->checkObjectExist_json(options, P_TouchSizeWidth); + bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight); if (tsw && tsh) { - textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight"))); + textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), DICTOOL->getFloatValue_json(options,P_TouchSizeHeight))); } - float dw = DICTOOL->getFloatValue_json(options, "width"); - float dh = DICTOOL->getFloatValue_json(options, "height"); - if (dw > 0.0f || dh > 0.0f) - { - //textField->setSize(Size(dw, dh)); - } - bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable"); +// float dw = DICTOOL->getFloatValue_json(options, "width"); +// float dh = DICTOOL->getFloatValue_json(options, "height"); +// if (dw > 0.0f || dh > 0.0f) +// { +// //textField->setSize(Size(dw, dh)); +// } + bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, P_MaxLengthEnable); textField->setMaxLengthEnabled(maxLengthEnable); if (maxLengthEnable) { - int maxLength = DICTOOL->getIntValue_json(options, "maxLength"); + int maxLength = DICTOOL->getIntValue_json(options, P_MaxLength); textField->setMaxLength(maxLength); } - bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable"); + bool passwordEnable = DICTOOL->getBooleanValue_json(options, P_PasswordEnable); textField->setPasswordEnabled(passwordEnable); if (passwordEnable) { - textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText")); + textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, P_PasswordStyleText)); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.h b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.h index 2daede6243a1..bcd01d002129 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) ; + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 9877354a8a7e..f7f0170bc7a9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -2,12 +2,22 @@ #include "TextReader.h" #include "ui/UIText.h" +#include "cocostudio/CocoLoader.h" USING_NS_CC; using namespace ui; namespace cocostudio { + static const char* P_TouchScaleEnable = "touchScaleEnable"; + static const char* P_Text = "text"; + static const char* P_FontSize = "fontSize"; + static const char* P_FontName = "fontName"; + static const char* P_AreaWidth = "areaWidth"; + static const char* P_AreaHeight = "areaHeight"; + static const char* P_HAlignment = "hAlignment"; + static const char* P_VAlignment = "vAlignment"; + static TextReader* instanceTextReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(TextReader) @@ -31,6 +41,47 @@ namespace cocostudio return instanceTextReader; } + void TextReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode) + { + this->beginSetBasicProperties(widget); + + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + Text* label = static_cast(widget); + + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + //read all basic properties of widget + CC_BASIC_PROPERTY_BINARY_READER + //read all color related properties of widget + CC_COLOR_PROPERTY_BINARY_READER + + else if (key == P_TouchScaleEnable) { + label->setTouchScaleChangeEnabled(valueToBool(value)); + } + + else if(key == P_Text){ + label->setString(value); + }else if(key == P_FontSize){ + label->setFontSize(valueToInt(value)); + }else if(key == P_FontName){ + label->setFontName(value); + }else if(key == P_AreaWidth){ + label->setTextAreaSize(Size(valueToFloat(value), label->getTextAreaSize().height)); + }else if(key == P_AreaHeight){ + label->setTextAreaSize(Size(label->getTextAreaSize().width, valueToFloat(value))); + }else if(key == P_HAlignment){ + label->setTextHorizontalAlignment((TextHAlignment)valueToInt(value)); + }else if(key == P_VAlignment){ + label->setTextVerticalAlignment((TextVAlignment)valueToInt(value)); + } + + } //end of for loop + this->endSetBasicProperties(widget); + } + void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); @@ -39,38 +90,38 @@ namespace cocostudio std::string jsonPath = GUIReader::getInstance()->getFilePath(); Text* label = static_cast(widget); - bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable"); + bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, P_TouchScaleEnable); label->setTouchScaleChangeEnabled(touchScaleChangeAble); - const char* text = DICTOOL->getStringValue_json(options, "text"); + const char* text = DICTOOL->getStringValue_json(options, P_Text); label->setString(text); - bool fs = DICTOOL->checkObjectExist_json(options, "fontSize"); + bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize); if (fs) { - label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize")); + label->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize)); } - bool fn = DICTOOL->checkObjectExist_json(options, "fontName"); + bool fn = DICTOOL->checkObjectExist_json(options, P_FontName); if (fn) { - std::string fontName = DICTOOL->getStringValue_json(options, "fontName"); + std::string fontName = DICTOOL->getStringValue_json(options, P_FontName); std::string fontFilePath = jsonPath.append(fontName); label->setFontName(fontFilePath); } - bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth"); - bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight"); + bool aw = DICTOOL->checkObjectExist_json(options, P_AreaWidth); + bool ah = DICTOOL->checkObjectExist_json(options, P_AreaHeight); if (aw && ah) { - Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight")); + Size size = Size(DICTOOL->getFloatValue_json(options, P_AreaWidth),DICTOOL->getFloatValue_json(options,P_AreaHeight)); label->setTextAreaSize(size); } - bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment"); + bool ha = DICTOOL->checkObjectExist_json(options, P_HAlignment); if (ha) { - label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment")); + label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, P_HAlignment)); } - bool va = DICTOOL->checkObjectExist_json(options, "vAlignment"); + bool va = DICTOOL->checkObjectExist_json(options, P_VAlignment); if (va) { - label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment")); + label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, P_VAlignment)); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.h b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.h index 84bf04cb8e29..9482ecbe6075 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.h @@ -41,6 +41,8 @@ namespace cocostudio static void purge(); virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); + }; } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index fb45ed701785..1864f208e825 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -1,22 +1,98 @@ #include "WidgetReader.h" +#include "cocostudio/CocoLoader.h" +#include "ui/UIButton.h" USING_NS_CC; using namespace ui; + + namespace cocostudio { + + + const char* P_IgnoreSize = "ignoreSize"; + const char* P_SizeType = "sizeType"; + const char* P_PositionType = "positionType"; + const char* P_SizePercentX = "sizePercentX"; + const char* P_SizePercentY = "sizePercentY"; + const char* P_PositionPercentX = "positionPercentX"; + const char* P_PositionPercentY = "positionPercentY"; + const char* P_AdaptScreen = "adaptScreen"; + const char* P_Width = "width"; + const char* P_Height = "height"; + const char* P_Tag = "tag"; + const char* P_ActionTag = "actiontag"; + const char* P_TouchAble = "touchAble"; + const char* P_Name = "name"; + const char* P_X = "x"; + const char* P_Y = "y"; + const char* P_ScaleX = "scaleX"; + const char* P_ScaleY = "scaleY"; + const char* P_Rotation = "rotation"; + const char* P_Visbile = "visible"; + const char* P_ZOrder = "ZOrder"; + const char* P_LayoutParameter = "layoutParameter"; + const char* P_Type = "type"; + const char* P_Gravity = "gravity"; + const char* P_RelativeName = "relativeName"; + const char* P_RelativeToName = "relativeToName"; + const char* P_Align = "align"; + const char* P_MarginLeft = "marginLeft"; + const char* P_MarginRight = "marginRight"; + const char* P_MarginTop = "marginTop"; + const char* P_MarginDown = "marginDown"; + + const char* P_Opacity = "opacity"; + const char* P_ColorR = "colorR"; + const char* P_ColorG = "colorG"; + const char* P_ColorB = "colorB"; + const char* P_FlipX = "flipX"; + const char* P_FlipY = "flipY"; + const char* P_AnchorPointX = "anchorPointX"; + const char* P_AnchorPointY = "anchorPointY"; + + + const char* P_ResourceType = "resourceType"; + const char* P_Path = "path"; + + static WidgetReader* instanceWidgetReader = NULL; IMPLEMENT_CLASS_WIDGET_READER_INFO(WidgetReader) WidgetReader::WidgetReader() + :_sizePercentX(0.0f), + _sizePercentY(0.0f), + _isAdaptScreen(false), + _width(0.0f), + _height(0.0f), + _positionPercentX(0.0f), + _positionPercentY(0.0f), + _opacity(255) { + valueToInt = [=](const std::string& str) -> int{ + return atoi(str.c_str()); + }; + valueToBool = [=](const std::string& str) -> bool{ + int intValue = valueToInt(str); + if (1 == intValue) { + return true; + }else{ + return false; + } + }; + + valueToFloat = [=](const std::string& str) -> float{ + return atof(str.c_str()); + }; } WidgetReader::~WidgetReader() + { } @@ -37,21 +113,21 @@ namespace cocostudio void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { - bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize"); + bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); if (ignoreSizeExsit) { - widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize")); + widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } - widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, "sizeType")); - widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, "positionType")); + widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); + widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType)); - widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY"))); - widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY"))); + widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, P_SizePercentX), DICTOOL->getFloatValue_json(options, P_SizePercentY))); + widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, P_PositionPercentX), DICTOOL->getFloatValue_json(options, P_PositionPercentY))); /* adapt screen */ float w = 0, h = 0; - bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen"); + bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen); if (adaptScrenn) { Size screenSize = CCDirector::getInstance()->getWinSize(); @@ -60,55 +136,49 @@ namespace cocostudio } else { - w = DICTOOL->getFloatValue_json(options, "width"); - h = DICTOOL->getFloatValue_json(options, "height"); + w = DICTOOL->getFloatValue_json(options, P_Width); + h = DICTOOL->getFloatValue_json(options, P_Height); } widget->setSize(Size(w, h)); - // before - /* - float w = DICTOOL->getFloatValue_json(options, "width"); - float h = DICTOOL->getFloatValue_json(options, "height"); - widget->setSize(CCSizeMake(w, h)); - */ - /**/ - - widget->setTag(DICTOOL->getIntValue_json(options, "tag")); - widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag")); - widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble")); - const char* name = DICTOOL->getStringValue_json(options, "name"); + + widget->setTag(DICTOOL->getIntValue_json(options, P_Tag)); + widget->setActionTag(DICTOOL->getIntValue_json(options, P_ActionTag)); + widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, P_TouchAble)); + const char* name = DICTOOL->getStringValue_json(options, P_Name); const char* widgetName = name?name:"default"; widget->setName(widgetName); - float x = DICTOOL->getFloatValue_json(options, "x"); - float y = DICTOOL->getFloatValue_json(options, "y"); + + 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, "scaleX"); + bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX); if (sx) { - widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX")); + widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX)); } - bool sy = DICTOOL->checkObjectExist_json(options, "scaleY"); + bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY); if (sy) { - widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY")); + widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY)); } - bool rt = DICTOOL->checkObjectExist_json(options, "rotation"); + bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation); if (rt) { - widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation")); + widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation)); } - bool vb = DICTOOL->checkObjectExist_json(options, "visible"); + bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile); if (vb) { - widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible")); + widget->setVisible(DICTOOL->getBooleanValue_json(options, P_Visbile)); } - int z = DICTOOL->getIntValue_json(options, "ZOrder"); + int z = DICTOOL->getIntValue_json(options, P_ZOrder); widget->setLocalZOrder(z); - bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter"); + bool layout = DICTOOL->checkObjectExist_json(options, P_LayoutParameter); if (layout) { - const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter"); - int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type"); + const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, P_LayoutParameter); + int paramType = DICTOOL->getIntValue_json(layoutParameterDic, P_Type); LayoutParameter* parameter = nullptr; switch (paramType) { @@ -117,7 +187,7 @@ namespace cocostudio case 1: { parameter = LinearLayoutParameter::create(); - int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity"); + int gravity = DICTOOL->getIntValue_json(layoutParameterDic, P_Gravity); ((LinearLayoutParameter*)parameter)->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)gravity); break; } @@ -125,11 +195,11 @@ namespace cocostudio { parameter = RelativeLayoutParameter::create(); RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter; - const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName"); + const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeName); rParameter->setRelativeName(relativeName); - const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName"); + const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeToName); rParameter->setRelativeToWidgetName(relativeToName); - int align = DICTOOL->getIntValue_json(layoutParameterDic, "align"); + int align = DICTOOL->getIntValue_json(layoutParameterDic, P_Align); rParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)align); break; } @@ -138,10 +208,10 @@ namespace cocostudio } if (parameter) { - float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft"); - float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop"); - float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight"); - float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown"); + float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginLeft); + float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginTop); + float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginRight); + float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginDown); parameter->setMargin(Margin(mgl, mgt, mgr, mgb)); widget->setLayoutParameter(parameter); } @@ -150,27 +220,55 @@ namespace cocostudio void WidgetReader::setColorPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { - bool op = DICTOOL->checkObjectExist_json(options, "opacity"); + bool op = DICTOOL->checkObjectExist_json(options, P_Opacity); if (op) { - widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity")); - } - bool cr = DICTOOL->checkObjectExist_json(options, "colorR"); - bool cg = DICTOOL->checkObjectExist_json(options, "colorG"); - bool cb = DICTOOL->checkObjectExist_json(options, "colorB"); - int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255; - int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255; - int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255; + widget->setOpacity(DICTOOL->getIntValue_json(options, P_Opacity)); + } + bool cr = DICTOOL->checkObjectExist_json(options, P_ColorR); + bool cg = DICTOOL->checkObjectExist_json(options, P_ColorG); + bool cb = DICTOOL->checkObjectExist_json(options, P_ColorB); + int colorR = cr ? DICTOOL->getIntValue_json(options, P_ColorR) : 255; + int colorG = cg ? DICTOOL->getIntValue_json(options, P_ColorG) : 255; + int colorB = cb ? DICTOOL->getIntValue_json(options, P_ColorB) : 255; widget->setColor(Color3B(colorR, colorG, colorB)); this->setAnchorPointForWidget(widget, options); - bool flipX = DICTOOL->getBooleanValue_json(options, "flipX"); - bool flipY = DICTOOL->getBooleanValue_json(options, "flipY"); + bool flipX = DICTOOL->getBooleanValue_json(options, P_FlipX); + bool flipY = DICTOOL->getBooleanValue_json(options, P_FlipY); widget->setFlippedX(flipX); widget->setFlippedY(flipY); } + void WidgetReader::beginSetBasicProperties(cocos2d::ui::Widget *widget) + { + _position = widget->getPosition(); + //set default color + _color = Color3B(255,255,255); + widget->setColor(_color); + _opacity = widget->getOpacity(); + _originalAnchorPoint = widget->getAnchorPoint(); + } + + void WidgetReader::endSetBasicProperties(Widget *widget) + { + Size screenSize = Director::getInstance()->getWinSize(); + + widget->setPositionPercent(Vec2(_positionPercentX, _positionPercentY)); + widget->setSizePercent(Vec2(_sizePercentX, _sizePercentY)); + if (_isAdaptScreen) { + _width = screenSize.width; + _height = screenSize.height; + } + widget->setColor(_color); + widget->setOpacity(_opacity); + //the setSize method will be conflict with scale9Width & scale9Height + widget->setSize(Size(_width, _height)); + widget->setPosition(_position); + widget->setAnchorPoint(_originalAnchorPoint); + } + std::string WidgetReader::getResourcePath(const rapidjson::Value &dict, const std::string &key, cocos2d::ui::Widget::TextureResType texType) @@ -193,20 +291,47 @@ namespace cocostudio return imageFileName_tp; } + std::string WidgetReader::getResourcePath(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::ui::Widget::TextureResType texType) + { + stExpCocoNode *backGroundChildren = cocoNode->GetChildArray(); + std::string backgroundValue = backGroundChildren[0].GetValue(); + + if (backgroundValue.size() < 3) { + return ""; + } + + std::string binaryPath = GUIReader::getInstance()->getFilePath(); + + std::string imageFileName_tp; + if (!backgroundValue.empty()) + { + if (texType == ui::Widget::TextureResType::LOCAL) { + imageFileName_tp = binaryPath + backgroundValue; + } + else if(texType == ui::Widget::TextureResType::PLIST){ + imageFileName_tp = backgroundValue; + } + else{ + CCASSERT(0, "invalid TextureResType!!!"); + } + } + return imageFileName_tp; + } + void WidgetReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options) { - bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX"); + bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, P_AnchorPointX); float anchorPointXInFile; if (isAnchorPointXExists) { - anchorPointXInFile = DICTOOL->getFloatValue_json(options, "anchorPointX"); + anchorPointXInFile = DICTOOL->getFloatValue_json(options, P_AnchorPointX); }else{ anchorPointXInFile = widget->getAnchorPoint().x; } - bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, "anchorPointY"); + bool isAnchorPointYExists = DICTOOL->checkObjectExist_json(options, P_AnchorPointY); float anchorPointYInFile; if (isAnchorPointYExists) { - anchorPointYInFile = DICTOOL->getFloatValue_json(options, "anchorPointY"); + anchorPointYInFile = DICTOOL->getFloatValue_json(options, P_AnchorPointY); } else{ anchorPointYInFile = widget->getAnchorPoint().y; @@ -216,6 +341,23 @@ namespace cocostudio widget->setAnchorPoint(Vec2(anchorPointXInFile, anchorPointYInFile)); } } + + void WidgetReader::setPropsFromBinary(cocos2d::ui::Widget *widget, cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode) + { + stExpCocoNode *stChildArray = cocoNode->GetChildArray(); + + this->beginSetBasicProperties(widget); + + for (int i = 0; i < cocoNode->GetChildNum(); ++i) { + std::string key = stChildArray[i].GetName(cocoLoader); + std::string value = stChildArray[i].GetValue(); + + CC_BASIC_PROPERTY_BINARY_READER + } + + this->endSetBasicProperties(widget); + } + } diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h index 9fff4d903bb9..25c5dbbe97f3 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.h @@ -26,12 +26,16 @@ #define __TestCpp__WidgetReader__ #include "WidgetReaderProtocol.h" -#include "../CCSGUIReader.h" +#include "cocostudio/CCSGUIReader.h" #include "ui/GUIDefine.h" #include "ui/UIWidget.h" + namespace cocostudio { + class CocoLoader; + struct stExpCocoNode; + class WidgetReader : public cocos2d::Ref, public WidgetReaderProtocol { public: @@ -49,13 +53,193 @@ namespace cocostudio virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options); + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode); protected: 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); + + + std::string getResourcePath(CocoLoader* cocoLoader, + stExpCocoNode* pCocoNode, + cocos2d::ui::Widget::TextureResType texType); + + void beginSetBasicProperties(cocos2d::ui::Widget *widget); + void endSetBasicProperties(cocos2d::ui::Widget *widget); + + + std::function valueToInt; + std::function valueToBool; + std::function valueToFloat; + + float _sizePercentX; + float _sizePercentY; + float _positionPercentX; + float _positionPercentY; + float _width ; + float _height; + cocos2d::Color3B _color; + int _opacity; + cocos2d::Vec2 _position; + bool _isAdaptScreen; + cocos2d::Vec2 _originalAnchorPoint; }; + + //property const define + extern const char* P_IgnoreSize; + extern const char* P_SizeType; + extern const char* P_PositionType; + extern const char* P_SizePercentX; + extern const char* P_SizePercentY; + extern const char* P_PositionPercentX; + extern const char* P_PositionPercentY; + extern const char* P_AdaptScreen; + extern const char* P_Width; + extern const char* P_Height; + extern const char* P_Tag; + extern const char* P_ActionTag; + extern const char* P_TouchAble; + extern const char* P_Name; + extern const char* P_X; + extern const char* P_Y; + extern const char* P_ScaleX; + extern const char* P_ScaleY; + extern const char* P_Rotation; + extern const char* P_Visbile; + extern const char* P_ZOrder; + extern const char* P_LayoutParameter; + extern const char* P_Type; + extern const char* P_Gravity; + extern const char* P_RelativeName; + extern const char* P_RelativeToName; + extern const char* P_Align; + extern const char* P_MarginLeft; + extern const char* P_MarginRight; + extern const char* P_MarginTop; + extern const char* P_MarginDown; + + extern const char* P_Opacity; + extern const char* P_ColorR; + extern const char* P_ColorG; + extern const char* P_ColorB; + extern const char* P_FlipX; + extern const char* P_FlipY; + extern const char* P_AnchorPointX; + extern const char* P_AnchorPointY; + + extern const char* P_ResourceType; + extern const char* P_Path; + +#define CC_BASIC_PROPERTY_BINARY_READER \ + if (key == P_IgnoreSize) { \ + widget->ignoreContentAdaptWithSize(valueToBool(value)); \ + }else if(key == P_SizeType){ \ + widget->setSizeType((Widget::SizeType)valueToInt(value)); \ + }else if(key == P_PositionType){ \ + widget->setPositionType((Widget::PositionType)valueToInt(value)); \ + }else if(key == P_SizePercentX){ \ + _sizePercentX = valueToFloat(value); \ + }else if(key == P_SizePercentY){ \ + _sizePercentY = valueToFloat(value); \ + }else if(key == P_PositionPercentX){ \ + _positionPercentX = valueToFloat(value); \ + }else if(key == P_PositionPercentY){ \ + _positionPercentY = valueToFloat(value); \ + } \ + else if (key == P_Width){ \ + _width = valueToFloat(value); \ + }else if(key == P_Height){ \ + _height = valueToFloat(value); \ + }else if(key == P_Tag){ \ + widget->setTag(valueToInt(value)); \ + }else if(key == P_ActionTag){ \ + widget->setActionTag(valueToInt(value)); \ + }else if(key == P_TouchAble){ \ + widget->setTouchEnabled(valueToBool(value)); \ + }else if(key == P_Name){ \ + std::string widgetName = value.empty() ? "default" : value; \ + widget->setName(widgetName); \ + }else if(key == P_X){ \ + _position.x = valueToFloat(value); \ + }else if(key == P_Y){ \ + _position.y = valueToFloat(value); \ + }else if(key == P_ScaleX){ \ + widget->setScaleX(valueToFloat(value)); \ + }else if(key == P_ScaleY){ \ + widget->setScaleY(valueToFloat(value)); \ + }else if(key == P_Rotation){ \ + widget->setRotation(valueToFloat(value)); \ + }else if(key == P_Visbile){ \ + widget->setVisible(valueToBool(value)); \ + }else if(key == P_ZOrder){ \ + widget->setZOrder(valueToInt(value)); \ + }else if(key == P_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(cocoLoader); \ + std::string innerValue = layoutCocosNode[j].GetValue(); \ + if (innerKey == P_Type) { \ + paramType = valueToInt(innerValue); \ + }else if(innerKey == P_Gravity){ \ + linearParameter->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)valueToInt(innerValue)); \ + }else if(innerKey == P_RelativeName){ \ + relativeParameter->setRelativeName(innerValue); \ + }else if(innerKey == P_RelativeToName){ \ + relativeParameter->setRelativeToWidgetName(innerValue); \ + }else if(innerKey == P_Align){ \ + relativeParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)valueToInt(innerValue)); \ + }else if(innerKey == P_MarginLeft){ \ + mg.left = valueToFloat(innerValue); \ + }else if(innerKey == P_MarginTop){ \ + mg.top = valueToFloat(innerValue); \ + }else if(innerKey == P_MarginRight){ \ + mg.right = valueToFloat(innerValue); \ + }else if(innerKey == P_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;\ + }\ + } + + +#define CC_COLOR_PROPERTY_BINARY_READER \ + else if (key == P_Opacity) { \ + _opacity = valueToInt(value); \ + }else if(key == P_ColorR){ \ + _color.r = valueToInt(value); \ + }else if(key == P_ColorG){ \ + _color.g = valueToInt(value); \ + }else if(key == P_ColorB) \ + {\ + _color.b = valueToInt(value);\ + }else if(key == P_FlipX){\ + widget->setFlippedX(valueToBool(value));\ + }else if(key == P_FlipY){\ + widget->setFlippedY(valueToBool(value));\ + } \ + else if(key == P_AnchorPointX){ \ + _originalAnchorPoint.x = valueToFloat(value); \ + }else if(key == P_AnchorPointY){ \ + _originalAnchorPoint.y = valueToFloat(value); \ + } + + } #endif /* defined(__TestCpp__WidgetReader__) */ diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReaderProtocol.h b/cocos/editor-support/cocostudio/WidgetReader/WidgetReaderProtocol.h index 3c69a78a00e2..0461ca5cec28 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReaderProtocol.h +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReaderProtocol.h @@ -28,6 +28,8 @@ #include "cocos2d.h" #include "cocostudio/DictionaryHelper.h" + + namespace cocos2d { namespace ui @@ -38,11 +40,15 @@ namespace cocos2d namespace cocostudio { + class CocoLoader; + struct stExpCocoNode; + class WidgetReaderProtocol { public: virtual ~WidgetReaderProtocol() {}; virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0; + virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0; }; } diff --git a/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj b/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj index 00f5d1bb569c..272c82c41d21 100644 --- a/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj +++ b/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj @@ -46,6 +46,7 @@ + @@ -113,6 +114,8 @@ + + diff --git a/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj.filters b/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj.filters index 978f5107d2bd..8e91fb082e96 100644 --- a/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj.filters +++ b/cocos/editor-support/cocostudio/proj.win32/libCocosStudio.vcxproj.filters @@ -231,6 +231,9 @@ reader\WidgetReader\PageViewReader + + json + TimelineAction @@ -428,6 +431,12 @@ reader\WidgetReader\PageViewReader + + json + + + json + TimelineAction diff --git a/cocos/ui/UIButton.h b/cocos/ui/UIButton.h index 7f02e0025f29..0619b2b760d5 100644 --- a/cocos/ui/UIButton.h +++ b/cocos/ui/UIButton.h @@ -71,7 +71,6 @@ class Button : public Widget const std::string& disableImage = "", TextureResType texType = TextureResType::LOCAL); - /** * Load textures for button. * diff --git a/cocos/ui/UIWidget.h b/cocos/ui/UIWidget.h index 4d201720b0fb..5eaf78784d14 100644 --- a/cocos/ui/UIWidget.h +++ b/cocos/ui/UIWidget.h @@ -603,7 +603,6 @@ class Widget : public ProtectedNode, public LayoutParameterProtocol *@return void */ void dispatchFocusEvent(Widget* widgetLoseFocus, Widget* widgetGetFocus); - protected: //call back function called when size changed. diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index 9100c94e42a2..8e023e244d34 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -75,6 +75,9 @@ Layer *CreateLayer(int index) case TEST_CHANGE_ANIMATION_INTERNAL: pLayer = new TestChangeAnimationInternal(); break; + case TEST_DIRECT_FROM_BINARY: + pLayer = new TestLoadFromBinary(); + break; default: break; } @@ -1487,3 +1490,101 @@ void TestChangeAnimationInternal::onTouchesEnded(const std::vector& touc Director::getInstance()->setAnimationInterval(1/30.0f); } } + + + +//TestDirectFromBinay + +const char* TestLoadFromBinary::m_binaryFilesNames[BINARYFILECOUNT] ={"armature/bear.csb","armature/horse.csb", + "armature/Cowboy.csb","armature/hero.csb", + "armature/HeroAnimation.csb","armature/testEasing.csb"}; +const char* TestLoadFromBinary::m_armatureNames[BINARYFILECOUNT] ={"bear","horse", + "Cowboy","hero", + "HeroAnimation","testEasing"}; + + +void TestLoadFromBinary::onEnter() +{ + ArmatureTestLayer::onEnter(); + + auto listener = EventListenerTouchAllAtOnce::create(); + listener->onTouchesEnded = CC_CALLBACK_2(TestLoadFromBinary::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + m_armatureIndex = -1; // none + + // remove json created + // remove sync resource + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson"); + ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]); + // load from binary + ArmatureDataManager::getInstance()->addArmatureFileInfo(m_binaryFilesNames[0]); + + m_armature = Armature::create(m_armatureNames[0]); + m_armature->getAnimation()->playWithIndex(0); + m_armature->setScale(1.0f); + + m_armature->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y)); + addChild(m_armature); + +} + + +std::string TestLoadFromBinary::title() const +{ + return "Test load from binary file"; +} +std::string TestLoadFromBinary::subtitle() const +{ + return "direct load.Touch to change to Asynchronous load."; +} + +void TestLoadFromBinary::onTouchesEnded(const std::vector& touches, Event* event) +{ + // remove json created + // remove sync resource + if(-1 == m_armatureIndex ) + { + ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]); + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/Cowboy.ExportJson"); + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/hero.ExportJson"); + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/horse.ExportJson"); + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/HeroAnimation.ExportJson"); + ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/testEasing.ExportJson"); + + for( int i = 0; i < BINARYFILECOUNT; i++) + { + ArmatureDataManager::getInstance()->addArmatureFileInfoAsync(m_binaryFilesNames[i], this, schedule_selector(TestLoadFromBinary::dataLoaded)); + } + + m_armatureIndex = -2; // is loading + } + else if(m_armatureIndex>=0 && m_armature != NULL) + { + this->removeChild(m_armature); + m_armatureIndex = m_armatureIndex==BINARYFILECOUNT-1 ? 0 : m_armatureIndex+1; + m_armature = Armature::create(m_armatureNames[m_armatureIndex]); + m_armature->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y)); + if(m_armatureIndex == 2 ) // cowboy is 0.2 + m_armature->setScale(0.2f); + m_armature->getAnimation()->playWithIndex(0); + addChild(m_armature); + } +} + + +void TestLoadFromBinary::dataLoaded( float percent ) +{ + Label *label = (Label *)getChildByTag(10001); + if (label) + { + char pszPercent[255]; + sprintf(pszPercent, "%s %f", "Asynchronous loading: ", percent * 100); + label->setString(pszPercent); + } + + if (percent >= 1) + { + label->setString("Touch to change armature"); + m_armatureIndex = 0; + } +} diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h index 227c77cd5c5e..4b353e6fcd45 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.h @@ -45,7 +45,8 @@ enum { TEST_PLAY_SEVERAL_MOVEMENT, TEST_EASING, TEST_CHANGE_ANIMATION_INTERNAL, - + TEST_DIRECT_FROM_BINARY, + TEST_LAYER_COUNT }; @@ -393,4 +394,25 @@ class TestChangeAnimationInternal : public ArmatureTestLayer void onTouchesEnded(const std::vector& touches, Event* event); }; + +#define BINARYFILECOUNT 6 +class TestLoadFromBinary : public ArmatureTestLayer +{ +public: + virtual void onEnter(); + virtual std::string title() const override; + virtual std::string subtitle() const override; + + void onTouchesEnded(const std::vector& touches, Event* event); + + + void dataLoaded(float percent); + +private: + cocostudio::Armature *m_armature; // current armature + static const char* m_binaryFilesNames[BINARYFILECOUNT]; + static const char* m_armatureNames[BINARYFILECOUNT]; + int m_armatureIndex; // index of sync loaded armature, default -1 is none +}; + #endif // __HELLOWORLD_SCENE_H__ 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 92f99b224d75..917e2b50930d 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp @@ -20,7 +20,13 @@ bool UIButtonTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); +// auto _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.json")); + + + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIButton_Editor/UIButton_Editor_1.csb")); + + + _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -30,21 +36,17 @@ bool UIButtonTest_Editor::init() Layout* root = static_cast(_layout->getChildByName("root_Panel")); Text* back_label = static_cast(Helper::seekWidgetByName(root, "back")); -// back_label->addTouchEventListener(this, toucheventselector(UIScene_Editor::toGUIEditorTestScene)); back_label->addTouchEventListener(CC_CALLBACK_2(UIScene_Editor::toGUIEditorTestScene, this)); _sceneTitle = static_cast(Helper::seekWidgetByName(root, "UItest")); Button* button = static_cast(Helper::seekWidgetByName(root, "Button_123")); -// button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent)); button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); Button* title_button = static_cast(Helper::seekWidgetByName(root, "Button_126")); -// title_button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent)); title_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); Button* scale9_button = static_cast(Helper::seekWidgetByName(root, "Button_129")); -// scale9_button->addTouchEventListener(this, toucheventselector(UIButtonTest_Editor::touchEvent)); scale9_button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Editor::touchEvent, this)); _displayValueLabel = Text::create(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp index 5ea65d689a61..8190d8eb8cd6 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp @@ -20,7 +20,8 @@ bool UICheckBoxTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_1.csb")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UICheckBox_Editor/ui_checkbox_editor_2.json")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp index c0e9f0ba167b..a8dab62bd714 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest_Editor.cpp @@ -9,7 +9,9 @@ bool UIImageViewTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIImageView_Editor/ui_ImageView_editor_1.csb")); + _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp index 792ed2b36a30..17a7d92bd2da 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILayoutTest/UILayoutTest_Editor.cpp @@ -19,7 +19,8 @@ bool UILayoutTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Editor/ui_layout_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -74,7 +75,8 @@ bool UILayoutTest_Color_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Color_Editor/ui_layout_color_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -129,7 +131,8 @@ bool UILayoutTest_Gradient_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Gradient_Color_Editor/ui_layout_gradient_color_editor_1_0.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -184,7 +187,8 @@ bool UILayoutTest_BackGroundImage_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_BackgroundImage_Editor/ui_layout_backgroundimage_editor_1_0_0.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -239,7 +243,8 @@ bool UILayoutTest_BackGroundImage_Scale9_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Scale9_BackgroundImage_Editor/ui_layout_scale9_backgroundimage_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -294,7 +299,8 @@ bool UILayoutTest_Layout_Linear_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Vertical_Layout_Editor/ui_layout_linear_vertical_layout_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -349,7 +355,8 @@ bool UILayoutTest_Layout_Linear_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Linear_Horizontal_Layout_Editor/ui_layout_linear_horizontal_layout_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -405,7 +412,8 @@ bool UILayoutTest_Layout_Relative_Align_Parent_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Parent_Editor/ui_layout_relative_align_parent_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -460,7 +468,8 @@ bool UILayoutTest_Layout_Relative_Location_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILayout_Editor/UILayout_Relative_Align_Location_Editor/ui_layout_relative_align_location_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp index 15f5f5567a1f..b45278649b13 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest_Editor.cpp @@ -19,7 +19,8 @@ bool UIListViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -80,7 +81,8 @@ bool UIListViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Horizontal_Editor/ui_listview_horizontal_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp index 63c0c15386b7..0d8017f33071 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest_Editor.cpp @@ -21,7 +21,8 @@ bool UILoadingBarTest_Editor::init() { scheduleUpdate(); - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILoadingBar_Editor/ui_loadingbar_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp index cec0c535f92f..93770b3662e4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest_Editor.cpp @@ -20,7 +20,8 @@ bool UIPageViewTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIPageView_Editor/ui_pageview_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp index dc7584afe9fe..3a792a9a1ce4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest_Editor.cpp @@ -19,7 +19,8 @@ bool UIScrollViewTest_Vertical_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Vertical_Editor/ui_scrollview_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -74,7 +75,8 @@ bool UIScrollViewTest_Horizontal_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Horizontal_Editor/ui_scrollview_horizontal_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -129,7 +131,8 @@ bool UIScrollViewTest_Both_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIScrollView_Editor/UIScrollView_Both_Editor/ui_scrollview_both_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -184,7 +187,8 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UITest/UITest.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); @@ -230,7 +234,8 @@ bool UIScrollViewTest_ScrollToPercentBothDirection_Bounce_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UITest/UITest.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UITest/UITest.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp index c6d0e0ea45ba..89170babb801 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp @@ -20,7 +20,8 @@ bool UISliderTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UISlider_Editor/ui_slider_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp index 396337a5ebc7..8f05b1ab3257 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp @@ -8,7 +8,8 @@ bool UITextAtlasTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelAtlas_Editor/ui_labelatlas_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp index 5b2bdcee10ab..b6733613ddda 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp @@ -9,7 +9,8 @@ bool UITextBMFontTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp index fe9bc0f92425..7e4f4ba96cc5 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp @@ -20,7 +20,8 @@ bool UITextFieldTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UITextField_Editor/ui_textfield_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp index e8ef5acf1ba0..e2645ef40689 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest_Editor.cpp @@ -11,7 +11,8 @@ bool UITextTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabel_Editor/ui_label_editor_1.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize(); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp index 31d176084d5a..e7561767e429 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp @@ -19,7 +19,8 @@ bool UIWidgetAddNodeTest_Editor::init() { if (UIScene_Editor::init()) { - _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); +// _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.json")); + _layout = static_cast(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIWidgetAddNode_Editor/ui_widget_add_node_editor.csb")); _touchGroup->addChild(_layout); Size screenSize = CCDirector::getInstance()->getWinSize(); Size rootSize = _layout->getSize();