From ca74486f60f42c1865a9210a24323fd1510059fe Mon Sep 17 00:00:00 2001 From: pipu Date: Wed, 8 Apr 2015 16:54:58 +0800 Subject: [PATCH] Update CSParseBinary_generated --- .../cocostudio/CSParseBinary_generated.h | 83 ++++++++++-- .../ParticleReader/ParticleReader.cpp | 39 +++++- .../SpriteReader/SpriteReader.cpp | 38 +++++- .../WidgetReader/TextReader/TextReader.cpp | 125 +++++++++++++++++- 4 files changed, 272 insertions(+), 13 deletions(-) diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index b2485fbbef..165c865f67 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -53,6 +53,7 @@ struct Color; struct ColorVector; struct FlatSize; struct CapInsets; +struct BlendFunc; struct ResourceData; MANUALLY_ALIGNED_STRUCT(4) RotationSkew { @@ -175,6 +176,20 @@ MANUALLY_ALIGNED_STRUCT(4) CapInsets { }; STRUCT_END(CapInsets, 16); +MANUALLY_ALIGNED_STRUCT(4) BlendFunc { + private: + int32_t src_; + int32_t dst_; + + public: + BlendFunc(int32_t src, int32_t dst) + : src_(flatbuffers::EndianScalar(src)), dst_(flatbuffers::EndianScalar(dst)) { } + + int32_t src() const { return flatbuffers::EndianScalar(src_); } + int32_t dst() const { return flatbuffers::EndianScalar(dst_); } +}; +STRUCT_END(BlendFunc, 8); + struct CSParseBinary : private flatbuffers::Table { const flatbuffers::String *version() const { return GetPointer(4); } const flatbuffers::Vector> *textures() const { return GetPointer> *>(6); } @@ -585,12 +600,14 @@ inline flatbuffers::Offset CreateSingleNodeOptions(flatbuffer struct SpriteOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } const ResourceData *fileNameData() const { return GetPointer(6); } + const BlendFunc *blendFunc() const { return GetStruct(8); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* nodeOptions */) && verifier.VerifyTable(nodeOptions()) && VerifyField(verifier, 6 /* fileNameData */) && verifier.VerifyTable(fileNameData()) && + VerifyField(verifier, 8 /* blendFunc */) && verifier.EndTable(); } }; @@ -600,18 +617,21 @@ struct SpriteOptionsBuilder { flatbuffers::uoffset_t start_; void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } void add_fileNameData(flatbuffers::Offset fileNameData) { fbb_.AddOffset(6, fileNameData); } + void add_blendFunc(const BlendFunc *blendFunc) { fbb_.AddStruct(8, blendFunc); } SpriteOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } SpriteOptionsBuilder &operator=(const SpriteOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); return o; } }; inline flatbuffers::Offset CreateSpriteOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset nodeOptions = 0, - flatbuffers::Offset fileNameData = 0) { + flatbuffers::Offset fileNameData = 0, + const BlendFunc *blendFunc = 0) { SpriteOptionsBuilder builder_(_fbb); + builder_.add_blendFunc(blendFunc); builder_.add_fileNameData(fileNameData); builder_.add_nodeOptions(nodeOptions); return builder_.Finish(); @@ -620,12 +640,14 @@ inline flatbuffers::Offset CreateSpriteOptions(flatbuffers::FlatB struct ParticleSystemOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } const ResourceData *fileNameData() const { return GetPointer(6); } + const BlendFunc *blendFunc() const { return GetStruct(8); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* nodeOptions */) && verifier.VerifyTable(nodeOptions()) && VerifyField(verifier, 6 /* fileNameData */) && verifier.VerifyTable(fileNameData()) && + VerifyField(verifier, 8 /* blendFunc */) && verifier.EndTable(); } }; @@ -635,18 +657,21 @@ struct ParticleSystemOptionsBuilder { flatbuffers::uoffset_t start_; void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } void add_fileNameData(flatbuffers::Offset fileNameData) { fbb_.AddOffset(6, fileNameData); } + void add_blendFunc(const BlendFunc *blendFunc) { fbb_.AddStruct(8, blendFunc); } ParticleSystemOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ParticleSystemOptionsBuilder &operator=(const ParticleSystemOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); return o; } }; inline flatbuffers::Offset CreateParticleSystemOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset nodeOptions = 0, - flatbuffers::Offset fileNameData = 0) { + flatbuffers::Offset fileNameData = 0, + const BlendFunc *blendFunc = 0) { ParticleSystemOptionsBuilder builder_(_fbb); + builder_.add_blendFunc(blendFunc); builder_.add_fileNameData(fileNameData); builder_.add_nodeOptions(nodeOptions); return builder_.Finish(); @@ -1011,6 +1036,14 @@ struct TextOptions : private flatbuffers::Table { int32_t vAlignment() const { return GetField(20, 0); } uint8_t touchScaleEnable() const { return GetField(22, 0); } uint8_t isCustomSize() const { return GetField(24, 0); } + uint8_t outlineEnabled() const { return GetField(26, 0); } + const Color *outlineColor() const { return GetStruct(28); } + int32_t outlineSize() const { return GetField(30, 1); } + uint8_t shadowEnabled() const { return GetField(32, 0); } + const Color *shadowColor() const { return GetStruct(34); } + float shadowOffsetX() const { return GetField(36, 2); } + float shadowOffsetY() const { return GetField(38, -2); } + int32_t shadowBlurRadius() const { return GetField(40, 0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* widgetOptions */) && @@ -1028,6 +1061,14 @@ struct TextOptions : private flatbuffers::Table { VerifyField(verifier, 20 /* vAlignment */) && VerifyField(verifier, 22 /* touchScaleEnable */) && VerifyField(verifier, 24 /* isCustomSize */) && + VerifyField(verifier, 26 /* outlineEnabled */) && + VerifyField(verifier, 28 /* outlineColor */) && + VerifyField(verifier, 30 /* outlineSize */) && + VerifyField(verifier, 32 /* shadowEnabled */) && + VerifyField(verifier, 34 /* shadowColor */) && + VerifyField(verifier, 36 /* shadowOffsetX */) && + VerifyField(verifier, 38 /* shadowOffsetY */) && + VerifyField(verifier, 40 /* shadowBlurRadius */) && verifier.EndTable(); } }; @@ -1046,10 +1087,18 @@ struct TextOptionsBuilder { void add_vAlignment(int32_t vAlignment) { fbb_.AddElement(20, vAlignment, 0); } void add_touchScaleEnable(uint8_t touchScaleEnable) { fbb_.AddElement(22, touchScaleEnable, 0); } void add_isCustomSize(uint8_t isCustomSize) { fbb_.AddElement(24, isCustomSize, 0); } + void add_outlineEnabled(uint8_t outlineEnabled) { fbb_.AddElement(26, outlineEnabled, 0); } + void add_outlineColor(const Color *outlineColor) { fbb_.AddStruct(28, outlineColor); } + void add_outlineSize(int32_t outlineSize) { fbb_.AddElement(30, outlineSize, 1); } + void add_shadowEnabled(uint8_t shadowEnabled) { fbb_.AddElement(32, shadowEnabled, 0); } + void add_shadowColor(const Color *shadowColor) { fbb_.AddStruct(34, shadowColor); } + void add_shadowOffsetX(float shadowOffsetX) { fbb_.AddElement(36, shadowOffsetX, 2); } + void add_shadowOffsetY(float shadowOffsetY) { fbb_.AddElement(38, shadowOffsetY, -2); } + void add_shadowBlurRadius(int32_t shadowBlurRadius) { fbb_.AddElement(40, shadowBlurRadius, 0); } TextOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } TextOptionsBuilder &operator=(const TextOptionsBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 11)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 19)); return o; } }; @@ -1065,8 +1114,22 @@ inline flatbuffers::Offset CreateTextOptions(flatbuffers::FlatBuffe int32_t hAlignment = 0, int32_t vAlignment = 0, uint8_t touchScaleEnable = 0, - uint8_t isCustomSize = 0) { + uint8_t isCustomSize = 0, + uint8_t outlineEnabled = 0, + const Color *outlineColor = 0, + int32_t outlineSize = 1, + uint8_t shadowEnabled = 0, + const Color *shadowColor = 0, + float shadowOffsetX = 2, + float shadowOffsetY = -2, + int32_t shadowBlurRadius = 0) { TextOptionsBuilder builder_(_fbb); + builder_.add_shadowBlurRadius(shadowBlurRadius); + builder_.add_shadowOffsetY(shadowOffsetY); + builder_.add_shadowOffsetX(shadowOffsetX); + builder_.add_shadowColor(shadowColor); + builder_.add_outlineSize(outlineSize); + builder_.add_outlineColor(outlineColor); builder_.add_vAlignment(vAlignment); builder_.add_hAlignment(hAlignment); builder_.add_areaHeight(areaHeight); @@ -1076,6 +1139,8 @@ inline flatbuffers::Offset CreateTextOptions(flatbuffers::FlatBuffe builder_.add_fontName(fontName); builder_.add_fontResource(fontResource); builder_.add_widgetOptions(widgetOptions); + builder_.add_shadowEnabled(shadowEnabled); + builder_.add_outlineEnabled(outlineEnabled); builder_.add_isCustomSize(isCustomSize); builder_.add_touchScaleEnable(touchScaleEnable); return builder_.Finish(); @@ -1685,7 +1750,7 @@ inline flatbuffers::Offset CreateListViewOptions(flatbuffers::F struct ProjectNodeOptions : private flatbuffers::Table { const WidgetOptions *nodeOptions() const { return GetPointer(4); } const flatbuffers::String *fileName() const { return GetPointer(6); } - float innerActionSpeed() const { return GetField(8, 0); } + float innerActionSpeed() const { return GetField(8, 1.0); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* nodeOptions */) && @@ -1702,7 +1767,7 @@ struct ProjectNodeOptionsBuilder { flatbuffers::uoffset_t start_; void add_nodeOptions(flatbuffers::Offset nodeOptions) { fbb_.AddOffset(4, nodeOptions); } void add_fileName(flatbuffers::Offset fileName) { fbb_.AddOffset(6, fileName); } - void add_innerActionSpeed(float innerActionSpeed) { fbb_.AddElement(8, innerActionSpeed, 0); } + void add_innerActionSpeed(float innerActionSpeed) { fbb_.AddElement(8, innerActionSpeed, 1.0); } ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &); flatbuffers::Offset Finish() { @@ -1714,7 +1779,7 @@ struct ProjectNodeOptionsBuilder { inline flatbuffers::Offset CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb, flatbuffers::Offset nodeOptions = 0, flatbuffers::Offset fileName = 0, - float innerActionSpeed = 0) { + float innerActionSpeed = 1.0) { ProjectNodeOptionsBuilder builder_(_fbb); builder_.add_innerActionSpeed(innerActionSpeed); builder_.add_fileName(fileName); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp index 63d3e9ec51..beae5bc194 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp @@ -79,6 +79,8 @@ namespace cocostudio std::string plistFile = ""; int resourceType = 0; + cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED; + // child elements const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -110,16 +112,40 @@ namespace cocostudio attribute = attribute->Next(); } } + else if (name == "BlendFunc") + { + const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); + + while (attribute) + { + name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "Src") + { + blendFunc.src = atoi(value.c_str()); + } + else if (name == "Dst") + { + blendFunc.dst = atoi(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } + flatbuffers::BlendFunc f_blendFunc(blendFunc.src, blendFunc.dst); + auto options = CreateParticleSystemOptions(*builder, nodeOptions, CreateResourceData(*builder, builder->CreateString(path), builder->CreateString(plistFile), - resourceType)); + resourceType), + &f_blendFunc); return *(Offset*)(&options); } @@ -127,7 +153,18 @@ namespace cocostudio void ParticleReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *particleOptions) { + auto particle = static_cast(node); auto options = (ParticleSystemOptions*)particleOptions; + + auto f_blendFunc = options->blendFunc(); + if (f_blendFunc) + { + cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED; + blendFunc.src = f_blendFunc->src(); + blendFunc.dst = f_blendFunc->dst(); + particle->setBlendFunc(blendFunc); + } + auto nodeReader = NodeReader::getInstance(); nodeReader->setPropsWithFlatBuffers(node, (Table*)options->nodeOptions()); } diff --git a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp index 56eb65df47..de217b8bb3 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp @@ -80,6 +80,8 @@ namespace cocostudio std::string plistFile = ""; int resourceType = 0; + cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED; + // FileData const tinyxml2::XMLElement* child = objectData->FirstChildElement(); while (child) @@ -121,17 +123,40 @@ namespace cocostudio fbs->_textures.push_back(builder->CreateString(texture)); } } + else if (name == "BlendFunc") + { + const tinyxml2::XMLAttribute* attribute = child->FirstAttribute(); + + while (attribute) + { + name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "Src") + { + blendFunc.src = atoi(value.c_str()); + } + else if (name == "Dst") + { + blendFunc.dst = atoi(value.c_str()); + } + + attribute = attribute->Next(); + } + } child = child->NextSiblingElement(); } + + flatbuffers::BlendFunc f_blendFunc(blendFunc.src, blendFunc.dst); auto options = CreateSpriteOptions(*builder, nodeOptions, CreateResourceData(*builder, builder->CreateString(path), builder->CreateString(plistFile), - resourceType) - ); + resourceType), + &f_blendFunc); return *(Offset
*)(&options); } @@ -208,6 +233,15 @@ namespace cocostudio sprite->addChild(label); } + auto f_blendFunc = options->blendFunc(); + if (f_blendFunc) + { + cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED; + blendFunc.src = f_blendFunc->src(); + blendFunc.dst = f_blendFunc->dst(); + sprite->setBlendFunc(blendFunc); + } + auto nodeReader = NodeReader::getInstance(); nodeReader->setPropsWithFlatBuffers(node, (Table*)(options->nodeOptions())); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index a49119f261..88055deca7 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -164,6 +164,13 @@ namespace cocostudio int areaHeight = 0; int h_alignment = 0; int v_alignment = 0; + 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; std::string path = ""; std::string plistFile = ""; @@ -234,6 +241,30 @@ namespace cocostudio { isCustomSize = (value == "True") ? true : false; } + 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()); + } attribute = attribute->Next(); } @@ -269,10 +300,71 @@ namespace cocostudio attribute = attribute->Next(); } } + 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(); + } + } child = child->NextSiblingElement(); } + flatbuffers::Color f_outlineColor(outlineColor.a, outlineColor.r, outlineColor.g, outlineColor.b); + flatbuffers::Color f_shadowColor(shadowColor.a, shadowColor.r, shadowColor.g, shadowColor.b); + auto options = CreateTextOptions(*builder, widgetOptions, CreateResourceData(*builder, @@ -287,7 +379,15 @@ namespace cocostudio h_alignment, v_alignment, touchScaleEnabled, - isCustomSize); + isCustomSize, + outlineEnabled, + &f_outlineColor, + outlineSize, + shadowEnabled, + &f_shadowColor, + shadowOffset.width, + shadowOffset.height, + shadowBlurRadius); return *(Offset
*)(&options); } @@ -348,6 +448,29 @@ namespace cocostudio } } + bool outlineEnabled = options->outlineEnabled(); + if (outlineEnabled) + { + auto f_outlineColor = options->outlineColor(); + if (f_outlineColor) + { + Color4B outlineColor(f_outlineColor->a(), f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b()); + label->enableOutline(outlineColor, options->outlineSize()); + } + } + + bool shadowEnabled = options->shadowEnabled(); + if (shadowEnabled) + { + auto f_shadowColor = options->shadowColor(); + if (f_shadowColor) + { + Color4B shadowColor(f_shadowColor->a(), f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b()); + label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius()); + } + } + + auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());