CCSGUIReader.h
10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
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"
#include "editor-support/cocostudio/DictionaryHelper.h"
#include "editor-support/cocostudio/WidgetReader/WidgetReaderProtocol.h"
#include "base/ObjectFactory.h"
#include "base/CCValue.h"
#include "editor-support/cocostudio/CocosStudioExport.h"
namespace protocolbuffers
{
class NodeTree;
}
namespace tinyxml2
{
class XMLElement;
}
namespace cocostudio {
class CocoLoader;
struct stExpCocoNode;
#define kCCSVersion 1.0
typedef void (cocos2d::Ref::*SEL_ParseEvent)(const std::string&, cocos2d::Ref*, const rapidjson::Value&);
#define parseselector(_SELECTOR) (SEL_ParseEvent)(&_SELECTOR)
class CC_STUDIO_DLL GUIReader : public cocos2d::Ref
{
public:
CC_DEPRECATED_ATTRIBUTE static GUIReader* shareReader() { return GUIReader::getInstance(); };
CC_DEPRECATED_ATTRIBUTE static void purgeGUIReader() { GUIReader::destroyInstance(); };
static GUIReader* getInstance();
static void destroyInstance();
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
int getVersionInteger(const char* str);
/**
* @js NA
*/
void storeFileDesignSize(const char* fileName, const cocos2d::Size &size);
/**
* @js NA
*/
cocos2d::Size getFileDesignSize(const char* fileName) const;
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);
protected:
GUIReader();
~GUIReader();
std::string m_strFilePath;
cocos2d::ValueMap _fileDesignSizes;
typedef std::map<std::string, SEL_ParseEvent> ParseCallBackMap;
ParseCallBackMap _mapParseSelector;
typedef std::map<std::string, Ref*> ParseObjectMap;
ParseObjectMap _mapObject;
public:
ParseCallBackMap* getParseCallBackMap() { return &_mapParseSelector; };
ParseObjectMap* getParseObjectMap() { return &_mapObject; };
};
class CC_STUDIO_DLL 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);
WidgetReaderProtocol* createWidgetReaderProtocol(const std::string& classname);
protected:
std::string m_strFilePath;
};
class CC_STUDIO_DLL WidgetPropertiesReader0250 : public WidgetPropertiesReader
{
public:
WidgetPropertiesReader0250(){};
virtual ~WidgetPropertiesReader0250(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName) override;
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic) override;
//added for binary parsing
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode,
const char* fileName) override;
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) override;
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) override;
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;
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions) override;
};
class CC_STUDIO_DLL WidgetPropertiesReader0300 : public WidgetPropertiesReader
{
public:
WidgetPropertiesReader0300(){};
virtual ~WidgetPropertiesReader0300(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic,
const char* fullPath,
const char* fileName) override;
//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) override;
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode) override;
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;
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
const rapidjson::Value& options) override;
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions) override;
};
}
#endif /* defined(__CCSGUIReader__) */