2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "WidgetReader/CheckBoxReader/CheckBoxReader.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "ui/UICheckBox.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
#include "2d/CCSpriteFrameCache.h"
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CocoLoader.h"
|
|
|
|
#include "CSParseBinary_generated.h"
|
|
|
|
#include "FlatBuffersSerialize.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-23 20:27:39 +08:00
|
|
|
using namespace ui;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
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)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
instanceCheckBoxReader = new CheckBoxReader();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return instanceCheckBoxReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBoxReader::destroyInstance()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_DELETE(instanceCheckBoxReader);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void CheckBoxReader::setPropsFromBinary(ax::ui::Widget* widget, CocoLoader* cocoLoader, stExpCocoNode* cocoNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
|
|
|
this->beginSetBasicProperties(widget);
|
|
|
|
stExpCocoNode* stChildArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
|
|
|
|
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
|
|
|
std::string value = stChildArray[i].GetValue(cocoLoader);
|
|
|
|
// read all basic properties of widget
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_BASIC_PROPERTY_BINARY_READER
|
2021-12-25 10:04:45 +08:00
|
|
|
// read all color related properties of widget
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_COLOR_PROPERTY_BINARY_READER
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
else if (key == P_BackGroundBoxData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +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);
|
|
|
|
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
|
|
|
|
}
|
|
|
|
// else if (key == "selectedState"){
|
|
|
|
// checkBox->setSelectedState(valueToBool(value));
|
|
|
|
// }
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
this->endSetBasicProperties(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckBoxReader::setPropsFromJsonDictionary(Widget* widget, const rapidjson::Value& options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
|
|
|
|
|
|
|
auto pHackAssets = new std::vector<std::string>();
|
|
|
|
checkBox->setUserData(pHackAssets);
|
|
|
|
auto& hackAssets = *pHackAssets;
|
|
|
|
hackAssets.resize(5);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
hackAssets[0] = backGroundTexturePath;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
hackAssets[1] = backGroundSelectedTexturePath;
|
|
|
|
// 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);
|
|
|
|
hackAssets[2] = frontCrossFileName;
|
|
|
|
// 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);
|
|
|
|
hackAssets[3] = backGroundDisabledFileName;
|
|
|
|
/// 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);
|
|
|
|
hackAssets[4] = frontCrossDisabledFileName;
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset<Table> CheckBoxReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
|
|
|
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
|
|
|
|
auto attribute = objectData.first_attribute();
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view name = attribute.name();
|
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "CheckedState")
|
|
|
|
{
|
|
|
|
selectedState = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (name == "DisplayState")
|
|
|
|
{
|
|
|
|
displaystate = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
// child elements
|
|
|
|
auto child = objectData.first_child();
|
|
|
|
while (child)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view name = child.name();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "NormalBackFileData")
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
|
|
|
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
|
|
|
backgroundboxPath = value;
|
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
|
|
|
backgroundboxResourceType = getResourceType(value);
|
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
|
|
|
backgroundboxPlistFile = value;
|
|
|
|
texture = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (backgroundboxResourceType == 1)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "PressedBackFileData")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
|
|
|
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxSelectedPath = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Type")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxSelectedResourceType = getResourceType(value);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Plist")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxSelectedPlistFile = value;
|
|
|
|
texture = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (backGroundBoxSelectedResourceType == 1)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (name == "NodeNormalFileData")
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
|
|
|
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossPath = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Type")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossResourceType = getResourceType(value);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Plist")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossPlistFile = value;
|
|
|
|
texture = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (frontCrossResourceType == 1)
|
|
|
|
{
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "DisableBackFileData")
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
|
|
|
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
|
|
|
backGroundBoxDisabledPath = value;
|
|
|
|
}
|
|
|
|
else if (name == "Type")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledResourceType = getResourceType(value);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Plist")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledPlistFile = value;
|
|
|
|
texture = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (backGroundBoxDisabledResourceType == 1)
|
|
|
|
{
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "NodeDisableFileData")
|
|
|
|
{
|
|
|
|
std::string texture;
|
|
|
|
std::string texturePng;
|
|
|
|
|
|
|
|
attribute = child.first_attribute();
|
|
|
|
|
|
|
|
while (attribute)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
name = attribute.name();
|
2021-12-31 15:49:45 +08:00
|
|
|
std::string_view value = attribute.value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (name == "Path")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossDisabledPath = value;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Type")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossDisabledResourceType = getResourceType(value);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
|
|
|
frontCrossDisabledPlistFile = value;
|
|
|
|
texture = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute.next_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frontCrossDisabledResourceType == 1)
|
|
|
|
{
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2022-08-09 09:54:53 +08:00
|
|
|
fbs->_textures.emplace_back(builder->CreateString(texture));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
child = child.next_sibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void CheckBoxReader::setPropsWithFlatBuffers(ax::Node* node, const flatbuffers::Table* checkBoxOptions)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
auto options = (CheckBoxOptions*)checkBoxOptions;
|
|
|
|
|
|
|
|
CheckBox* checkBox = static_cast<CheckBox*>(node);
|
|
|
|
|
|
|
|
// load background image
|
|
|
|
bool backGroundFileExist = false;
|
|
|
|
std::string backGroundErrorFilePath;
|
|
|
|
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
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundErrorFilePath = backGroundTexturePath;
|
|
|
|
backGroundFileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-08-04 00:14:35 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = backGroundDic->plistFile()->c_str();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(backGroundTexturePath);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
backGroundFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundErrorFilePath = textureFileName;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundErrorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundFileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (backGroundFileExist)
|
|
|
|
{
|
|
|
|
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load background selected image
|
|
|
|
bool backGroundSelectedfileExist = false;
|
|
|
|
std::string backGroundSelectedErrorFilePath;
|
|
|
|
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();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(backGroundSelectedTexturePath);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundSelectedfileExist = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundSelectedErrorFilePath = textureFileName;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundSelectedErrorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundSelectedfileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (backGroundSelectedfileExist)
|
|
|
|
{
|
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath,
|
|
|
|
(Widget::TextureResType)backGroundSelectedType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load frontCross image
|
|
|
|
bool frontCrossFileExist = false;
|
|
|
|
std::string frontCrossErrorFilePath;
|
|
|
|
auto frontCrossDic = (options->frontCrossData());
|
|
|
|
int frontCrossType = frontCrossDic->resourceType();
|
|
|
|
std::string frontCrossFileName = frontCrossDic->path()->c_str();
|
|
|
|
switch (frontCrossType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(frontCrossFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossFileExist = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossErrorFilePath = frontCrossFileName;
|
|
|
|
frontCrossFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = frontCrossDic->plistFile()->c_str();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(frontCrossFileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
frontCrossFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossErrorFilePath = textureFileName;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossErrorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (frontCrossFileExist)
|
|
|
|
{
|
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load backGroundBoxDisabledData
|
|
|
|
bool backGroundBoxDisabledFileExist = false;
|
|
|
|
std::string backGroundBoxDisabledErrorFilePath;
|
|
|
|
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;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName;
|
|
|
|
backGroundBoxDisabledFileExist = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = backGroundDisabledDic->plistFile()->c_str();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(backGroundDisabledFileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
backGroundBoxDisabledFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledErrorFilePath = textureFileName;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledErrorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
backGroundBoxDisabledFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (backGroundBoxDisabledFileExist)
|
|
|
|
{
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName,
|
|
|
|
(Widget::TextureResType)backGroundDisabledType);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/// load frontCrossDisabledData
|
|
|
|
bool frontCrossDisabledFileExist = false;
|
|
|
|
std::string frontCrossDisabledErrorFilePath;
|
|
|
|
auto frontCrossDisabledDic = (options->frontCrossDisabledData());
|
|
|
|
int frontCrossDisabledType = frontCrossDisabledDic->resourceType();
|
|
|
|
std::string frontCrossDisabledFileName = frontCrossDisabledDic->path()->c_str();
|
|
|
|
switch (frontCrossDisabledType)
|
|
|
|
{
|
|
|
|
case 0:
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName))
|
|
|
|
{
|
|
|
|
frontCrossDisabledFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frontCrossDisabledErrorFilePath = frontCrossDisabledFileName;
|
|
|
|
frontCrossDisabledFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
case 1:
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string plist = frontCrossDisabledDic->plistFile()->c_str();
|
2022-08-03 09:53:53 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->findFrame(frontCrossDisabledFileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossDisabledFileExist = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
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
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frontCrossDisabledErrorFilePath = plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
CheckBox* checkBox = CheckBox::create();
|
|
|
|
|
|
|
|
setPropsWithFlatBuffers(checkBox, (Table*)checkBoxOptions);
|
|
|
|
|
|
|
|
return checkBox;
|
|
|
|
}
|
|
|
|
|
2021-12-31 15:49:45 +08:00
|
|
|
int CheckBoxReader::getResourceType(std::string_view key)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
if (key == "Normal" || key == "Default")
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
|
|
|
if (fbs->_isSimulator)
|
|
|
|
{
|
|
|
|
if (key == "MarkedSubImage")
|
|
|
|
{
|
|
|
|
return 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return 1;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|