2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "TextBMFontReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UITextBMFont.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_FileNameData = "fileNameData";
|
|
|
|
static const char* P_Text = "text";
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
static TextBMFontReader* instanceTextBMFontReader = NULL;
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)
|
|
|
|
|
|
|
|
TextBMFontReader::TextBMFontReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextBMFontReader::~TextBMFontReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextBMFontReader* TextBMFontReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceTextBMFontReader)
|
|
|
|
{
|
|
|
|
instanceTextBMFontReader = new TextBMFontReader();
|
|
|
|
}
|
|
|
|
return instanceTextBMFontReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void TextBMFontReader::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
|
|
|
|
|
|
|
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
|
|
|
|
|
|
|
|
|
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-05 10:25:08 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_FileNameData){
|
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
|
|
|
if (imageFileNameType == (Widget::TextureResType)0) {
|
|
|
|
labelBMFont->setFntFile(backgroundValue);
|
|
|
|
}
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Text){
|
2014-06-05 10:25:08 +08:00
|
|
|
labelBMFont->setString(value);
|
|
|
|
}
|
|
|
|
} //end of for loop
|
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 TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
|
|
|
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
|
|
|
|
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, P_FileNameData);
|
|
|
|
int cmfType = DICTOOL->getIntValue_json(cmftDic, P_ResourceType);
|
2014-03-04 16:51:35 +08:00
|
|
|
switch (cmfType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
std::string tp_c = jsonPath;
|
2014-06-19 17:04:14 +08:00
|
|
|
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, P_Path);
|
2014-03-04 16:51:35 +08:00
|
|
|
const char* cmf_tp = tp_c.append(cmfPath).c_str();
|
|
|
|
labelBMFont->setFntFile(cmf_tp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
CCLOG("Wrong res type of LabelAtlas!");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, P_Text);
|
2014-05-14 16:02:31 +08:00
|
|
|
labelBMFont->setString(text);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|