2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "CheckBoxReader.h"
|
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-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
|
|
|
|
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-03-04 16:51:35 +08:00
|
|
|
static CheckBoxReader* instanceCheckBoxReader = NULL;
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(CheckBoxReader)
|
|
|
|
|
|
|
|
CheckBoxReader::CheckBoxReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBoxReader::~CheckBoxReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBoxReader* CheckBoxReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceCheckBoxReader)
|
|
|
|
{
|
|
|
|
instanceCheckBoxReader = new CheckBoxReader();
|
|
|
|
}
|
|
|
|
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-06-23 10:02:09 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
|
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-06-05 10:25:08 +08:00
|
|
|
std::string value = stChildArray[i].GetValue();
|
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
|
|
|
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
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-06-05 10:25:08 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
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-06-05 10:25:08 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
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-06-05 10:25:08 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
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-06-05 10:25:08 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|