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.
2022-08-08 18:02:17 +08:00
https://axys1.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
2022-08-08 18:02:17 +08:00
typedef void (ax::Ref::*SEL_ParseEvent)(std::string_view, ax::Ref*, const rapidjson::Value&);
2014-03-04 16:51:35 +08:00
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
2022-08-08 18:02:17 +08:00
class CCS_DLL GUIReader : public ax::Ref
2013-09-13 22:20:20 +08:00
{
public:
2022-07-15 19:17:01 +08:00
AX_DEPRECATED_ATTRIBUTE static GUIReader* shareReader() { return GUIReader::getInstance(); };
AX_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
2022-08-08 18:02:17 +08:00
ax::ui::Widget* widgetFromJsonFile(const char* fileName);
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
ax::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
*/
2022-08-08 18:02:17 +08:00
void storeFileDesignSize(const char* fileName, const ax::Size& size);
/**
* @js NA
*/
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::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;
2022-08-08 18:02:17 +08:00
ax::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
};
2022-08-08 18:02:17 +08:00
class CCS_DLL WidgetPropertiesReader : public ax::Ref
2013-11-11 18:22:14 +08:00
{
public:
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* createWidget(const rapidjson::Value& dic,
2021-12-25 10:04:45 +08:00
const char* fullPath,
const char* fileName) = 0;
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
2021-12-25 10:04:45 +08:00
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::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
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode,
const char* fileName) = 0;
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader, stExpCocoNode* pCocoNode) = 0;
2014-06-05 11:43:43 +08:00
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
2022-08-08 18:02:17 +08:00
ax::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:
2022-08-08 18:02:17 +08:00
void setAnchorPointForWidget(ax::ui::Widget* widget, const rapidjson::Value& options);
2021-12-26 23:26:34 +08:00
std::string getWidgetReaderClassName(std::string_view classname);
2022-08-08 18:02:17 +08:00
std::string getWidgetReaderClassName(ax::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);
2022-08-08 18:02:17 +08:00
ax::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
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* createWidget(const rapidjson::Value& dic,
2021-12-25 10:04:45 +08:00
const char* fullPath,
const char* fileName) override;
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
2021-12-25 10:04:45 +08:00
// added for binary parsing
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
const char* fileName) override;
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
virtual ax::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,
2022-08-08 18:02:17 +08:00
ax::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) override;
2022-08-08 18:02:17 +08:00
virtual void setPropsForWidgetFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
virtual void setColorPropsForWidgetFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForButtonFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForCheckBoxFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForImageViewFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelAtlasFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLabelBMFontFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForLoadingBarFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForSliderFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForTextFieldFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
virtual void setPropsForLayoutFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsForScrollViewFromJsonDictionary(ax::ui::Widget* widget, const rapidjson::Value& options);
2021-12-25 10:04:45 +08:00
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::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
2022-08-08 18:02:17 +08:00
virtual ax::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
2022-08-08 18:02:17 +08:00
virtual ax::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
2021-12-25 10:04:45 +08:00
stExpCocoNode* pCocoNode,
const char* fileName) override;
2022-08-08 18:02:17 +08:00
virtual ax::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,
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::ui::Widget* widget,
2014-06-23 10:02:09 +08:00
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode);
2022-08-08 18:02:17 +08:00
virtual ax::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,
2022-08-08 18:02:17 +08:00
ax::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,
2022-08-08 18:02:17 +08:00
ax::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__) */