2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "LoadingBarReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UILoadingBar.h"
|
2014-06-05 10:25:08 +08:00
|
|
|
#include "cocostudio/CocoLoader.h"
|
2014-10-09 18:28:09 +08:00
|
|
|
#include "../../CSParseBinary.pb.h"
|
|
|
|
#include "tinyxml2/tinyxml2.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
2014-06-05 10:25:08 +08:00
|
|
|
using namespace cocostudio;
|
2014-03-06 16:15:03 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
static const char* P_Scale9Enable = "scale9Enable";
|
|
|
|
static const char* P_CapInsetsX = "capInsetsX";
|
|
|
|
static const char* P_CapInsetsY = "capInsetsY";
|
|
|
|
static const char* P_CapInsetsWidth = "capInsetsWidth";
|
|
|
|
static const char* P_CapInsetsHeight = "capInsetsHeight";
|
|
|
|
static const char* P_TextureData = "textureData";
|
|
|
|
static const char* P_Direction = "direction";
|
|
|
|
static const char* P_Percent = "percent";
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
static LoadingBarReader* instanceLoadingBar = nullptr;
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(LoadingBarReader)
|
|
|
|
|
|
|
|
LoadingBarReader::LoadingBarReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadingBarReader::~LoadingBarReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadingBarReader* LoadingBarReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceLoadingBar)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
instanceLoadingBar = new (std::nothrow) LoadingBarReader();
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
return instanceLoadingBar;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
WidgetReader::setPropsFromBinary(widget, cocoLoader, cocoNode);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
2014-06-11 09:35:24 +08:00
|
|
|
this->beginSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
|
2014-06-18 14:44:00 +08:00
|
|
|
int percent = loadingBar->getPercent();
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
|
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-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-11 09:35:24 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_Scale9Enable) {
|
2014-06-05 10:25:08 +08:00
|
|
|
loadingBar->setScale9Enabled(valueToBool(value));
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_TextureData){
|
2014-06-05 10:25:08 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
loadingBar->loadTexture(backgroundValue, imageFileNameType);
|
|
|
|
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_CapInsetsX){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsx = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsY){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsy = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsWidth){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsWidth = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_CapInsetsHeight){
|
2014-06-05 10:25:08 +08:00
|
|
|
capsHeight = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Direction){
|
2014-06-05 10:25:08 +08:00
|
|
|
loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Percent){
|
2014-06-18 14:44:00 +08:00
|
|
|
percent = valueToInt(value);
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} //end of for loop
|
|
|
|
|
|
|
|
if (loadingBar->isScale9Enabled()) {
|
|
|
|
loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
|
|
|
|
}
|
2014-06-18 14:44:00 +08:00
|
|
|
loadingBar->setPercent(percent);
|
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 LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_TextureData);
|
|
|
|
int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType);
|
|
|
|
std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType);
|
2014-05-09 14:56:05 +08:00
|
|
|
loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
|
2014-04-04 17:25:20 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
/* gui mark add load bar scale9 parse */
|
2014-06-19 17:04:14 +08:00
|
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
|
2014-03-04 16:51:35 +08:00
|
|
|
loadingBar->setScale9Enabled(scale9Enable);
|
|
|
|
|
2014-07-01 14:01:27 +08:00
|
|
|
|
|
|
|
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) {
|
2014-03-04 16:51:35 +08:00
|
|
|
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
2014-07-01 14:01:27 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
2014-07-01 14:01:27 +08:00
|
|
|
|
|
|
|
float width = DICTOOL->getFloatValue_json(options, P_Width);
|
|
|
|
float height = DICTOOL->getFloatValue_json(options, P_Height);
|
2014-07-10 00:45:27 +08:00
|
|
|
loadingBar->setContentSize(Size(width, height));
|
2014-07-01 14:01:27 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
/**/
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction)));
|
2014-07-01 10:57:12 +08:00
|
|
|
loadingBar->setPercent(DICTOOL->getIntValue_json(options, P_Percent,100));
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
void LoadingBarReader::setPropsFromProtocolBuffers(ui::Widget *widget, const protocolbuffers::NodeTree &nodeTree)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromProtocolBuffers(widget, nodeTree);
|
|
|
|
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
|
|
|
const protocolbuffers::LoadingBarOptions& options = nodeTree.loadingbaroptions();
|
|
|
|
|
|
|
|
std::string protocolBuffersPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
|
|
|
|
const protocolbuffers::ResourceData& imageFileNameDic = options.texturedata();
|
|
|
|
int imageFileNameType = imageFileNameDic.resourcetype();
|
|
|
|
if (imageFileNameType == 1)
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(protocolBuffersPath + imageFileNameDic.plistfile());
|
|
|
|
}
|
|
|
|
std::string imageFileName = this->getResourcePath(imageFileNameDic.path(), (Widget::TextureResType)imageFileNameType);
|
|
|
|
loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType);
|
|
|
|
|
|
|
|
|
|
|
|
/* gui mark add load bar scale9 parse */
|
|
|
|
bool scale9Enable = options.scale9enable();
|
|
|
|
loadingBar->setScale9Enabled(scale9Enable);
|
|
|
|
|
|
|
|
|
|
|
|
float cx = options.capinsetsx();
|
|
|
|
float cy = options.capinsetsy();
|
|
|
|
float cw = options.has_capinsetswidth() ? options.capinsetswidth() : 1;
|
|
|
|
float ch = options.has_capinsetsheight() ? options.capinsetsheight() : 1;
|
|
|
|
|
|
|
|
if (scale9Enable) {
|
|
|
|
loadingBar->setCapInsets(Rect(cx, cy, cw, ch));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const protocolbuffers::WidgetOptions& widgetOptions = nodeTree.widgetoptions();
|
|
|
|
float width = widgetOptions.width();
|
|
|
|
float height = widgetOptions.height();
|
|
|
|
loadingBar->setContentSize(Size(width, height));
|
|
|
|
|
|
|
|
/**/
|
|
|
|
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction(options.direction()));
|
|
|
|
int percent = options.has_percent() ? options.percent() : 100;
|
|
|
|
loadingBar->setPercent(percent);
|
|
|
|
|
|
|
|
|
|
|
|
// other commonly protperties
|
|
|
|
WidgetReader::setColorPropsFromProtocolBuffers(widget, nodeTree);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingBarReader::setPropsFromXML(cocos2d::ui::Widget *widget, const tinyxml2::XMLElement *objectData)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromXML(widget, objectData);
|
|
|
|
|
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
|
|
|
|
|
|
|
|
std::string xmlPath = GUIReader::getInstance()->getFilePath();
|
|
|
|
|
|
|
|
bool scale9Enabled = false;
|
|
|
|
float cx = 0.0f, cy = 0.0f, cw = 0.0f, ch = 0.0f;
|
|
|
|
float swf = 0.0f, shf = 0.0f;
|
|
|
|
int direction = 0;
|
|
|
|
|
|
|
|
int percent = 0;
|
|
|
|
|
|
|
|
int opacity = 255;
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
std::string name = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "ProgressType")
|
|
|
|
{
|
|
|
|
direction = (value == "Left_To_Right") ? 0 : 1;
|
|
|
|
}
|
|
|
|
else if (name == "ProgressInfo")
|
|
|
|
{
|
|
|
|
percent = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "Scale9Enable")
|
|
|
|
{
|
|
|
|
if (value == "True")
|
|
|
|
{
|
|
|
|
scale9Enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginX")
|
|
|
|
{
|
|
|
|
cx = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginY")
|
|
|
|
{
|
|
|
|
cy = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "Scale9Width")
|
|
|
|
{
|
|
|
|
cw = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "Scale9Height")
|
|
|
|
{
|
|
|
|
ch = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "Alpha")
|
|
|
|
{
|
|
|
|
opacity = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// child elements
|
|
|
|
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
std::string name = child->Name();
|
|
|
|
|
|
|
|
if (name == "ImageFileData")
|
|
|
|
{
|
|
|
|
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
|
|
|
|
int resourceType = 0;
|
|
|
|
std::string path = "", plistFile = "";
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
std::string name = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
|
|
|
path = value;
|
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
|
|
|
resourceType = (value == "Normal" || value == "Default" || value == "MarkedSubImage") ? 0 : 1;
|
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
|
|
|
plistFile = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (resourceType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
loadingBar->loadTexture(xmlPath + path, Widget::TextureResType::LOCAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(xmlPath + plistFile);
|
|
|
|
loadingBar->loadTexture(path, Widget::TextureResType::PLIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
child = child->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
loadingBar->setDirection((LoadingBar::Direction)direction);
|
|
|
|
loadingBar->setPercent(percent);
|
|
|
|
|
|
|
|
loadingBar->setOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|