2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UIButton.h"
|
2016-04-18 15:09:21 +08:00
|
|
|
#include "2d/CCSpriteFrameCache.h"
|
|
|
|
#include "2d/CCLabel.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocostudio/CocoLoader.h"
|
|
|
|
#include "editor-support/cocostudio/CSParseBinary_generated.h"
|
|
|
|
#include "editor-support/cocostudio/FlatBuffersSerialize.h"
|
|
|
|
#include "editor-support/cocostudio/LocalizationManager.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2014-12-14 17:14:16 +08:00
|
|
|
#include "tinyxml2.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
#include "flatbuffers/flatbuffers.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
2014-11-21 15:15:38 +08:00
|
|
|
using namespace flatbuffers;
|
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_NormalData = "normalData";
|
|
|
|
static const char* P_PressedData = "pressedData";
|
|
|
|
static const char* P_DisabledData = "disabledData";
|
|
|
|
static const char* P_Text = "text";
|
|
|
|
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_Scale9Width = "scale9Width";
|
|
|
|
static const char* P_Scale9Height = "scale9Height";
|
|
|
|
static const char* P_TextColorR = "textColorR";
|
|
|
|
static const char* P_TextColorG = "textColorG";
|
|
|
|
static const char* P_TextColorB = "textColorB";
|
|
|
|
static const char* P_FontSize = "fontSize";
|
|
|
|
static const char* P_FontName = "fontName";
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-23 10:12:54 +08:00
|
|
|
static ButtonReader* instanceButtonReader = nullptr;
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(ButtonReader)
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
ButtonReader::ButtonReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonReader::~ButtonReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonReader* ButtonReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceButtonReader)
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
instanceButtonReader = new (std::nothrow) ButtonReader();
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
return instanceButtonReader;
|
|
|
|
}
|
|
|
|
|
2015-03-31 14:56:24 +08:00
|
|
|
void ButtonReader::purge()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(instanceButtonReader);
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:46:33 +08:00
|
|
|
void ButtonReader::destroyInstance()
|
2014-03-04 16:51:35 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(instanceButtonReader);
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void ButtonReader::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
|
|
|
|
|
|
|
Button *button = static_cast<Button*>(widget);
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
|
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
|
|
|
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
|
|
|
|
int cri = 255, cgi = 255, cbi = 255;
|
|
|
|
float scale9Width = 0.0f, scale9Height = 0.0f;
|
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-11 09:35:24 +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-05 10:25:08 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
|
|
|
|
else if (key == P_Scale9Enable) {
|
2014-06-05 10:25:08 +08:00
|
|
|
button->setScale9Enabled(valueToBool(value));
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_NormalData){
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
2016-09-12 09:45:34 +08:00
|
|
|
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
|
|
|
|
|
|
|
button->loadTextureNormal(backgroundValue, imageFileNameType);
|
|
|
|
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_PressedData){
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
2016-09-12 09:45:34 +08:00
|
|
|
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
|
|
|
|
|
|
|
button->loadTexturePressed(backgroundValue, imageFileNameType);
|
|
|
|
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
else if (key == P_DisabledData){
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
|
2016-09-12 09:45:34 +08:00
|
|
|
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
|
|
|
|
|
|
|
button->loadTextureDisabled(backgroundValue, imageFileNameType);
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if (key == P_Text){
|
2014-06-05 10:25:08 +08:00
|
|
|
button->setTitleText(value);
|
|
|
|
}
|
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_Scale9Width){
|
2014-06-05 10:25:08 +08:00
|
|
|
scale9Width = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Scale9Height){
|
2014-06-05 10:25:08 +08:00
|
|
|
scale9Height = valueToFloat(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_TextColorR){
|
2014-06-05 10:25:08 +08:00
|
|
|
cri = valueToInt(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_TextColorG){
|
2014-06-05 10:25:08 +08:00
|
|
|
cgi = valueToInt(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_TextColorB){
|
2014-06-05 10:25:08 +08:00
|
|
|
cbi = valueToInt(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_FontSize){
|
2014-06-05 10:25:08 +08:00
|
|
|
button->setTitleFontSize(valueToFloat(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_FontName){
|
2014-06-05 10:25:08 +08:00
|
|
|
button->setTitleFontName(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} //end of for loop
|
|
|
|
|
2014-06-11 09:35:24 +08:00
|
|
|
this->endSetBasicProperties(widget);
|
|
|
|
|
2014-06-05 10:25:08 +08:00
|
|
|
if (button->isScale9Enabled()) {
|
|
|
|
button->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
|
2014-07-10 00:45:27 +08:00
|
|
|
button->setContentSize(Size(scale9Width, scale9Height));
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
button->setTitleColor(Color3B(cri, cgi, cbi));
|
|
|
|
|
2014-06-11 09:35:24 +08:00
|
|
|
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
|
|
|
Button* button = static_cast<Button*>(widget);
|
2014-06-19 17:04:14 +08:00
|
|
|
bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable);
|
2014-03-04 16:51:35 +08:00
|
|
|
button->setScale9Enabled(scale9Enable);
|
|
|
|
|
2014-04-04 16:51:07 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& normalDic = DICTOOL->getSubDictionary_json(options, P_NormalData);
|
|
|
|
int normalType = DICTOOL->getIntValue_json(normalDic, P_ResourceType);
|
|
|
|
std::string normalTexturePath = this->getResourcePath(normalDic, P_Path, (Widget::TextureResType)normalType);
|
2014-05-09 14:56:05 +08:00
|
|
|
button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType);
|
2014-04-04 16:51:07 +08:00
|
|
|
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& pressedDic = DICTOOL->getSubDictionary_json(options, P_PressedData);
|
|
|
|
int pressedType = DICTOOL->getIntValue_json(pressedDic, P_ResourceType);
|
2014-04-04 16:51:07 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
std::string pressedTexturePath = this->getResourcePath(pressedDic, P_Path, (Widget::TextureResType)pressedType);
|
2014-05-09 14:56:05 +08:00
|
|
|
button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType);
|
2014-04-04 16:51:07 +08:00
|
|
|
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
const rapidjson::Value& disabledDic = DICTOOL->getSubDictionary_json(options, P_DisabledData);
|
|
|
|
int disabledType = DICTOOL->getIntValue_json(disabledDic, P_ResourceType);
|
2014-04-04 16:51:07 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
std::string disabledTexturePath = this->getResourcePath(disabledDic, P_Path, (Widget::TextureResType)disabledType);
|
2014-05-09 14:56:05 +08:00
|
|
|
button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType);
|
2014-04-04 16:51:07 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
if (scale9Enable)
|
|
|
|
{
|
2014-06-19 17:04:14 +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);
|
|
|
|
float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
button->setCapInsets(Rect(cx, cy, cw, ch));
|
2014-06-19 17:04:14 +08:00
|
|
|
bool sw = DICTOOL->checkObjectExist_json(options, P_Scale9Width);
|
|
|
|
bool sh = DICTOOL->checkObjectExist_json(options, P_Scale9Height);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (sw && sh)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
float swf = DICTOOL->getFloatValue_json(options, P_Scale9Width);
|
|
|
|
float shf = DICTOOL->getFloatValue_json(options, P_Scale9Height);
|
2014-07-10 00:45:27 +08:00
|
|
|
button->setContentSize(Size(swf, shf));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
bool tt = DICTOOL->checkObjectExist_json(options, P_Text);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (tt)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
const char* text = DICTOOL->getStringValue_json(options, P_Text);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
button->setTitleText(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 10:57:12 +08:00
|
|
|
|
|
|
|
int cri = DICTOOL->getIntValue_json(options, P_TextColorR,255);
|
|
|
|
int cgi = DICTOOL->getIntValue_json(options, P_TextColorG,255);
|
|
|
|
int cbi = DICTOOL->getIntValue_json(options, P_TextColorB,255);
|
2014-03-04 16:51:35 +08:00
|
|
|
button->setTitleColor(Color3B(cri,cgi,cbi));
|
2014-07-01 10:57:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
button->setTitleFontSize(DICTOOL->getIntValue_json(options, P_FontSize,14));
|
|
|
|
|
|
|
|
|
2014-12-10 15:46:58 +08:00
|
|
|
button->setTitleFontName(DICTOOL->getStringValue_json(options, P_FontName, ""));
|
2014-07-01 10:57:12 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
2014-12-01 12:46:29 +08:00
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
Offset<Table> ButtonReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData, flatbuffers::FlatBufferBuilder *builder)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
|
|
|
auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
bool displaystate = true;
|
2014-10-09 18:28:09 +08:00
|
|
|
bool scale9Enabled = false;
|
2014-11-21 15:15:38 +08:00
|
|
|
Rect capInsets;
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string text = "";
|
2016-02-29 18:00:14 +08:00
|
|
|
bool isLocalized = false;
|
2014-11-21 15:15:38 +08:00
|
|
|
int fontSize = 14;
|
2014-12-01 11:48:04 +08:00
|
|
|
std::string fontName = "";
|
2014-11-21 15:15:38 +08:00
|
|
|
cocos2d::Size scale9Size;
|
|
|
|
Color4B textColor(255, 255, 255, 255);
|
|
|
|
|
|
|
|
std::string normalPath = "";
|
|
|
|
std::string normalPlistFile = "";
|
|
|
|
int normalResourceType = 0;
|
|
|
|
|
|
|
|
std::string pressedPath = "";
|
|
|
|
std::string pressedPlistFile = "";
|
|
|
|
int pressedResourceType = 0;
|
|
|
|
|
|
|
|
std::string disabledPath = "";
|
|
|
|
std::string disabledPlistFile = "";
|
|
|
|
int disabledResourceType = 0;
|
|
|
|
|
|
|
|
std::string fontResourcePath = "";
|
|
|
|
std::string fontResourcePlistFile = "";
|
|
|
|
int fontResourceResourceType = 0;
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2015-04-20 11:39:43 +08:00
|
|
|
bool outlineEnabled = false;
|
|
|
|
Color4B outlineColor = Color4B::BLACK;
|
|
|
|
int outlineSize = 1;
|
|
|
|
bool shadowEnabled = false;
|
|
|
|
Color4B shadowColor = Color4B::BLACK;
|
|
|
|
Size shadowOffset = Size(2, -2);
|
|
|
|
int shadowBlurRadius = 0;
|
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
// attributes
|
|
|
|
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
std::string name = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Scale9Enable")
|
|
|
|
{
|
|
|
|
if (value == "True")
|
|
|
|
{
|
|
|
|
scale9Enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginX")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
capInsets.origin.x = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9OriginY")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
capInsets.origin.y = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9Width")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
capInsets.size.width = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Scale9Height")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
capInsets.size.height = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "ButtonText")
|
|
|
|
{
|
|
|
|
text = value;
|
|
|
|
}
|
2016-02-29 18:00:14 +08:00
|
|
|
else if (name == "IsLocalized")
|
|
|
|
{
|
|
|
|
isLocalized = (value == "True") ? true : false;
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
else if (name == "FontSize")
|
|
|
|
{
|
|
|
|
fontSize = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "FontName")
|
|
|
|
{
|
|
|
|
fontName = value;
|
|
|
|
}
|
|
|
|
else if (name == "DisplayState")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
displaystate = (value == "True") ? true : false;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
2015-04-20 11:39:43 +08:00
|
|
|
else if (name == "OutlineEnabled")
|
|
|
|
{
|
|
|
|
outlineEnabled = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (name == "OutlineSize")
|
|
|
|
{
|
|
|
|
outlineSize = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "ShadowEnabled")
|
|
|
|
{
|
|
|
|
shadowEnabled = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (name == "ShadowOffsetX")
|
|
|
|
{
|
|
|
|
shadowOffset.width = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "ShadowOffsetY")
|
|
|
|
{
|
|
|
|
shadowOffset.height = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "ShadowBlurRadius")
|
|
|
|
{
|
|
|
|
shadowBlurRadius = atoi(value.c_str());
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// child elements
|
|
|
|
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
std::string name = child->Name();
|
|
|
|
|
|
|
|
if (name == "Size" && scale9Enabled)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "X")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
scale9Size.width = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Y")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
scale9Size.height = atof(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "TextColor")
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "R")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
textColor.r = atoi(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "G")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
textColor.g = atoi(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "B")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
textColor.b = atoi(value.c_str());
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "DisabledFileData")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
std::string texture = "";
|
|
|
|
std::string texturePng = "";
|
|
|
|
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
disabledPath = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
2016-09-12 09:45:34 +08:00
|
|
|
disabledResourceType = getResourceType(value);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
disabledPlistFile = value;
|
|
|
|
texture = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
if (disabledResourceType == 1)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
|
|
|
fbs->_textures.push_back(builder->CreateString(texture));
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "PressedFileData")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
std::string texture = "";
|
|
|
|
std::string texturePng = "";
|
|
|
|
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
pressedPath = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
pressedResourceType = getResourceType(value);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
pressedPlistFile = value;
|
|
|
|
texture = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
if (pressedResourceType == 1)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2014-12-11 19:15:04 +08:00
|
|
|
fbs->_textures.push_back(builder->CreateString(texture));
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "NormalFileData")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
std::string texture = "";
|
|
|
|
std::string texturePng = "";
|
|
|
|
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
normalPath = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
normalResourceType = getResourceType(value);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
normalPlistFile = value;
|
|
|
|
texture = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
if (normalResourceType == 1)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2014-12-11 19:15:04 +08:00
|
|
|
fbs->_textures.push_back(builder->CreateString(texture));
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "FontResource")
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
attribute = child->FirstAttribute();
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
2014-10-15 17:20:54 +08:00
|
|
|
name = attribute->Name();
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "Path")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
fontResourcePath = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Type")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
fontResourceResourceType = getResourceType(value);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (name == "Plist")
|
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
fontResourcePlistFile = value;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 11:39:43 +08:00
|
|
|
else if (name == "OutlineColor")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
name = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "A")
|
|
|
|
{
|
|
|
|
outlineColor.a = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "R")
|
|
|
|
{
|
|
|
|
outlineColor.r = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "G")
|
|
|
|
{
|
|
|
|
outlineColor.g = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "B")
|
|
|
|
{
|
|
|
|
outlineColor.b = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "ShadowColor")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
name = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (name == "A")
|
|
|
|
{
|
|
|
|
shadowColor.a = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "R")
|
|
|
|
{
|
|
|
|
shadowColor.r = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "G")
|
|
|
|
{
|
|
|
|
shadowColor.g = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (name == "B")
|
|
|
|
{
|
|
|
|
shadowColor.b = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
child = child->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
Color f_textColor(255, textColor.r, textColor.g, textColor.b);
|
|
|
|
CapInsets f_capInsets(capInsets.origin.x, capInsets.origin.y, capInsets.size.width, capInsets.size.height);
|
|
|
|
FlatSize f_scale9Size(scale9Size.width, scale9Size.height);
|
2015-04-20 11:39:43 +08:00
|
|
|
flatbuffers::Color f_outlineColor(outlineColor.a, outlineColor.r, outlineColor.g, outlineColor.b);
|
|
|
|
flatbuffers::Color f_shadowColor(shadowColor.a, shadowColor.r, shadowColor.g, shadowColor.b);
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
auto options = CreateButtonOptions(*builder,
|
|
|
|
widgetOptions,
|
|
|
|
CreateResourceData(*builder,
|
|
|
|
builder->CreateString(normalPath),
|
|
|
|
builder->CreateString(normalPlistFile),
|
|
|
|
normalResourceType),
|
|
|
|
CreateResourceData(*builder,
|
|
|
|
builder->CreateString(pressedPath),
|
|
|
|
builder->CreateString(pressedPlistFile),
|
|
|
|
pressedResourceType),
|
|
|
|
CreateResourceData(*builder,
|
|
|
|
builder->CreateString(disabledPath),
|
|
|
|
builder->CreateString(disabledPlistFile),
|
|
|
|
disabledResourceType),
|
|
|
|
CreateResourceData(*builder,
|
|
|
|
builder->CreateString(fontResourcePath),
|
|
|
|
builder->CreateString(fontResourcePlistFile),
|
|
|
|
fontResourceResourceType),
|
|
|
|
builder->CreateString(text),
|
|
|
|
builder->CreateString(fontName),
|
|
|
|
fontSize,
|
|
|
|
&f_textColor,
|
|
|
|
&f_capInsets,
|
|
|
|
&f_scale9Size,
|
|
|
|
scale9Enabled,
|
2015-04-20 11:39:43 +08:00
|
|
|
displaystate,
|
|
|
|
outlineEnabled,
|
|
|
|
&f_outlineColor,
|
|
|
|
outlineSize,
|
|
|
|
shadowEnabled,
|
|
|
|
&f_shadowColor,
|
|
|
|
shadowOffset.width,
|
|
|
|
shadowOffset.height,
|
2017-06-15 13:42:50 +08:00
|
|
|
shadowBlurRadius,
|
|
|
|
isLocalized);
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *buttonOptions)
|
|
|
|
{
|
|
|
|
Button* button = static_cast<Button*>(node);
|
|
|
|
auto options = (ButtonOptions*)buttonOptions;
|
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool scale9Enabled = options->scale9Enabled() != 0;
|
2014-10-09 18:28:09 +08:00
|
|
|
button->setScale9Enabled(scale9Enabled);
|
|
|
|
|
2014-12-17 19:00:24 +08:00
|
|
|
bool normalFileExist = false;
|
|
|
|
std::string normalErrorFilePath = "";
|
2014-11-21 15:15:38 +08:00
|
|
|
auto normalDic = options->normalData();
|
|
|
|
int normalType = normalDic->resourceType();
|
2014-12-22 13:42:18 +08:00
|
|
|
std::string normalTexturePath = normalDic->path()->c_str();
|
2014-12-17 19:00:24 +08:00
|
|
|
switch (normalType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (FileUtils::getInstance()->isFileExist(normalTexturePath))
|
|
|
|
{
|
|
|
|
normalFileExist = true;
|
|
|
|
}
|
2016-07-02 16:31:32 +08:00
|
|
|
else if (SpriteFrameCache::getInstance()->getSpriteFrameByName(normalTexturePath))
|
|
|
|
{
|
|
|
|
normalFileExist = true;
|
|
|
|
normalType = 1;
|
|
|
|
}
|
2014-12-17 19:00:24 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
normalErrorFilePath = normalTexturePath;
|
|
|
|
normalFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = normalDic->plistFile()->c_str();
|
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(normalTexturePath);
|
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
normalFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
|
|
|
{
|
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
|
|
|
{
|
|
|
|
normalErrorFilePath = textureFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
normalErrorFilePath = plist;
|
|
|
|
}
|
|
|
|
normalFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (normalFileExist)
|
|
|
|
{
|
|
|
|
button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType);
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2014-12-17 19:00:24 +08:00
|
|
|
bool pressedFileExist = false;
|
|
|
|
std::string pressedErrorFilePath = "";
|
2014-11-21 15:15:38 +08:00
|
|
|
auto pressedDic = options->pressedData();
|
|
|
|
int pressedType = pressedDic->resourceType();
|
2014-12-22 13:42:18 +08:00
|
|
|
std::string pressedTexturePath = pressedDic->path()->c_str();
|
2014-12-17 19:00:24 +08:00
|
|
|
switch (pressedType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(pressedTexturePath))
|
|
|
|
{
|
|
|
|
pressedFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressedErrorFilePath = pressedTexturePath;
|
|
|
|
pressedFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = pressedDic->plistFile()->c_str();
|
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pressedTexturePath);
|
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
pressedFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
|
|
|
{
|
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
|
|
|
{
|
|
|
|
pressedErrorFilePath = textureFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pressedErrorFilePath = plist;
|
|
|
|
}
|
|
|
|
pressedFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pressedFileExist)
|
|
|
|
{
|
|
|
|
button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType);
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
2014-12-17 19:00:24 +08:00
|
|
|
bool disabledFileExist = false;
|
|
|
|
std::string disabledErrorFilePath = "";
|
2014-11-21 15:15:38 +08:00
|
|
|
auto disabledDic = options->disabledData();
|
|
|
|
int disabledType = disabledDic->resourceType();
|
2014-12-22 13:42:18 +08:00
|
|
|
std::string disabledTexturePath = disabledDic->path()->c_str();
|
2014-12-17 19:00:24 +08:00
|
|
|
switch (disabledType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(disabledTexturePath))
|
|
|
|
{
|
|
|
|
disabledFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disabledErrorFilePath = disabledTexturePath;
|
|
|
|
disabledFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
std::string plist = disabledDic->plistFile()->c_str();
|
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(disabledTexturePath);
|
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
disabledFileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
|
|
|
{
|
|
|
|
ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
|
|
|
|
ValueMap metadata = value["metadata"].asValueMap();
|
|
|
|
std::string textureFileName = metadata["textureFileName"].asString();
|
|
|
|
if (!FileUtils::getInstance()->isFileExist(textureFileName))
|
|
|
|
{
|
|
|
|
disabledErrorFilePath = textureFileName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disabledErrorFilePath = plist;
|
|
|
|
}
|
|
|
|
disabledFileExist = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (disabledFileExist)
|
|
|
|
{
|
|
|
|
button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType);
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
std::string titleText = options->text()->c_str();
|
2016-02-29 18:00:14 +08:00
|
|
|
bool isLocalized = options->isLocalized() != 0;
|
|
|
|
if (isLocalized)
|
|
|
|
{
|
2016-03-01 14:27:12 +08:00
|
|
|
ILocalizationManager* lm = LocalizationHelper::getCurrentManager();
|
|
|
|
button->setTitleText(lm->getLocalizationString(titleText));
|
2016-02-29 18:00:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
button->setTitleText(titleText);
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
auto textColor = options->textColor();
|
|
|
|
Color3B titleColor(textColor->r(), textColor->g(), textColor->b());
|
|
|
|
button->setTitleColor(titleColor);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int titleFontSize = options->fontSize();
|
|
|
|
button->setTitleFontSize(titleFontSize);
|
|
|
|
|
|
|
|
std::string titleFontName = options->fontName()->c_str();
|
|
|
|
button->setTitleFontName(titleFontName);
|
|
|
|
|
|
|
|
auto resourceData = options->fontResource();
|
2014-12-17 19:00:24 +08:00
|
|
|
bool fileExist = false;
|
|
|
|
std::string errorFilePath = "";
|
2014-11-21 15:15:38 +08:00
|
|
|
std::string path = resourceData->path()->c_str();
|
|
|
|
if (path != "")
|
|
|
|
{
|
2014-12-17 19:00:24 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(path))
|
|
|
|
{
|
|
|
|
fileExist = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorFilePath = path;
|
|
|
|
fileExist = false;
|
|
|
|
}
|
|
|
|
if (fileExist)
|
|
|
|
{
|
|
|
|
button->setTitleFontName(path);
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool displaystate = options->displaystate() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
button->setBright(displaystate);
|
|
|
|
button->setEnabled(displaystate);
|
2014-12-17 19:00:24 +08:00
|
|
|
|
2015-07-07 23:10:04 +08:00
|
|
|
bool outlineEnabled = options->outlineEnabled() != 0;
|
2015-04-20 11:39:43 +08:00
|
|
|
if (outlineEnabled)
|
|
|
|
{
|
|
|
|
auto f_outlineColor = options->outlineColor();
|
|
|
|
if (f_outlineColor)
|
|
|
|
{
|
|
|
|
Color4B outlineColor(f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b(), f_outlineColor->a());
|
|
|
|
auto label = button->getTitleRenderer();
|
|
|
|
label->enableOutline(outlineColor, options->outlineSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 23:10:04 +08:00
|
|
|
bool shadowEnabled = options->shadowEnabled() != 0;
|
2015-04-20 11:39:43 +08:00
|
|
|
if (shadowEnabled)
|
|
|
|
{
|
|
|
|
auto f_shadowColor = options->shadowColor();
|
|
|
|
if (f_shadowColor)
|
|
|
|
{
|
|
|
|
Color4B shadowColor(f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b(), f_shadowColor->a());
|
|
|
|
auto label = button->getTitleRenderer();
|
|
|
|
label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
auto widgetReader = WidgetReader::getInstance();
|
|
|
|
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
2014-12-10 17:35:39 +08:00
|
|
|
|
|
|
|
if (scale9Enabled)
|
2014-12-05 19:19:53 +08:00
|
|
|
{
|
2014-12-10 17:35:39 +08:00
|
|
|
button->setUnifySizeEnabled(false);
|
|
|
|
button->ignoreContentAdaptWithSize(false);
|
|
|
|
|
|
|
|
auto f_capInsets = options->capInsets();
|
|
|
|
Rect capInsets(f_capInsets->x(), f_capInsets->y(), f_capInsets->width(), f_capInsets->height());
|
|
|
|
button->setCapInsets(capInsets);
|
|
|
|
|
|
|
|
Size scale9Size(options->scale9Size()->width(), options->scale9Size()->height());
|
|
|
|
button->setContentSize(scale9Size);
|
2014-12-05 19:19:53 +08:00
|
|
|
}
|
2014-12-22 15:38:47 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height());
|
|
|
|
button->setContentSize(contentSize);
|
|
|
|
}
|
2015-06-12 15:47:34 +08:00
|
|
|
|
|
|
|
button->setBright(displaystate);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
|
|
|
|
2014-11-26 11:50:42 +08:00
|
|
|
Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
|
|
|
Button* button = Button::create();
|
|
|
|
|
|
|
|
setPropsWithFlatBuffers(button, (Table*)buttonOptions);
|
|
|
|
|
|
|
|
return button;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
int ButtonReader::getResourceType(std::string key)
|
|
|
|
{
|
|
|
|
if(key == "Normal" || key == "Default")
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
|
|
|
if(fbs->_isSimulator)
|
|
|
|
{
|
|
|
|
if(key == "MarkedSubImage")
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|