mirror of https://github.com/axmolengine/axmol.git
92 lines
3.0 KiB
C++
92 lines
3.0 KiB
C++
|
|
|
|
#include "LoadingBarReader.h"
|
|
#include "gui/UILoadingBar.h"
|
|
|
|
namespace cocostudio
|
|
{
|
|
static LoadingBarReader* instanceLoadingBar = NULL;
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
|
|
|
|
LoadingBarReader::LoadingBarReader()
|
|
{
|
|
|
|
}
|
|
|
|
LoadingBarReader::~LoadingBarReader()
|
|
{
|
|
|
|
}
|
|
|
|
LoadingBarReader* LoadingBarReader::getInstance()
|
|
{
|
|
if (!instanceLoadingBar)
|
|
{
|
|
instanceLoadingBar = new LoadingBarReader();
|
|
}
|
|
return instanceLoadingBar;
|
|
}
|
|
|
|
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
{
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, "textureData");
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, "resourceType");
|
|
switch (imageFileNameType)
|
|
{
|
|
case 0:
|
|
{
|
|
std::string tp_i = jsonPath;
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
|
const char* imageFileName_tp = nullptr;
|
|
if (imageFileName && (strcmp(imageFileName, "") != 0))
|
|
{
|
|
imageFileName_tp = tp_i.append(imageFileName).c_str();
|
|
loadingBar->loadTexture(imageFileName_tp);
|
|
}
|
|
break;
|
|
}
|
|
case 1:
|
|
{
|
|
const char* imageFileName = DICTOOL->getStringValue_json(imageFileNameDic, "path");
|
|
loadingBar->loadTexture(imageFileName,UI_TEX_TYPE_PLIST);
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* gui mark add load bar scale9 parse */
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, "scale9Enable");
|
|
loadingBar->setScale9Enabled(scale9Enable);
|
|
|
|
if (scale9Enable)
|
|
{
|
|
float cx = DICTOOL->getFloatValue_json(options, "capInsetsX");
|
|
float cy = DICTOOL->getFloatValue_json(options, "capInsetsY");
|
|
float cw = DICTOOL->getFloatValue_json(options, "capInsetsWidth");
|
|
float ch = DICTOOL->getFloatValue_json(options, "capInsetsHeight");
|
|
|
|
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
|
|
|
float width = DICTOOL->getFloatValue_json(options, "width");
|
|
float height = DICTOOL->getFloatValue_json(options, "height");
|
|
loadingBar->setSize(Size(width, height));
|
|
}
|
|
/**/
|
|
|
|
loadingBar->setDirection(LoadingBarType(DICTOOL->getIntValue_json(options, "direction")));
|
|
loadingBar->setPercent(DICTOOL->getIntValue_json(options, "percent"));
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
}
|
|
}
|