2013-09-13 22:20:20 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
#ifndef __CCSGUIREADER_H__
|
|
|
|
#define __CCSGUIREADER_H__
|
|
|
|
|
2014-07-21 22:45:33 +08:00
|
|
|
#include "ui/UILayout.h"
|
2013-12-24 20:33:55 +08:00
|
|
|
#include "cocostudio/DictionaryHelper.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
#include "WidgetReader/WidgetReaderProtocol.h"
|
2014-06-04 14:27:14 +08:00
|
|
|
#include "base/ObjectFactory.h"
|
2014-07-21 17:45:56 +08:00
|
|
|
#include "cocostudio/CocosStudioExport.h"
|
2014-06-04 14:27:14 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocostudio {
|
2014-06-23 17:09:54 +08:00
|
|
|
|
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2014-06-04 14:27:14 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
#define kCCSVersion 1.0
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
typedef void (cocos2d::Ref::*SEL_ParseEvent)(const std::string&, cocos2d::Ref*, const rapidjson::Value&);
|
2014-03-04 16:51:35 +08:00
|
|
|
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
|
2014-01-04 14:23:40 +08:00
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_STUDIO_DLL GUIReader : public cocos2d::Ref
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-01-04 14:23:40 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static GUIReader* shareReader() { return GUIReader::getInstance(); };
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static void purgeGUIReader() { GUIReader::destroyInstance(); };
|
|
|
|
|
|
|
|
static GUIReader* getInstance();
|
|
|
|
static void destroyInstance();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
int getVersionInteger(const char* str);
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-11-07 21:26:56 +08:00
|
|
|
void storeFileDesignSize(const char* fileName, const cocos2d::Size &size);
|
2013-11-20 12:04:47 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2013-11-07 21:26:56 +08:00
|
|
|
const cocos2d::Size getFileDesignSize(const char* fileName) const;
|
2014-01-04 14:23:40 +08:00
|
|
|
|
2014-06-11 21:11:22 +08:00
|
|
|
void setFilePath(const std::string& strFilePath) { m_strFilePath = strFilePath; }
|
|
|
|
const std::string& getFilePath() const { return m_strFilePath; }
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void registerTypeAndCallBack(const std::string& classType,
|
2014-06-04 14:27:14 +08:00
|
|
|
cocos2d::ObjectFactory::Instance ins,
|
2014-03-04 16:51:35 +08:00
|
|
|
Ref* object,
|
|
|
|
SEL_ParseEvent callBack);
|
2014-08-12 17:19:52 +08:00
|
|
|
|
|
|
|
void registerTypeAndCallBack(const std::string& classType,
|
|
|
|
cocos2d::ObjectFactory::InstanceFunc ins,
|
|
|
|
Ref* object,
|
|
|
|
SEL_ParseEvent callBack);
|
2013-09-13 22:20:20 +08:00
|
|
|
protected:
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader();
|
|
|
|
~GUIReader();
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
std::string m_strFilePath;
|
2013-12-24 10:41:01 +08:00
|
|
|
cocos2d::ValueMap _fileDesignSizes;
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
typedef std::map<std::string, SEL_ParseEvent> ParseCallBackMap;
|
|
|
|
ParseCallBackMap _mapParseSelector;
|
|
|
|
typedef std::map<std::string, Ref*> ParseObjectMap;
|
|
|
|
ParseObjectMap _mapObject;
|
|
|
|
|
|
|
|
public:
|
2014-08-12 17:05:23 +08:00
|
|
|
ParseCallBackMap* getParseCallBackMap() { return &_mapParseSelector; };
|
|
|
|
ParseObjectMap* getParseObjectMap() { return &_mapObject; };
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
};
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_STUDIO_DLL WidgetPropertiesReader : public cocos2d::Ref
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName)=0;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
|
2014-03-04 16:51:35 +08:00
|
|
|
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& customOptions) = 0;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
//add binary parsing
|
2014-06-23 10:02:09 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,stExpCocoNode* pCocoNode, const char* fileName)=0;
|
|
|
|
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0;
|
2014-06-05 11:43:43 +08:00
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
2014-06-23 10:02:09 +08:00
|
|
|
CocoLoader* cocoLoader,
|
2014-06-05 11:43:43 +08:00
|
|
|
stExpCocoNode* pCocoNode) = 0;
|
|
|
|
|
2014-05-13 09:56:10 +08:00
|
|
|
protected:
|
|
|
|
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
|
2014-06-05 10:25:08 +08:00
|
|
|
std::string getWidgetReaderClassName(const std::string& classname);
|
|
|
|
std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget);
|
2014-05-13 09:56:10 +08:00
|
|
|
|
2014-06-04 14:27:14 +08:00
|
|
|
std::string getGUIClassName(const std::string& name);
|
|
|
|
cocos2d::ui::Widget *createGUI(const std::string& classname);
|
|
|
|
WidgetReaderProtocol* createWidgetReaderProtocol(const std::string& classname);
|
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
protected:
|
|
|
|
std::string m_strFilePath;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_STUDIO_DLL WidgetPropertiesReader0250 : public WidgetPropertiesReader
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
WidgetPropertiesReader0250(){};
|
|
|
|
virtual ~WidgetPropertiesReader0250(){};
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
//added for binary parsing
|
2014-06-23 10:02:09 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode,
|
2014-06-11 14:45:35 +08:00
|
|
|
const char* fileName)override{return nullptr;}
|
2014-06-11 14:15:34 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode){return nullptr;}
|
|
|
|
|
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
2014-06-23 10:02:09 +08:00
|
|
|
CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode) {}
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
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);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual void setPropsForLayoutFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
|
|
|
virtual void setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
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);
|
2013-11-11 18:22:14 +08:00
|
|
|
};
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-21 17:45:56 +08:00
|
|
|
class CC_STUDIO_DLL WidgetPropertiesReader0300 : public WidgetPropertiesReader
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
WidgetPropertiesReader0300(){};
|
|
|
|
virtual ~WidgetPropertiesReader0300(){};
|
|
|
|
|
2014-06-11 14:15:34 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic,
|
|
|
|
const char* fullPath,
|
|
|
|
const char* fileName);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
//add bin parse support
|
2014-06-23 10:02:09 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode,
|
|
|
|
const char* fileName)override;
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode);
|
|
|
|
|
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
2014-06-23 10:02:09 +08:00
|
|
|
CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode);
|
|
|
|
|
2014-06-05 11:43:43 +08:00
|
|
|
virtual void setPropsForAllCustomWidgetFromBinary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
2014-06-23 10:02:09 +08:00
|
|
|
CocoLoader* cocoLoader,
|
2014-06-11 14:15:34 +08:00
|
|
|
stExpCocoNode* pCocoNode) {
|
|
|
|
//TODO: custom property
|
|
|
|
}
|
2014-06-05 11:43:43 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2014-06-11 14:15:34 +08:00
|
|
|
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& options);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& customOptions);
|
2013-11-11 18:22:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
#endif /* defined(__CCSGUIReader__) */
|