diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index d6b9ed2d73..16e839a296 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -574,6 +574,12 @@ Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::B bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -591,6 +597,12 @@ Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers:: bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -609,6 +621,12 @@ Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::Sca bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -627,6 +645,12 @@ Frame* ActionTimelineCache::loadRotationSkewFrameWithFlatBuffers(const flatbuffe bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -644,6 +668,12 @@ Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::Col bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -701,6 +731,12 @@ Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::T bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -711,9 +747,7 @@ Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::Eve std::string event = flatbuffers->value()->c_str(); if (event != "") - frame->setEvent(event); - - CCLOG("event = %s", event.c_str()); + frame->setEvent(event); int frameIndex = flatbuffers->frameIndex(); frame->setFrameIndex(frameIndex); @@ -721,6 +755,12 @@ Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::Eve bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -741,23 +781,29 @@ Frame* ActionTimelineCache::loadAlphaFrameWithFlatBuffers(const flatbuffers::Int return frame; } - Frame* ActionTimelineCache::loadAnchorPointFrameWithFlatBuffers(const flatbuffers::ScaleFrame *flatbuffers) +Frame* ActionTimelineCache::loadAnchorPointFrameWithFlatBuffers(const flatbuffers::ScaleFrame *flatbuffers) +{ + AnchorPointFrame* frame = AnchorPointFrame::create(); + + auto f_scale = flatbuffers->scale(); + Vec2 scale(f_scale->scaleX(), f_scale->scaleY()); + frame->setAnchorPoint(scale); + + int frameIndex = flatbuffers->frameIndex(); + frame->setFrameIndex(frameIndex); + + bool tween = flatbuffers->tween() != 0; + frame->setTween(tween); + + auto easingData = flatbuffers->easingData(); + if (easingData) { - AnchorPointFrame* frame = AnchorPointFrame::create(); - - auto f_scale = flatbuffers->scale(); - Vec2 scale(f_scale->scaleX(), f_scale->scaleY()); - frame->setAnchorPoint(scale); - - int frameIndex = flatbuffers->frameIndex(); - frame->setFrameIndex(frameIndex); - - bool tween = flatbuffers->tween() != 0; - frame->setTween(tween); - - return frame; + loadEasingDataWithFlatBuffers(frame, easingData); } + return frame; +} + Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::IntFrame *flatbuffers) { ZOrderFrame* frame = ZOrderFrame::create(); @@ -772,6 +818,12 @@ Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::In bool tween = flatbuffers->tween() != 0; frame->setTween(tween); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } @@ -797,9 +849,33 @@ Frame* ActionTimelineCache::loadInnerActionFrameWithFlatBuffers(const flatbuffer frame->setEnterWithName(true); frame->setAnimationName(currentAnimationFrame); + auto easingData = flatbuffers->easingData(); + if (easingData) + { + loadEasingDataWithFlatBuffers(frame, easingData); + } + return frame; } +void ActionTimelineCache::loadEasingDataWithFlatBuffers(cocostudio::timeline::Frame *frame, + const flatbuffers::EasingData *flatbuffers) +{ + int type = flatbuffers->type(); + frame->setTweenType((cocos2d::tweenfunc::TweenType)type); + auto points = flatbuffers->points(); + if (points) + { + for (auto it = points->begin(); it != points->end(); ++it) + { + std::vector easings; + easings.push_back(it->x()); + easings.push_back(it->y()); + frame->setEasingParams(easings); + } + } +} + ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(const std::string& fileName) { FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance(); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h index 62cf4fba9c..012ee837a6 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.h @@ -46,6 +46,7 @@ namespace flatbuffers struct IntFrame; struct BoolFrame; struct InnerActionFrame; + struct EasingData; } NS_TIMELINE_BEGIN @@ -115,6 +116,8 @@ protected: Frame* loadAnchorPointFrameWithFlatBuffers (const flatbuffers::ScaleFrame* flatbuffers); Frame* loadZOrderFrameWithFlatBuffers (const flatbuffers::IntFrame* flatbuffers); Frame* loadInnerActionFrameWithFlatBuffers (const flatbuffers::InnerActionFrame* flatbuffers); + + void loadEasingDataWithFlatBuffers(Frame* frame, const flatbuffers::EasingData* flatbuffers); protected: diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp index 654fa1dfc4..a25a95676f 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.cpp @@ -38,14 +38,17 @@ NS_TIMELINE_BEGIN Frame::Frame() : _frameIndex(0) , _tween(true) + , _tweenType(TweenType::Linear) , _enterWhenPassed(false) , _timeline(nullptr) , _node(nullptr) { + _easingParam.clear(); } Frame::~Frame() { + _easingParam.clear(); } void Frame::emitEvent() @@ -60,6 +63,37 @@ void Frame::cloneProperty(Frame* frame) { _frameIndex = frame->getFrameIndex(); _tween = frame->isTween(); + + _tweenType = frame->getTweenType(); + setEasingParams(frame->getEasingParams()); +} + +void Frame::apply(float percent) +{ + if (!_tween) + return; + + float tweenpercent = percent; + if ( _tweenType != tweenfunc::TWEEN_EASING_MAX && _tweenType != tweenfunc::Linear) + { + tweenpercent = tweenPercent(tweenpercent); + } + onApply(tweenpercent); +} + +float Frame::tweenPercent(float percent) +{ + return tweenfunc::tweenTo(percent, _tweenType, _easingParam.data()); +} + +void Frame::setEasingParams(const std::vector& easingParams) +{ + _easingParam.assign(easingParams.begin(), easingParams.end()); +} + +const std::vector& Frame::getEasingParams() const +{ + return _easingParam; } @@ -83,10 +117,7 @@ VisibleFrame::VisibleFrame() void VisibleFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node) - { - _node->setVisible(_visible); - } + _node->setVisible(_visible); } @@ -173,11 +204,6 @@ RotationFrame::RotationFrame() void RotationFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setRotation(_rotation); if(_tween) @@ -186,9 +212,9 @@ void RotationFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void RotationFrame::apply(float percent) +void RotationFrame::onApply(float percent) { - if (_node && _tween && _betwennRotation != 0) + if (_betwennRotation != 0) { float rotation = _rotation + percent * _betwennRotation; _node->setRotation(rotation); @@ -228,11 +254,6 @@ SkewFrame::SkewFrame() void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setSkewX(_skewX); _node->setSkewY(_skewY); @@ -243,9 +264,9 @@ void SkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void SkewFrame::apply(float percent) +void SkewFrame::onApply(float percent) { - if (_node && _tween && (_betweenSkewX != 0 || _betweenSkewY != 0)) + if (_betweenSkewX != 0 || _betweenSkewY != 0) { float skewx = _skewX + percent * _betweenSkewX; float skewy = _skewY + percent * _betweenSkewY; @@ -288,11 +309,6 @@ RotationSkewFrame::RotationSkewFrame() void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setRotationSkewX(_skewX); _node->setRotationSkewY(_skewY); @@ -303,9 +319,9 @@ void RotationSkewFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void RotationSkewFrame::apply(float percent) +void RotationSkewFrame::onApply(float percent) { - if (_node && _tween && (_betweenSkewX != 0 || _betweenSkewY != 0)) + if (_betweenSkewX != 0 || _betweenSkewY != 0) { float skewx = _skewX + percent * _betweenSkewX; float skewy = _skewY + percent * _betweenSkewY; @@ -347,11 +363,6 @@ PositionFrame::PositionFrame() void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setPosition(_position); if(_tween) @@ -361,9 +372,9 @@ void PositionFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void PositionFrame::apply(float percent) +void PositionFrame::onApply(float percent) { - if (_node && _tween && (_betweenX != 0 || _betweenY != 0)) + if (_betweenX != 0 || _betweenY != 0) { Point p; p.x = _position.x + _betweenX * percent; @@ -405,11 +416,6 @@ ScaleFrame::ScaleFrame() void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setScaleX(_scaleX); _node->setScaleY(_scaleY); @@ -420,9 +426,9 @@ void ScaleFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void ScaleFrame::apply(float percent) +void ScaleFrame::onApply(float percent) { - if (_node && _tween && (_betweenScaleX != 0 || _betweenScaleY != 0)) + if (_betweenScaleX != 0 || _betweenScaleY != 0) { float scaleX = _scaleX + _betweenScaleX * percent; float scaleY = _scaleY + _betweenScaleY * percent; @@ -464,11 +470,6 @@ AnchorPointFrame::AnchorPointFrame() void AnchorPointFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setAnchorPoint(_anchorPoint); } @@ -505,19 +506,14 @@ InnerActionFrame::InnerActionFrame() , _startFrameIndex(0) , _endFrameIndex(0) , _singleFrameIndex(0) -, _animationName("") , _enterWithName(false) +, _animationName("") { } void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - auto innerActiontimeline = static_cast(_node->getActionByTag(_node->getTag())); if( nullptr == innerActiontimeline) return; @@ -633,20 +629,20 @@ ColorFrame* ColorFrame::create() } ColorFrame::ColorFrame() -: _color(Color3B(255, 255, 255)) + : _alpha(255) + , _color(Color3B(255, 255, 255)) { } void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } + _node->setOpacity(_alpha); _node->setColor(_color); if(_tween) { + _betweenAlpha = static_cast(nextFrame)->_alpha - _alpha; + const Color3B& color = static_cast(nextFrame)->_color; _betweenRed = color.r - _color.r; _betweenGreen = color.g - _color.g; @@ -654,15 +650,18 @@ void ColorFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void ColorFrame::apply(float percent) +void ColorFrame::onApply(float percent) { - if (_node && _tween && (_betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0)) + if (_betweenAlpha !=0 || _betweenRed != 0 || _betweenGreen != 0 || _betweenBlue != 0) { + GLubyte alpha = _alpha + _betweenAlpha * percent; + Color3B color; color.r = _color.r+ _betweenRed * percent; color.g = _color.g+ _betweenGreen * percent; color.b = _color.b+ _betweenBlue * percent; + _node->setOpacity(alpha); _node->setColor(color); } } @@ -670,6 +669,7 @@ void ColorFrame::apply(float percent) Frame* ColorFrame::clone() { ColorFrame* frame = ColorFrame::create(); + frame->setAlpha(_alpha); frame->setColor(_color); frame->cloneProperty(this); @@ -697,11 +697,6 @@ AlphaFrame::AlphaFrame() void AlphaFrame::onEnter(Frame *nextFrame, int currentFrameIndex) { - if (_node == nullptr) - { - return; - } - _node->setOpacity(_alpha); if (_tween) @@ -710,13 +705,10 @@ void AlphaFrame::onEnter(Frame *nextFrame, int currentFrameIndex) } } -void AlphaFrame::apply(float percent) +void AlphaFrame::onApply(float percent) { - if (_node && _tween) - { - GLubyte alpha = _alpha + _betweenAlpha * percent; - _node->setOpacity(alpha); - } + GLubyte alpha = _alpha + _betweenAlpha * percent; + _node->setOpacity(alpha); } Frame* AlphaFrame::clone() diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h index 51996bcce7..f44ca77baa 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCFrame.h @@ -30,9 +30,11 @@ THE SOFTWARE. #include "base/CCVector.h" #include "2d/CCNode.h" #include "2d/CCSprite.h" +#include "2d/CCTweenFunction.h" #include "CCTimelineMacro.h" #include "cocostudio/CocosStudioExport.h" +using namespace cocos2d::tweenfunc; NS_TIMELINE_BEGIN @@ -55,15 +57,26 @@ public: virtual void setTween(bool tween) { _tween = tween; } virtual bool isTween() const { return _tween; } + virtual void setTweenType(const TweenType& tweenType) { _tweenType = tweenType; } + virtual TweenType getTweenType() const { return _tweenType; } + + // !to make easing with params, need setTweenType(TweenType::CUSTOM_EASING) + virtual void setEasingParams(const std::vector& easingParams); + virtual const std::vector& getEasingParams() const; + virtual bool isEnterWhenPassed() { return _enterWhenPassed; } virtual void onEnter(Frame* nextFrame, int currentFrameIndex) = 0; - virtual void apply(float percent) {} + virtual void apply(float percent); virtual Frame* clone() = 0; protected: Frame(); virtual ~Frame(); + virtual void onApply(float percent){} + + //update percent depends _tweenType, and return the Calculated percent + virtual float tweenPercent(float percent); virtual void emitEvent(); virtual void cloneProperty(Frame* frame); @@ -71,12 +84,14 @@ protected: unsigned int _frameIndex; bool _tween; + TweenType _tweenType; + std::vector _easingParam; bool _enterWhenPassed; Timeline* _timeline; cocos2d::Node* _node; -}; +}; class CC_STUDIO_DLL VisibleFrame : public Frame { @@ -103,7 +118,7 @@ public: TextureFrame(); - virtual void setNode(cocos2d::Node* node) override; + virtual void setNode(cocos2d::Node* node); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; virtual Frame* clone() override; @@ -124,13 +139,14 @@ public: RotationFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; inline void setRotation(float rotation) { _rotation = rotation; } inline float getRotation() const { return _rotation; } protected: + virtual void onApply(float percent) override; + float _rotation; float _betwennRotation; }; @@ -143,7 +159,6 @@ public: SkewFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; inline void setSkewX(float skewx) { _skewX = skewx; } @@ -153,6 +168,8 @@ public: inline float getSkewY() const { return _skewY; } protected: + virtual void onApply(float percent) override; + float _skewX; float _skewY; float _betweenSkewX; @@ -168,8 +185,10 @@ public: RotationSkewFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; + +protected: + virtual void onApply(float percent) override; }; @@ -181,7 +200,6 @@ public: PositionFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; inline void setPosition(const cocos2d::Point& position) { _position = position; } @@ -193,6 +211,8 @@ public: inline float getX() const { return _position.x; } inline float getY() const { return _position.y; } protected: + virtual void onApply(float percent) override; + cocos2d::Point _position; float _betweenX; float _betweenY; @@ -207,7 +227,6 @@ public: ScaleFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; inline void setScale(float scale) { _scaleX = scale; _scaleY = scale; } @@ -219,6 +238,8 @@ public: inline float getScaleY() const { return _scaleY; } protected: + virtual void onApply(float percent) override; + float _scaleX; float _scaleY; float _betweenScaleX; @@ -296,20 +317,21 @@ public: ColorFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; - /** @deprecated Use method setAlpha() and getAlpha() of AlphaFrame instead */ - CC_DEPRECATED_ATTRIBUTE inline void setAlpha(GLubyte alpha) { _alpha = alpha; } - CC_DEPRECATED_ATTRIBUTE inline GLubyte getAlpha() const { return _alpha; } + inline void setAlpha(GLubyte alpha) { _alpha = alpha; } + inline GLubyte getAlpha() const { return _alpha; } inline void setColor(const cocos2d::Color3B& color) { _color = color; } inline cocos2d::Color3B getColor() const { return _color; } protected: + virtual void onApply(float percent) override; + GLubyte _alpha; cocos2d::Color3B _color; + int _betweenAlpha; int _betweenRed; int _betweenGreen; int _betweenBlue; @@ -322,13 +344,14 @@ public: AlphaFrame(); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; - virtual void apply(float percent) override; virtual Frame* clone() override; inline void setAlpha(GLubyte alpha) { _alpha = alpha; } inline GLubyte getAlpha() const { return _alpha; } protected: + virtual void onApply(float percent) override; + GLubyte _alpha; int _betweenAlpha; }; @@ -341,7 +364,7 @@ public: EventFrame(); - virtual void setNode(cocos2d::Node* node) override; + virtual void setNode(cocos2d::Node* node); virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override; virtual Frame* clone() override; diff --git a/cocos/editor-support/cocostudio/CSParseBinary_generated.h b/cocos/editor-support/cocostudio/CSParseBinary_generated.h index 165c865f67..a37718f560 100644 --- a/cocos/editor-support/cocostudio/CSParseBinary_generated.h +++ b/cocos/editor-support/cocostudio/CSParseBinary_generated.h @@ -45,6 +45,7 @@ struct EventFrame; struct IntFrame; struct BoolFrame; struct InnerActionFrame; +struct EasingData; struct RotationSkew; struct Position; struct Scale; @@ -2085,11 +2086,14 @@ struct PointFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } const Position *postion() const { return GetStruct(8); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* postion */) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2100,10 +2104,11 @@ struct PointFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_postion(const Position *postion) { fbb_.AddStruct(8, postion); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } PointFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } PointFrameBuilder &operator=(const PointFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2111,8 +2116,10 @@ struct PointFrameBuilder { inline flatbuffers::Offset CreatePointFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - const Position *postion = 0) { + const Position *postion = 0, + flatbuffers::Offset easingData = 0) { PointFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_postion(postion); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2123,11 +2130,14 @@ struct ScaleFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } const Scale *scale() const { return GetStruct(8); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* scale */) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2138,10 +2148,11 @@ struct ScaleFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_scale(const Scale *scale) { fbb_.AddStruct(8, scale); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } ScaleFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ScaleFrameBuilder &operator=(const ScaleFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2149,8 +2160,10 @@ struct ScaleFrameBuilder { inline flatbuffers::Offset CreateScaleFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - const Scale *scale = 0) { + const Scale *scale = 0, + flatbuffers::Offset easingData = 0) { ScaleFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_scale(scale); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2161,11 +2174,14 @@ struct ColorFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } const Color *color() const { return GetStruct(8); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* color */) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2176,10 +2192,11 @@ struct ColorFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_color(const Color *color) { fbb_.AddStruct(8, color); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } ColorFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } ColorFrameBuilder &operator=(const ColorFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2187,8 +2204,10 @@ struct ColorFrameBuilder { inline flatbuffers::Offset CreateColorFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - const Color *color = 0) { + const Color *color = 0, + flatbuffers::Offset easingData = 0) { ColorFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_color(color); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2199,12 +2218,15 @@ struct TextureFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } const ResourceData *textureFile() const { return GetPointer(8); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* textureFile */) && verifier.VerifyTable(textureFile()) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2215,10 +2237,11 @@ struct TextureFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_textureFile(flatbuffers::Offset textureFile) { fbb_.AddOffset(8, textureFile); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } TextureFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } TextureFrameBuilder &operator=(const TextureFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2226,8 +2249,10 @@ struct TextureFrameBuilder { inline flatbuffers::Offset CreateTextureFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - flatbuffers::Offset textureFile = 0) { + flatbuffers::Offset textureFile = 0, + flatbuffers::Offset easingData = 0) { TextureFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_textureFile(textureFile); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2238,12 +2263,15 @@ struct EventFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } const flatbuffers::String *value() const { return GetPointer(8); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* value */) && verifier.Verify(value()) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2254,10 +2282,11 @@ struct EventFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_value(flatbuffers::Offset value) { fbb_.AddOffset(8, value); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } EventFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } EventFrameBuilder &operator=(const EventFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2265,8 +2294,10 @@ struct EventFrameBuilder { inline flatbuffers::Offset CreateEventFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - flatbuffers::Offset value = 0) { + flatbuffers::Offset value = 0, + flatbuffers::Offset easingData = 0) { EventFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_value(value); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2277,11 +2308,14 @@ struct IntFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } int32_t value() const { return GetField(8, 0); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* value */) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2292,10 +2326,11 @@ struct IntFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_value(int32_t value) { fbb_.AddElement(8, value, 0); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } IntFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } IntFrameBuilder &operator=(const IntFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2303,8 +2338,10 @@ struct IntFrameBuilder { inline flatbuffers::Offset CreateIntFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - int32_t value = 0) { + int32_t value = 0, + flatbuffers::Offset easingData = 0) { IntFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_value(value); builder_.add_frameIndex(frameIndex); builder_.add_tween(tween); @@ -2315,11 +2352,14 @@ struct BoolFrame : private flatbuffers::Table { int32_t frameIndex() const { return GetField(4, 0); } uint8_t tween() const { return GetField(6, 1); } uint8_t value() const { return GetField(8, 1); } + const EasingData *easingData() const { return GetPointer(10); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && VerifyField(verifier, 6 /* tween */) && VerifyField(verifier, 8 /* value */) && + VerifyField(verifier, 10 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2330,10 +2370,11 @@ struct BoolFrameBuilder { void add_frameIndex(int32_t frameIndex) { fbb_.AddElement(4, frameIndex, 0); } void add_tween(uint8_t tween) { fbb_.AddElement(6, tween, 1); } void add_value(uint8_t value) { fbb_.AddElement(8, value, 1); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(10, easingData); } BoolFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } BoolFrameBuilder &operator=(const BoolFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 3)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 4)); return o; } }; @@ -2341,8 +2382,10 @@ struct BoolFrameBuilder { inline flatbuffers::Offset CreateBoolFrame(flatbuffers::FlatBufferBuilder &_fbb, int32_t frameIndex = 0, uint8_t tween = 1, - uint8_t value = 1) { + uint8_t value = 1, + flatbuffers::Offset easingData = 0) { BoolFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_frameIndex(frameIndex); builder_.add_value(value); builder_.add_tween(tween); @@ -2355,6 +2398,7 @@ struct InnerActionFrame : private flatbuffers::Table { int32_t innerActionType() const { return GetField(8, 0); } const flatbuffers::String *currentAniamtionName() const { return GetPointer(10); } int32_t singleFrameIndex() const { return GetField(12, 0); } + const EasingData *easingData() const { return GetPointer(14); } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, 4 /* frameIndex */) && @@ -2363,6 +2407,8 @@ struct InnerActionFrame : private flatbuffers::Table { VerifyField(verifier, 10 /* currentAniamtionName */) && verifier.Verify(currentAniamtionName()) && VerifyField(verifier, 12 /* singleFrameIndex */) && + VerifyField(verifier, 14 /* easingData */) && + verifier.VerifyTable(easingData()) && verifier.EndTable(); } }; @@ -2375,10 +2421,11 @@ struct InnerActionFrameBuilder { void add_innerActionType(int32_t innerActionType) { fbb_.AddElement(8, innerActionType, 0); } void add_currentAniamtionName(flatbuffers::Offset currentAniamtionName) { fbb_.AddOffset(10, currentAniamtionName); } void add_singleFrameIndex(int32_t singleFrameIndex) { fbb_.AddElement(12, singleFrameIndex, 0); } + void add_easingData(flatbuffers::Offset easingData) { fbb_.AddOffset(14, easingData); } InnerActionFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } InnerActionFrameBuilder &operator=(const InnerActionFrameBuilder &); flatbuffers::Offset Finish() { - auto o = flatbuffers::Offset(fbb_.EndTable(start_, 5)); + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 6)); return o; } }; @@ -2388,8 +2435,10 @@ inline flatbuffers::Offset CreateInnerActionFrame(flatbuffers: uint8_t tween = 1, int32_t innerActionType = 0, flatbuffers::Offset currentAniamtionName = 0, - int32_t singleFrameIndex = 0) { + int32_t singleFrameIndex = 0, + flatbuffers::Offset easingData = 0) { InnerActionFrameBuilder builder_(_fbb); + builder_.add_easingData(easingData); builder_.add_singleFrameIndex(singleFrameIndex); builder_.add_currentAniamtionName(currentAniamtionName); builder_.add_innerActionType(innerActionType); @@ -2398,6 +2447,40 @@ inline flatbuffers::Offset CreateInnerActionFrame(flatbuffers: return builder_.Finish(); } +struct EasingData : private flatbuffers::Table { + int32_t type() const { return GetField(4, -1); } + const flatbuffers::Vector *points() const { return GetPointer *>(6); } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, 4 /* type */) && + VerifyField(verifier, 6 /* points */) && + verifier.Verify(points()) && + verifier.EndTable(); + } +}; + +struct EasingDataBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(int32_t type) { fbb_.AddElement(4, type, -1); } + void add_points(flatbuffers::Offset> points) { fbb_.AddOffset(6, points); } + EasingDataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } + EasingDataBuilder &operator=(const EasingDataBuilder &); + flatbuffers::Offset Finish() { + auto o = flatbuffers::Offset(fbb_.EndTable(start_, 2)); + return o; + } +}; + +inline flatbuffers::Offset CreateEasingData(flatbuffers::FlatBufferBuilder &_fbb, + int32_t type = -1, + flatbuffers::Offset> points = 0) { + EasingDataBuilder builder_(_fbb); + builder_.add_points(points); + builder_.add_type(type); + return builder_.Finish(); +} + struct ResourceData : private flatbuffers::Table { const flatbuffers::String *path() const { return GetPointer(4); } const flatbuffers::String *plistFile() const { return GetPointer(6); } diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 3e38985e0a..96e1dcbdbe 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -790,12 +790,15 @@ Offset FlatBuffersSerialize::createPointFrame(const tin attribute = attribute->Next(); } + + Position f_position(position.x, position.y); return CreatePointFrame(*_builder, frameIndex, tween, - &f_position); + &f_position, + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createScaleFrame(const tinyxml2::XMLElement *objectData) @@ -835,7 +838,8 @@ Offset FlatBuffersSerialize::createScaleFrame(const tin return CreateScaleFrame(*_builder, frameIndex, tween, - &f_scale); + &f_scale, + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createColorFrame(const tinyxml2::XMLElement *objectData) @@ -896,7 +900,8 @@ Offset FlatBuffersSerialize::createColorFrame(const tin return CreateColorFrame(*_builder, frameIndex, tween, - &f_color); + &f_color, + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createTextureFrame(const tinyxml2::XMLElement *objectData) @@ -969,7 +974,8 @@ Offset FlatBuffersSerialize::createTextureFrame(const CreateResourceData(*_builder, _builder->CreateString(path), _builder->CreateString(plistFile), - resourceType)); + resourceType), + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createEventFrame(const tinyxml2::XMLElement *objectData) @@ -1003,7 +1009,8 @@ Offset FlatBuffersSerialize::createEventFrame(const tin return CreateEventFrame(*_builder, frameIndex, tween, - _builder->CreateString(value)); + _builder->CreateString(value), + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createIntFrame(const tinyxml2::XMLElement *objectData) @@ -1037,7 +1044,8 @@ Offset FlatBuffersSerialize::createIntFrame(const tinyxml return CreateIntFrame(*_builder, frameIndex, tween, - value); + value, + createEasingData(objectData->FirstChildElement())); } Offset FlatBuffersSerialize::createBoolFrame(const tinyxml2::XMLElement *objectData) @@ -1069,67 +1077,133 @@ Offset FlatBuffersSerialize::createBoolFrame(const tinyx } return CreateBoolFrame(*_builder, - frameIndex, - tween, - value); + frameIndex, + tween, + value, + createEasingData(objectData->FirstChildElement())); } - Offset FlatBuffersSerialize::createInnerActionFrame(const tinyxml2::XMLElement *objectData) +Offset FlatBuffersSerialize::createInnerActionFrame(const tinyxml2::XMLElement *objectData) +{ + int frameIndex = 0; + bool tween = true; + int innerActionType = 0; + std::string currentAniamtionName = ""; + int singleFrameIndex = 0; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + while (attribute) { - int frameIndex = 0; - bool tween = true; - int innerActionType = 0; - std::string currentAniamtionName = ""; - int singleFrameIndex = 0; + std::string name = attribute->Name(); + std::string attrivalue = attribute->Value(); - const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); - while (attribute) + if (name == "InnerActionType") { - std::string name = attribute->Name(); - std::string attrivalue = attribute->Value(); - - if (name == "InnerActionType") + if (attrivalue == "LoopAction") { - if (attrivalue == "LoopAction") - { - innerActionType = 0; - } - else if (attrivalue == "NoLoopAction") - { - innerActionType = 1; - } - else if (attrivalue == "SingleFrame") - { - innerActionType = 2; - } + innerActionType = 0; } - else if (name == "CurrentAniamtionName") + else if (attrivalue == "NoLoopAction") { - currentAniamtionName = attrivalue; + innerActionType = 1; } - else if (name == "SingleFrameIndex") + else if (attrivalue == "SingleFrame") { - singleFrameIndex = atoi(attrivalue.c_str()); + innerActionType = 2; } - else if (name == "FrameIndex") - { - frameIndex = atoi(attrivalue.c_str()); - } - else if (name == "Tween") - { - tween = (attrivalue == "True") ? true : false; - } - - attribute = attribute->Next(); + } + else if (name == "CurrentAniamtionName") + { + currentAniamtionName = attrivalue; + } + else if (name == "SingleFrameIndex") + { + singleFrameIndex = atoi(attrivalue.c_str()); + } + else if (name == "FrameIndex") + { + frameIndex = atoi(attrivalue.c_str()); + } + else if (name == "Tween") + { + tween = (attrivalue == "True") ? true : false; } - return CreateInnerActionFrame(*_builder, - frameIndex, - tween, - innerActionType, - _builder->CreateString(currentAniamtionName), - singleFrameIndex); + attribute = attribute->Next(); } + + return CreateInnerActionFrame(*_builder, + frameIndex, + tween, + innerActionType, + _builder->CreateString(currentAniamtionName), + singleFrameIndex, + createEasingData(objectData->FirstChildElement())); +} + +flatbuffers::Offset FlatBuffersSerialize::createEasingData(const tinyxml2::XMLElement *objectData) +{ + if (!objectData) + { + return 0; + } + + int type = -1; + std::vector points; + + const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute(); + + while (attribute) + { + std::string name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "Type") + { + type = atoi(value.c_str()); + break; + } + + attribute = attribute->Next(); + } + + const tinyxml2::XMLElement* Points = objectData->FirstChildElement(); + if (Points) + { + const tinyxml2::XMLElement* PointF = Points->FirstChildElement(); + while (PointF) + { + Vec2 pointF = Vec2::ZERO; + + attribute = PointF->FirstAttribute(); + + while (attribute) + { + std::string name = attribute->Name(); + std::string value = attribute->Value(); + + if (name == "X") + { + pointF.x = atof(value.c_str()); + } + else if (name == "Y") + { + pointF.y = atof(value.c_str()); + } + attribute = attribute->Next(); + } + flatbuffers::Position f_PointF(pointF.x, pointF.y); + points.push_back(f_PointF); + + PointF = PointF->NextSiblingElement(); + } + } + + return CreateEasingData(*_builder, + type, + _builder->CreateVectorOfStructs(points)); +} + /* create flat buffers with XML */ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulator(const std::string &xmlFileName) diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h index f05c059c58..9ea54c15b7 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.h +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.h @@ -77,6 +77,7 @@ namespace flatbuffers struct IntFrame; struct BoolFrame; struct InnerActionFrame; + struct EasingData; } namespace tinyxml2 @@ -122,6 +123,8 @@ public: flatbuffers::Offset createIntFrame(const tinyxml2::XMLElement* objectData); flatbuffers::Offset createBoolFrame(const tinyxml2::XMLElement* objectData); flatbuffers::Offset createInnerActionFrame(const tinyxml2::XMLElement* objectData); + + flatbuffers::Offset createEasingData(const tinyxml2::XMLElement* objectData); //Animation Info flatbuffers::Offset createAnimationInfo(const tinyxml2::XMLElement* objectData);