diff --git a/src/GuiComponent.cpp b/src/GuiComponent.cpp index c6ab22a3e..75f6d7e08 100644 --- a/src/GuiComponent.cpp +++ b/src/GuiComponent.cpp @@ -202,28 +202,31 @@ void GuiComponent::textInput(const char* text) } } -void GuiComponent::setAnimation(Animation* anim, std::function finishedCallback, bool reverse, unsigned char slot) +void GuiComponent::setAnimation(Animation* anim, int delay, std::function finishedCallback, bool reverse, unsigned char slot) { assert(slot < MAX_ANIMATIONS); AnimationController* oldAnim = mAnimationMap[slot]; - mAnimationMap[slot] = new AnimationController(anim, finishedCallback, reverse); + mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse); if(oldAnim) delete oldAnim; } -void GuiComponent::stopAnimation(unsigned char slot) +bool GuiComponent::stopAnimation(unsigned char slot) { assert(slot < MAX_ANIMATIONS); if(mAnimationMap[slot]) { delete mAnimationMap[slot]; mAnimationMap[slot] = NULL; + return true; + }else{ + return false; } } -void GuiComponent::cancelAnimation(unsigned char slot) +bool GuiComponent::cancelAnimation(unsigned char slot) { assert(slot < MAX_ANIMATIONS); if(mAnimationMap[slot]) @@ -231,6 +234,26 @@ void GuiComponent::cancelAnimation(unsigned char slot) mAnimationMap[slot]->removeFinishedCallback(); delete mAnimationMap[slot]; mAnimationMap[slot] = NULL; + return true; + }else{ + return false; + } +} + +bool GuiComponent::finishAnimation(unsigned char slot) +{ + assert(slot < MAX_ANIMATIONS); + if(mAnimationMap[slot]) + { + // skip to animation's end + const bool done = mAnimationMap[slot]->update(mAnimationMap[slot]->getAnimation()->getDuration() - mAnimationMap[slot]->getTime()); + assert(done); + + delete mAnimationMap[slot]; // will also call finishedCallback + mAnimationMap[slot] = NULL; + return true; + }else{ + return false; } } diff --git a/src/GuiComponent.h b/src/GuiComponent.h index cea2765c5..39b01c282 100644 --- a/src/GuiComponent.h +++ b/src/GuiComponent.h @@ -58,9 +58,10 @@ public: bool isAnimationPlaying(unsigned char slot) const; bool isAnimationReversed(unsigned char slot) const; int getAnimationTime(unsigned char slot) const; - void setAnimation(Animation* animation, std::function finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0); - void stopAnimation(unsigned char slot); - void cancelAnimation(unsigned char slot); // like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving things in their current state + void setAnimation(Animation* animation, int delay = 0, std::function finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0); + bool stopAnimation(unsigned char slot); + bool cancelAnimation(unsigned char slot); // like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving things in their current state + bool finishAnimation(unsigned char slot); // calls update(1.f) and finishedCallback, then deletes the animation - basically skips to the end void stopAllAnimations(); void cancelAllAnimations(); diff --git a/src/animations/AnimationController.cpp b/src/animations/AnimationController.cpp index 3c92105d2..09f751477 100644 --- a/src/animations/AnimationController.cpp +++ b/src/animations/AnimationController.cpp @@ -1,7 +1,7 @@ #include "AnimationController.h" -AnimationController::AnimationController(Animation* anim, std::function finishedCallback, bool reverse) - : mAnimation(anim), mFinishedCallback(finishedCallback), mReverse(reverse), mTime(0) +AnimationController::AnimationController(Animation* anim, int delay, std::function finishedCallback, bool reverse) + : mAnimation(anim), mFinishedCallback(finishedCallback), mReverse(reverse), mTime(-delay), mDelay(delay) { } @@ -16,6 +16,10 @@ AnimationController::~AnimationController() bool AnimationController::update(int deltaTime) { mTime += deltaTime; + + if(mTime < 0) // are we still in delay? + return false; + float t = (float)mTime / mAnimation->getDuration(); if(t > 1.0f) diff --git a/src/animations/AnimationController.h b/src/animations/AnimationController.h index 4df334809..7a648546d 100644 --- a/src/animations/AnimationController.h +++ b/src/animations/AnimationController.h @@ -8,7 +8,7 @@ class AnimationController { public: // Takes ownership of anim (will delete in destructor). - AnimationController(Animation* anim, std::function finishedCallback = nullptr, bool reverse = false); + AnimationController(Animation* anim, int delay = 0, std::function finishedCallback = nullptr, bool reverse = false); virtual ~AnimationController(); // Returns true if the animation is complete. @@ -16,7 +16,9 @@ public: inline bool isReversed() const { return mReverse; } inline int getTime() const { return mTime; } + inline int getDelay() const { return mDelay; } inline const std::function& getFinishedCallback() const { return mFinishedCallback; } + inline Animation* getAnimation() const { return mAnimation; } inline void removeFinishedCallback() { mFinishedCallback = nullptr; } @@ -25,4 +27,5 @@ private: std::function mFinishedCallback; bool mReverse; int mTime; + int mDelay; }; diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 9cf02ea1c..caf420b31 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -112,12 +112,12 @@ void ViewController::launch(FileData* game, Eigen::Vector3f center) center += mCurrentView->getPosition(); stopAnimation(1); // make sure the fade in isn't still playing mLockInput = true; - setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 1500), [this, origCamera, center, game] + setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 1500), 0, [this, origCamera, center, game] { game->getSystem()->launchGame(mWindow, game); mCamera = origCamera; mLockInput = false; - setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 600), nullptr, true); + setAnimation(new LaunchAnimation(mCamera, mFadeOpacity, center, 600), 0, nullptr, true); this->onFileChanged(game, FILE_METADATA_CHANGED); }); } diff --git a/src/views/gamelist/DetailedGameListView.cpp b/src/views/gamelist/DetailedGameListView.cpp index 395a7350c..5285f372c 100644 --- a/src/views/gamelist/DetailedGameListView.cpp +++ b/src/views/gamelist/DetailedGameListView.cpp @@ -224,7 +224,7 @@ void DetailedGameListView::updateInfoPanel() { comp->setOpacity((unsigned char)(lerp(0.0f, 1.0f, t)*255)); }; - comp->setAnimation(new LambdaAnimation(func, 150), nullptr, fadingOut); + comp->setAnimation(new LambdaAnimation(func, 150), 0, nullptr, fadingOut); } } }