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

154 lines
7.8 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "CheckBoxReader.h"
2014-03-11 17:13:54 +08:00
#include "ui/UICheckBox.h"
#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 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;
2014-03-04 16:51:35 +08:00
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)
{
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-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
else if (key == P_BackGroundBoxData){
2014-07-01 16:31:17 +08:00
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
}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);;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
}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);;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
}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);;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
}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);;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
2014-06-23 10:02:09 +08:00
std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
}
2014-06-05 11:43:43 +08:00
// else if (key == "selectedState"){
// checkBox->setSelectedState(valueToBool(value));
// }
}
2014-06-11 09:35:24 +08:00
this->endSetBasicProperties(widget);
2014-06-05 11:43:43 +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
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);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +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);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +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);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +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);
2014-03-04 16:51:35 +08:00
2014-04-04 17:12:47 +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);
2014-03-04 16:51:35 +08:00
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
}
}