issue #4636. refactor SliderReader

This commit is contained in:
andyque 2014-04-04 17:35:15 +08:00
parent af5fe04480
commit e20b3d8eb8
1 changed files with 24 additions and 128 deletions

View File

@ -36,158 +36,54 @@ namespace cocostudio
WidgetReader::setPropsFromJsonDictionary(widget, options);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
Slider* slider = static_cast<Slider*>(widget);
bool barTextureScale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
slider->setScale9Enabled(barTextureScale9Enable);
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
bool bt = DICTOOL->checkObjectExist_json(options, "barFileName");
float barLength = DICTOOL->getFloatValue_json(options, "length");
if (bt)
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
std::string imageFileName = this->getResourcePath(imageFileNameDic, "path", (TextureResType)imageFileNameType);
slider->loadBarTexture(imageFileName, (TextureResType)imageFileNameType);
if (barTextureScale9Enable)
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
slider->setSize(Size(barLength, slider->getContentSize().height));
}
else
{
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "barFileNameData");
int imageFileType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
switch (imageFileType)
{
case 0:
{
std::string tp_b = jsonPath;
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char*imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
slider->loadBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
}
}
//loading normal slider ball texture
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, "ballNormalData");
int normalType = DICTOOL->getIntValue_json(normalDic, "resourceType");
switch (normalType)
{
case 0:
{
std::string tp_n = jsonPath;
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
const char* normalFileName_tp = (normalFileName && (strcmp(normalFileName, "") != 0))?tp_n.append(normalFileName).c_str():nullptr;
slider->loadSlidBallTextureNormal(normalFileName_tp);
break;
}
case 1:
{
const char* normalFileName = DICTOOL->getStringValue_json(normalDic, "path");
slider->loadSlidBallTextureNormal(normalFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string imageFileName = this->getResourcePath(normalDic, "path", (TextureResType)normalType);
slider->loadSlidBallTextureNormal(imageFileName, (TextureResType)normalType);
//loading slider ball press texture
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, "ballPressedData");
int pressedType = DICTOOL->getIntValue_json(pressedDic, "resourceType");
switch (pressedType)
{
case 0:
{
std::string tp_p = jsonPath;
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
const char* pressedFileName_tp = (pressedFileName && (strcmp(pressedFileName, "") != 0))?tp_p.append(pressedFileName).c_str():nullptr;
slider->loadSlidBallTexturePressed(pressedFileName_tp);
break;
}
case 1:
{
const char* pressedFileName = DICTOOL->getStringValue_json(pressedDic, "path");
slider->loadSlidBallTexturePressed(pressedFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string pressedFileName = this->getResourcePath(pressedDic, "path", (TextureResType)pressedType);
slider->loadSlidBallTexturePressed(pressedFileName, (TextureResType)pressedType);
//loading silder ball disable texture
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, "ballDisabledData");
int disabledType = DICTOOL->getIntValue_json(disabledDic, "resourceType");
switch (disabledType)
{
case 0:
{
std::string tp_d = jsonPath;
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
const char* disabledFileName_tp = (disabledFileName && (strcmp(disabledFileName, "") != 0))?tp_d.append(disabledFileName).c_str():nullptr;
slider->loadSlidBallTextureDisabled(disabledFileName_tp);
break;
}
case 1:
{
const char* disabledFileName = DICTOOL->getStringValue_json(disabledDic, "path");
slider->loadSlidBallTextureDisabled(disabledFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
slider->setPercent(DICTOOL->getIntValue_json(options, "percent"));
std::string disabledFileName = this->getResourcePath(disabledDic, "path", (TextureResType)disabledType);
slider->loadSlidBallTextureDisabled(disabledFileName, (TextureResType)disabledType);
//load slider progress texture
const rapidjson::Value& progressBarDic = DICTOOL->getSubDictionary_json(options, "progressBarData");
int progressBarType = DICTOOL->getIntValue_json(progressBarDic, "resourceType");
switch (progressBarType)
{
case 0:
{
std::string tp_b = jsonPath;
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
const char* imageFileName_tp = (imageFileName && (strcmp(imageFileName, "") != 0))?tp_b.append(imageFileName).c_str():nullptr;
slider->loadProgressBarTexture(imageFileName_tp);
break;
}
case 1:
{
const char* imageFileName = DICTOOL->getStringValue_json(progressBarDic, "path");
slider->loadProgressBarTexture(imageFileName,UI_TEX_TYPE_PLIST);
break;
}
default:
break;
}
std::string progressBarFileName = this->getResourcePath(progressBarDic, "path", (TextureResType)progressBarType);
slider->loadProgressBarTexture(progressBarFileName, (TextureResType)progressBarType);
WidgetReader::setColorPropsFromJsonDictionary(widget, options);