2014-11-21 15:15:38 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "NodeReader.h"
|
|
|
|
|
|
|
|
#include "cocostudio/CSParseBinary_generated.h"
|
|
|
|
#include "cocostudio/ActionTimeline/CCActionTimeline.h"
|
2015-07-23 16:30:23 +08:00
|
|
|
#include "cocostudio/CCComExtensionData.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-12-22 15:38:47 +08:00
|
|
|
#include "ui/UILayoutComponent.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace flatbuffers;
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2015-03-05 14:34:35 +08:00
|
|
|
const char* Layout_PositionPercentXEnabled = "PositionPercentXEnabled";
|
|
|
|
const char* Layout_PositionPercentYEnabled = "PositionPercentYEnabled";
|
|
|
|
const char* Layout_PercentWidthEnable = "PercentWidthEnabled";
|
|
|
|
const char* Layout_PercentHeightEnable = "PercentHeightEnabled";
|
2014-12-23 20:29:53 +08:00
|
|
|
const char* Layout_StretchWidthEnable = "StretchWidthEnable";
|
|
|
|
const char* Layout_StretchHeightEnable = "StretchHeightEnable";
|
|
|
|
const char* Layout_HorizontalEdge = "HorizontalEdge";
|
|
|
|
const char* Layout_VerticalEdge = "VerticalEdge";
|
|
|
|
const char* Layout_LeftMargin = "LeftMargin";
|
|
|
|
const char* Layout_RightMargin = "RightMargin";
|
|
|
|
const char* Layout_TopMargin = "TopMargin";
|
|
|
|
const char* Layout_BottomMargin = "BottomMargin";
|
|
|
|
const char* Layout_BothEdge = "BothEdge";
|
|
|
|
const char* Layout_LeftEdge = "LeftEdge";
|
|
|
|
const char* Layout_RightEdge = "RightEdge";
|
|
|
|
const char* Layout_TopEdge = "TopEdge";
|
|
|
|
const char* Layout_BottomEdge = "BottomEdge";
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
IMPLEMENT_CLASS_NODE_READER_INFO(NodeReader)
|
|
|
|
|
|
|
|
NodeReader::NodeReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeReader::~NodeReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static NodeReader* _instanceNodeReader = nullptr;
|
|
|
|
|
|
|
|
NodeReader* NodeReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!_instanceNodeReader)
|
|
|
|
{
|
|
|
|
_instanceNodeReader = new NodeReader();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _instanceNodeReader;
|
|
|
|
}
|
|
|
|
|
2015-03-30 16:46:33 +08:00
|
|
|
void NodeReader::destroyInstance()
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_instanceNodeReader);
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset<Table> NodeReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData,
|
|
|
|
flatbuffers::FlatBufferBuilder *builder)
|
|
|
|
{
|
|
|
|
std::string name = "";
|
|
|
|
long actionTag = 0;
|
2015-04-20 01:40:52 +08:00
|
|
|
Vec2 rotationSkew;
|
2014-11-21 15:15:38 +08:00
|
|
|
int zOrder = 0;
|
|
|
|
bool visible = true;
|
|
|
|
GLubyte alpha = 255;
|
|
|
|
int tag = 0;
|
2015-04-20 01:40:52 +08:00
|
|
|
Vec2 position;
|
|
|
|
Vec2 scale(1.0f, 1.0f);
|
|
|
|
Vec2 anchorPoint;
|
2014-11-27 21:21:04 +08:00
|
|
|
Color4B color(255, 255, 255, 255);
|
|
|
|
|
2015-04-20 01:40:52 +08:00
|
|
|
Vec2 size;
|
2014-11-21 15:15:38 +08:00
|
|
|
bool flipX = false;
|
|
|
|
bool flipY = false;
|
|
|
|
bool ignoreSize = false;
|
|
|
|
bool touchEnabled = false;
|
|
|
|
std::string frameEvent = "";
|
|
|
|
std::string customProperty = "";
|
2014-12-22 15:38:47 +08:00
|
|
|
|
|
|
|
bool positionXPercentEnabled = false;
|
|
|
|
bool positionYPercentEnabled = false;
|
|
|
|
float positionXPercent = 0;
|
|
|
|
float positionYPercent = 0;
|
|
|
|
bool sizeXPercentEnable = false;
|
|
|
|
bool sizeYPercentEnable = false;
|
|
|
|
float sizeXPercent = 0;
|
|
|
|
float sizeYPercent = 0;
|
|
|
|
bool stretchHorizontalEnabled = false;
|
|
|
|
bool stretchVerticalEnabled = false;
|
|
|
|
std::string horizontalEdge;
|
|
|
|
std::string verticalEdge;
|
|
|
|
float leftMargin = 0;
|
|
|
|
float rightMargin = 0;
|
|
|
|
float topMargin = 0;
|
|
|
|
float bottomMargin = 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
// attributes
|
|
|
|
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
std::string attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "Name")
|
|
|
|
{
|
|
|
|
name = value;
|
|
|
|
}
|
|
|
|
else if (attriname == "ActionTag")
|
|
|
|
{
|
|
|
|
actionTag = atol(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "RotationSkewX")
|
|
|
|
{
|
|
|
|
rotationSkew.x = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "RotationSkewY")
|
|
|
|
{
|
|
|
|
rotationSkew.y = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Rotation")
|
|
|
|
{
|
|
|
|
// rotation = atoi(value.c_str());
|
|
|
|
}
|
2014-12-01 11:48:04 +08:00
|
|
|
else if (attriname == "FlipX")
|
|
|
|
{
|
|
|
|
flipX = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (attriname == "FlipY")
|
|
|
|
{
|
|
|
|
flipY = (value == "True") ? true : false;
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
else if (attriname == "ZOrder")
|
|
|
|
{
|
|
|
|
zOrder = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Visible")
|
|
|
|
{
|
|
|
|
// visible = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (attriname == "VisibleForFrame")
|
|
|
|
{
|
|
|
|
visible = (value == "True") ? true : false;
|
|
|
|
}
|
|
|
|
else if (attriname == "Alpha")
|
|
|
|
{
|
|
|
|
alpha = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Tag")
|
|
|
|
{
|
|
|
|
tag = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "TouchEnable")
|
|
|
|
{
|
|
|
|
touchEnabled = (value == "True") ? true : false;
|
|
|
|
}
|
2015-03-12 15:47:15 +08:00
|
|
|
else if (attriname == "UserData")
|
|
|
|
{
|
|
|
|
customProperty = value;
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
else if (attriname == "FrameEvent")
|
|
|
|
{
|
|
|
|
frameEvent = value;
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_PositionPercentXEnabled)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
positionXPercentEnabled = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_PositionPercentYEnabled)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
positionYPercentEnabled = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_PercentWidthEnable)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
sizeXPercentEnable = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_PercentHeightEnable)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
sizeYPercentEnable = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_StretchWidthEnable)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
stretchHorizontalEnabled = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_StretchHeightEnable)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
stretchVerticalEnabled = value == "True";
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_HorizontalEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
horizontalEdge = value;
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_VerticalEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
verticalEdge = value;
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_LeftMargin)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
leftMargin = atof(value.c_str());
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_RightMargin)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
rightMargin = atof(value.c_str());
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_TopMargin)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
topMargin = atof(value.c_str());
|
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (attriname == Layout_BottomMargin)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
|
|
|
bottomMargin = atof(value.c_str());
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
std::string attriname = child->Name();
|
2015-04-16 13:58:01 +08:00
|
|
|
if (attriname == "Position")
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "X")
|
|
|
|
{
|
|
|
|
position.x = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Y")
|
|
|
|
{
|
|
|
|
position.y = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attriname == "Scale")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "ScaleX")
|
|
|
|
{
|
|
|
|
scale.x = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "ScaleY")
|
|
|
|
{
|
|
|
|
scale.y = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attriname == "AnchorPoint")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "ScaleX")
|
|
|
|
{
|
|
|
|
anchorPoint.x = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "ScaleY")
|
|
|
|
{
|
|
|
|
anchorPoint.y = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attriname == "CColor")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "A")
|
|
|
|
{
|
|
|
|
color.a = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "R")
|
|
|
|
{
|
|
|
|
color.r = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "G")
|
|
|
|
{
|
|
|
|
color.g = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "B")
|
|
|
|
{
|
|
|
|
color.b = atoi(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attriname == "Size")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "X")
|
|
|
|
{
|
|
|
|
size.x = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Y")
|
|
|
|
{
|
|
|
|
size.y = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
2014-12-22 15:38:47 +08:00
|
|
|
else if (attriname == "PrePosition")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "X")
|
|
|
|
{
|
|
|
|
positionXPercent = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Y")
|
|
|
|
{
|
|
|
|
positionYPercent = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (attriname == "PreSize")
|
|
|
|
{
|
|
|
|
attribute = child->FirstAttribute();
|
|
|
|
|
|
|
|
while (attribute)
|
|
|
|
{
|
|
|
|
attriname = attribute->Name();
|
|
|
|
std::string value = attribute->Value();
|
|
|
|
|
|
|
|
if (attriname == "X")
|
|
|
|
{
|
|
|
|
sizeXPercent = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if (attriname == "Y")
|
|
|
|
{
|
|
|
|
sizeYPercent = atof(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
attribute = attribute->Next();
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 15:15:38 +08:00
|
|
|
child = child->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
RotationSkew f_rotationskew(rotationSkew.x, rotationSkew.y);
|
|
|
|
Position f_position(position.x, position.y);
|
|
|
|
Scale f_scale(scale.x, scale.y);
|
|
|
|
AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y);
|
|
|
|
Color f_color(color.a, color.r, color.g, color.b);
|
|
|
|
FlatSize f_size(size.x, size.y);
|
2014-12-22 15:38:47 +08:00
|
|
|
auto f_layoutComponent = CreateLayoutComponentTable(*builder,
|
|
|
|
positionXPercentEnabled,
|
|
|
|
positionYPercentEnabled,
|
|
|
|
positionXPercent,
|
|
|
|
positionYPercent,
|
|
|
|
sizeXPercentEnable,
|
|
|
|
sizeYPercentEnable,
|
|
|
|
sizeXPercent,
|
|
|
|
sizeYPercent,
|
|
|
|
stretchHorizontalEnabled,
|
|
|
|
stretchVerticalEnabled,
|
|
|
|
builder->CreateString(horizontalEdge),
|
|
|
|
builder->CreateString(verticalEdge),
|
|
|
|
leftMargin,
|
|
|
|
rightMargin,
|
|
|
|
topMargin,
|
|
|
|
bottomMargin);
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
auto options = CreateWidgetOptions(*builder,
|
|
|
|
builder->CreateString(name),
|
2014-12-10 17:35:39 +08:00
|
|
|
(int)actionTag,
|
2014-11-21 15:15:38 +08:00
|
|
|
&f_rotationskew,
|
|
|
|
zOrder,
|
|
|
|
visible,
|
|
|
|
alpha,
|
|
|
|
tag,
|
|
|
|
&f_position,
|
|
|
|
&f_scale,
|
|
|
|
&f_anchortpoint,
|
|
|
|
&f_color,
|
|
|
|
&f_size,
|
|
|
|
flipX,
|
|
|
|
flipY,
|
|
|
|
ignoreSize,
|
|
|
|
touchEnabled,
|
|
|
|
builder->CreateString(frameEvent),
|
2014-12-22 15:38:47 +08:00
|
|
|
builder->CreateString(customProperty),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
f_layoutComponent);
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
return *(Offset<Table>*)(&options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
|
|
|
const flatbuffers::Table* nodeOptions)
|
|
|
|
{
|
|
|
|
auto options = (WidgetOptions*)(nodeOptions);
|
|
|
|
|
|
|
|
std::string name = options->name()->c_str();
|
|
|
|
float x = options->position()->x();
|
|
|
|
float y = options->position()->y();
|
|
|
|
float scalex = options->scale()->scaleX();
|
|
|
|
float scaley = options->scale()->scaleY();
|
|
|
|
// float rotation = options.rotation();
|
|
|
|
float rotationSkewX = options->rotationSkew()->rotationSkewX();
|
|
|
|
float rotationSkewY = options->rotationSkew()->rotationSkewY();
|
|
|
|
float anchorx = options->anchorPoint()->scaleX();
|
|
|
|
float anchory = options->anchorPoint()->scaleY();
|
2015-07-23 16:30:23 +08:00
|
|
|
int zorder = options->zOrder();
|
2014-11-21 15:15:38 +08:00
|
|
|
int tag = options->tag();
|
|
|
|
int actionTag = options->actionTag();
|
2015-01-23 09:02:33 +08:00
|
|
|
bool visible = options->visible() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
float w = options->size()->width();
|
|
|
|
float h = options->size()->height();
|
|
|
|
int alpha = options->alpha();
|
2014-12-01 16:27:21 +08:00
|
|
|
Color3B color(options->color()->r(), options->color()->g(), options->color()->b());
|
2015-03-12 15:47:15 +08:00
|
|
|
std::string customProperty = options->customProperty()->c_str();
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
node->setName(name);
|
|
|
|
|
|
|
|
// if(x != 0 || y != 0)
|
|
|
|
node->setPosition(Point(x, y));
|
|
|
|
if(scalex != 1)
|
|
|
|
node->setScaleX(scalex);
|
|
|
|
if(scaley != 1)
|
|
|
|
node->setScaleY(scaley);
|
|
|
|
// if (rotation != 0)
|
|
|
|
// node->setRotation(rotation);
|
|
|
|
if (rotationSkewX != 0)
|
|
|
|
node->setRotationSkewX(rotationSkewX);
|
|
|
|
if (rotationSkewY != 0)
|
|
|
|
node->setRotationSkewY(rotationSkewY);
|
|
|
|
if(anchorx != 0.5f || anchory != 0.5f)
|
|
|
|
node->setAnchorPoint(Point(anchorx, anchory));
|
|
|
|
if(zorder != 0)
|
|
|
|
node->setLocalZOrder(zorder);
|
|
|
|
if(visible != true)
|
|
|
|
node->setVisible(visible);
|
|
|
|
// if (w != 0 || h != 0)
|
|
|
|
node->setContentSize(Size(w, h));
|
|
|
|
if (alpha != 255)
|
|
|
|
node->setOpacity(alpha);
|
|
|
|
|
2014-12-01 16:27:21 +08:00
|
|
|
node->setColor(color);
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
node->setTag(tag);
|
2015-03-12 15:47:15 +08:00
|
|
|
|
2015-07-23 16:30:23 +08:00
|
|
|
ComExtensionData* extensionData = ComExtensionData::create();
|
2015-03-12 15:47:15 +08:00
|
|
|
extensionData->setCustomProperty(customProperty);
|
|
|
|
extensionData->setActionTag(actionTag);
|
2015-07-23 16:30:23 +08:00
|
|
|
if (node->getComponent("ComExtensionData"))
|
|
|
|
{
|
|
|
|
node->removeComponent("ComExtensionData");
|
|
|
|
}
|
|
|
|
node->addComponent(extensionData);
|
2015-03-12 15:47:15 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
node->setCascadeColorEnabled(true);
|
|
|
|
node->setCascadeOpacityEnabled(true);
|
2014-12-22 15:38:47 +08:00
|
|
|
|
|
|
|
setLayoutComponentPropsWithFlatBuffers(node, nodeOptions);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2014-12-22 15:38:47 +08:00
|
|
|
|
|
|
|
void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions)
|
|
|
|
{
|
|
|
|
auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent();
|
|
|
|
if (!layoutComponentTable) return;
|
|
|
|
|
2014-12-25 15:02:22 +08:00
|
|
|
auto layoutComponent = ui::LayoutComponent::bindLayoutComponent(node);
|
2014-12-25 14:11:05 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled() != 0;
|
|
|
|
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled() != 0;
|
2014-12-22 15:38:47 +08:00
|
|
|
float positionXPercent = layoutComponentTable->positionXPercent();
|
|
|
|
float positionYPercent = layoutComponentTable->positionYPercent();
|
2015-01-23 09:02:33 +08:00
|
|
|
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable() != 0;
|
|
|
|
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable() != 0;
|
2014-12-22 15:38:47 +08:00
|
|
|
float sizeXPercent = layoutComponentTable->sizeXPercent();
|
|
|
|
float sizeYPercent = layoutComponentTable->sizeYPercent();
|
2015-01-23 09:02:33 +08:00
|
|
|
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled() != 0;
|
|
|
|
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled() != 0;
|
2014-12-22 15:38:47 +08:00
|
|
|
std::string horizontalEdge = layoutComponentTable->horizontalEdge()->c_str();
|
|
|
|
std::string verticalEdge = layoutComponentTable->verticalEdge()->c_str();
|
|
|
|
float leftMargin = layoutComponentTable->leftMargin();
|
|
|
|
float rightMargin = layoutComponentTable->rightMargin();
|
|
|
|
float topMargin = layoutComponentTable->topMargin();
|
|
|
|
float bottomMargin = layoutComponentTable->bottomMargin();
|
|
|
|
|
|
|
|
layoutComponent->setPositionPercentXEnabled(positionXPercentEnabled);
|
|
|
|
layoutComponent->setPositionPercentYEnabled(positionYPercentEnabled);
|
|
|
|
layoutComponent->setPositionPercentX(positionXPercent);
|
|
|
|
layoutComponent->setPositionPercentY(positionYPercent);
|
|
|
|
layoutComponent->setPercentWidthEnabled(sizeXPercentEnable);
|
|
|
|
layoutComponent->setPercentHeightEnabled(sizeYPercentEnable);
|
|
|
|
layoutComponent->setPercentWidth(sizeXPercent);
|
|
|
|
layoutComponent->setPercentHeight(sizeYPercent);
|
|
|
|
layoutComponent->setStretchWidthEnabled(stretchHorizontalEnabled);
|
|
|
|
layoutComponent->setStretchHeightEnabled(stretchVerticalEnabled);
|
2014-12-24 10:56:01 +08:00
|
|
|
ui::LayoutComponent::HorizontalEdge horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::None;
|
2014-12-23 20:29:53 +08:00
|
|
|
if (horizontalEdge == Layout_LeftEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Left;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (horizontalEdge == Layout_RightEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Right;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (horizontalEdge == Layout_BothEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEdge::Center;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-24 10:56:01 +08:00
|
|
|
layoutComponent->setHorizontalEdge(horizontalEdgeType);
|
|
|
|
ui::LayoutComponent::VerticalEdge verticalEdgeType = ui::LayoutComponent::VerticalEdge::None;
|
2014-12-23 20:29:53 +08:00
|
|
|
if (verticalEdge == Layout_TopEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
verticalEdgeType = ui::LayoutComponent::VerticalEdge::Top;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (verticalEdge == Layout_BottomEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
verticalEdgeType = ui::LayoutComponent::VerticalEdge::Bottom;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-23 20:29:53 +08:00
|
|
|
else if (verticalEdge == Layout_BothEdge)
|
2014-12-22 15:38:47 +08:00
|
|
|
{
|
2014-12-24 10:56:01 +08:00
|
|
|
verticalEdgeType = ui::LayoutComponent::VerticalEdge::Center;
|
2014-12-22 15:38:47 +08:00
|
|
|
}
|
2014-12-24 10:56:01 +08:00
|
|
|
layoutComponent->setVerticalEdge(verticalEdgeType);
|
2014-12-22 15:38:47 +08:00
|
|
|
|
|
|
|
layoutComponent->setTopMargin(topMargin);
|
2014-12-24 10:56:01 +08:00
|
|
|
layoutComponent->setBottomMargin(bottomMargin);
|
2014-12-22 15:38:47 +08:00
|
|
|
layoutComponent->setLeftMargin(leftMargin);
|
|
|
|
layoutComponent->setRightMargin(rightMargin);
|
|
|
|
}
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
Node* NodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions)
|
|
|
|
{
|
|
|
|
Node* node = Node::create();
|
|
|
|
|
|
|
|
setPropsWithFlatBuffers(node, nodeOptions);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|