2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "TextAtlasReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UITextAtlas.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_StringValue = "stringValue";
|
|
|
|
static const char* P_CharMapFileData = "charMapFileData";
|
|
|
|
static const char* P_ItemWidth = "itemWidth";
|
|
|
|
static const char* P_ItemHeight = "itemHeight";
|
|
|
|
static const char* P_StartCharMap = "startCharMap";
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
static TextAtlasReader* instanceTextAtalsReader = nullptr;
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextAtlasReader)
|
|
|
|
|
|
|
|
TextAtlasReader::TextAtlasReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextAtlasReader::~TextAtlasReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextAtlasReader* TextAtlasReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceTextAtalsReader)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
instanceTextAtalsReader = new (std::nothrow) TextAtlasReader();
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
return instanceTextAtalsReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void TextAtlasReader::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
|
|
|
|
|
|
|
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
|
|
|
|
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-05 10:25:08 +08:00
|
|
|
Widget::TextureResType type;
|
|
|
|
std::string charMapFileName;
|
|
|
|
std::string stringValue;
|
|
|
|
std::string startCharMap;
|
|
|
|
float itemWidth;
|
|
|
|
float itemHeight;
|
2014-06-23 10:02:09 +08:00
|
|
|
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
|
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string value = stChildArray[i].GetValue(cocoLoader);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
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-19 17:04:14 +08:00
|
|
|
else if (key == P_StringValue) {
|
2014-06-05 10:25:08 +08:00
|
|
|
stringValue = value;
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_CharMapFileData){
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
|
|
|
std::string resType = backGroundChildren[2].GetValue(cocoLoader);;
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
charMapFileName = backgroundValue;
|
|
|
|
type = imageFileNameType;
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_ItemWidth){
|
2014-06-05 10:25:08 +08:00
|
|
|
itemWidth = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_ItemHeight){
|
2014-06-05 10:25:08 +08:00
|
|
|
itemHeight = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_StartCharMap){
|
2014-06-05 10:25:08 +08:00
|
|
|
startCharMap = value;
|
|
|
|
}
|
|
|
|
} //end of for loop
|
|
|
|
|
|
|
|
if (type == (Widget::TextureResType)0) {
|
|
|
|
labelAtlas->setProperty(stringValue, charMapFileName, itemWidth, itemHeight, startCharMap);
|
|
|
|
}
|
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 TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
|
|
|
std::string jsonPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
|
|
|
|
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
|
2014-07-01 14:01:27 +08:00
|
|
|
// 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)
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
2014-07-01 14:01:27 +08:00
|
|
|
case 0:
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
2014-07-01 14:01:27 +08:00
|
|
|
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;
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
2014-07-01 14:01:27 +08:00
|
|
|
case 1:
|
|
|
|
CCLOG("Wrong res type of LabelAtlas!");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-01 14:01:27 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|