2021-04-22 22:01:47 +08:00
|
|
|
/****************************************************************************
|
2019-11-24 23:15:56 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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 __CCSGUIREADER_H__
|
|
|
|
#define __CCSGUIREADER_H__
|
|
|
|
|
|
|
|
#include "ui/UILayout.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "WidgetReader/WidgetReaderProtocol.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "base/ObjectFactory.h"
|
|
|
|
#include "base/CCValue.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocosStudioExport.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
namespace protocolbuffers
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
class NodeTree;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
namespace tinyxml2
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
class XMLElement;
|
2020-10-17 16:32:16 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
|
|
|
|
class CocoLoader;
|
|
|
|
struct stExpCocoNode;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#define kCCSVersion 1.0
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
typedef void (cocos2d::Ref::*SEL_ParseEvent)(const std::string&, cocos2d::Ref*, const rapidjson::Value&);
|
2019-11-23 20:27:39 +08:00
|
|
|
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL GUIReader : public cocos2d::Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static GUIReader* shareReader() { return GUIReader::getInstance(); };
|
|
|
|
CC_DEPRECATED_ATTRIBUTE static void purgeGUIReader() { GUIReader::destroyInstance(); };
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
static GUIReader* getInstance();
|
|
|
|
static void destroyInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-04-22 22:01:47 +08:00
|
|
|
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-04-22 22:01:47 +08:00
|
|
|
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
int getVersionInteger(const char* str);
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void storeFileDesignSize(const char* fileName, const cocos2d::Size& size);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
cocos2d::Size getFileDesignSize(const char* fileName) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void setFilePath(const std::string& strFilePath) { m_strFilePath = strFilePath; }
|
|
|
|
const std::string& getFilePath() const { return m_strFilePath; }
|
|
|
|
|
|
|
|
void registerTypeAndCallBack(const std::string& classType,
|
|
|
|
cocos2d::ObjectFactory::Instance ins,
|
|
|
|
Ref* object,
|
|
|
|
SEL_ParseEvent callBack);
|
|
|
|
|
|
|
|
void registerTypeAndCallBack(const std::string& classType,
|
|
|
|
cocos2d::ObjectFactory::InstanceFunc ins,
|
|
|
|
Ref* object,
|
|
|
|
SEL_ParseEvent callBack);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
GUIReader();
|
|
|
|
~GUIReader();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string m_strFilePath;
|
|
|
|
cocos2d::ValueMap _fileDesignSizes;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
typedef std::map<std::string, SEL_ParseEvent> ParseCallBackMap;
|
2019-11-23 20:27:39 +08:00
|
|
|
ParseCallBackMap _mapParseSelector;
|
|
|
|
typedef std::map<std::string, Ref*> ParseObjectMap;
|
|
|
|
ParseObjectMap _mapObject;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
ParseCallBackMap* getParseCallBackMap() { return &_mapParseSelector; };
|
|
|
|
ParseObjectMap* getParseObjectMap() { return &_mapObject; };
|
|
|
|
};
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL WidgetPropertiesReader : public cocos2d::Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
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;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& customOptions) = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// 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;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
CocoLoader* cocoLoader,
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* pCocoNode) = 0;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
|
|
|
std::string getWidgetReaderClassName(const std::string& classname);
|
|
|
|
std::string getWidgetReaderClassName(cocos2d::ui::Widget* widget);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string getGUIClassName(const std::string& name);
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::ui::Widget* createGUI(const std::string& classname);
|
2019-11-23 20:27:39 +08:00
|
|
|
WidgetReaderProtocol* createWidgetReaderProtocol(const std::string& classname);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
|
|
|
std::string m_strFilePath;
|
|
|
|
};
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL WidgetPropertiesReader0250 : public WidgetPropertiesReader
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
WidgetPropertiesReader0250(){};
|
|
|
|
virtual ~WidgetPropertiesReader0250(){};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic,
|
|
|
|
const char* fullPath,
|
|
|
|
const char* fileName) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// added for binary parsing
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
|
|
|
|
stExpCocoNode* pCocoNode,
|
|
|
|
const char* fileName) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) override;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
CocoLoader* cocoLoader,
|
|
|
|
stExpCocoNode* pCocoNode) override;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
|
|
|
|
|
|
|
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 setPropsForScrollViewFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
|
|
|
|
|
|
|
|
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& options) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& customOptions) override;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
class CCS_DLL WidgetPropertiesReader0300 : public WidgetPropertiesReader
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
WidgetPropertiesReader0300(){};
|
|
|
|
virtual ~WidgetPropertiesReader0300(){};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic,
|
|
|
|
const char* fullPath,
|
|
|
|
const char* fileName) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// add bin parse support
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* pCocoNode,
|
|
|
|
const char* fileName) override;
|
|
|
|
|
|
|
|
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) override;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
CocoLoader* cocoLoader,
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* pCocoNode) override;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllCustomWidgetFromBinary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
CocoLoader* cocoLoader,
|
|
|
|
stExpCocoNode* pCocoNode);
|
|
|
|
|
|
|
|
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
|
|
|
|
cocos2d::ui::Widget* widget,
|
|
|
|
const rapidjson::Value& options) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
|
|
|
|
cocos2d::ui::Widget* widget,
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& customOptions) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /* defined(__CCSGUIReader__) */
|