axmol/extensions/cocostudio/CCSGUIReader.h

239 lines
11 KiB
C
Raw Normal View History

2021-01-09 18:32:22 +08:00
/****************************************************************************
2019-11-24 23:15:56 +08:00
Copyright (c) 2013-2017 Chukong Technologies Inc.
https://axis-project.github.io/
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"
#include "DictionaryHelper.h"
#include "WidgetReader/WidgetReaderProtocol.h"
2014-06-04 14:27:14 +08:00
#include "base/ObjectFactory.h"
2016-04-18 15:09:21 +08:00
#include "base/CCValue.h"
#include "CocosStudioExport.h"
2014-06-04 14:27:14 +08:00
2014-10-09 18:28:09 +08:00
namespace protocolbuffers
{
2021-12-25 10:04:45 +08:00
class NodeTree;
2014-10-09 18:28:09 +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;
2013-09-13 22:20:20 +08:00
#define kCCSVersion 1.0
2021-12-25 10:04:45 +08:00
typedef void (axis::Ref::*SEL_ParseEvent)(std::string_view, axis::Ref*, const rapidjson::Value&);
2014-03-04 16:51:35 +08:00
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
class CCS_DLL GUIReader : public axis::Ref
2013-09-13 22:20:20 +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
static GUIReader* getInstance();
static void destroyInstance();
2021-12-25 10:04:45 +08:00
axis::ui::Widget* widgetFromJsonFile(const char* fileName);
2021-12-25 10:04:45 +08:00
axis::ui::Widget* widgetFromBinaryFile(const char* fileName);
2021-12-25 10:04:45 +08:00
2013-09-13 22:20:20 +08:00
int getVersionInteger(const char* str);
/**
* @js NA
*/
void storeFileDesignSize(const char* fileName, const axis::Size& size);
/**
* @js NA
*/
axis::Size getFileDesignSize(const char* fileName) const;
2021-12-25 10:04:45 +08:00
2021-12-26 23:26:34 +08:00
void setFilePath(std::string_view strFilePath) { m_strFilePath = strFilePath; }
std::string_view getFilePath() const { return m_strFilePath; }
2014-06-11 21:11:22 +08:00
2021-12-26 23:26:34 +08:00
void registerTypeAndCallBack(std::string_view classType,
axis::ObjectFactory::Instance ins,
2014-03-04 16:51:35 +08:00
Ref* object,
SEL_ParseEvent callBack);
2021-12-26 23:26:34 +08:00
void registerTypeAndCallBack(std::string_view classType,
axis::ObjectFactory::InstanceFunc ins,
Ref* object,
SEL_ParseEvent callBack);
2021-12-25 10:04:45 +08:00
2013-09-13 22:20:20 +08:00
protected:
GUIReader();
~GUIReader();
2021-12-25 10:04:45 +08:00
2013-09-13 22:20:20 +08:00
std::string m_strFilePath;
axis::ValueMap _fileDesignSizes;
2021-12-25 10:04:45 +08:00
2021-12-27 13:52:08 +08:00
typedef hlookup::string_map<SEL_ParseEvent> ParseCallBackMap;
2014-03-04 16:51:35 +08:00
ParseCallBackMap _mapParseSelector;
2021-12-27 13:52:08 +08:00
typedef hlookup::string_map<Ref*> ParseObjectMap;
2014-03-04 16:51:35 +08:00
ParseObjectMap _mapObject;
2021-12-25 10:04:45 +08:00
2014-03-04 16:51:35 +08:00
public:
ParseCallBackMap* getParseCallBackMap() { return &_mapParseSelector; };
ParseObjectMap* getParseObjectMap() { return &_mapObject; };
2013-09-13 22:20:20 +08:00
};
class CCS_DLL WidgetPropertiesReader : public axis::Ref
2013-11-11 18:22:14 +08:00
{
public:
virtual axis::ui::Widget* createWidget(const rapidjson::Value& dic,
2021-12-25 10:04:45 +08:00
const char* fullPath,
const char* fileName) = 0;
virtual axis::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
2021-12-25 10:04:45 +08:00
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
2021-12-25 10:04:45 +08:00
const rapidjson::Value& options) = 0;
2021-12-26 23:26:34 +08:00
virtual void setPropsForAllCustomWidgetFromJsonDictionary(std::string_view classType,
axis::ui::Widget* widget,
2014-03-04 16:51:35 +08:00
const rapidjson::Value& customOptions) = 0;
2021-12-25 10:04:45 +08:00
// add binary parsing
virtual axis::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode,
const char* fileName) = 0;
virtual axis::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0;
2014-06-05 11:43:43 +08:00
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode) = 0;
protected:
void setAnchorPointForWidget(axis::ui::Widget* widget, const rapidjson::Value& options);
2021-12-26 23:26:34 +08:00
std::string getWidgetReaderClassName(std::string_view classname);
std::string getWidgetReaderClassName(axis::ui::Widget* widget);
2021-12-25 10:04:45 +08:00
2021-12-26 23:26:34 +08:00
std::string getGUIClassName(std::string_view name);
axis::ui::Widget* createGUI(std::string_view classname);
2021-12-26 23:26:34 +08:00
WidgetReaderProtocol* createWidgetReaderProtocol(std::string_view classname);
2021-12-25 10:04:45 +08:00
2013-11-11 18:22:14 +08:00
protected:
std::string m_strFilePath;
};
2020-10-17 16:32:16 +08:00
class CCS_DLL WidgetPropertiesReader0250 : public WidgetPropertiesReader
2013-11-11 18:22:14 +08:00
{
2021-12-25 10:04:45 +08:00
2013-11-11 18:22:14 +08:00
public:
WidgetPropertiesReader0250(){};
virtual ~WidgetPropertiesReader0250(){};
2021-12-25 10:04:45 +08:00
virtual axis::ui::Widget* createWidget(const rapidjson::Value& dic,
2021-12-25 10:04:45 +08:00
const char* fullPath,
const char* fileName) override;
virtual axis::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
2021-12-25 10:04:45 +08:00
// added for binary parsing
virtual axis::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
const char* fileName) override;
2021-12-25 10:04:45 +08:00
virtual axis::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) override;
2021-12-25 10:04:45 +08:00
2014-06-11 14:15:34 +08:00
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) override;
virtual void setPropsForWidgetFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
virtual void setColorPropsForWidgetFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForButtonFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForCheckBoxFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForImageViewFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelAtlasFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelBMFontFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLoadingBarFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForSliderFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForTextFieldFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
virtual void setPropsForLayoutFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForScrollViewFromJsonDictionary(axis::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
2021-12-25 10:04:45 +08:00
const rapidjson::Value& options) override;
2021-12-26 23:26:34 +08:00
virtual void setPropsForAllCustomWidgetFromJsonDictionary(std::string_view classType,
axis::ui::Widget* widget,
const rapidjson::Value& customOptions) override;
2013-11-11 18:22:14 +08:00
};
2021-12-25 10:04:45 +08:00
2020-10-17 16:32:16 +08:00
class CCS_DLL WidgetPropertiesReader0300 : public WidgetPropertiesReader
2013-11-11 18:22:14 +08:00
{
2021-12-25 10:04:45 +08:00
2013-11-11 18:22:14 +08:00
public:
WidgetPropertiesReader0300(){};
virtual ~WidgetPropertiesReader0300(){};
2021-12-25 10:04:45 +08:00
virtual axis::ui::Widget* createWidget(const rapidjson::Value& dic,
2014-06-11 14:15:34 +08:00
const char* fullPath,
const char* fileName) override;
2021-12-25 10:04:45 +08:00
// add bin parse support
virtual axis::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode,
const char* fileName) override;
virtual axis::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) override;
2021-12-25 10:04:45 +08:00
2014-06-11 14:15:34 +08:00
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode) override;
2021-12-26 23:26:34 +08:00
virtual void setPropsForAllCustomWidgetFromBinary(std::string_view classType,
axis::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode);
virtual axis::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
2021-12-25 10:04:45 +08:00
2014-06-11 14:15:34 +08:00
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
axis::ui::Widget* widget,
const rapidjson::Value& options) override;
2021-12-25 10:04:45 +08:00
2021-12-26 23:26:34 +08:00
virtual void setPropsForAllCustomWidgetFromJsonDictionary(std::string_view classType,
axis::ui::Widget* widget,
2021-12-25 10:04:45 +08:00
const rapidjson::Value& customOptions) override;
2013-11-11 18:22:14 +08:00
};
2021-12-25 10:04:45 +08:00
} // namespace cocostudio
2013-09-13 22:20:20 +08:00
#endif /* defined(__CCSGUIReader__) */