mirror of https://github.com/axmolengine/axmol.git
update object reader for new lay out system
This commit is contained in:
parent
f5a242be97
commit
ce9f269680
|
@ -762,6 +762,9 @@ Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName)
|
||||||
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str());
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto v = csparsebinary->version();
|
||||||
|
if (v) _csdVersion = v->c_str();
|
||||||
|
|
||||||
Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree());
|
Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree());
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
@ -1083,6 +1086,10 @@ Node* CSLoader::createNodeWithFlatBuffersForSimulator(const std::string& filenam
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nodeTree = csparsebinary->nodeTree();
|
auto nodeTree = csparsebinary->nodeTree();
|
||||||
|
|
||||||
|
auto v = csparsebinary->version();
|
||||||
|
if (v) _csdVersion = v->c_str();
|
||||||
|
|
||||||
Node* node = nodeWithFlatBuffersForSimulator(nodeTree);
|
Node* node = nodeWithFlatBuffersForSimulator(nodeTree);
|
||||||
|
|
||||||
_rootNode = nullptr;
|
_rootNode = nullptr;
|
||||||
|
@ -1189,6 +1196,7 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod
|
||||||
node->addChild(child);
|
node->addChild(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Helper::doLayout(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _loadingNodeParentHierarchy.pop_back();
|
// _loadingNodeParentHierarchy.pop_back();
|
||||||
|
|
|
@ -100,6 +100,7 @@ public:
|
||||||
|
|
||||||
cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename);
|
cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename);
|
||||||
cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree);
|
cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree);
|
||||||
|
std::string getCsdVersion() { return _csdVersion; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -147,6 +148,7 @@ protected:
|
||||||
|
|
||||||
Node* _rootNode;
|
Node* _rootNode;
|
||||||
// std::vector<Node*> _loadingNodeParentHierarchy;
|
// std::vector<Node*> _loadingNodeParentHierarchy;
|
||||||
|
std::string _csdVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -12,6 +12,7 @@ struct CSParseBinary;
|
||||||
struct NodeTree;
|
struct NodeTree;
|
||||||
struct Options;
|
struct Options;
|
||||||
struct WidgetOptions;
|
struct WidgetOptions;
|
||||||
|
struct LayoutComponentTable;
|
||||||
struct SingleNodeOptions;
|
struct SingleNodeOptions;
|
||||||
struct SpriteOptions;
|
struct SpriteOptions;
|
||||||
struct ParticleSystemOptions;
|
struct ParticleSystemOptions;
|
||||||
|
@ -176,6 +177,7 @@ struct CSParseBinary : private flatbuffers::Table {
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *texturePngs() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(6); }
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *texturePngs() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(6); }
|
||||||
const NodeTree *nodeTree() const { return GetPointer<const NodeTree *>(8); }
|
const NodeTree *nodeTree() const { return GetPointer<const NodeTree *>(8); }
|
||||||
const NodeAction *action() const { return GetPointer<const NodeAction *>(10); }
|
const NodeAction *action() const { return GetPointer<const NodeAction *>(10); }
|
||||||
|
const flatbuffers::String *version() const { return GetPointer<const flatbuffers::String *>(12); }
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* textures */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* textures */) &&
|
||||||
|
@ -188,6 +190,8 @@ struct CSParseBinary : private flatbuffers::Table {
|
||||||
verifier.VerifyTable(nodeTree()) &&
|
verifier.VerifyTable(nodeTree()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* action */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* action */) &&
|
||||||
verifier.VerifyTable(action()) &&
|
verifier.VerifyTable(action()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* version */) &&
|
||||||
|
verifier.Verify(version()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -199,10 +203,11 @@ struct CSParseBinaryBuilder {
|
||||||
void add_texturePngs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs) { fbb_.AddOffset(6, texturePngs); }
|
void add_texturePngs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs) { fbb_.AddOffset(6, texturePngs); }
|
||||||
void add_nodeTree(flatbuffers::Offset<NodeTree> nodeTree) { fbb_.AddOffset(8, nodeTree); }
|
void add_nodeTree(flatbuffers::Offset<NodeTree> nodeTree) { fbb_.AddOffset(8, nodeTree); }
|
||||||
void add_action(flatbuffers::Offset<NodeAction> action) { fbb_.AddOffset(10, action); }
|
void add_action(flatbuffers::Offset<NodeAction> action) { fbb_.AddOffset(10, action); }
|
||||||
|
void add_version(flatbuffers::Offset<flatbuffers::String> version) { fbb_.AddOffset(12, version); }
|
||||||
CSParseBinaryBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
CSParseBinaryBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||||
CSParseBinaryBuilder &operator=(const CSParseBinaryBuilder &);
|
CSParseBinaryBuilder &operator=(const CSParseBinaryBuilder &);
|
||||||
flatbuffers::Offset<CSParseBinary> Finish() {
|
flatbuffers::Offset<CSParseBinary> Finish() {
|
||||||
auto o = flatbuffers::Offset<CSParseBinary>(fbb_.EndTable(start_, 4));
|
auto o = flatbuffers::Offset<CSParseBinary>(fbb_.EndTable(start_, 5));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -211,8 +216,10 @@ inline flatbuffers::Offset<CSParseBinary> CreateCSParseBinary(flatbuffers::FlatB
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> textures = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> textures = 0,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs = 0,
|
||||||
flatbuffers::Offset<NodeTree> nodeTree = 0,
|
flatbuffers::Offset<NodeTree> nodeTree = 0,
|
||||||
flatbuffers::Offset<NodeAction> action = 0) {
|
flatbuffers::Offset<NodeAction> action = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> version = 0) {
|
||||||
CSParseBinaryBuilder builder_(_fbb);
|
CSParseBinaryBuilder builder_(_fbb);
|
||||||
|
builder_.add_version(version);
|
||||||
builder_.add_action(action);
|
builder_.add_action(action);
|
||||||
builder_.add_nodeTree(nodeTree);
|
builder_.add_nodeTree(nodeTree);
|
||||||
builder_.add_texturePngs(texturePngs);
|
builder_.add_texturePngs(texturePngs);
|
||||||
|
@ -318,6 +325,7 @@ struct WidgetOptions : private flatbuffers::Table {
|
||||||
const flatbuffers::String *customProperty() const { return GetPointer<const flatbuffers::String *>(38); }
|
const flatbuffers::String *customProperty() const { return GetPointer<const flatbuffers::String *>(38); }
|
||||||
const flatbuffers::String *callBackType() const { return GetPointer<const flatbuffers::String *>(40); }
|
const flatbuffers::String *callBackType() const { return GetPointer<const flatbuffers::String *>(40); }
|
||||||
const flatbuffers::String *callBackName() const { return GetPointer<const flatbuffers::String *>(42); }
|
const flatbuffers::String *callBackName() const { return GetPointer<const flatbuffers::String *>(42); }
|
||||||
|
const LayoutComponentTable *layoutComponent() const { return GetPointer<const LayoutComponentTable *>(44); }
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
||||||
|
@ -345,6 +353,8 @@ struct WidgetOptions : private flatbuffers::Table {
|
||||||
verifier.Verify(callBackType()) &&
|
verifier.Verify(callBackType()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 42 /* callBackName */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 42 /* callBackName */) &&
|
||||||
verifier.Verify(callBackName()) &&
|
verifier.Verify(callBackName()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, 44 /* layoutComponent */) &&
|
||||||
|
verifier.VerifyTable(layoutComponent()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -372,10 +382,11 @@ struct WidgetOptionsBuilder {
|
||||||
void add_customProperty(flatbuffers::Offset<flatbuffers::String> customProperty) { fbb_.AddOffset(38, customProperty); }
|
void add_customProperty(flatbuffers::Offset<flatbuffers::String> customProperty) { fbb_.AddOffset(38, customProperty); }
|
||||||
void add_callBackType(flatbuffers::Offset<flatbuffers::String> callBackType) { fbb_.AddOffset(40, callBackType); }
|
void add_callBackType(flatbuffers::Offset<flatbuffers::String> callBackType) { fbb_.AddOffset(40, callBackType); }
|
||||||
void add_callBackName(flatbuffers::Offset<flatbuffers::String> callBackName) { fbb_.AddOffset(42, callBackName); }
|
void add_callBackName(flatbuffers::Offset<flatbuffers::String> callBackName) { fbb_.AddOffset(42, callBackName); }
|
||||||
|
void add_layoutComponent(flatbuffers::Offset<LayoutComponentTable> layoutComponent) { fbb_.AddOffset(44, layoutComponent); }
|
||||||
WidgetOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
WidgetOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||||
WidgetOptionsBuilder &operator=(const WidgetOptionsBuilder &);
|
WidgetOptionsBuilder &operator=(const WidgetOptionsBuilder &);
|
||||||
flatbuffers::Offset<WidgetOptions> Finish() {
|
flatbuffers::Offset<WidgetOptions> Finish() {
|
||||||
auto o = flatbuffers::Offset<WidgetOptions>(fbb_.EndTable(start_, 20));
|
auto o = flatbuffers::Offset<WidgetOptions>(fbb_.EndTable(start_, 21));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -400,8 +411,10 @@ inline flatbuffers::Offset<WidgetOptions> CreateWidgetOptions(flatbuffers::FlatB
|
||||||
flatbuffers::Offset<flatbuffers::String> frameEvent = 0,
|
flatbuffers::Offset<flatbuffers::String> frameEvent = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> customProperty = 0,
|
flatbuffers::Offset<flatbuffers::String> customProperty = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> callBackType = 0,
|
flatbuffers::Offset<flatbuffers::String> callBackType = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> callBackName = 0) {
|
flatbuffers::Offset<flatbuffers::String> callBackName = 0,
|
||||||
|
flatbuffers::Offset<LayoutComponentTable> layoutComponent = 0) {
|
||||||
WidgetOptionsBuilder builder_(_fbb);
|
WidgetOptionsBuilder builder_(_fbb);
|
||||||
|
builder_.add_layoutComponent(layoutComponent);
|
||||||
builder_.add_callBackName(callBackName);
|
builder_.add_callBackName(callBackName);
|
||||||
builder_.add_callBackType(callBackType);
|
builder_.add_callBackType(callBackType);
|
||||||
builder_.add_customProperty(customProperty);
|
builder_.add_customProperty(customProperty);
|
||||||
|
@ -425,6 +438,111 @@ inline flatbuffers::Offset<WidgetOptions> CreateWidgetOptions(flatbuffers::FlatB
|
||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LayoutComponentTable : private flatbuffers::Table {
|
||||||
|
uint8_t positionXPercentEnabled() const { return GetField<uint8_t>(4, 0); }
|
||||||
|
uint8_t positionYPercentEnabled() const { return GetField<uint8_t>(6, 0); }
|
||||||
|
float positionXPercent() const { return GetField<float>(8, 0); }
|
||||||
|
float positionYPercent() const { return GetField<float>(10, 0); }
|
||||||
|
uint8_t sizeXPercentEnable() const { return GetField<uint8_t>(12, 0); }
|
||||||
|
uint8_t sizeYPercentEnable() const { return GetField<uint8_t>(14, 0); }
|
||||||
|
float sizeXPercent() const { return GetField<float>(16, 0); }
|
||||||
|
float sizeYPercent() const { return GetField<float>(18, 0); }
|
||||||
|
uint8_t stretchHorizontalEnabled() const { return GetField<uint8_t>(20, 0); }
|
||||||
|
uint8_t stretchVerticalEnabled() const { return GetField<uint8_t>(22, 0); }
|
||||||
|
const flatbuffers::String *horizontalEdge() const { return GetPointer<const flatbuffers::String *>(24); }
|
||||||
|
const flatbuffers::String *verticalEdge() const { return GetPointer<const flatbuffers::String *>(26); }
|
||||||
|
float leftMargin() const { return GetField<float>(28, 0); }
|
||||||
|
float rightMargin() const { return GetField<float>(30, 0); }
|
||||||
|
float topMargin() const { return GetField<float>(32, 0); }
|
||||||
|
float bottomMargin() const { return GetField<float>(34, 0); }
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 4 /* positionXPercentEnabled */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 6 /* positionYPercentEnabled */) &&
|
||||||
|
VerifyField<float>(verifier, 8 /* positionXPercent */) &&
|
||||||
|
VerifyField<float>(verifier, 10 /* positionYPercent */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 12 /* sizeXPercentEnable */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 14 /* sizeYPercentEnable */) &&
|
||||||
|
VerifyField<float>(verifier, 16 /* sizeXPercent */) &&
|
||||||
|
VerifyField<float>(verifier, 18 /* sizeYPercent */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 20 /* stretchHorizontalEnabled */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 22 /* stretchVerticalEnabled */) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, 24 /* horizontalEdge */) &&
|
||||||
|
verifier.Verify(horizontalEdge()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, 26 /* verticalEdge */) &&
|
||||||
|
verifier.Verify(verticalEdge()) &&
|
||||||
|
VerifyField<float>(verifier, 28 /* leftMargin */) &&
|
||||||
|
VerifyField<float>(verifier, 30 /* rightMargin */) &&
|
||||||
|
VerifyField<float>(verifier, 32 /* topMargin */) &&
|
||||||
|
VerifyField<float>(verifier, 34 /* bottomMargin */) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LayoutComponentTableBuilder {
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_positionXPercentEnabled(uint8_t positionXPercentEnabled) { fbb_.AddElement<uint8_t>(4, positionXPercentEnabled, 0); }
|
||||||
|
void add_positionYPercentEnabled(uint8_t positionYPercentEnabled) { fbb_.AddElement<uint8_t>(6, positionYPercentEnabled, 0); }
|
||||||
|
void add_positionXPercent(float positionXPercent) { fbb_.AddElement<float>(8, positionXPercent, 0); }
|
||||||
|
void add_positionYPercent(float positionYPercent) { fbb_.AddElement<float>(10, positionYPercent, 0); }
|
||||||
|
void add_sizeXPercentEnable(uint8_t sizeXPercentEnable) { fbb_.AddElement<uint8_t>(12, sizeXPercentEnable, 0); }
|
||||||
|
void add_sizeYPercentEnable(uint8_t sizeYPercentEnable) { fbb_.AddElement<uint8_t>(14, sizeYPercentEnable, 0); }
|
||||||
|
void add_sizeXPercent(float sizeXPercent) { fbb_.AddElement<float>(16, sizeXPercent, 0); }
|
||||||
|
void add_sizeYPercent(float sizeYPercent) { fbb_.AddElement<float>(18, sizeYPercent, 0); }
|
||||||
|
void add_stretchHorizontalEnabled(uint8_t stretchHorizontalEnabled) { fbb_.AddElement<uint8_t>(20, stretchHorizontalEnabled, 0); }
|
||||||
|
void add_stretchVerticalEnabled(uint8_t stretchVerticalEnabled) { fbb_.AddElement<uint8_t>(22, stretchVerticalEnabled, 0); }
|
||||||
|
void add_horizontalEdge(flatbuffers::Offset<flatbuffers::String> horizontalEdge) { fbb_.AddOffset(24, horizontalEdge); }
|
||||||
|
void add_verticalEdge(flatbuffers::Offset<flatbuffers::String> verticalEdge) { fbb_.AddOffset(26, verticalEdge); }
|
||||||
|
void add_leftMargin(float leftMargin) { fbb_.AddElement<float>(28, leftMargin, 0); }
|
||||||
|
void add_rightMargin(float rightMargin) { fbb_.AddElement<float>(30, rightMargin, 0); }
|
||||||
|
void add_topMargin(float topMargin) { fbb_.AddElement<float>(32, topMargin, 0); }
|
||||||
|
void add_bottomMargin(float bottomMargin) { fbb_.AddElement<float>(34, bottomMargin, 0); }
|
||||||
|
LayoutComponentTableBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||||
|
LayoutComponentTableBuilder &operator=(const LayoutComponentTableBuilder &);
|
||||||
|
flatbuffers::Offset<LayoutComponentTable> Finish() {
|
||||||
|
auto o = flatbuffers::Offset<LayoutComponentTable>(fbb_.EndTable(start_, 16));
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<LayoutComponentTable> CreateLayoutComponentTable(flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
uint8_t positionXPercentEnabled = 0,
|
||||||
|
uint8_t positionYPercentEnabled = 0,
|
||||||
|
float positionXPercent = 0,
|
||||||
|
float positionYPercent = 0,
|
||||||
|
uint8_t sizeXPercentEnable = 0,
|
||||||
|
uint8_t sizeYPercentEnable = 0,
|
||||||
|
float sizeXPercent = 0,
|
||||||
|
float sizeYPercent = 0,
|
||||||
|
uint8_t stretchHorizontalEnabled = 0,
|
||||||
|
uint8_t stretchVerticalEnabled = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> horizontalEdge = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> verticalEdge = 0,
|
||||||
|
float leftMargin = 0,
|
||||||
|
float rightMargin = 0,
|
||||||
|
float topMargin = 0,
|
||||||
|
float bottomMargin = 0) {
|
||||||
|
LayoutComponentTableBuilder builder_(_fbb);
|
||||||
|
builder_.add_bottomMargin(bottomMargin);
|
||||||
|
builder_.add_topMargin(topMargin);
|
||||||
|
builder_.add_rightMargin(rightMargin);
|
||||||
|
builder_.add_leftMargin(leftMargin);
|
||||||
|
builder_.add_verticalEdge(verticalEdge);
|
||||||
|
builder_.add_horizontalEdge(horizontalEdge);
|
||||||
|
builder_.add_sizeYPercent(sizeYPercent);
|
||||||
|
builder_.add_sizeXPercent(sizeXPercent);
|
||||||
|
builder_.add_positionYPercent(positionYPercent);
|
||||||
|
builder_.add_positionXPercent(positionXPercent);
|
||||||
|
builder_.add_stretchVerticalEnabled(stretchVerticalEnabled);
|
||||||
|
builder_.add_stretchHorizontalEnabled(stretchHorizontalEnabled);
|
||||||
|
builder_.add_sizeYPercentEnable(sizeYPercentEnable);
|
||||||
|
builder_.add_sizeXPercentEnable(sizeXPercentEnable);
|
||||||
|
builder_.add_positionYPercentEnabled(positionYPercentEnabled);
|
||||||
|
builder_.add_positionXPercentEnabled(positionXPercentEnabled);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
struct SingleNodeOptions : private flatbuffers::Table {
|
struct SingleNodeOptions : private flatbuffers::Table {
|
||||||
const WidgetOptions *nodeOptions() const { return GetPointer<const WidgetOptions *>(4); }
|
const WidgetOptions *nodeOptions() const { return GetPointer<const WidgetOptions *>(4); }
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
@ -1557,12 +1675,16 @@ inline flatbuffers::Offset<ListViewOptions> CreateListViewOptions(flatbuffers::F
|
||||||
struct ProjectNodeOptions : private flatbuffers::Table {
|
struct ProjectNodeOptions : private flatbuffers::Table {
|
||||||
const WidgetOptions *nodeOptions() const { return GetPointer<const WidgetOptions *>(4); }
|
const WidgetOptions *nodeOptions() const { return GetPointer<const WidgetOptions *>(4); }
|
||||||
const flatbuffers::String *fileName() const { return GetPointer<const flatbuffers::String *>(6); }
|
const flatbuffers::String *fileName() const { return GetPointer<const flatbuffers::String *>(6); }
|
||||||
|
uint8_t isLoop() const { return GetField<uint8_t>(8, 1); }
|
||||||
|
uint8_t isAutoPlay() const { return GetField<uint8_t>(10, 1); }
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* nodeOptions */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* nodeOptions */) &&
|
||||||
verifier.VerifyTable(nodeOptions()) &&
|
verifier.VerifyTable(nodeOptions()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* fileName */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* fileName */) &&
|
||||||
verifier.Verify(fileName()) &&
|
verifier.Verify(fileName()) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 8 /* isLoop */) &&
|
||||||
|
VerifyField<uint8_t>(verifier, 10 /* isAutoPlay */) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1572,20 +1694,26 @@ struct ProjectNodeOptionsBuilder {
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_nodeOptions(flatbuffers::Offset<WidgetOptions> nodeOptions) { fbb_.AddOffset(4, nodeOptions); }
|
void add_nodeOptions(flatbuffers::Offset<WidgetOptions> nodeOptions) { fbb_.AddOffset(4, nodeOptions); }
|
||||||
void add_fileName(flatbuffers::Offset<flatbuffers::String> fileName) { fbb_.AddOffset(6, fileName); }
|
void add_fileName(flatbuffers::Offset<flatbuffers::String> fileName) { fbb_.AddOffset(6, fileName); }
|
||||||
|
void add_isLoop(uint8_t isLoop) { fbb_.AddElement<uint8_t>(8, isLoop, 1); }
|
||||||
|
void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement<uint8_t>(10, isAutoPlay, 1); }
|
||||||
ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
||||||
ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &);
|
ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &);
|
||||||
flatbuffers::Offset<ProjectNodeOptions> Finish() {
|
flatbuffers::Offset<ProjectNodeOptions> Finish() {
|
||||||
auto o = flatbuffers::Offset<ProjectNodeOptions>(fbb_.EndTable(start_, 2));
|
auto o = flatbuffers::Offset<ProjectNodeOptions>(fbb_.EndTable(start_, 4));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<ProjectNodeOptions> CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<ProjectNodeOptions> CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<WidgetOptions> nodeOptions = 0,
|
flatbuffers::Offset<WidgetOptions> nodeOptions = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> fileName = 0) {
|
flatbuffers::Offset<flatbuffers::String> fileName = 0,
|
||||||
|
uint8_t isLoop = 1,
|
||||||
|
uint8_t isAutoPlay = 1) {
|
||||||
ProjectNodeOptionsBuilder builder_(_fbb);
|
ProjectNodeOptionsBuilder builder_(_fbb);
|
||||||
builder_.add_fileName(fileName);
|
builder_.add_fileName(fileName);
|
||||||
builder_.add_nodeOptions(nodeOptions);
|
builder_.add_nodeOptions(nodeOptions);
|
||||||
|
builder_.add_isAutoPlay(isAutoPlay);
|
||||||
|
builder_.add_isLoop(isLoop);
|
||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,14 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str
|
||||||
while (element)
|
while (element)
|
||||||
{
|
{
|
||||||
// CCLOG("entity name = %s", element->Name());
|
// CCLOG("entity name = %s", element->Name());
|
||||||
|
if (strcmp("PropertyGroup", element->Name()) == 0)
|
||||||
|
{
|
||||||
|
const tinyxml2::XMLAttribute* attribute = element->FirstAttribute();
|
||||||
|
while (attribute && strcmp("Version", attribute->Name()) != 0)
|
||||||
|
attribute = attribute->Next();
|
||||||
|
if (attribute)
|
||||||
|
_csdVersion = attribute->Value();
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp("Content", element->Name()) == 0)
|
if (strcmp("Content", element->Name()) == 0)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +258,8 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str
|
||||||
_builder->CreateVector(_textures),
|
_builder->CreateVector(_textures),
|
||||||
_builder->CreateVector(_texturePngs),
|
_builder->CreateVector(_texturePngs),
|
||||||
nodeTree,
|
nodeTree,
|
||||||
aciton);
|
aciton,
|
||||||
|
_builder->CreateString(_csdVersion));
|
||||||
_builder->Finish(csparsebinary);
|
_builder->Finish(csparsebinary);
|
||||||
|
|
||||||
_textures.clear();
|
_textures.clear();
|
||||||
|
@ -988,6 +997,14 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato
|
||||||
while (element)
|
while (element)
|
||||||
{
|
{
|
||||||
// CCLOG("entity name = %s", element->Name());
|
// CCLOG("entity name = %s", element->Name());
|
||||||
|
if (strcmp("PropertyGroup", element->Name()) == 0)
|
||||||
|
{
|
||||||
|
const tinyxml2::XMLAttribute* attribute = element->FirstAttribute();
|
||||||
|
while (attribute && strcmp("Version", attribute->Name()) != 0)
|
||||||
|
attribute = attribute->Next();
|
||||||
|
if (attribute)
|
||||||
|
_csdVersion = attribute->Value();
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp("Content", element->Name()) == 0)
|
if (strcmp("Content", element->Name()) == 0)
|
||||||
{
|
{
|
||||||
|
@ -1049,7 +1066,8 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato
|
||||||
_builder->CreateVector(_textures),
|
_builder->CreateVector(_textures),
|
||||||
_builder->CreateVector(_texturePngs),
|
_builder->CreateVector(_texturePngs),
|
||||||
nodeTree,
|
nodeTree,
|
||||||
aciton);
|
aciton,
|
||||||
|
_builder->CreateString(_csdVersion));
|
||||||
_builder->Finish(csparsebinary);
|
_builder->Finish(csparsebinary);
|
||||||
|
|
||||||
_textures.clear();
|
_textures.clear();
|
||||||
|
|
|
@ -128,6 +128,7 @@ public:
|
||||||
std::string classType);
|
std::string classType);
|
||||||
flatbuffers::Offset<flatbuffers::ProjectNodeOptions> createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData);
|
flatbuffers::Offset<flatbuffers::ProjectNodeOptions> createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData);
|
||||||
/**/
|
/**/
|
||||||
|
std::string getCsdVersion() { return _csdVersion; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<flatbuffers::Offset<flatbuffers::String>> _textures;
|
std::vector<flatbuffers::Offset<flatbuffers::String>> _textures;
|
||||||
|
@ -137,7 +138,7 @@ public:
|
||||||
private:
|
private:
|
||||||
flatbuffers::FlatBufferBuilder* _builder;
|
flatbuffers::FlatBufferBuilder* _builder;
|
||||||
flatbuffers::Offset<flatbuffers::CSParseBinary>* _csparsebinary;
|
flatbuffers::Offset<flatbuffers::CSParseBinary>* _csparsebinary;
|
||||||
|
std::string _csdVersion;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -796,6 +796,11 @@ namespace cocostudio
|
||||||
Size scale9Size(options->scale9Size()->width(), options->scale9Size()->height());
|
Size scale9Size(options->scale9Size()->width(), options->scale9Size()->height());
|
||||||
button->setContentSize(scale9Size);
|
button->setContentSize(scale9Size);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height());
|
||||||
|
button->setContentSize(contentSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions)
|
Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions)
|
||||||
|
|
|
@ -375,7 +375,11 @@ namespace cocostudio
|
||||||
Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height());
|
Rect capInsets(f_capInset->x(), f_capInset->y(), f_capInset->width(), f_capInset->height());
|
||||||
imageView->setCapInsets(capInsets);
|
imageView->setCapInsets(capInsets);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Size contentSize(options->widgetOptions()->size()->width(), options->widgetOptions()->size()->height());
|
||||||
|
imageView->setContentSize(contentSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* ImageViewReader::createNodeWithFlatBuffers(const flatbuffers::Table *imageViewOptions)
|
Node* ImageViewReader::createNodeWithFlatBuffers(const flatbuffers::Table *imageViewOptions)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
#include "ui/UILayoutComponent.h"
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
using namespace flatbuffers;
|
using namespace flatbuffers;
|
||||||
|
@ -88,6 +88,23 @@ namespace cocostudio
|
||||||
std::string frameEvent = "";
|
std::string frameEvent = "";
|
||||||
std::string customProperty = "";
|
std::string customProperty = "";
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||||
while (attribute)
|
while (attribute)
|
||||||
|
@ -151,6 +168,54 @@ namespace cocostudio
|
||||||
{
|
{
|
||||||
frameEvent = value;
|
frameEvent = value;
|
||||||
}
|
}
|
||||||
|
else if (attriname == "PositionPrecentXEnabled")
|
||||||
|
{
|
||||||
|
positionXPercentEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PositionPrecentYEnabled")
|
||||||
|
{
|
||||||
|
positionYPercentEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PercentWidthEnable")
|
||||||
|
{
|
||||||
|
sizeXPercentEnable = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PercentHeightEnbale")
|
||||||
|
{
|
||||||
|
sizeYPercentEnable = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "StretchWidthEnable")
|
||||||
|
{
|
||||||
|
stretchHorizontalEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "StretchHeightEnable")
|
||||||
|
{
|
||||||
|
stretchVerticalEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "HorizontalEage")
|
||||||
|
{
|
||||||
|
horizontalEdge = value;
|
||||||
|
}
|
||||||
|
else if (attriname == "VerticalEage")
|
||||||
|
{
|
||||||
|
verticalEdge = value;
|
||||||
|
}
|
||||||
|
else if (attriname == "LeftMargin")
|
||||||
|
{
|
||||||
|
leftMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "RightMargin")
|
||||||
|
{
|
||||||
|
rightMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "TopMargin")
|
||||||
|
{
|
||||||
|
topMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "ButtomMargin")
|
||||||
|
{
|
||||||
|
bottomMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
}
|
}
|
||||||
|
@ -276,7 +341,48 @@ namespace cocostudio
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
child = child->NextSiblingElement();
|
child = child->NextSiblingElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +392,23 @@ namespace cocostudio
|
||||||
AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y);
|
AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y);
|
||||||
Color f_color(color.a, color.r, color.g, color.b);
|
Color f_color(color.a, color.r, color.g, color.b);
|
||||||
FlatSize f_size(size.x, size.y);
|
FlatSize f_size(size.x, size.y);
|
||||||
|
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);
|
||||||
|
|
||||||
auto options = CreateWidgetOptions(*builder,
|
auto options = CreateWidgetOptions(*builder,
|
||||||
builder->CreateString(name),
|
builder->CreateString(name),
|
||||||
|
@ -306,8 +428,10 @@ namespace cocostudio
|
||||||
ignoreSize,
|
ignoreSize,
|
||||||
touchEnabled,
|
touchEnabled,
|
||||||
builder->CreateString(frameEvent),
|
builder->CreateString(frameEvent),
|
||||||
builder->CreateString(customProperty)
|
builder->CreateString(customProperty),
|
||||||
);
|
0,
|
||||||
|
0,
|
||||||
|
f_layoutComponent);
|
||||||
|
|
||||||
return *(Offset<Table>*)(&options);
|
return *(Offset<Table>*)(&options);
|
||||||
}
|
}
|
||||||
|
@ -368,6 +492,78 @@ namespace cocostudio
|
||||||
|
|
||||||
node->setCascadeColorEnabled(true);
|
node->setCascadeColorEnabled(true);
|
||||||
node->setCascadeOpacityEnabled(true);
|
node->setCascadeOpacityEnabled(true);
|
||||||
|
|
||||||
|
setLayoutComponentPropsWithFlatBuffers(node, nodeOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions)
|
||||||
|
{
|
||||||
|
auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent();
|
||||||
|
if (!layoutComponentTable) return;
|
||||||
|
|
||||||
|
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled();
|
||||||
|
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled();
|
||||||
|
float positionXPercent = layoutComponentTable->positionXPercent();
|
||||||
|
float positionYPercent = layoutComponentTable->positionYPercent();
|
||||||
|
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable();
|
||||||
|
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable();
|
||||||
|
float sizeXPercent = layoutComponentTable->sizeXPercent();
|
||||||
|
float sizeYPercent = layoutComponentTable->sizeYPercent();
|
||||||
|
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled();
|
||||||
|
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled();
|
||||||
|
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();
|
||||||
|
|
||||||
|
auto layoutComponent = ui::LayoutComponent::create();
|
||||||
|
node->addComponent(layoutComponent);
|
||||||
|
|
||||||
|
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);
|
||||||
|
ui::LayoutComponent::HorizontalEage horizontalEdgeType = ui::LayoutComponent::HorizontalEage::None;
|
||||||
|
if (horizontalEdge == "LeftEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Left;
|
||||||
|
}
|
||||||
|
else if (horizontalEdge == "RightEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Right;
|
||||||
|
}
|
||||||
|
else if (horizontalEdge == "BothEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Center;
|
||||||
|
}
|
||||||
|
layoutComponent->setHorizontalEage(horizontalEdgeType);
|
||||||
|
ui::LayoutComponent::VerticalEage verticalEdgeType = ui::LayoutComponent::VerticalEage::None;
|
||||||
|
if (verticalEdge == "TopEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Top;
|
||||||
|
}
|
||||||
|
else if (verticalEdge == "ButtomEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Bottom;
|
||||||
|
}
|
||||||
|
else if (verticalEdge == "BothEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Center;
|
||||||
|
}
|
||||||
|
layoutComponent->setVerticalEage(verticalEdgeType);
|
||||||
|
|
||||||
|
layoutComponent->setTopMargin(topMargin);
|
||||||
|
layoutComponent->setButtomMargin(bottomMargin);
|
||||||
|
layoutComponent->setLeftMargin(leftMargin);
|
||||||
|
layoutComponent->setRightMargin(rightMargin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* NodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions)
|
Node* NodeReader::createNodeWithFlatBuffers(const flatbuffers::Table *nodeOptions)
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace cocostudio
|
||||||
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
||||||
flatbuffers::FlatBufferBuilder* builder);
|
flatbuffers::FlatBufferBuilder* builder);
|
||||||
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions);
|
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions);
|
||||||
|
void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions);
|
||||||
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions);
|
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* nodeOptions);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
#include "ui/UILayoutComponent.h"
|
||||||
|
#include "../ActionTimeline/CSLoader.h"
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
@ -385,6 +387,23 @@ namespace cocostudio
|
||||||
std::string callbackType = "";
|
std::string callbackType = "";
|
||||||
std::string callbackName = "";
|
std::string callbackName = "";
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
|
||||||
while (attribute)
|
while (attribute)
|
||||||
|
@ -456,6 +475,54 @@ namespace cocostudio
|
||||||
{
|
{
|
||||||
callbackName = value;
|
callbackName = value;
|
||||||
}
|
}
|
||||||
|
else if (attriname == "PositionPrecentXEnabled")
|
||||||
|
{
|
||||||
|
positionXPercentEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PositionPrecentYEnabled")
|
||||||
|
{
|
||||||
|
positionYPercentEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PercentWidthEnable")
|
||||||
|
{
|
||||||
|
sizeXPercentEnable = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "PercentHeightEnbale")
|
||||||
|
{
|
||||||
|
sizeYPercentEnable = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "StretchWidthEnable")
|
||||||
|
{
|
||||||
|
stretchHorizontalEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "StretchHeightEnable")
|
||||||
|
{
|
||||||
|
stretchVerticalEnabled = value == "True";
|
||||||
|
}
|
||||||
|
else if (attriname == "HorizontalEage")
|
||||||
|
{
|
||||||
|
horizontalEdge = value;
|
||||||
|
}
|
||||||
|
else if (attriname == "VerticalEage")
|
||||||
|
{
|
||||||
|
verticalEdge = value;
|
||||||
|
}
|
||||||
|
else if (attriname == "LeftMargin")
|
||||||
|
{
|
||||||
|
leftMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "RightMargin")
|
||||||
|
{
|
||||||
|
rightMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "TopMargin")
|
||||||
|
{
|
||||||
|
topMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
else if (attriname == "ButtomMargin")
|
||||||
|
{
|
||||||
|
bottomMargin = atof(value.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
}
|
}
|
||||||
|
@ -581,6 +648,48 @@ namespace cocostudio
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
child = child->NextSiblingElement();
|
child = child->NextSiblingElement();
|
||||||
}
|
}
|
||||||
|
@ -591,6 +700,23 @@ namespace cocostudio
|
||||||
AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y);
|
AnchorPoint f_anchortpoint(anchorPoint.x, anchorPoint.y);
|
||||||
Color f_color(color.a, color.r, color.g, color.b);
|
Color f_color(color.a, color.r, color.g, color.b);
|
||||||
FlatSize f_size(size.x, size.y);
|
FlatSize f_size(size.x, size.y);
|
||||||
|
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);
|
||||||
|
|
||||||
auto options = CreateWidgetOptions(*builder,
|
auto options = CreateWidgetOptions(*builder,
|
||||||
builder->CreateString(name),
|
builder->CreateString(name),
|
||||||
|
@ -612,8 +738,8 @@ namespace cocostudio
|
||||||
builder->CreateString(frameEvent),
|
builder->CreateString(frameEvent),
|
||||||
builder->CreateString(customProperty),
|
builder->CreateString(customProperty),
|
||||||
builder->CreateString(callbackType),
|
builder->CreateString(callbackType),
|
||||||
builder->CreateString(callbackName)
|
builder->CreateString(callbackName),
|
||||||
);
|
f_layoutComponent);
|
||||||
|
|
||||||
return *(Offset<Table>*)(&options);
|
return *(Offset<Table>*)(&options);
|
||||||
}
|
}
|
||||||
|
@ -629,6 +755,32 @@ namespace cocostudio
|
||||||
widget->setAnchorPoint(Vec2::ZERO);
|
widget->setAnchorPoint(Vec2::ZERO);
|
||||||
|
|
||||||
widget->setUnifySizeEnabled(true);
|
widget->setUnifySizeEnabled(true);
|
||||||
|
std::string versionString = CSLoader::getInstance()->getCsdVersion();
|
||||||
|
|
||||||
|
//assume versionString is like "2.0.6.0"
|
||||||
|
if (versionString.length() > 0)
|
||||||
|
{
|
||||||
|
int p1, p2, p3, v1, v2, v3;
|
||||||
|
p1 = p2 = p3 = v1 = v2 = v3 = 0;
|
||||||
|
p1 = versionString.find('.');
|
||||||
|
if (p1 > 0)
|
||||||
|
{
|
||||||
|
p2 = versionString.find('.', p1 + 1);
|
||||||
|
v1 = atoi(versionString.substr(0, p1).c_str());
|
||||||
|
}
|
||||||
|
if (p2 > p1)
|
||||||
|
{
|
||||||
|
p3 = versionString.find('.', p2 + 1);
|
||||||
|
v2 = atoi(versionString.substr(p1 + 1, p2 - p1 - 1).c_str());
|
||||||
|
}
|
||||||
|
if (p3 > p2)
|
||||||
|
{
|
||||||
|
v3 = atoi(versionString.substr(p2 + 1, p3 - p2 - 1).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(v1 <= 2 && v2 == 0 && v3 <= 6))
|
||||||
|
widget->setUnifySizeEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
bool ignoreSize = options->ignoreSize();
|
bool ignoreSize = options->ignoreSize();
|
||||||
widget->ignoreContentAdaptWithSize(ignoreSize);
|
widget->ignoreContentAdaptWithSize(ignoreSize);
|
||||||
|
@ -691,6 +843,77 @@ namespace cocostudio
|
||||||
std::string callbackName = options->callBackName()->c_str();
|
std::string callbackName = options->callBackName()->c_str();
|
||||||
widget->setCallbackName(callbackName);
|
widget->setCallbackName(callbackName);
|
||||||
|
|
||||||
|
setLayoutComponentPropsWithFlatBuffers(widget, widgetOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetReader::setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* nodeOptions)
|
||||||
|
{
|
||||||
|
auto layoutComponentTable = ((WidgetOptions*)nodeOptions)->layoutComponent();
|
||||||
|
if (!layoutComponentTable) return;
|
||||||
|
|
||||||
|
bool positionXPercentEnabled = layoutComponentTable->positionXPercentEnabled();
|
||||||
|
bool positionYPercentEnabled = layoutComponentTable->positionYPercentEnabled();
|
||||||
|
float positionXPercent = layoutComponentTable->positionXPercent();
|
||||||
|
float positionYPercent = layoutComponentTable->positionYPercent();
|
||||||
|
bool sizeXPercentEnable = layoutComponentTable->sizeXPercentEnable();
|
||||||
|
bool sizeYPercentEnable = layoutComponentTable->sizeYPercentEnable();
|
||||||
|
float sizeXPercent = layoutComponentTable->sizeXPercent();
|
||||||
|
float sizeYPercent = layoutComponentTable->sizeYPercent();
|
||||||
|
bool stretchHorizontalEnabled = layoutComponentTable->stretchHorizontalEnabled();
|
||||||
|
bool stretchVerticalEnabled = layoutComponentTable->stretchVerticalEnabled();
|
||||||
|
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();
|
||||||
|
|
||||||
|
auto layoutComponent = ui::LayoutComponent::create();
|
||||||
|
node->addComponent(layoutComponent);
|
||||||
|
|
||||||
|
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);
|
||||||
|
ui::LayoutComponent::HorizontalEage horizontalEdgeType = ui::LayoutComponent::HorizontalEage::None;
|
||||||
|
if (horizontalEdge == "LeftEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Left;
|
||||||
|
}
|
||||||
|
else if (horizontalEdge == "RightEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Right;
|
||||||
|
}
|
||||||
|
else if (horizontalEdge == "BothEage")
|
||||||
|
{
|
||||||
|
horizontalEdgeType = ui::LayoutComponent::HorizontalEage::Center;
|
||||||
|
}
|
||||||
|
layoutComponent->setHorizontalEage(horizontalEdgeType);
|
||||||
|
ui::LayoutComponent::VerticalEage verticalEdgeType = ui::LayoutComponent::VerticalEage::None;
|
||||||
|
if (verticalEdge == "TopEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Top;
|
||||||
|
}
|
||||||
|
else if (verticalEdge == "ButtomEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Bottom;
|
||||||
|
}
|
||||||
|
else if (verticalEdge == "BothEage")
|
||||||
|
{
|
||||||
|
verticalEdgeType = ui::LayoutComponent::VerticalEage::Center;
|
||||||
|
}
|
||||||
|
layoutComponent->setVerticalEage(verticalEdgeType);
|
||||||
|
|
||||||
|
layoutComponent->setTopMargin(topMargin);
|
||||||
|
layoutComponent->setButtomMargin(bottomMargin);
|
||||||
|
layoutComponent->setLeftMargin(leftMargin);
|
||||||
|
layoutComponent->setRightMargin(rightMargin);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* WidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table *widgetOptions)
|
Node* WidgetReader::createNodeWithFlatBuffers(const flatbuffers::Table *widgetOptions)
|
||||||
|
|
|
@ -60,6 +60,7 @@ namespace cocostudio
|
||||||
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
flatbuffers::Offset<flatbuffers::Table> createOptionsWithFlatBuffers(const tinyxml2::XMLElement* objectData,
|
||||||
flatbuffers::FlatBufferBuilder* builder);
|
flatbuffers::FlatBufferBuilder* builder);
|
||||||
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions);
|
void setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions);
|
||||||
|
void setLayoutComponentPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* widgetOptions);
|
||||||
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* widgetOptions);
|
cocos2d::Node* createNodeWithFlatBuffers(const flatbuffers::Table* widgetOptions);
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue