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
|
|
|
|
{
|
|
|
|
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-05 10:25:08 +08:00
|
|
|
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
|
|
|
|
|
|
|
|
CheckBox *checkBox = static_cast<CheckBox*>(widget);
|
|
|
|
|
|
|
|
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
|
|
|
|
|
|
|
|
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
|
|
|
|
std::string key = stChildArray[i].GetName(pCocoLoader);
|
|
|
|
std::string value = stChildArray[i].GetValue();
|
|
|
|
|
|
|
|
if (key == "backGroundBoxData"){
|
|
|
|
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
|
|
|
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
|
|
|
|
|
|
|
|
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
|
|
|
|
}else if(key == "backGroundBoxSelectedData"){
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
|
|
|
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
|
|
|
|
|
|
|
|
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
|
|
|
|
}else if(key == "frontCrossData"){
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
|
|
|
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
|
|
|
|
|
|
|
|
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
|
|
|
|
}else if(key == "backGroundBoxDisabledData"){
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
|
|
|
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
|
|
|
|
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
|
|
|
|
}else if (key == "frontCrossDisabledData"){
|
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
|
|
|
|
std::string resType = backGroundChildren[2].GetValue();;
|
|
|
|
|
|
|
|
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
|
|
|
|
|
|
|
|
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
|
|
|
|
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-03-04 16:51:35 +08:00
|
|
|
const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxData");
|
|
|
|
int backGroundType = DICTOOL->getIntValue_json(backGroundDic, "resourceType");
|
2014-05-09 14:56:05 +08:00
|
|
|
std::string backGroundTexturePath = this->getResourcePath(backGroundDic, "path", (Widget::TextureResType)backGroundType);
|
|
|
|
checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
//load background selected image
|
2014-03-04 16:51:35 +08:00
|
|
|
const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxSelectedData");
|
|
|
|
int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, "resourceType");
|
2014-05-09 14:56:05 +08:00
|
|
|
std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, "path", (Widget::TextureResType)backGroundSelectedType);
|
|
|
|
checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
//load frontCross image
|
2014-03-04 16:51:35 +08:00
|
|
|
const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, "frontCrossData");
|
|
|
|
int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, "resourceType");
|
2014-05-09 14:56:05 +08:00
|
|
|
std::string frontCrossFileName = this->getResourcePath(frontCrossDic, "path", (Widget::TextureResType)frontCrossType);
|
|
|
|
checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
//load backGroundBoxDisabledData
|
2014-03-04 16:51:35 +08:00
|
|
|
const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, "backGroundBoxDisabledData");
|
|
|
|
int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, "resourceType");
|
2014-05-09 14:56:05 +08:00
|
|
|
std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, "path", (Widget::TextureResType)backGroundDisabledType);
|
|
|
|
checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:12:47 +08:00
|
|
|
///load frontCrossDisabledData
|
2014-03-04 16:51:35 +08:00
|
|
|
const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, "frontCrossDisabledData");
|
|
|
|
int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, "resourceType");
|
2014-05-09 14:56:05 +08:00
|
|
|
std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, "path", (Widget::TextureResType)frontCrossDisabledType);
|
|
|
|
checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|