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-10-16 16:48:39 +08:00
|
|
|
#include "cocostudio/CCSGUIReader.h"
|
|
|
|
#include "gui/CocosGUI.h"
|
|
|
|
#include "cocostudio/CCActionManagerEx.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2014-03-04 16:51:35 +08:00
|
|
|
#include "WidgetReader/ButtonReader/ButtonReader.h"
|
|
|
|
#include "WidgetReader/CheckBoxReader/CheckBoxReader.h"
|
|
|
|
#include "WidgetReader/SliderReader/SliderReader.h"
|
|
|
|
#include "WidgetReader/ImageViewReader/ImageViewReader.h"
|
|
|
|
#include "WidgetReader/LoadingBarReader/LoadingBarReader.h"
|
|
|
|
#include "WidgetReader/TextAtlasReader/TextAtlasReader.h"
|
|
|
|
#include "WidgetReader/TextReader/TextReader.h"
|
|
|
|
#include "WidgetReader/TextBMFontReader/TextBMFontReader.h"
|
|
|
|
#include "WidgetReader/TextFieldReader/TextFieldReader.h"
|
|
|
|
#include "WidgetReader/LayoutReader/LayoutReader.h"
|
|
|
|
#include "WidgetReader/PageViewReader/PageViewReader.h"
|
|
|
|
#include "WidgetReader/ScrollViewReader/ScrollViewReader.h"
|
|
|
|
#include "WidgetReader/ListViewReader/ListViewReader.h"
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
using namespace cocos2d::ui;
|
2013-12-23 15:02:52 +08:00
|
|
|
using namespace cocos2d;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-14 11:37:46 +08:00
|
|
|
static GUIReader* sharedReader = nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
GUIReader::GUIReader():
|
|
|
|
m_strFilePath("")
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
ObjectFactory* factoryCreate = ObjectFactory::getInstance();
|
|
|
|
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ButtonReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(CheckBoxReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(SliderReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ImageViewReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LoadingBarReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextAtlasReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextBMFontReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(TextFieldReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(LayoutReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(PageViewReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ScrollViewReader));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_WIDGET_READER_INFO(ListViewReader));
|
|
|
|
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Button));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(CheckBox));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ImageView));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Text));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextAtlas));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextBMFont));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(LoadingBar));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Slider));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(TextField));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(Layout));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ListView));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(PageView));
|
|
|
|
factoryCreate->registerType(CREATE_CLASS_GUI_INFO(ScrollView));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
GUIReader::~GUIReader()
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader* GUIReader::getInstance()
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
if (!sharedReader)
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
sharedReader = new GUIReader();
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
return sharedReader;
|
|
|
|
}
|
|
|
|
|
2014-01-04 14:23:40 +08:00
|
|
|
void GUIReader::destroyInstance()
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
CC_SAFE_DELETE(sharedReader);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
int GUIReader::getVersionInteger(const char *str)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
std::string strVersion = str;
|
2013-12-28 14:34:52 +08:00
|
|
|
size_t length = strVersion.length();
|
2013-09-13 22:20:20 +08:00
|
|
|
if (length < 7)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-28 14:34:52 +08:00
|
|
|
size_t pos = strVersion.find_first_of(".");
|
2013-09-13 22:20:20 +08:00
|
|
|
std::string t = strVersion.substr(0,pos);
|
|
|
|
strVersion = strVersion.substr(pos+1,strVersion.length()-1);
|
|
|
|
|
|
|
|
pos = strVersion.find_first_of(".");
|
|
|
|
std::string h = strVersion.substr(0,pos);
|
|
|
|
strVersion = strVersion.substr(pos+1,strVersion.length()-1);
|
|
|
|
|
|
|
|
pos = strVersion.find_first_of(".");
|
|
|
|
std::string te = strVersion.substr(0,pos);
|
|
|
|
strVersion = strVersion.substr(pos+1,strVersion.length()-1);
|
|
|
|
|
|
|
|
pos = strVersion.find_first_of(".");
|
|
|
|
std::string s = strVersion.substr(0,pos);
|
|
|
|
|
|
|
|
int it = atoi(t.c_str());
|
|
|
|
int ih = atoi(h.c_str());
|
|
|
|
int ite = atoi(te.c_str());
|
|
|
|
int is = atoi(s.c_str());
|
|
|
|
|
|
|
|
int iVersion = it*1000+ih*100+ite*10+is;
|
|
|
|
CCLOG("iversion %d",iVersion);
|
|
|
|
return iVersion;
|
|
|
|
/************************/
|
|
|
|
}
|
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
void GUIReader::storeFileDesignSize(const char *fileName, const cocos2d::Size &size)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 10:41:01 +08:00
|
|
|
std::string keyWidth = fileName;
|
|
|
|
keyWidth.append("width");
|
|
|
|
std::string keyHeight = fileName;
|
|
|
|
keyHeight.append("height");
|
|
|
|
_fileDesignSizes[keyWidth] = Value(size.width);
|
|
|
|
_fileDesignSizes[keyHeight] = Value(size.height);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const
|
|
|
|
{
|
2013-12-24 10:41:01 +08:00
|
|
|
std::string keyWidth = fileName;
|
|
|
|
keyWidth.append("width");
|
|
|
|
std::string keyHeight = fileName;
|
|
|
|
keyHeight.append("height");
|
|
|
|
float w = _fileDesignSizes.at(keyWidth).asFloat();
|
|
|
|
float h = _fileDesignSizes.at(keyHeight).asFloat();
|
|
|
|
return Size(w, h);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
void GUIReader::registerTypeAndCallBack(const std::string& classType,
|
|
|
|
ObjectFactory::Instance ins,
|
|
|
|
Object *object,
|
|
|
|
SEL_ParseEvent callBack)
|
|
|
|
{
|
|
|
|
ObjectFactory* factoryCreate = ObjectFactory::getInstance();
|
|
|
|
|
|
|
|
ObjectFactory::TInfo t(classType, ins);
|
|
|
|
factoryCreate->registerType(t);
|
|
|
|
|
|
|
|
if (object)
|
|
|
|
{
|
|
|
|
_mapObject.insert(ParseObjectMap::value_type(classType, object));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callBack)
|
|
|
|
{
|
|
|
|
_mapParseSelector.insert(ParseCallBackMap::value_type(classType, callBack));
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* GUIReader::widgetFromJsonFile(const char *fileName)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
std::string jsonpath;
|
|
|
|
rapidjson::Document jsonDict;
|
2013-11-11 18:22:14 +08:00
|
|
|
jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
|
2013-12-28 14:34:52 +08:00
|
|
|
size_t pos = jsonpath.find_last_of('/');
|
2013-12-24 20:33:55 +08:00
|
|
|
m_strFilePath = jsonpath.substr(0,pos+1);
|
2013-12-24 22:05:13 +08:00
|
|
|
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
|
|
|
|
jsonDict.Parse<0>(contentStr.c_str());
|
2013-12-24 20:33:55 +08:00
|
|
|
if (jsonDict.HasParseError())
|
|
|
|
{
|
|
|
|
CCLOG("GetParseError %s\n",jsonDict.GetParseError());
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* widget = nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* fileVersion = DICTOOL->getStringValue_json(jsonDict, "version");
|
2013-11-14 11:37:46 +08:00
|
|
|
WidgetPropertiesReader * pReader = nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fileVersion)
|
|
|
|
{
|
|
|
|
int versionInteger = getVersionInteger(fileVersion);
|
|
|
|
if (versionInteger < 250)
|
|
|
|
{
|
|
|
|
pReader = new WidgetPropertiesReader0250();
|
|
|
|
widget = pReader->createWidget(jsonDict, m_strFilePath.c_str(), fileName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pReader = new WidgetPropertiesReader0300();
|
|
|
|
widget = pReader->createWidget(jsonDict, m_strFilePath.c_str(), fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pReader = new WidgetPropertiesReader0250();
|
|
|
|
widget = pReader->createWidget(jsonDict, m_strFilePath.c_str(), fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pReader);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
m_strFilePath = fullPath;
|
2013-12-24 20:33:55 +08:00
|
|
|
int texturesCount = DICTOOL->getArrayCount_json(data, "textures");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
for (int i=0; i<texturesCount; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* file = DICTOOL->getStringValueFromArray_json(data, "textures", i);
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp = fullPath;
|
|
|
|
tp.append(file);
|
|
|
|
CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(tp.c_str());
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
float fileDesignWidth = DICTOOL->getFloatValue_json(data, "designWidth");
|
|
|
|
float fileDesignHeight = DICTOOL->getFloatValue_json(data, "designHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
|
2014-01-04 14:23:40 +08:00
|
|
|
CCLOGERROR("Read design size error!\n");
|
2013-11-11 18:22:14 +08:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader::getInstance()->storeFileDesignSize(fileName, winSize);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader::getInstance()->storeFileDesignSize(fileName, Size(fileDesignWidth, fileDesignHeight));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& widgetTree = DICTOOL->getSubDictionary_json(data, "widgetTree");
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* widget = widgetFromJsonDictionary(widgetTree);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
/* *********temp********* */
|
|
|
|
if (widget->getContentSize().equals(Size::ZERO))
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
Layout* rootWidget = dynamic_cast<Layout*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
|
|
|
|
}
|
|
|
|
/* ********************** */
|
|
|
|
|
|
|
|
// widget->setFileDesignSize(Size(fileDesignWidth, fileDesignHeight));
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& actions = DICTOOL->getSubDictionary_json(data, "animation");
|
2013-11-11 18:22:14 +08:00
|
|
|
/* *********temp********* */
|
2013-12-27 10:43:49 +08:00
|
|
|
// ActionManager::getInstance()->releaseActions();
|
2013-11-11 18:22:14 +08:00
|
|
|
/* ********************** */
|
|
|
|
CCLOG("file name == [%s]",fileName);
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* rootWidget = (Ref*) widget;
|
2013-12-27 10:43:49 +08:00
|
|
|
ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
|
2013-11-11 18:22:14 +08:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
Widget* WidgetPropertiesReader0250::widgetFromJsonDictionary(const rapidjson::Value&data)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* widget = nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* classname = DICTOOL->getStringValue_json(data, "classname");
|
|
|
|
const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (classname && strcmp(classname, "Button") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::Button::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForButtonFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "CheckBox") == 0)
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
widget = CheckBox::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "Label") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::Text::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForLabelFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "LabelAtlas") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::TextAtlas::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "LoadingBar") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::LoadingBar::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
|
|
|
|
}else if (classname && strcmp(classname, "ScrollView") == 0){
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::ScrollView::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "TextArea") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::Text::create();
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForLabelFromJsonDictionary(widget, uiOptions);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "TextButton") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::Button::create();
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForButtonFromJsonDictionary(widget, uiOptions);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "TextField") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::TextField::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "ImageView") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::ImageView::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForImageViewFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "Panel") == 0)
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
widget = Layout::create();
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForLayoutFromJsonDictionary(widget, uiOptions);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "Slider") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::Slider::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForSliderFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "LabelBMFont") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::TextBMFont::create();
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForLabelBMFontFromJsonDictionary(widget, uiOptions);
|
|
|
|
}
|
|
|
|
else if (classname && strcmp(classname, "DragPanel") == 0)
|
|
|
|
{
|
2014-02-24 18:56:45 +08:00
|
|
|
widget = cocos2d::ui::ScrollView::create();
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int childrenCount = DICTOOL->getArrayCount_json(data, "children");
|
2013-09-13 22:20:20 +08:00
|
|
|
for (int i=0;i<childrenCount;i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& subData = DICTOOL->getDictionaryFromArray_json(data, "children", i);
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* child = widgetFromJsonDictionary(subData);
|
2013-09-13 22:20:20 +08:00
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
widget->addChild(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForWidgetFromJsonDictionary(Widget*widget,const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (ignoreSizeExsit)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float w = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
float h = DICTOOL->getFloatValue_json(options, "height");
|
2013-09-16 15:32:52 +08:00
|
|
|
widget->setSize(Size(w, h));
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
|
|
|
|
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
|
|
|
|
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble"));
|
|
|
|
const char* name = DICTOOL->getStringValue_json(options, "name");
|
2013-09-13 22:20:20 +08:00
|
|
|
const char* widgetName = name?name:"default";
|
|
|
|
widget->setName(widgetName);
|
2013-12-24 20:33:55 +08:00
|
|
|
float x = DICTOOL->getFloatValue_json(options, "x");
|
|
|
|
float y = DICTOOL->getFloatValue_json(options, "y");
|
2013-09-16 15:32:52 +08:00
|
|
|
widget->setPosition(Point(x,y));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sx = DICTOOL->checkObjectExist_json(options, "scaleX");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (sx)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sy = DICTOOL->checkObjectExist_json(options, "scaleY");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (sy)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool rt = DICTOOL->checkObjectExist_json(options, "rotation");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (rt)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool vb = DICTOOL->checkObjectExist_json(options, "visible");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (vb)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
int z = DICTOOL->getIntValue_json(options, "ZOrder");
|
2014-01-19 03:35:27 +08:00
|
|
|
widget->setLocalZOrder(z);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setColorPropsForWidgetFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (op)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool cr = DICTOOL->checkObjectExist_json(options, "colorR");
|
|
|
|
bool cg = DICTOOL->checkObjectExist_json(options, "colorG");
|
|
|
|
bool cb = DICTOOL->checkObjectExist_json(options, "colorB");
|
|
|
|
int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255;
|
|
|
|
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
|
|
|
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
2013-09-16 15:32:52 +08:00
|
|
|
widget->setColor(Color3B(colorR, colorG, colorB));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
|
|
|
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
|
|
|
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
|
|
|
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
2013-09-16 15:32:52 +08:00
|
|
|
widget->setAnchorPoint(Point(apxf, apyf));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
|
|
|
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
2014-03-05 15:04:30 +08:00
|
|
|
widget->setFlippedX(flipX);
|
|
|
|
widget->setFlippedY(flipY);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForButtonFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Button* button = static_cast<Button*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
std::string tp_n = m_strFilePath;
|
|
|
|
std::string tp_p = m_strFilePath;
|
|
|
|
std::string tp_d = m_strFilePath;
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(options, "normal");
|
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(options, "pressed");
|
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(options, "disabled");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
|
|
|
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
|
|
|
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (scale9Enable)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextures(normalFileName, pressedFileName, disabledFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
|
|
|
|
}
|
|
|
|
button->setCapInsets(Rect(cx, cy, cw, ch));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
|
|
|
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sw && sh)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setSize(Size(swf, shf));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextures(normalFileName, pressedFileName, disabledFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
else
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool tt = DICTOOL->checkObjectExist_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (tt)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (text)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setTitleText(text);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool cr = DICTOOL->checkObjectExist_json(options, "textColorR");
|
|
|
|
bool cg = DICTOOL->checkObjectExist_json(options, "textColorG");
|
|
|
|
bool cb = DICTOOL->checkObjectExist_json(options, "textColorB");
|
|
|
|
int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255;
|
|
|
|
int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255;
|
|
|
|
int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255;
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setTitleColor(Color3B(cri,cgi,cbi));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForCheckBoxFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2013-12-25 22:13:19 +08:00
|
|
|
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundFileName = DICTOOL->getStringValue_json(options, "backGroundBox");
|
|
|
|
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(options, "backGroundBoxSelected");
|
|
|
|
const char* frontCrossFileName = DICTOOL->getStringValue_json(options, "frontCross");
|
|
|
|
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(options, "backGroundBoxDisabled");
|
|
|
|
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "frontCrossDisabled");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
std::string tp_b = m_strFilePath;
|
|
|
|
std::string tp_bs = m_strFilePath;
|
|
|
|
std::string tp_c = m_strFilePath;
|
|
|
|
std::string tp_bd = m_strFilePath;
|
|
|
|
std::string tp_cd = m_strFilePath;
|
|
|
|
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr;
|
|
|
|
const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr;
|
|
|
|
const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr;
|
|
|
|
const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr;
|
|
|
|
const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
|
|
|
checkBox->loadTextures(backGroundFileName, backGroundSelectedFileName, frontCrossFileName,backGroundDisabledFileName,frontCrossDisabledFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
checkBox->loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp,backGroundDisabledFileName_tp,frontCrossDisabledFileName_tp);
|
|
|
|
}
|
2014-01-15 20:06:49 +08:00
|
|
|
checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState"));
|
2013-11-11 18:22:14 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForImageViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::ImageView* imageView = static_cast<ImageView*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(options, "fileName");
|
|
|
|
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
bool scale9Enable = false;
|
|
|
|
if (scale9EnableExist)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
imageView->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
std::string tp_i = m_strFilePath;
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
|
|
|
{
|
|
|
|
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (scale9Enable)
|
|
|
|
{
|
2013-09-13 22:20:20 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->loadTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
|
|
|
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sw && sh)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->setSize(Size(swf, shf));
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->setCapInsets(Rect(cx, cy, cw, ch));
|
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
else
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->loadTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForLabelFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Text* label = static_cast<cocos2d::ui::Text*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
|
2013-11-11 18:22:14 +08:00
|
|
|
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
label->setText(text);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-01-14 14:37:31 +08:00
|
|
|
bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth");
|
|
|
|
bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight");
|
|
|
|
if (aw && ah)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-01-14 14:37:31 +08:00
|
|
|
Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight"));
|
|
|
|
label->setTextAreaSize(size);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (ha)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool va = DICTOOL->checkObjectExist_json(options, "vAlignment");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (va)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForLabelAtlasFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextAtlas* labelAtlas = static_cast<cocos2d::ui::TextAtlas*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sv = DICTOOL->checkObjectExist_json(options, "stringValue");
|
|
|
|
bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile");
|
|
|
|
bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth");
|
|
|
|
bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight");
|
|
|
|
bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap");
|
|
|
|
if (sv && cmf && iw && ih && scm && (strcmp(DICTOOL->getStringValue_json(options, "charMapFile"), "") != 0))
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
std::string tp_c = m_strFilePath;
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* cmf_tp = nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* cmft = DICTOOL->getStringValue_json(options, "charMapFile");
|
2013-11-11 18:22:14 +08:00
|
|
|
cmf_tp = tp_c.append(cmft).c_str();
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"),DICTOOL->getStringValue_json(options, "startCharMap"));
|
2013-12-26 23:01:34 +08:00
|
|
|
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth") / CC_CONTENT_SCALE_FACTOR() ,DICTOOL->getIntValue_json(options,"itemHeight") / CC_CONTENT_SCALE_FACTOR(), DICTOOL->getStringValue_json(options, "startCharMap"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForLayoutFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2013-12-25 22:13:19 +08:00
|
|
|
Layout* containerWidget = static_cast<Layout*>(widget);
|
2014-02-24 18:56:45 +08:00
|
|
|
if (!dynamic_cast<cocos2d::ui::ScrollView*>(containerWidget)
|
|
|
|
&& !dynamic_cast<cocos2d::ui::ListView*>(containerWidget))
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
containerWidget->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-23 15:02:52 +08:00
|
|
|
Layout* panel = (Layout*)widget;
|
2013-12-24 20:33:55 +08:00
|
|
|
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
|
2013-12-24 20:33:55 +08:00
|
|
|
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
|
|
|
|
int cg = DICTOOL->getIntValue_json(options, "bgColorG");
|
|
|
|
int cb = DICTOOL->getIntValue_json(options, "bgColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int scr = DICTOOL->getIntValue_json(options, "bgStartColorR");
|
|
|
|
int scg = DICTOOL->getIntValue_json(options, "bgStartColorG");
|
|
|
|
int scb = DICTOOL->getIntValue_json(options, "bgStartColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR");
|
|
|
|
int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG");
|
|
|
|
int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX");
|
|
|
|
float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundColorVector(Point(bgcv1, bgcv2));
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int co = DICTOOL->getIntValue_json(options, "bgColorOpacity");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int colorType = DICTOOL->getIntValue_json(options, "colorType");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundColorType(LayoutBackGroundColorType(colorType));
|
|
|
|
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
|
|
|
|
panel->setBackGroundColor(Color3B(cr, cg, cb));
|
|
|
|
panel->setBackGroundColorOpacity(co);
|
|
|
|
|
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(options, "backGroundImage");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (backGroundScale9Enable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
else
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
else
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
else
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForScrollViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForLayoutFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::ScrollView* scrollView = static_cast<cocos2d::ui::ScrollView*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
|
|
|
|
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
2013-12-24 20:33:55 +08:00
|
|
|
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
2013-11-11 18:22:14 +08:00
|
|
|
scrollView->setDirection((SCROLLVIEW_DIR)direction);
|
2013-12-24 20:33:55 +08:00
|
|
|
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable"));
|
2013-11-11 18:22:14 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForSliderFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Slider* slider = static_cast<cocos2d::ui::Slider*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->setScale9Enabled(barTextureScale9Enable);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
|
|
|
|
float barLength = DICTOOL->getFloatValue_json(options, "length");
|
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (bt)
|
|
|
|
{
|
|
|
|
if (barTextureScale9Enable)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(options, "barFileName");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->setSize(Size(barLength, slider->getContentSize().height));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(options, "barFileName");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-09-13 22:20:20 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
std::string tp_n = m_strFilePath;
|
|
|
|
std::string tp_p = m_strFilePath;
|
|
|
|
std::string tp_d = m_strFilePath;
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(options, "ballNormal");
|
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(options, "ballPressed");
|
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(options, "ballDisabled");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
|
|
|
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
|
|
|
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
|
|
|
slider->loadSlidBallTextures(normalFileName,pressedFileName,disabledFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTextures(normalFileName_tp,pressedFileName_tp,disabledFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(options, "progressBarFileName");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
|
|
|
slider->loadProgressBarTexture(imageFileName, UI_TEX_TYPE_PLIST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slider->loadProgressBarTexture(imageFileName_tp);
|
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForTextFieldFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextField* textField = static_cast<cocos2d::ui::TextField*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (ph)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setText(DICTOOL->getStringValue_json(options, "text"));
|
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth");
|
|
|
|
bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (tsw && tsh)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight")));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float dw = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
float dh = DICTOOL->getFloatValue_json(options, "height");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (dw > 0.0f || dh > 0.0f)
|
|
|
|
{
|
|
|
|
//textField->setSize(Size(dw, dh));
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
|
2013-11-11 18:22:14 +08:00
|
|
|
textField->setMaxLengthEnabled(maxLengthEnable);
|
|
|
|
|
|
|
|
if (maxLengthEnable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
int maxLength = DICTOOL->getIntValue_json(options, "maxLength");
|
2013-11-11 18:22:14 +08:00
|
|
|
textField->setMaxLength(maxLength);
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
|
2013-11-11 18:22:14 +08:00
|
|
|
textField->setPasswordEnabled(passwordEnable);
|
|
|
|
if (passwordEnable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForLoadingBarFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::LoadingBar* loadingBar = static_cast<cocos2d::ui::LoadingBar*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool useMergedTexture = DICTOOL->getBooleanValue_json(options, "useMergedTexture");
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char*imageFileName = DICTOOL->getStringValue_json(options, "texture");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (useMergedTexture)
|
|
|
|
{
|
|
|
|
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
loadingBar->loadTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction")));
|
|
|
|
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
2013-11-11 18:22:14 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0250::setPropsForLabelBMFontFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-09-13 22:20:20 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextBMFont* labelBMFont = static_cast<cocos2d::ui::TextBMFont*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
std::string tp_c = m_strFilePath;
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* cmf_tp = nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* cmft = DICTOOL->getStringValue_json(options, "fileName");
|
2013-11-11 18:22:14 +08:00
|
|
|
cmf_tp = tp_c.append(cmft).c_str();
|
|
|
|
|
|
|
|
labelBMFont->setFntFile(cmf_tp);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
labelBMFont->setText(text);
|
|
|
|
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
void WidgetPropertiesReader0250::setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol *reader, Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void WidgetPropertiesReader0250::setPropsForAllCustomWidgetFromJsonDictionary(const std::string &classType,
|
|
|
|
cocos2d::ui::Widget *widget,
|
|
|
|
const rapidjson::Value &customOptions)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*0.3.0.0~1.0.0.0*/
|
2013-12-26 12:55:52 +08:00
|
|
|
Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
m_strFilePath = fullPath;
|
2013-12-24 20:33:55 +08:00
|
|
|
|
|
|
|
int texturesCount = DICTOOL->getArrayCount_json(data, "textures");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
for (int i=0; i<texturesCount; i++)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* file = DICTOOL->getStringValueFromArray_json(data, "textures", i);
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp = fullPath;
|
|
|
|
tp.append(file);
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(tp.c_str());
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
float fileDesignWidth = DICTOOL->getFloatValue_json(data, "designWidth");
|
|
|
|
float fileDesignHeight = DICTOOL->getFloatValue_json(data, "designHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
|
2014-01-04 14:23:40 +08:00
|
|
|
CCLOGERROR("Read design size error!\n");
|
2013-11-11 18:22:14 +08:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader::getInstance()->storeFileDesignSize(fileName, winSize);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
GUIReader::getInstance()->storeFileDesignSize(fileName, Size(fileDesignWidth, fileDesignHeight));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& widgetTree = DICTOOL->getSubDictionary_json(data, "widgetTree");
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* widget = widgetFromJsonDictionary(widgetTree);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
/* *********temp********* */
|
|
|
|
if (widget->getContentSize().equals(Size::ZERO))
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
Layout* rootWidget = dynamic_cast<Layout*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
|
|
|
|
}
|
|
|
|
/* ********************** */
|
|
|
|
|
|
|
|
// widget->setFileDesignSize(Size(fileDesignWidth, fileDesignHeight));
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& actions = DICTOOL->getSubDictionary_json(data, "animation");
|
2013-11-11 18:22:14 +08:00
|
|
|
/* *********temp********* */
|
2013-12-27 10:43:49 +08:00
|
|
|
// ActionManager::getInstance()->releaseActions();
|
2013-11-11 18:22:14 +08:00
|
|
|
/* ********************** */
|
|
|
|
CCLOG("file name == [%s]",fileName);
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* rootWidget = (Ref*) widget;
|
2013-12-27 10:43:49 +08:00
|
|
|
ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
|
2013-11-11 18:22:14 +08:00
|
|
|
return widget;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* classname = DICTOOL->getStringValue_json(data, "classname");
|
|
|
|
const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options");
|
2014-03-04 16:51:35 +08:00
|
|
|
Widget* widget = ObjectFactory::getInstance()->createGUI(classname);
|
|
|
|
|
|
|
|
// create widget reader to parse properties of widget
|
|
|
|
std::string readerName = classname;
|
|
|
|
if (readerName == "Panel")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "Layout";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else if (readerName == "TextArea")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "Text";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else if (readerName == "TextButton")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "Button";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else if (readerName == "Label")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "Text";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else if (readerName == "LabelAtlas")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "TextAtlas";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else if (readerName == "LabelBMFont")
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName = "TextBMFont";
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
readerName.append("Reader");
|
|
|
|
WidgetReaderProtocol* reader = ObjectFactory::getInstance()->createWidgetReaderProtocol(readerName);
|
|
|
|
|
|
|
|
if (reader)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
// widget parse with widget reader
|
|
|
|
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
else
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-03-04 16:51:35 +08:00
|
|
|
// 1st., custom widget parse properties of parent widget with parent widget reader
|
|
|
|
if (dynamic_cast<Button*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "ButtonReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<CheckBox*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "CheckBoxReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<ImageView*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "ImageViewReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<TextAtlas*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "TextAtlasReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<TextBMFont*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "TextBMFontReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<Text*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "TextReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<LoadingBar*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "LoadingBarReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<Slider*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "SliderReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<TextField*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "TextFieldReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<Layout*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "LayoutReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<ScrollView*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "ScrollViewReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<ListView*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "ListViewReader";
|
|
|
|
}
|
|
|
|
else if (dynamic_cast<PageView*>(widget))
|
|
|
|
{
|
|
|
|
readerName = "PageViewReader";
|
|
|
|
}
|
|
|
|
reader = ObjectFactory::getInstance()->createWidgetReaderProtocol(readerName);
|
|
|
|
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
|
|
|
|
|
|
|
|
// 2nd., custom widget parse with custom reader
|
|
|
|
const char* customProperty = DICTOOL->getStringValue_json(uiOptions, "customProperty");
|
|
|
|
rapidjson::Document customJsonDict;
|
|
|
|
customJsonDict.Parse<0>(customProperty);
|
|
|
|
if (customJsonDict.HasParseError())
|
|
|
|
{
|
|
|
|
CCLOG("GetParseError %s\n", customJsonDict.GetParseError());
|
|
|
|
}
|
|
|
|
setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int childrenCount = DICTOOL->getArrayCount_json(data, "children");
|
2014-03-04 16:51:35 +08:00
|
|
|
for (int i = 0; i < childrenCount; i++)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& subData = DICTOOL->getDictionaryFromArray_json(data, "children", i);
|
2014-03-04 16:51:35 +08:00
|
|
|
cocos2d::ui::Widget* child = widgetFromJsonDictionary(subData);
|
2013-11-11 18:22:14 +08:00
|
|
|
if (child)
|
|
|
|
{
|
2013-12-26 21:02:47 +08:00
|
|
|
PageView* pageView = dynamic_cast<PageView*>(widget);
|
|
|
|
if (pageView)
|
2013-12-26 17:53:22 +08:00
|
|
|
{
|
2013-12-26 21:02:47 +08:00
|
|
|
pageView->addPage(static_cast<Layout*>(child));
|
2013-12-26 17:53:22 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-26 21:02:47 +08:00
|
|
|
ListView* listView = dynamic_cast<ListView*>(widget);
|
|
|
|
if (listView)
|
|
|
|
{
|
|
|
|
listView->pushBackCustomItem(child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget->addChild(child);
|
|
|
|
}
|
2013-12-26 17:53:22 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForWidgetFromJsonDictionary(Widget*widget,const rapidjson::Value&options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, "ignoreSize");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (ignoreSizeExsit)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, "ignoreSize"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setSizeType((SizeType)DICTOOL->getIntValue_json(options, "sizeType"));
|
|
|
|
widget->setPositionType((PositionType)DICTOOL->getIntValue_json(options, "positionType"));
|
2013-11-13 20:01:57 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setSizePercent(Point(DICTOOL->getFloatValue_json(options, "sizePercentX"), DICTOOL->getFloatValue_json(options, "sizePercentY")));
|
|
|
|
widget->setPositionPercent(Point(DICTOOL->getFloatValue_json(options, "positionPercentX"), DICTOOL->getFloatValue_json(options, "positionPercentY")));
|
2013-11-13 20:01:57 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float w = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
float h = DICTOOL->getFloatValue_json(options, "height");
|
2013-11-11 18:22:14 +08:00
|
|
|
widget->setSize(Size(w, h));
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setTag(DICTOOL->getIntValue_json(options, "tag"));
|
|
|
|
widget->setActionTag(DICTOOL->getIntValue_json(options, "actiontag"));
|
|
|
|
widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, "touchAble"));
|
|
|
|
const char* name = DICTOOL->getStringValue_json(options, "name");
|
2013-11-11 18:22:14 +08:00
|
|
|
const char* widgetName = name?name:"default";
|
|
|
|
widget->setName(widgetName);
|
2013-12-24 20:33:55 +08:00
|
|
|
float x = DICTOOL->getFloatValue_json(options, "x");
|
|
|
|
float y = DICTOOL->getFloatValue_json(options, "y");
|
2013-11-11 18:22:14 +08:00
|
|
|
widget->setPosition(Point(x,y));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sx = DICTOOL->checkObjectExist_json(options, "scaleX");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sx)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setScaleX(DICTOOL->getFloatValue_json(options, "scaleX"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sy = DICTOOL->checkObjectExist_json(options, "scaleY");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sy)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setScaleY(DICTOOL->getFloatValue_json(options, "scaleY"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool rt = DICTOOL->checkObjectExist_json(options, "rotation");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (rt)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setRotation(DICTOOL->getFloatValue_json(options, "rotation"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool vb = DICTOOL->checkObjectExist_json(options, "visible");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (vb)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setVisible(DICTOOL->getBooleanValue_json(options, "visible"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
int z = DICTOOL->getIntValue_json(options, "ZOrder");
|
2014-01-19 03:35:27 +08:00
|
|
|
widget->setLocalZOrder(z);
|
2013-11-13 20:01:57 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool layout = DICTOOL->checkObjectExist_json(options, "layoutParameter");
|
|
|
|
if (layout)
|
|
|
|
{
|
|
|
|
const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, "layoutParameter");
|
|
|
|
int paramType = DICTOOL->getIntValue_json(layoutParameterDic, "type");
|
2013-12-23 15:02:52 +08:00
|
|
|
LayoutParameter* parameter = nullptr;
|
2013-11-13 20:01:57 +08:00
|
|
|
switch (paramType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
parameter = LinearLayoutParameter::create();
|
2013-12-24 20:33:55 +08:00
|
|
|
int gravity = DICTOOL->getIntValue_json(layoutParameterDic, "gravity");
|
2013-12-23 15:02:52 +08:00
|
|
|
((LinearLayoutParameter*)parameter)->setGravity((LinearGravity)gravity);
|
2013-11-13 20:01:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
parameter = RelativeLayoutParameter::create();
|
|
|
|
RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeName");
|
2013-11-13 20:01:57 +08:00
|
|
|
rParameter->setRelativeName(relativeName);
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, "relativeToName");
|
2013-11-13 20:01:57 +08:00
|
|
|
rParameter->setRelativeToWidgetName(relativeToName);
|
2013-12-24 20:33:55 +08:00
|
|
|
int align = DICTOOL->getIntValue_json(layoutParameterDic, "align");
|
2013-12-23 15:02:52 +08:00
|
|
|
rParameter->setAlign((RelativeAlign)align);
|
2013-11-13 20:01:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-11-18 10:19:40 +08:00
|
|
|
if (parameter)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, "marginLeft");
|
|
|
|
float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, "marginTop");
|
|
|
|
float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, "marginRight");
|
|
|
|
float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, "marginDown");
|
2013-12-23 15:02:52 +08:00
|
|
|
parameter->setMargin(Margin(mgl, mgt, mgr, mgb));
|
2013-11-18 10:19:40 +08:00
|
|
|
widget->setLayoutParameter(parameter);
|
|
|
|
}
|
2013-11-13 20:01:57 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setColorPropsForWidgetFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (op)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
widget->setOpacity(DICTOOL->getIntValue_json(options, "opacity"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool cr = DICTOOL->checkObjectExist_json(options, "colorR");
|
|
|
|
bool cg = DICTOOL->checkObjectExist_json(options, "colorG");
|
|
|
|
bool cb = DICTOOL->checkObjectExist_json(options, "colorB");
|
|
|
|
int colorR = cr ? DICTOOL->getIntValue_json(options, "colorR") : 255;
|
|
|
|
int colorG = cg ? DICTOOL->getIntValue_json(options, "colorG") : 255;
|
|
|
|
int colorB = cb ? DICTOOL->getIntValue_json(options, "colorB") : 255;
|
2013-11-11 18:22:14 +08:00
|
|
|
widget->setColor(Color3B(colorR, colorG, colorB));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool apx = DICTOOL->checkObjectExist_json(options, "anchorPointX");
|
|
|
|
float apxf = apx ? DICTOOL->getFloatValue_json(options, "anchorPointX") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
|
|
|
bool apy = DICTOOL->checkObjectExist_json(options, "anchorPointY");
|
|
|
|
float apyf = apy ? DICTOOL->getFloatValue_json(options, "anchorPointY") : ((widget->getWidgetType() == WidgetTypeWidget) ? 0.5f : 0.0f);
|
2013-11-11 18:22:14 +08:00
|
|
|
widget->setAnchorPoint(Point(apxf, apyf));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool flipX = DICTOOL->getBooleanValue_json(options, "flipX");
|
|
|
|
bool flipY = DICTOOL->getBooleanValue_json(options, "flipY");
|
2014-03-05 15:04:30 +08:00
|
|
|
widget->setFlippedX(flipX);
|
|
|
|
widget->setFlippedY(flipY);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForButtonFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Button* button = static_cast<cocos2d::ui::Button*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setScale9Enabled(scale9Enable);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "normalData");
|
|
|
|
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (normalType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_n = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextureNormal(normalFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "pressedData");
|
|
|
|
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (pressedType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_p = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTexturePressed(pressedFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "disabledData");
|
|
|
|
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (disabledType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_d = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextureDisabled(disabledFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->loadTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (scale9Enable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setCapInsets(Rect(cx, cy, cw, ch));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
|
|
|
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sw && sh)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setSize(Size(swf, shf));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool tt = DICTOOL->checkObjectExist_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (tt)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (text)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setTitleText(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool cr = DICTOOL->checkObjectExist_json(options, "textColorR");
|
|
|
|
bool cg = DICTOOL->checkObjectExist_json(options, "textColorG");
|
|
|
|
bool cb = DICTOOL->checkObjectExist_json(options, "textColorB");
|
|
|
|
int cri = cr?DICTOOL->getIntValue_json(options, "textColorR"):255;
|
|
|
|
int cgi = cg?DICTOOL->getIntValue_json(options, "textColorG"):255;
|
|
|
|
int cbi = cb?DICTOOL->getIntValue_json(options, "textColorB"):255;
|
2013-11-11 18:22:14 +08:00
|
|
|
button->setTitleColor(Color3B(cri,cgi,cbi));
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
button->setTitleFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
button->setTitleFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForCheckBoxFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
CheckBox* checkBox = static_cast<cocos2d::ui::CheckBox*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
|
|
|
|
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (backGroundType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* backGroundFileName_tp = (backGroundFileName && (strcmp(backGroundFileName, "") != 0))?tp_b.append(backGroundFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGround(backGroundFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundFileName = DICTOOL->getStringValue_json(backGroundDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGround(backGroundFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
|
|
|
|
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (backGroundSelectedType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_bs = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* backGroundSelectedFileName_tp = (backGroundSelectedFileName && (strcmp(backGroundSelectedFileName, "") != 0))?tp_bs.append(backGroundSelectedFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundSelectedFileName = DICTOOL->getStringValue_json(backGroundSelectedDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
|
|
|
|
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (frontCrossType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_c = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* frontCrossFileName_tp = (frontCrossFileName && (strcmp(frontCrossFileName, "") != 0))?tp_c.append(frontCrossFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* frontCrossFileName = DICTOOL->getStringValue_json(frontCrossDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
|
|
|
|
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (backGroundDisabledType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_bd = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* backGroundDisabledFileName_tp = (backGroundDisabledFileName && (strcmp(backGroundDisabledFileName, "") != 0))?tp_bd.append(backGroundDisabledFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* backGroundDisabledFileName = DICTOOL->getStringValue_json(backGroundDisabledDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
|
|
|
|
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (frontCrossDisabledType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_cd = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* frontCrossDisabledFileName_tp = (frontCrossDisabledFileName && (strcmp(frontCrossDisabledFileName, "") != 0))?tp_cd.append(frontCrossDisabledFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* frontCrossDisabledFileName = DICTOOL->getStringValue_json(options, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-01-15 20:06:49 +08:00
|
|
|
checkBox->setSelectedState(DICTOOL->getBooleanValue_json(options, "selectedState"));
|
2013-11-11 18:22:14 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForImageViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::ImageView* imageView = static_cast<cocos2d::ui::ImageView*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (imageFileNameType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_i = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
|
|
|
imageView->loadTexture(imageFileName_tp);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool scale9EnableExist = DICTOOL->checkObjectExist_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
bool scale9Enable = false;
|
|
|
|
if (scale9EnableExist)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
imageView->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
|
|
|
|
if (scale9Enable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sw = DICTOOL->checkObjectExist_json(options, "scale9Width");
|
|
|
|
bool sh = DICTOOL->checkObjectExist_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sw && sh)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float swf = DICTOOL->getFloatValue_json(options, "scale9Width");
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, "scale9Height");
|
2013-11-11 18:22:14 +08:00
|
|
|
imageView->setSize(Size(swf, shf));
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
imageView->setCapInsets(Rect(cx, cy, cw, ch));
|
|
|
|
|
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForLabelFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Text* label = static_cast<cocos2d::ui::Text*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool touchScaleChangeAble = DICTOOL->getBooleanValue_json(options, "touchScaleEnable");
|
2013-11-11 18:22:14 +08:00
|
|
|
label->setTouchScaleChangeEnabled(touchScaleChangeAble);
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
label->setText(text);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2014-01-14 14:37:31 +08:00
|
|
|
bool aw = DICTOOL->checkObjectExist_json(options, "areaWidth");
|
|
|
|
bool ah = DICTOOL->checkObjectExist_json(options, "areaHeight");
|
|
|
|
if (aw && ah)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2014-01-14 14:37:31 +08:00
|
|
|
Size size = Size(DICTOOL->getFloatValue_json(options, "areaWidth"),DICTOOL->getFloatValue_json(options,"areaHeight"));
|
|
|
|
label->setTextAreaSize(size);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ha = DICTOOL->checkObjectExist_json(options, "hAlignment");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (ha)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setTextHorizontalAlignment((TextHAlignment)DICTOOL->getIntValue_json(options, "hAlignment"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool va = DICTOOL->checkObjectExist_json(options, "vAlignment");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (va)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
label->setTextVerticalAlignment((TextVAlignment)DICTOOL->getIntValue_json(options, "vAlignment"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForLabelAtlasFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextAtlas* labelAtlas = static_cast<cocos2d::ui::TextAtlas*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool sv = DICTOOL->checkObjectExist_json(options, "stringValue");
|
|
|
|
bool cmf = DICTOOL->checkObjectExist_json(options, "charMapFile");
|
|
|
|
bool iw = DICTOOL->checkObjectExist_json(options, "itemWidth");
|
|
|
|
bool ih = DICTOOL->checkObjectExist_json(options, "itemHeight");
|
|
|
|
bool scm = DICTOOL->checkObjectExist_json(options, "startCharMap");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (sv && cmf && iw && ih && scm)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "charMapFileData");
|
|
|
|
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (cmfType)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_c = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
2014-03-04 16:51:35 +08:00
|
|
|
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, "stringValue"),cmf_tp,DICTOOL->getIntValue_json(options, "itemWidth"),DICTOOL->getIntValue_json(options,"itemHeight"), DICTOOL->getStringValue_json(options, "startCharMap"));
|
2013-09-13 22:20:20 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
2013-11-11 18:22:14 +08:00
|
|
|
CCLOG("Wrong res type of LabelAtlas!");
|
2013-09-13 22:20:20 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForLayoutFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
float w = 0, h = 0;
|
|
|
|
bool adaptScrenn = DICTOOL->getBooleanValue_json(options, "adaptScreen");
|
|
|
|
if (adaptScrenn)
|
|
|
|
{
|
|
|
|
Size screenSize = CCDirector::getInstance()->getWinSize();
|
|
|
|
w = screenSize.width;
|
|
|
|
h = screenSize.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
h = DICTOOL->getFloatValue_json(options, "height");
|
|
|
|
}
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
Layout* panel = static_cast<cocos2d::ui::Layout*>(widget);
|
|
|
|
if (!dynamic_cast<cocos2d::ui::ScrollView*>(widget)
|
|
|
|
&& !dynamic_cast<cocos2d::ui::ListView*>(widget))
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
panel->setClippingEnabled(DICTOOL->getBooleanValue_json(options, "clipAble"));
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool backGroundScale9Enable = DICTOOL->getBooleanValue_json(options, "backGroundScale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImageScale9Enabled(backGroundScale9Enable);
|
2013-12-24 20:33:55 +08:00
|
|
|
int cr = DICTOOL->getIntValue_json(options, "bgColorR");
|
|
|
|
int cg = DICTOOL->getIntValue_json(options, "bgColorG");
|
|
|
|
int cb = DICTOOL->getIntValue_json(options, "bgColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int scr = DICTOOL->getIntValue_json(options, "bgStartColorR");
|
|
|
|
int scg = DICTOOL->getIntValue_json(options, "bgStartColorG");
|
|
|
|
int scb = DICTOOL->getIntValue_json(options, "bgStartColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int ecr = DICTOOL->getIntValue_json(options, "bgEndColorR");
|
|
|
|
int ecg = DICTOOL->getIntValue_json(options, "bgEndColorG");
|
|
|
|
int ecb = DICTOOL->getIntValue_json(options, "bgEndColorB");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float bgcv1 = DICTOOL->getFloatValue_json(options, "vectorX");
|
|
|
|
float bgcv2 = DICTOOL->getFloatValue_json(options, "vectorY");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundColorVector(Point(bgcv1, bgcv2));
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int co = DICTOOL->getIntValue_json(options, "bgColorOpacity");
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int colorType = DICTOOL->getIntValue_json(options, "colorType");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundColorType(LayoutBackGroundColorType(colorType));
|
|
|
|
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
|
|
|
|
panel->setBackGroundColor(Color3B(cr, cg, cb));
|
|
|
|
panel->setBackGroundColorOpacity(co);
|
|
|
|
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "backGroundImageData");
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (imageFileNameType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImage(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backGroundScale9Enable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-11-11 18:22:14 +08:00
|
|
|
panel->setBackGroundImageCapInsets(Rect(cx, cy, cw, ch));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
panel->setLayoutType((LayoutType)DICTOOL->getIntValue_json(options, "layoutType"));
|
2013-11-11 18:22:14 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForScrollViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForLayoutFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::ScrollView* scrollView = static_cast<cocos2d::ui::ScrollView*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
|
|
|
|
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
|
2013-09-16 15:32:52 +08:00
|
|
|
scrollView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
2013-12-24 20:33:55 +08:00
|
|
|
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
2013-11-11 18:22:14 +08:00
|
|
|
scrollView->setDirection((SCROLLVIEW_DIR)direction);
|
2013-12-24 20:33:55 +08:00
|
|
|
scrollView->setBounceEnabled(DICTOOL->getBooleanValue_json(options, "bounceEnable"));
|
2013-09-13 22:20:20 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForSliderFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::Slider* slider = static_cast<cocos2d::ui::Slider*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "barTextureScale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->setScale9Enabled(barTextureScale9Enable);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
|
|
|
|
float barLength = DICTOOL->getFloatValue_json(options, "length");
|
2013-11-11 18:22:14 +08:00
|
|
|
if (bt)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
if (barTextureScale9Enable)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
|
|
|
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (imageFileType)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
|
|
|
slider->setSize(Size(barLength, slider->getContentSize().height));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
|
|
|
|
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (imageFileType)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
|
|
|
|
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (normalType)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_n = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTextureNormal(normalFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
|
|
|
|
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (pressedType)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_p = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTexturePressed(pressedFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
|
|
|
|
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (disabledType)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_d = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTextureDisabled(disabledFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
|
|
|
|
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (progressBarType)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_b = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadProgressBarTexture(imageFileName_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForTextFieldFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextField* textField = static_cast<cocos2d::ui::TextField*>(widget);
|
2013-12-24 20:33:55 +08:00
|
|
|
bool ph = DICTOOL->checkObjectExist_json(options, "placeHolder");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (ph)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, "placeHolder"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setText(DICTOOL->getStringValue_json(options, "text"));
|
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, "fontSize");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setFontSize(DICTOOL->getIntValue_json(options, "fontSize"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, "fontName");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setFontName(DICTOOL->getStringValue_json(options, "fontName"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool tsw = DICTOOL->checkObjectExist_json(options, "touchSizeWidth");
|
|
|
|
bool tsh = DICTOOL->checkObjectExist_json(options, "touchSizeHeight");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (tsw && tsh)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, "touchSizeWidth"), DICTOOL->getFloatValue_json(options,"touchSizeHeight")));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float dw = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
float dh = DICTOOL->getFloatValue_json(options, "height");
|
2013-09-13 22:20:20 +08:00
|
|
|
if (dw > 0.0f || dh > 0.0f)
|
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
//textField->setSize(Size(dw, dh));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, "maxLengthEnable");
|
2013-11-11 18:22:14 +08:00
|
|
|
textField->setMaxLengthEnabled(maxLengthEnable);
|
|
|
|
|
|
|
|
if (maxLengthEnable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
int maxLength = DICTOOL->getIntValue_json(options, "maxLength");
|
2013-11-11 18:22:14 +08:00
|
|
|
textField->setMaxLength(maxLength);
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
bool passwordEnable = DICTOOL->getBooleanValue_json(options, "passwordEnable");
|
2013-11-06 16:04:06 +08:00
|
|
|
textField->setPasswordEnabled(passwordEnable);
|
2013-09-13 22:20:20 +08:00
|
|
|
if (passwordEnable)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, "passwordStyleText"));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForLoadingBarFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::LoadingBar* loadingBar = static_cast<cocos2d::ui::LoadingBar*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (imageFileNameType)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_i = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-14 11:37:46 +08:00
|
|
|
const char* imageFileName_tp = nullptr;
|
2013-11-11 18:22:14 +08:00
|
|
|
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
|
|
|
{
|
|
|
|
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
|
|
|
loadingBar->loadTexture(imageFileName_tp);
|
|
|
|
}
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
/* ui mark add load bar scale9 parse */
|
2013-12-24 20:33:55 +08:00
|
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
2013-11-11 18:22:14 +08:00
|
|
|
loadingBar->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
if (scale9Enable)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-11-11 18:22:14 +08:00
|
|
|
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
2013-09-13 22:20:20 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float width = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
float height = DICTOOL->getFloatValue_json(options, "height");
|
2013-11-11 18:22:14 +08:00
|
|
|
loadingBar->setSize(Size(width, height));
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
/**/
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction")));
|
|
|
|
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
2013-09-13 22:20:20 +08:00
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForLabelBMFontFromJsonDictionary(Widget *widget, const rapidjson::Value&options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
setPropsForWidgetFromJsonDictionary(widget, options);
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
cocos2d::ui::TextBMFont* labelBMFont = static_cast<cocos2d::ui::TextBMFont*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
|
|
|
|
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
|
2013-11-11 18:22:14 +08:00
|
|
|
switch (cmfType)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
case 0:
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-11-11 18:22:14 +08:00
|
|
|
std::string tp_c = m_strFilePath;
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
|
2013-11-11 18:22:14 +08:00
|
|
|
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
|
|
|
labelBMFont->setFntFile(cmf_tp);
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
case 1:
|
|
|
|
CCLOG("Wrong res type of LabelAtlas!");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, "text");
|
2013-11-11 18:22:14 +08:00
|
|
|
labelBMFont->setText(text);
|
|
|
|
|
|
|
|
setColorPropsForWidgetFromJsonDictionary(widget,options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForPageViewFromJsonDictionary(Widget*widget,const rapidjson::Value& options)
|
2013-09-13 22:20:20 +08:00
|
|
|
{
|
2013-12-26 17:53:22 +08:00
|
|
|
setPropsForLayoutFromJsonDictionary(widget, options);
|
2013-09-13 22:20:20 +08:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:55:52 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForListViewFromJsonDictionary(Widget* widget, const rapidjson::Value& options)
|
2013-11-11 18:22:14 +08:00
|
|
|
{
|
2013-12-26 17:53:22 +08:00
|
|
|
setPropsForLayoutFromJsonDictionary(widget, options);
|
|
|
|
|
2013-12-26 21:02:47 +08:00
|
|
|
ListView* listView = static_cast<ListView*>(widget);
|
2013-11-11 18:22:14 +08:00
|
|
|
|
2013-12-26 17:53:22 +08:00
|
|
|
float innerWidth = DICTOOL->getFloatValue_json(options, "innerWidth");
|
|
|
|
float innerHeight = DICTOOL->getFloatValue_json(options, "innerHeight");
|
|
|
|
listView->setInnerContainerSize(Size(innerWidth, innerHeight));
|
|
|
|
int direction = DICTOOL->getFloatValue_json(options, "direction");
|
|
|
|
listView->setDirection((SCROLLVIEW_DIR)direction);
|
|
|
|
|
|
|
|
ListViewGravity gravity = (ListViewGravity)DICTOOL->getIntValue_json(options, "gravity");
|
|
|
|
listView->setGravity(gravity);
|
|
|
|
|
|
|
|
float itemMargin = DICTOOL->getFloatValue_json(options, "itemMargin");
|
|
|
|
listView->setItemsMargin(itemMargin);
|
2013-11-11 18:22:14 +08:00
|
|
|
}
|
2013-12-26 17:53:22 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void WidgetPropertiesReader0300::setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol *reader, Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
reader->setPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WidgetPropertiesReader0300::setPropsForAllCustomWidgetFromJsonDictionary(const std::string &classType,
|
|
|
|
cocos2d::ui::Widget *widget,
|
|
|
|
const rapidjson::Value &customOptions)
|
|
|
|
{
|
|
|
|
GUIReader* guiReader = GUIReader::getInstance();
|
|
|
|
|
|
|
|
std::map<std::string, Object*> object_map = GUIReader::getInstance()->getParseObjectMap();
|
|
|
|
Object* object = object_map[classType];
|
|
|
|
|
|
|
|
std::map<std::string, SEL_ParseEvent> selector_map = guiReader->getParseCallBackMap();
|
|
|
|
SEL_ParseEvent selector = selector_map[classType];
|
|
|
|
|
|
|
|
if (object && selector)
|
|
|
|
{
|
|
|
|
(object->*selector)(classType, widget, customOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 18:56:45 +08:00
|
|
|
}
|