2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "CheckBoxReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UICheckBox.h"
|
2014-06-05 10:25:08 +08:00
|
|
|
#include "cocostudio/CocoLoader.h"
|
2014-10-12 17:46:09 +08:00
|
|
|
#include "cocostudio/CSParseBinary.pb.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
#include "cocostudio/CSParseBinary_generated.h"
|
|
|
|
#include "cocostudio/FlatBuffersSerialize.h"
|
|
|
|
|
|
|
|
#include "tinyxml2/tinyxml2.h"
|
|
|
|
#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
|
|
|
|
{
|
2014-06-19 17:04:14 +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";
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
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)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
instanceCheckBoxReader = new (std::nothrow) CheckBoxReader();
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
return instanceCheckBoxReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
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-05 10:25:08 +08:00
|
|
|
|
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-18 14:44:00 +08:00
|
|
|
// CCLOG("key = %s, index : %d", key.c_str(), i);
|
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
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_BackGroundBoxData){
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BackGroundBoxSelectedData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_FrontCrossData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BackGroundBoxDisabledData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if (key == P_FrontCrossDisabledData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
|
|
|
|
}
|
2014-06-05 11:43:43 +08:00
|
|
|
// else if (key == "selectedState"){
|
|
|
|
// checkBox->setSelectedState(valueToBool(value));
|
|
|
|
// }
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 09:35:24 +08:00
|
|
|
this->endSetBasicProperties(widget);
|
2014-06-05 11:43:43 +08:00
|
|
|
|
2014-06-05 10:25:08 +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
|
2014-06-19 17:04:14 +08:00
|
|
|
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);
|
2014-05-09 14:56:05 +08:00
|
|
|
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
|
2014-06-19 17:04:14 +08:00
|
|
|
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);
|
2014-05-09 14:56:05 +08:00
|
|
|
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
|
2014-06-19 17:04:14 +08:00
|
|
|
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);
|
2014-05-09 14:56:05 +08:00
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
//load backGroundBoxDisabledData
|
2014-06-19 17:04:14 +08:00
|
|
|
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);
|
2014-05-09 14:56:05 +08:00
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
///load frontCrossDisabledData
|
2014-06-19 17:04:14 +08:00
|
|
|
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);
|
2014-05-09 14:56:05 +08:00
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
void CheckBoxReader::setPropsFromProtocolBuffers(ui::Widget *widget, const protocolbuffers::NodeTree &nodeTree)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromProtocolBuffers(widget, nodeTree);
|
|
|
|
|
|
|
|
CheckBox* checkBox = static_cast<CheckBox*>(widget);
|
|
|
|
const protocolbuffers::CheckBoxOptions& options = nodeTree.checkboxoptions();
|
|
|
|
|
|
|
|
std::string protocolBuffersPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
|
|
|
|
//load background image
|
|
|
|
const protocolbuffers::ResourceData& backGroundDic = options.backgroundboxdata();
|
|
|
|
int backGroundType = backGroundDic.resourcetype();
|
|
|
|
std::string backGroundTexturePath = this->getResourcePath(backGroundDic.path(), (Widget::TextureResType)backGroundType);
|
|
|
|
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
|
|
|
|
|
|
|
|
//load background selected image
|
|
|
|
const protocolbuffers::ResourceData& backGroundSelectedDic = options.backgroundboxselecteddata();
|
|
|
|
int backGroundSelectedType = backGroundSelectedDic.resourcetype();
|
|
|
|
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic.path(), (Widget::TextureResType)backGroundSelectedType);
|
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
|
|
|
|
|
|
|
|
//load frontCross image
|
|
|
|
const protocolbuffers::ResourceData& frontCrossDic = options.frontcrossdata();
|
|
|
|
int frontCrossType = frontCrossDic.resourcetype();
|
|
|
|
std::string frontCrossFileName = this->getResourcePath(frontCrossDic.path(), (Widget::TextureResType)frontCrossType);
|
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
|
|
|
|
|
|
|
|
//load backGroundBoxDisabledData
|
|
|
|
const protocolbuffers::ResourceData& backGroundDisabledDic = options.backgroundboxdisableddata();
|
|
|
|
int backGroundDisabledType = backGroundDisabledDic.resourcetype();
|
|
|
|
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic.path(), (Widget::TextureResType)backGroundDisabledType);
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
|
|
|
|
|
|
|
|
///load frontCrossDisabledData
|
|
|
|
const protocolbuffers::ResourceData& frontCrossDisabledDic = options.frontcrossdisableddata();
|
|
|
|
int frontCrossDisabledType = frontCrossDisabledDic.resourcetype();
|
|
|
|
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic.path(), (Widget::TextureResType)frontCrossDisabledType);
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
|
|
|
|
|
2014-10-15 17:20:54 +08:00
|
|
|
checkBox->setSelected(options.selectedstate());
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
bool displaystate = true;
|
|
|
|
if(options.has_displaystate())
|
|
|
|
{
|
|
|
|
displaystate = options.displaystate();
|
|
|
|
}
|
|
|
|
checkBox->setBright(displaystate);
|
|
|
|
|
|
|
|
// other commonly protperties
|
|
|
|
WidgetReader::setColorPropsFromProtocolBuffers(widget, nodeTree);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
bool selectedState = true;
|
|
|
|
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));
|
|
|
|
|
|
|
|
texturePng = texture.substr(0, texture.find_last_of('.')).append(".png");
|
|
|
|
fbs->_texturePngs.push_back(builder->CreateString(texturePng));
|
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));
|
|
|
|
|
|
|
|
texturePng = texture.substr(0, texture.find_last_of('.')).append(".png");
|
|
|
|
fbs->_texturePngs.push_back(builder->CreateString(texturePng));
|
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));
|
|
|
|
|
|
|
|
texturePng = texture.substr(0, texture.find_last_of('.')).append(".png");
|
|
|
|
fbs->_texturePngs.push_back(builder->CreateString(texturePng));
|
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();
|
|
|
|
fbs->_textures.push_back(builder->CreateString(texture));
|
|
|
|
|
|
|
|
texturePng = texture.substr(0, texture.find_last_of('.')).append(".png");
|
|
|
|
fbs->_texturePngs.push_back(builder->CreateString(texturePng));
|
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();
|
|
|
|
fbs->_textures.push_back(builder->CreateString(texture));
|
|
|
|
|
|
|
|
texturePng = texture.substr(0, texture.find_last_of('.')).append(".png");
|
|
|
|
fbs->_texturePngs.push_back(builder->CreateString(texturePng));
|
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
|
|
|
|
auto backGroundDic = options->backGroundBoxData();
|
|
|
|
int backGroundType = backGroundDic->resourceType();
|
|
|
|
std::string backGroundTexturePath = this->getResourcePath(backGroundDic->path()->c_str(), (Widget::TextureResType)backGroundType);
|
|
|
|
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
|
|
|
|
|
|
|
|
//load background selected image
|
|
|
|
auto backGroundSelectedDic = options->backGroundBoxSelectedData();
|
|
|
|
int backGroundSelectedType = backGroundSelectedDic->resourceType();
|
|
|
|
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic->path()->c_str(), (Widget::TextureResType)backGroundSelectedType);
|
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
|
|
|
|
|
|
|
|
//load frontCross image
|
|
|
|
auto frontCrossDic = options->frontCrossData();
|
|
|
|
int frontCrossType = frontCrossDic->resourceType();
|
|
|
|
std::string frontCrossFileName = this->getResourcePath(frontCrossDic->path()->c_str(), (Widget::TextureResType)frontCrossType);
|
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
|
|
|
|
|
|
|
|
//load backGroundBoxDisabledData
|
|
|
|
auto backGroundDisabledDic = options->backGroundBoxDisabledData();
|
|
|
|
int backGroundDisabledType = backGroundDisabledDic->resourceType();
|
|
|
|
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic->path()->c_str(), (Widget::TextureResType)backGroundDisabledType);
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
|
|
|
|
|
|
|
|
///load frontCrossDisabledData
|
|
|
|
auto frontCrossDisabledDic = options->frontCrossDisabledData();
|
|
|
|
int frontCrossDisabledType = frontCrossDisabledDic->resourceType();
|
|
|
|
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic->path()->c_str(), (Widget::TextureResType)frontCrossDisabledType);
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
|
|
|
|
|
|
|
|
bool selectedstate = options->selectedState();
|
|
|
|
checkBox->setSelected(selectedstate);
|
|
|
|
|
|
|
|
bool displaystate = options->displaystate();
|
|
|
|
checkBox->setBright(displaystate);
|
|
|
|
|
|
|
|
|
|
|
|
auto widgetReader = WidgetReader::getInstance();
|
|
|
|
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-26 11:50:42 +08:00
|
|
|
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" || key == "MarkedSubImage")
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|