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

92 lines
3.7 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "SliderReader.h"
2014-03-11 17:13:54 +08:00
#include "ui/UISlider.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 SliderReader* instanceSliderReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(SliderReader)
SliderReader::SliderReader()
{
}
SliderReader::~SliderReader()
{
}
SliderReader* SliderReader::getInstance()
{
if (!instanceSliderReader)
{
instanceSliderReader = new SliderReader();
}
return instanceSliderReader;
}
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-03-07 10:35:58 +08:00
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
2014-03-04 16:51:35 +08:00
slider->setScale9Enabled(barTextureScale9Enable);
2014-04-04 17:35:15 +08:00
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
2014-03-04 16:51:35 +08:00
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
float barLength = DICTOOL->getFloatValue_json(options, "length");
if (bt)
{
2014-04-04 17:35:15 +08:00
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (Widget::TextureResType)imageFileNameType);
slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
2014-04-04 17:35:15 +08:00
2014-03-04 16:51:35 +08:00
if (barTextureScale9Enable)
{
slider->setSize(Size(barLength, slider->getContentSize().height));
}
}
2014-04-04 17:35:15 +08:00
//loading normal slider ball texture
2014-03-04 16:51:35 +08:00
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
std::string imageFileName = this->getResourcePath(normalDic, "path", (Widget::TextureResType)normalType);
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-03-04 16:51:35 +08:00
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
std::string pressedFileName = this->getResourcePath(pressedDic, "path", (Widget::TextureResType)pressedType);
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-03-04 16:51:35 +08:00
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
std::string disabledFileName = this->getResourcePath(disabledDic, "path", (Widget::TextureResType)disabledType);
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-03-04 16:51:35 +08:00
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (Widget::TextureResType)progressBarType);
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);
}
}