add default value to widget reader

This commit is contained in:
andyque 2014-07-01 14:01:27 +08:00
parent b9a968680f
commit fefdc70af9
4 changed files with 61 additions and 69 deletions

View File

@ -117,19 +117,21 @@ namespace cocostudio
bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
loadingBar->setScale9Enabled(scale9Enable);
if (scale9Enable)
{
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1);
float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX);
float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY);
float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1);
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1);
if (scale9Enable) {
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
float width = DICTOOL->getFloatValue_json(options, P_Width);
float height = DICTOOL->getFloatValue_json(options, P_Height);
loadingBar->setSize(Size(width, height));
}
float width = DICTOOL->getFloatValue_json(options, P_Width);
float height = DICTOOL->getFloatValue_json(options, P_Height);
loadingBar->setSize(Size(width, height));
/**/
loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction)));

View File

@ -145,25 +145,24 @@ namespace cocostudio
slider->setPercent(DICTOOL->getIntValue_json(options, P_Percent));
bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName);
// bool bt = DICTOOL->checkObjectExist_json(options, P_BarFileName);
float barLength = DICTOOL->getFloatValue_json(options, P_Length,290);
if (bt)
{
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);
slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
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);
slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
if (barTextureScale9Enable)
{
slider->setContentSize(Size(barLength, slider->getContentSize().height));
}
if (barTextureScale9Enable)
{
slider->setContentSize(Size(barLength, slider->getContentSize().height));
}
//loading normal slider ball texture
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);
imageFileName = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType);
slider->loadSlidBallTextureNormal(imageFileName, (Widget::TextureResType)normalType);

View File

@ -101,38 +101,37 @@ namespace cocostudio
std::string jsonPath = GUIReader::getInstance()->getFilePath();
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue);
bool cmf = DICTOOL->checkObjectExist_json(options, P_CharMapFile);
bool iw = DICTOOL->checkObjectExist_json(options, P_ItemWidth);
bool ih = DICTOOL->checkObjectExist_json(options, P_ItemHeight);
bool scm = DICTOOL->checkObjectExist_json(options, P_StartCharMap);
if (sv && cmf && iw && ih && scm)
// bool sv = DICTOOL->checkObjectExist_json(options, P_StringValue);
// bool cmf = DICTOOL->checkObjectExist_json(options, P_CharMapFile);
// bool iw = DICTOOL->checkObjectExist_json(options, P_ItemWidth);
// bool ih = DICTOOL->checkObjectExist_json(options, P_ItemHeight);
// bool scm = DICTOOL->checkObjectExist_json(options, P_StartCharMap);
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData);
int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType);
switch (cmfType)
{
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_CharMapFileData);
int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType);
switch (cmfType)
case 0:
{
case 0:
{
std::string tp_c = jsonPath;
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue,"12345678"),
cmf_tp,
DICTOOL->getIntValue_json(options, P_ItemWidth,24),
DICTOOL->getIntValue_json(options,P_ItemHeight,32),
DICTOOL->getStringValue_json(options, P_StartCharMap));
break;
}
case 1:
CCLOG("Wrong res type of LabelAtlas!");
break;
default:
break;
std::string tp_c = jsonPath;
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
const char* cmf_tp = tp_c.append(cmfPath).c_str();
labelAtlas->setProperty(DICTOOL->getStringValue_json(options, P_StringValue,"12345678"),
cmf_tp,
DICTOOL->getIntValue_json(options, P_ItemWidth,24),
DICTOOL->getIntValue_json(options,P_ItemHeight,32),
DICTOOL->getStringValue_json(options, P_StartCharMap));
break;
}
case 1:
CCLOG("Wrong res type of LabelAtlas!");
break;
default:
break;
}
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
}
}

View File

@ -113,11 +113,9 @@ namespace cocostudio
void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize);
if (ignoreSizeExsit)
{
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize));
}
widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize,false));
widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType));
widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType));
@ -151,21 +149,15 @@ namespace cocostudio
float x = DICTOOL->getFloatValue_json(options, P_X);
float y = DICTOOL->getFloatValue_json(options, P_Y);
widget->setPosition(Vec2(x,y));
bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX);
if (sx)
{
widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX));
}
bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY);
if (sy)
{
widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY));
}
bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation);
if (rt)
{
widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation));
}
widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX,1.0));
widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY,1.0));
widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation,0));
bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile);
if (vb)
{