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

790 lines
33 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
#include "editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h"
#include "ui/UICheckBox.h"
#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"
#include "flatbuffers/flatbuffers.h"
USING_NS_CC;
using namespace ui;
using namespace flatbuffers;
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;
IMPLEMENT_CLASS_NODE_READER_INFO(CheckBoxReader)
CheckBoxReader::CheckBoxReader()
{
}
CheckBoxReader::~CheckBoxReader()
{
}
CheckBoxReader* CheckBoxReader::getInstance()
{
if (!instanceCheckBoxReader)
{
instanceCheckBoxReader = new (std::nothrow) CheckBoxReader();
}
return instanceCheckBoxReader;
}
void CheckBoxReader::destroyInstance()
{
CC_SAFE_DELETE(instanceCheckBoxReader);
}
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
{
CheckBox *checkBox = static_cast<CheckBox*>(widget);
this->beginSetBasicProperties(widget);
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue(cocoLoader);
//read all basic properties of widget
CC_BASIC_PROPERTY_BINARY_READER
//read all color related properties of widget
CC_COLOR_PROPERTY_BINARY_READER
else if (key == P_BackGroundBoxData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
2019-11-24 23:15:56 +08:00
auto fileData = cocos2d::wext::makeResourceData(backgroundValue, (int)imageFileNameType);
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, fileData, 0);
checkBox->loadTextureBackGround(fileData.file, imageFileNameType);
2019-11-23 20:27:39 +08:00
}else if(key == P_BackGroundBoxSelectedData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
2019-11-24 23:15:56 +08:00
auto fileData = cocos2d::wext::makeResourceData(backgroundValue, (int)imageFileNameType);
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, fileData, 1);
checkBox->loadTextureBackGroundSelected(fileData.file, imageFileNameType);
2019-11-23 20:27:39 +08:00
}else if(key == P_FrontCrossData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
2019-11-24 23:15:56 +08:00
auto fileData = cocos2d::wext::makeResourceData(backgroundValue, (int)imageFileNameType);
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, fileData, 2);
checkBox->loadTextureFrontCross(fileData.file, imageFileNameType);
2019-11-23 20:27:39 +08:00
}else if(key == P_BackGroundBoxDisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
2019-11-24 23:15:56 +08:00
auto fileData = cocos2d::wext::makeResourceData(backgroundValue, (int)imageFileNameType);
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, fileData, 3);
checkBox->loadTextureBackGroundDisabled(fileData.file, imageFileNameType);
2019-11-23 20:27:39 +08:00
}else if (key == P_FrontCrossDisabledData){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
2019-11-24 23:15:56 +08:00
auto fileData = cocos2d::wext::makeResourceData(backgroundValue, (int)imageFileNameType);
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, fileData, 4);
checkBox->loadTextureFrontCrossDisabled(fileData.file, imageFileNameType);
2019-11-23 20:27:39 +08:00
}
// else if (key == "selectedState"){
// checkBox->setSelectedState(valueToBool(value));
// }
}
this->endSetBasicProperties(widget);
}
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);
CheckBox* checkBox = static_cast<CheckBox*>(widget);
2019-11-24 23:15:56 +08:00
auto pHackAssets = new std::vector<std::string>();
checkBox->setUserData(pHackAssets);
auto& hackAssets = *pHackAssets;
hackAssets.resize(5);
2019-11-23 20:27:39 +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);
2019-11-24 23:15:56 +08:00
hackAssets[0] = backGroundTexturePath;
2019-11-23 20:27:39 +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);
2019-11-24 23:15:56 +08:00
hackAssets[1] = backGroundSelectedTexturePath;
2019-11-23 20:27:39 +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);
2019-11-24 23:15:56 +08:00
hackAssets[2] = frontCrossFileName;
2019-11-23 20:27:39 +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);
2019-11-24 23:15:56 +08:00
hackAssets[3] = backGroundDisabledFileName;
2019-11-23 20:27:39 +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);
2019-11-24 23:15:56 +08:00
hackAssets[4] = frontCrossDisabledFileName;
2019-11-23 20:27:39 +08:00
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
}
2019-11-24 23:15:56 +08:00
Offset<Table> CheckBoxReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
2019-11-23 20:27:39 +08:00
flatbuffers::FlatBufferBuilder *builder)
{
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
bool selectedState = false;
bool displaystate = true;
int backgroundboxResourceType = 0;
std::string backgroundboxPath = "";
std::string backgroundboxPlistFile = "";
int backGroundBoxSelectedResourceType = 0;
std::string backGroundBoxSelectedPath = "";
std::string backGroundBoxSelectedPlistFile = "";
int frontCrossResourceType = 0;
std::string frontCrossPath = "";
std::string frontCrossPlistFile = "";
int backGroundBoxDisabledResourceType = 0;
std::string backGroundBoxDisabledPath = "";
std::string backGroundBoxDisabledPlistFile = "";
int frontCrossDisabledResourceType = 0;
std::string frontCrossDisabledPath = "";
std::string frontCrossDisabledPlistFile = "";
// attributes
2019-11-24 23:15:56 +08:00
auto attribute = objectData.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
std::string name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "CheckedState")
{
selectedState = (value == "True") ? true : false;
}
else if (name == "DisplayState")
{
displaystate = (value == "True") ? true : false;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
// child elements
2019-11-24 23:15:56 +08:00
auto child = objectData.first_child();
2019-11-23 20:27:39 +08:00
while (child)
{
2019-11-24 23:15:56 +08:00
std::string name = child.name();
2019-11-23 20:27:39 +08:00
if (name == "NormalBackFileData")
{
std::string texture = "";
std::string texturePng = "";
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backgroundboxPath = value;
}
else if (name == "Type")
{
backgroundboxResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backgroundboxPlistFile = value;
texture = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
if (backgroundboxResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "PressedBackFileData")
{
std::string texture = "";
std::string texturePng = "";
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backGroundBoxSelectedPath = value;
}
else if (name == "Type")
{
backGroundBoxSelectedResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backGroundBoxSelectedPlistFile = value;
texture = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
if (backGroundBoxSelectedResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "NodeNormalFileData")
{
std::string texture = "";
std::string texturePng = "";
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
frontCrossPath = value;
}
else if (name == "Type")
{
frontCrossResourceType = getResourceType(value);
}
else if (name == "Plist")
{
frontCrossPlistFile = value;
texture = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
if (frontCrossResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "DisableBackFileData")
{
std::string texture = "";
std::string texturePng = "";
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
backGroundBoxDisabledPath = value;
}
else if (name == "Type")
{
backGroundBoxDisabledResourceType = getResourceType(value);
}
else if (name == "Plist")
{
backGroundBoxDisabledPlistFile = value;
texture = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
if (backGroundBoxDisabledResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
else if (name == "NodeDisableFileData")
{
std::string texture = "";
std::string texturePng = "";
2019-11-24 23:15:56 +08:00
attribute = child.first_attribute();
2019-11-23 20:27:39 +08:00
while (attribute)
{
2019-11-24 23:15:56 +08:00
name = attribute.name();
std::string value = attribute.value();
2019-11-23 20:27:39 +08:00
if (name == "Path")
{
frontCrossDisabledPath = value;
}
else if (name == "Type")
{
frontCrossDisabledResourceType = getResourceType(value);
}
else if (name == "Plist")
{
frontCrossDisabledPlistFile = value;
texture = value;
}
2019-11-24 23:15:56 +08:00
attribute = attribute.next_attribute();
2019-11-23 20:27:39 +08:00
}
if (frontCrossDisabledResourceType == 1)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
fbs->_textures.push_back(builder->CreateString(texture));
}
}
2019-11-24 23:15:56 +08:00
child = child.next_sibling();
2019-11-23 20:27:39 +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 = "";
2019-11-24 23:15:56 +08:00
auto backGroundDic = cocos2d::wext::makeResourceData(options->backGroundBoxData());
int backGroundType = backGroundDic.type;
std::string& backGroundTexturePath = backGroundDic.file;
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, backGroundDic, 0);
2019-11-23 20:27:39 +08:00
switch (backGroundType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundTexturePath))
{
backGroundFileExist = true;
}
else
{
backGroundErrorFilePath = backGroundTexturePath;
backGroundFileExist = false;
}
break;
}
case 1:
{
2019-11-24 23:15:56 +08:00
std::string plist = backGroundDic.plist;
2019-11-23 20:27:39 +08:00
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);
}
//load background selected image
bool backGroundSelectedfileExist = false;
std::string backGroundSelectedErrorFilePath = "";
2019-11-24 23:15:56 +08:00
auto backGroundSelectedDic = cocos2d::wext::makeResourceData(options->backGroundBoxSelectedData());
int backGroundSelectedType = backGroundSelectedDic.type;
std::string& backGroundSelectedTexturePath = backGroundSelectedDic.file;
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, backGroundSelectedDic, 1);
2019-11-23 20:27:39 +08:00
switch (backGroundSelectedType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundSelectedTexturePath))
{
backGroundSelectedfileExist = true;
}
else
{
backGroundSelectedErrorFilePath = backGroundSelectedTexturePath;
backGroundSelectedfileExist = false;
}
break;
}
case 1:
{
2019-11-24 23:15:56 +08:00
std::string plist = backGroundSelectedDic.plist;
2019-11-23 20:27:39 +08:00
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);
}
//load frontCross image
bool frontCrossFileExist = false;
std::string frontCrossErrorFilePath = "";
2019-11-24 23:15:56 +08:00
auto frontCrossDic = cocos2d::wext::makeResourceData(options->frontCrossData());
int frontCrossType = frontCrossDic.type;
std::string& frontCrossFileName = frontCrossDic.file;
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, frontCrossDic, 2);
2019-11-23 20:27:39 +08:00
switch (frontCrossType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossFileName))
{
frontCrossFileExist = true;
}
else
{
frontCrossErrorFilePath = frontCrossFileName;
frontCrossFileExist = false;
}
break;
}
case 1:
{
2019-11-24 23:15:56 +08:00
std::string plist = frontCrossDic.plist;
2019-11-23 20:27:39 +08:00
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);
}
//load backGroundBoxDisabledData
bool backGroundBoxDisabledFileExist = false;
std::string backGroundBoxDisabledErrorFilePath = "";
2019-11-24 23:15:56 +08:00
auto backGroundDisabledDic = cocos2d::wext::makeResourceData(options->backGroundBoxDisabledData());
int backGroundDisabledType = backGroundDisabledDic.type;
std::string& backGroundDisabledFileName = backGroundDisabledDic.file;
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, backGroundDisabledDic, 3);
2019-11-23 20:27:39 +08:00
switch (backGroundDisabledType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(backGroundDisabledFileName))
{
backGroundBoxDisabledFileExist = true;
}
else
{
backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName;
backGroundBoxDisabledFileExist = false;
}
break;
}
case 1:
{
2019-11-24 23:15:56 +08:00
std::string plist = backGroundDisabledDic.plist;
2019-11-23 20:27:39 +08:00
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);
}
///load frontCrossDisabledData
bool frontCrossDisabledFileExist = false;
std::string frontCrossDisabledErrorFilePath = "";
2019-11-24 23:15:56 +08:00
auto frontCrossDisabledDic = cocos2d::wext::makeResourceData(options->frontCrossDisabledData());
int frontCrossDisabledType = frontCrossDisabledDic.type;
std::string& frontCrossDisabledFileName = frontCrossDisabledDic.file;
cocos2d::wext::onBeforeLoadObjectAsset(checkBox, frontCrossDisabledDic, 4);
2019-11-23 20:27:39 +08:00
switch (frontCrossDisabledType)
{
case 0:
{
if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName))
{
frontCrossDisabledFileExist = true;
}
else
{
frontCrossDisabledErrorFilePath = frontCrossDisabledFileName;
frontCrossDisabledFileExist = false;
}
break;
}
case 1:
{
2019-11-24 23:15:56 +08:00
std::string plist = frontCrossDisabledDic.plist;
2019-11-23 20:27:39 +08:00
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);
}
bool selectedstate = options->selectedState() != 0;
checkBox->setSelected(selectedstate);
bool displaystate = options->displaystate() != 0;
checkBox->setBright(displaystate);
checkBox->setEnabled(displaystate);
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
}
Node* CheckBoxReader::createNodeWithFlatBuffers(const flatbuffers::Table *checkBoxOptions)
{
2019-11-24 23:15:56 +08:00
CheckBox* checkBox = wext::aCheckBox();// CheckBox::create();
2019-11-23 20:27:39 +08:00
setPropsWithFlatBuffers(checkBox, (Table*)checkBoxOptions);
return checkBox;
}
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;
}
}