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

101 lines
3.2 KiB
C++
Raw Normal View History

2014-03-04 16:51:35 +08:00
#include "TextBMFontReader.h"
2014-03-11 17:13:54 +08:00
#include "ui/UITextBMFont.h"
#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
{
static TextBMFontReader* instanceTextBMFontReader = NULL;
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextBMFontReader)
TextBMFontReader::TextBMFontReader()
{
}
TextBMFontReader::~TextBMFontReader()
{
}
TextBMFontReader* TextBMFontReader::getInstance()
{
if (!instanceTextBMFontReader)
{
instanceTextBMFontReader = new TextBMFontReader();
}
return instanceTextBMFontReader;
}
void TextBMFontReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if(key == "fileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
if (imageFileNameType == (Widget::TextureResType)0) {
labelBMFont->setFntFile(backgroundValue);
}
}else if(key == "text"){
labelBMFont->setString(value);
}
} //end of for loop
}
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);
const rapidjson::Value& cmftDic = DICTOOL->getSubDictionary_json(options, "fileNameData");
int cmfType = DICTOOL->getIntValue_json(cmftDic, "resourceType");
switch (cmfType)
{
case 0:
{
std::string tp_c = jsonPath;
const char* cmfPath = DICTOOL->getStringValue_json(cmftDic, "path");
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;
}
const char* text = DICTOOL->getStringValue_json(options, "text");
2014-05-14 16:02:31 +08:00
labelBMFont->setString(text);
2014-03-04 16:51:35 +08:00
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
}
}