axmol/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp

796 lines
33 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2014-03-04 16:51:35 +08:00
#include "editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h"
2014-11-21 15:15:38 +08:00
2014-03-11 17:13:54 +08:00
#include "ui/UICheckBox.h"
2016-04-18 15:09:21 +08:00
#include "platform/CCFileUtils.h"
#include "2d/CCSpriteFrameCache.h"
#include "editor-support/cocostudio/CocoLoader.h"
#include "editor-support/cocostudio/CSParseBinary_generated.h"
#include "editor-support/cocostudio/FlatBuffersSerialize.h"
2014-11-21 15:15:38 +08:00
#include "tinyxml2.h"
2014-11-21 15:15:38 +08:00
#include "flatbuffers/flatbuffers.h"
2014-03-04 16:51:35 +08:00
2014-03-06 16:15:03 +08:00
USING_NS_CC;
using namespace ui;
2014-11-21 15:15:38 +08:00
using namespace flatbuffers;
2014-03-06 16:15:03 +08:00
2014-03-04 16:51:35 +08:00
namespace cocostudio
{
static const char* P_BackGroundBoxData = "backGroundBoxData";
static const char* P_BackGroundBoxSelectedData = "backGroundBoxSelectedData";
static const char* P_FrontCrossData = "frontCrossData";
static const char* P_BackGroundBoxDisabledData = "backGroundBoxDisabledData";
static const char* P_FrontCrossDisabledData = "frontCrossDisabledData";
static CheckBoxReader* instanceCheckBoxReader = nullptr;
2014-03-04 16:51:35 +08:00
2014-11-21 15:15:38 +08:00
IMPLEMENT_CLASS_NODE_READER_INFO(CheckBoxReader)
2014-03-04 16:51:35 +08:00
CheckBoxReader::CheckBoxReader()
{
}
CheckBoxReader::~CheckBoxReader()
{
}
CheckBoxReader* CheckBoxReader::getInstance()
{
if (!instanceCheckBoxReader)
{
instanceCheckBoxReader = new (std::nothrow) CheckBoxReader();
2014-03-04 16:51:35 +08:00
}
return instanceCheckBoxReader;
}
2015-03-30 16:46:33 +08:00
void CheckBoxReader::destroyInstance()
{
CC_SAFE_DELETE(instanceCheckBoxReader);
}
2014-06-23 10:02:09 +08:00
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
CheckBox *checkBox = static_cast<CheckBox*>(widget);
2014-06-11 09:35:24 +08:00
this->beginSetBasicProperties(widget);
2014-07-01 16:31:17 +08:00
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
2014-06-23 10:02:09 +08:00
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
2014-07-01 16:31:17 +08:00
std::string value = stChildArray[i].GetValue(cocoLoader);
2014-06-19 15:16:56 +08:00
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
2014-06-11 09:35:24 +08:00
else if (key == P_BackGroundBoxData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
2016-09-12 09:45:34 +08:00
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
}else if(key == P_BackGroundBoxSelectedData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
2016-09-12 09:45:34 +08:00
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
}else if(key == P_FrontCrossData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
2016-09-12 09:45:34 +08:00
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
}else if(key == P_BackGroundBoxDisabledData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
2016-09-12 09:45:34 +08:00
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
}else if (key == P_FrontCrossDisabledData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
2016-09-12 09:45:34 +08:00
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
}
2014-06-05 11:43:43 +08:00
// else if (key == "selectedState"){
// checkBox->setSelectedState(valueToBool(value));
// }
}
2014-06-11 09:35:24 +08:00
this->endSetBasicProperties(widget);
2014-06-05 11:43:43 +08:00
}
2014-03-04 16:51:35 +08:00
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
CheckBox* checkBox = static_cast<CheckBox*>(widget);
2014-04-04 17:12:47 +08:00
//load background image
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxData);
int backGroundType = DICTOOL->getIntValue_json(backGroundDic,P_ResourceType);
std::string backGroundTexturePath = this->getResourcePath(backGroundDic, P_Path, (Widget::TextureResType)backGroundType);
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +08:00
//load background selected image
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxSelectedData);
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, P_ResourceType);
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, P_Path, (Widget::TextureResType)backGroundSelectedType);
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +08:00
//load frontCross image
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossData);
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, P_ResourceType);
std::string frontCrossFileName = this->getResourcePath(frontCrossDic, P_Path, (Widget::TextureResType)frontCrossType);
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +08:00
//load backGroundBoxDisabledData
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxDisabledData);
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, P_ResourceType);
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, P_Path, (Widget::TextureResType)backGroundDisabledType);
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +08:00
///load frontCrossDisabledData
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossDisabledData);
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, P_ResourceType);
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, P_Path, (Widget::TextureResType)frontCrossDisabledType);
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
2014-03-04 16:51:35 +08:00
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
2014-12-01 12:46:29 +08:00
}
2014-10-09 18:28:09 +08:00
2014-11-21 15:15:38 +08:00
Offset<Table> CheckBoxReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData,
flatbuffers::FlatBufferBuilder *builder)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
2014-10-09 18:28:09 +08:00
bool selectedState = false;
2014-11-21 15:15:38 +08:00
bool displaystate = true;
int backgroundboxResourceType = 0;
std::string backgroundboxPath = "";
std::string backgroundboxPlistFile = "";
int backGroundBoxSelectedResourceType = 0;
std::string backGroundBoxSelectedPath = "";
std::string backGroundBoxSelectedPlistFile = "";
2014-10-09 18:28:09 +08:00
2014-11-21 15:15:38 +08:00
int frontCrossResourceType = 0;
std::string frontCrossPath = "";
std::string frontCrossPlistFile = "";
2014-10-09 18:28:09 +08:00
2014-11-21 15:15:38 +08:00
int backGroundBoxDisabledResourceType = 0;
std::string backGroundBoxDisabledPath = "";
std::string backGroundBoxDisabledPlistFile = "";
int frontCrossDisabledResourceType = 0;
std::string frontCrossDisabledPath = "";
std::string frontCrossDisabledPlistFile = "";
2014-10-09 18:28:09 +08:00
// attributes
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string value = attribute->Value();
if (name == "CheckedState")
{
2014-11-21 15:15:38 +08:00
selectedState = (value == "True") ? true : false;
2014-10-09 18:28:09 +08:00
}
else if (name == "DisplayState")
{
2014-11-21 15:15:38 +08:00
displaystate = (value == "True") ? true : false;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
// child elements
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
while (child)
{
std::string name = child->Name();
if (name == "NormalBackFileData")
{
2014-11-21 15:15:38 +08:00
std::string texture = "";
std::string texturePng = "";
2014-10-15 17:20:54 +08:00
attribute = child->FirstAttribute();
2014-10-09 18:28:09 +08:00
while (attribute)
{
2014-10-15 17:20:54 +08:00
name = attribute->Name();
2014-10-09 18:28:09 +08:00
std::string value = attribute->Value();
if (name == "Path")
{
2014-11-21 15:15:38 +08:00
backgroundboxPath = value;
2014-10-09 18:28:09 +08:00
}
else if (name == "Type")
{
2014-11-21 15:15:38 +08:00
backgroundboxResourceType = getResourceType(value);
2014-10-09 18:28:09 +08:00
}
else if (name == "Plist")
{
2014-11-21 15:15:38 +08:00
backgroundboxPlistFile = value;
texture = value;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
2014-11-21 15:15:38 +08:00
if (backgroundboxResourceType == 1)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
2014-10-09 18:28:09 +08:00
}
}
else if (name == "PressedBackFileData")
{
2014-11-21 15:15:38 +08:00
std::string texture = "";
std::string texturePng = "";
2014-10-15 17:20:54 +08:00
attribute = child->FirstAttribute();
2014-10-09 18:28:09 +08:00
while (attribute)
{
2014-10-15 17:20:54 +08:00
name = attribute->Name();
2014-10-09 18:28:09 +08:00
std::string value = attribute->Value();
if (name == "Path")
{
2014-11-21 15:15:38 +08:00
backGroundBoxSelectedPath = value;
2014-10-09 18:28:09 +08:00
}
else if (name == "Type")
{
2014-11-21 15:15:38 +08:00
backGroundBoxSelectedResourceType = getResourceType(value);
2014-10-09 18:28:09 +08:00
}
else if (name == "Plist")
{
2014-11-21 15:15:38 +08:00
backGroundBoxSelectedPlistFile = value;
texture = value;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
2014-11-21 15:15:38 +08:00
if (backGroundBoxSelectedResourceType == 1)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
2014-10-09 18:28:09 +08:00
}
}
else if (name == "NodeNormalFileData")
{
2014-11-21 15:15:38 +08:00
std::string texture = "";
std::string texturePng = "";
2014-10-15 17:20:54 +08:00
attribute = child->FirstAttribute();
2014-10-09 18:28:09 +08:00
while (attribute)
{
2014-10-15 17:20:54 +08:00
name = attribute->Name();
2014-10-09 18:28:09 +08:00
std::string value = attribute->Value();
if (name == "Path")
{
2014-11-21 15:15:38 +08:00
frontCrossPath = value;
2014-10-09 18:28:09 +08:00
}
else if (name == "Type")
{
2014-11-21 15:15:38 +08:00
frontCrossResourceType = getResourceType(value);
2014-10-09 18:28:09 +08:00
}
else if (name == "Plist")
{
2014-11-21 15:15:38 +08:00
frontCrossPlistFile = value;
texture = value;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
2014-11-21 15:15:38 +08:00
if (frontCrossResourceType == 1)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
2014-10-09 18:28:09 +08:00
}
}
else if (name == "DisableBackFileData")
{
2014-11-21 15:15:38 +08:00
std::string texture = "";
std::string texturePng = "";
2014-10-15 17:20:54 +08:00
attribute = child->FirstAttribute();
2014-10-09 18:28:09 +08:00
while (attribute)
{
2014-10-15 17:20:54 +08:00
name = attribute->Name();
2014-10-09 18:28:09 +08:00
std::string value = attribute->Value();
if (name == "Path")
{
2014-11-21 15:15:38 +08:00
backGroundBoxDisabledPath = value;
2014-10-09 18:28:09 +08:00
}
else if (name == "Type")
{
2014-11-21 15:15:38 +08:00
backGroundBoxDisabledResourceType = getResourceType(value);
2014-10-09 18:28:09 +08:00
}
else if (name == "Plist")
{
2014-11-21 15:15:38 +08:00
backGroundBoxDisabledPlistFile = value;
texture = value;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
2014-11-21 15:15:38 +08:00
if (backGroundBoxDisabledResourceType == 1)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
2014-12-11 19:15:04 +08:00
fbs->_textures.push_back(builder->CreateString(texture));
2014-10-09 18:28:09 +08:00
}
}
else if (name == "NodeDisableFileData")
{
2014-11-21 15:15:38 +08:00
std::string texture = "";
std::string texturePng = "";
2014-10-15 17:20:54 +08:00
attribute = child->FirstAttribute();
2014-10-09 18:28:09 +08:00
while (attribute)
{
2014-10-15 17:20:54 +08:00
name = attribute->Name();
2014-10-09 18:28:09 +08:00
std::string value = attribute->Value();
if (name == "Path")
{
2014-11-21 15:15:38 +08:00
frontCrossDisabledPath = value;
2014-10-09 18:28:09 +08:00
}
else if (name == "Type")
{
2014-11-21 15:15:38 +08:00
frontCrossDisabledResourceType = getResourceType(value);
2014-10-09 18:28:09 +08:00
}
else if (name == "Plist")
{
2014-11-21 15:15:38 +08:00
frontCrossDisabledPlistFile = value;
texture = value;
2014-10-09 18:28:09 +08:00
}
attribute = attribute->Next();
}
2014-11-21 15:15:38 +08:00
if (frontCrossDisabledResourceType == 1)
2014-10-09 18:28:09 +08:00
{
2014-11-21 15:15:38 +08:00
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
2014-12-11 19:15:04 +08:00
fbs->_textures.push_back(builder->CreateString(texture));
2014-10-09 18:28:09 +08:00
}
}
child = child->NextSiblingElement();
}
2014-11-21 15:15:38 +08:00
auto options = CreateCheckBoxOptions(*builder,
widgetOptions,
CreateResourceData(*builder,
builder->CreateString(backgroundboxPath),
builder->CreateString(backgroundboxPlistFile),
backgroundboxResourceType),
CreateResourceData(*builder,
builder->CreateString(backGroundBoxSelectedPath),
builder->CreateString(backGroundBoxSelectedPlistFile),
backGroundBoxSelectedResourceType),
CreateResourceData(*builder,
builder->CreateString(frontCrossPath),
builder->CreateString(frontCrossPlistFile),
frontCrossResourceType),
CreateResourceData(*builder,
builder->CreateString(backGroundBoxDisabledPath),
builder->CreateString(backGroundBoxDisabledPlistFile),
backGroundBoxDisabledResourceType),
CreateResourceData(*builder,
builder->CreateString(frontCrossDisabledPath),
builder->CreateString(frontCrossDisabledPlistFile),
frontCrossDisabledResourceType),
selectedState,
displaystate
);
return *(Offset<Table>*)&options;
}
void CheckBoxReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *checkBoxOptions)
{
auto options = (CheckBoxOptions*)checkBoxOptions;
CheckBox* checkBox = static_cast<CheckBox*>(node);
//load background image
bool backGroundFileExist = false;
std::string backGroundErrorFilePath = "";
2014-11-21 15:15:38 +08:00
auto backGroundDic = options->backGroundBoxData();
int backGroundType = backGroundDic->resourceType();
std::string backGroundTexturePath = backGroundDic->path()->c_str();
switch (backGroundType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundTexturePath))
{
backGroundFileExist = true;
}
else
{
backGroundErrorFilePath = backGroundTexturePath;
backGroundFileExist = false;
}
break;
}
case 1:
{
std::string plist = backGroundDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundTexturePath);
if (spriteFrame)
{
backGroundFileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
backGroundErrorFilePath = textureFileName;
}
}
else
{
backGroundErrorFilePath = plist;
}
backGroundFileExist = false;
}
break;
}
default:
break;
}
if (backGroundFileExist)
{
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
}
2014-11-21 15:15:38 +08:00
//load background selected image
bool backGroundSelectedfileExist = false;
std::string backGroundSelectedErrorFilePath = "";
2014-11-21 15:15:38 +08:00
auto backGroundSelectedDic = options->backGroundBoxSelectedData();
int backGroundSelectedType = backGroundSelectedDic->resourceType();
std::string backGroundSelectedTexturePath = backGroundSelectedDic->path()->c_str();
switch (backGroundSelectedType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundSelectedTexturePath))
{
backGroundSelectedfileExist = true;
}
else
{
backGroundSelectedErrorFilePath = backGroundSelectedTexturePath;
backGroundSelectedfileExist = false;
}
break;
}
case 1:
{
std::string plist = backGroundSelectedDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundSelectedTexturePath);
if (spriteFrame)
{
backGroundSelectedfileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
backGroundSelectedErrorFilePath = textureFileName;
}
}
else
{
backGroundSelectedErrorFilePath = plist;
}
backGroundSelectedfileExist = false;
}
break;
}
default:
break;
}
if (backGroundSelectedfileExist)
{
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
}
2014-11-21 15:15:38 +08:00
//load frontCross image
bool frontCrossFileExist = false;
std::string frontCrossErrorFilePath = "";
2014-11-21 15:15:38 +08:00
auto frontCrossDic = options->frontCrossData();
int frontCrossType = frontCrossDic->resourceType();
std::string frontCrossFileName = frontCrossDic->path()->c_str();
switch (frontCrossType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossFileName))
{
frontCrossFileExist = true;
}
else
{
frontCrossErrorFilePath = frontCrossFileName;
frontCrossFileExist = false;
}
break;
}
case 1:
{
std::string plist = frontCrossDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossFileName);
if (spriteFrame)
{
frontCrossFileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
frontCrossErrorFilePath = textureFileName;
}
}
else
{
frontCrossErrorFilePath = plist;
}
frontCrossFileExist = false;
}
break;
}
default:
break;
}
if (frontCrossFileExist)
{
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
}
2014-11-21 15:15:38 +08:00
//load backGroundBoxDisabledData
bool backGroundBoxDisabledFileExist = false;
std::string backGroundBoxDisabledErrorFilePath = "";
2014-11-21 15:15:38 +08:00
auto backGroundDisabledDic = options->backGroundBoxDisabledData();
int backGroundDisabledType = backGroundDisabledDic->resourceType();
std::string backGroundDisabledFileName = backGroundDisabledDic->path()->c_str();
switch (backGroundDisabledType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundDisabledFileName))
{
backGroundBoxDisabledFileExist = true;
}
else
{
backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName;
backGroundBoxDisabledFileExist = false;
}
break;
}
case 1:
{
std::string plist = backGroundDisabledDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundDisabledFileName);
if (spriteFrame)
{
backGroundBoxDisabledFileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
backGroundBoxDisabledErrorFilePath = textureFileName;
}
}
else
{
backGroundBoxDisabledErrorFilePath = plist;
}
backGroundBoxDisabledFileExist = false;
}
break;
}
default:
break;
}
if (backGroundBoxDisabledFileExist)
{
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
}
2014-11-21 15:15:38 +08:00
///load frontCrossDisabledData
bool frontCrossDisabledFileExist = false;
std::string frontCrossDisabledErrorFilePath = "";
2014-11-21 15:15:38 +08:00
auto frontCrossDisabledDic = options->frontCrossDisabledData();
int frontCrossDisabledType = frontCrossDisabledDic->resourceType();
std::string frontCrossDisabledFileName = frontCrossDisabledDic->path()->c_str();
switch (frontCrossDisabledType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName))
{
frontCrossDisabledFileExist = true;
}
else
{
frontCrossDisabledErrorFilePath = frontCrossDisabledFileName;
frontCrossDisabledFileExist = false;
}
break;
}
case 1:
{
std::string plist = frontCrossDisabledDic->plistFile()->c_str();
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossDisabledFileName);
if (spriteFrame)
{
frontCrossDisabledFileExist = true;
}
else
{
if (FileUtils::getInstance()->isFileExist(plist))
{
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
ValueMap metadata = value["metadata"].asValueMap();
std::string textureFileName = metadata["textureFileName"].asString();
if (!FileUtils::getInstance()->isFileExist(textureFileName))
{
frontCrossDisabledErrorFilePath = textureFileName;
}
}
else
{
frontCrossDisabledErrorFilePath = plist;
}
frontCrossDisabledFileExist = false;
}
break;
}
default:
break;
}
if (frontCrossDisabledFileExist)
{
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
}
2014-11-21 15:15:38 +08:00
bool selectedstate = options->selectedState() != 0;
2014-11-21 15:15:38 +08:00
checkBox->setSelected(selectedstate);
bool displaystate = options->displaystate() != 0;
2014-11-21 15:15:38 +08:00
checkBox->setBright(displaystate);
2014-12-04 20:38:46 +08:00
checkBox->setEnabled(displaystate);
2014-11-21 15:15:38 +08:00
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
}
Node* CheckBoxReader::createNodeWithFlatBuffers(const flatbuffers::Table *checkBoxOptions)
2014-11-21 15:15:38 +08:00
{
CheckBox* checkBox = CheckBox::create();
setPropsWithFlatBuffers(checkBox, (Table*)checkBoxOptions);
return checkBox;
2014-10-09 18:28:09 +08:00
}
int CheckBoxReader::getResourceType(std::string key)
{
if(key == "Normal" || key == "Default")
{
return 0;
}
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
if(fbs->_isSimulator)
{
if(key == "MarkedSubImage")
{
return 0;
}
}
return 1;
}
2014-03-04 16:51:35 +08:00
}