2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "SliderReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UISlider.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_Scale9Enable = "scale9Enable";
|
|
|
|
static const char* P_Percent = "percent";
|
|
|
|
static const char* P_BarFileNameData = "barFileNameData";
|
|
|
|
static const char* P_Length = "length";
|
|
|
|
static const char* P_BallNormalData = "ballNormalData";
|
|
|
|
static const char* P_BallPressedData = "ballPressedData";
|
|
|
|
static const char* P_BallDisabledData = "ballDisabledData";
|
|
|
|
static const char* P_ProgressBarData = "progressBarData";
|
|
|
|
|
|
|
|
static const char* P_BarFileName = "barFileName";
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
static SliderReader* instanceSliderReader = NULL;
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
|
|
|
|
|
|
|
|
SliderReader::SliderReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SliderReader::~SliderReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SliderReader* SliderReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceSliderReader)
|
|
|
|
{
|
|
|
|
instanceSliderReader = new SliderReader();
|
|
|
|
}
|
|
|
|
return instanceSliderReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void SliderReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
this->beginSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
Slider* slider = static_cast<Slider*>(widget);
|
|
|
|
|
|
|
|
float barLength = 0.0f;
|
2014-06-18 14:44:00 +08:00
|
|
|
int percent = slider->getPercent();
|
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-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
|
|
|
|
|
|
|
//control custom properties
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_Scale9Enable) {
|
2014-06-05 10:25:08 +08:00
|
|
|
slider->setScale9Enabled(valueToBool(value));
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_Percent){
|
2014-06-18 14:44:00 +08:00
|
|
|
percent = valueToInt(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BarFileNameData){
|
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
|
|
|
|
|
|
|
slider->loadBarTexture(backgroundValue, imageFileNameType);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Length){
|
2014-06-05 10:25:08 +08:00
|
|
|
barLength = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BallNormalData){
|
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
|
|
|
|
|
|
|
slider->loadSlidBallTextureNormal(backgroundValue, imageFileNameType);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BallPressedData){
|
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
|
|
|
|
|
|
|
slider->loadSlidBallTexturePressed(backgroundValue, imageFileNameType);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_BallDisabledData){
|
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
|
|
|
|
|
|
|
slider->loadSlidBallTextureDisabled(backgroundValue, imageFileNameType);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_ProgressBarData){
|
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
|
|
|
|
|
|
|
slider->loadProgressBarTexture(backgroundValue, imageFileNameType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} //end of for loop
|
|
|
|
|
|
|
|
if (slider->isScale9Enabled()) {
|
|
|
|
slider->setSize(Size(barLength, slider->getContentSize().height));
|
|
|
|
}
|
2014-06-18 14:44:00 +08:00
|
|
|
slider->setPercent(percent);
|
2014-06-11 09:35:24 +08:00
|
|
|
|
|
|
|
this->endSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
2014-04-04 17:35:15 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
Slider* slider = static_cast<Slider*>(widget);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
|
2014-03-04 16:51:35 +08:00
|
|
|
slider->setScale9Enabled(barTextureScale9Enable);
|
2014-04-04 17:35:15 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
slider->setPercent(DICTOOL->getIntValue_json(options, P_Percent));
|
2014-04-04 17:35:15 +08:00
|
|
|
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName);
|
|
|
|
float barLength = DICTOOL->getFloatValue_json(options, P_Length);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (bt)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_BarFileNameData);
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
|
|
|
|
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
|
2014-05-09 14:56:05 +08:00
|
|
|
slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
|
2014-04-04 17:35:15 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
if (barTextureScale9Enable)
|
|
|
|
{
|
2014-06-20 14:03:33 +08:00
|
|
|
slider->setContentSize(Size(barLength, slider->getContentSize().height));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 17:35:15 +08:00
|
|
|
//loading normal slider ball texture
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_BallNormalData);
|
|
|
|
int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType);
|
|
|
|
std::string imageFileName = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType);
|
2014-05-09 14:56:05 +08:00
|
|
|
slider->loadSlidBallTextureNormal(imageFileName, (Widget::TextureResType)normalType);
|
2014-04-04 17:35:15 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:35:15 +08:00
|
|
|
//loading slider ball press texture
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_BallPressedData);
|
|
|
|
int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType);
|
|
|
|
std::string pressedFileName = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType);
|
2014-05-09 14:56:05 +08:00
|
|
|
slider->loadSlidBallTexturePressed(pressedFileName, (Widget::TextureResType)pressedType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:35:15 +08:00
|
|
|
//loading silder ball disable texture
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_BallDisabledData);
|
|
|
|
int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType);
|
|
|
|
std::string disabledFileName = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType);
|
2014-05-09 14:56:05 +08:00
|
|
|
slider->loadSlidBallTextureDisabled(disabledFileName, (Widget::TextureResType)disabledType);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-04-04 17:35:15 +08:00
|
|
|
//load slider progress texture
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, P_ProgressBarData);
|
|
|
|
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, P_ResourceType);
|
|
|
|
std::string progressBarFileName = this->getResourcePath(progressBarDic, P_Path, (Widget::TextureResType)progressBarType);
|
2014-05-09 14:56:05 +08:00
|
|
|
slider->loadProgressBarTexture(progressBarFileName, (Widget::TextureResType)progressBarType);
|
2014-04-04 17:35:15 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|