mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-18 12:55:38 +00:00
ViewController renders help prompts early so they appear "below" the fade.
The "fade" transition style can now be "cancelled" out of like the slide animations.
This commit is contained in:
parent
b8ebbc84bb
commit
4f33a3a963
|
@ -40,16 +40,7 @@ void GuiComponent::update(int deltaTime)
|
||||||
{
|
{
|
||||||
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||||
{
|
{
|
||||||
AnimationController* anim = mAnimationMap[i];
|
advanceAnimation(i, deltaTime);
|
||||||
if(anim)
|
|
||||||
{
|
|
||||||
bool done = anim->update(deltaTime);
|
|
||||||
if(done)
|
|
||||||
{
|
|
||||||
mAnimationMap[i] = NULL;
|
|
||||||
delete anim;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0; i < getChildCount(); i++)
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
||||||
|
@ -257,6 +248,24 @@ bool GuiComponent::finishAnimation(unsigned char slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GuiComponent::advanceAnimation(unsigned char slot, unsigned int time)
|
||||||
|
{
|
||||||
|
assert(slot < MAX_ANIMATIONS);
|
||||||
|
AnimationController* anim = mAnimationMap[slot];
|
||||||
|
if(anim)
|
||||||
|
{
|
||||||
|
bool done = anim->update(time);
|
||||||
|
if(done)
|
||||||
|
{
|
||||||
|
mAnimationMap[slot] = NULL;
|
||||||
|
delete anim;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GuiComponent::stopAllAnimations()
|
void GuiComponent::stopAllAnimations()
|
||||||
{
|
{
|
||||||
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
|
||||||
|
|
|
@ -60,8 +60,9 @@ public:
|
||||||
int getAnimationTime(unsigned char slot) const;
|
int getAnimationTime(unsigned char slot) const;
|
||||||
void setAnimation(Animation* animation, int delay = 0, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
|
void setAnimation(Animation* animation, int delay = 0, std::function<void()> finishedCallback = nullptr, bool reverse = false, unsigned char slot = 0);
|
||||||
bool stopAnimation(unsigned char slot);
|
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 cancelAnimation(unsigned char slot); // Like stopAnimation, but doesn't call finishedCallback - only removes the animation, leaving things in their current state. Returns true if successful (an animation was in this slot).
|
||||||
bool finishAnimation(unsigned char slot); // calls update(1.f) and finishedCallback, then deletes the animation - basically skips to the end
|
bool finishAnimation(unsigned char slot); // Calls update(1.f) and finishedCallback, then deletes the animation - basically skips to the end. Returns true if successful (an animation was in this slot).
|
||||||
|
bool advanceAnimation(unsigned char slot, unsigned int time); // Returns true if successful (an animation was in this slot).
|
||||||
void stopAllAnimations();
|
void stopAllAnimations();
|
||||||
void cancelAllAnimations();
|
void cancelAllAnimations();
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,8 @@ void Window::render()
|
||||||
{
|
{
|
||||||
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
Eigen::Affine3f transform = Eigen::Affine3f::Identity();
|
||||||
|
|
||||||
|
mRenderedHelpPrompts = false;
|
||||||
|
|
||||||
// draw only bottom and top of GuiStack (if they are different)
|
// draw only bottom and top of GuiStack (if they are different)
|
||||||
if(mGuiStack.size())
|
if(mGuiStack.size())
|
||||||
{
|
{
|
||||||
|
@ -199,6 +201,7 @@ void Window::render()
|
||||||
mBackgroundOverlay->render(transform);
|
mBackgroundOverlay->render(transform);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
if(!mRenderedHelpPrompts)
|
||||||
mHelp->render(transform);
|
mHelp->render(transform);
|
||||||
|
|
||||||
if(Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
if(Settings::getInstance()->getBool("DrawFramerate") && mFrameDataText)
|
||||||
|
@ -239,6 +242,12 @@ void Window::renderLoadingScreen()
|
||||||
Renderer::swapBuffers();
|
Renderer::swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::renderHelpPromptsEarly()
|
||||||
|
{
|
||||||
|
mHelp->render(Eigen::Affine3f::Identity());
|
||||||
|
mRenderedHelpPrompts = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts)
|
void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts)
|
||||||
{
|
{
|
||||||
mHelp->clearPrompts();
|
mHelp->clearPrompts();
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
|
|
||||||
void renderLoadingScreen();
|
void renderLoadingScreen();
|
||||||
|
|
||||||
|
void renderHelpPromptsEarly(); // used by ViewController to render HelpPrompts before a fade
|
||||||
void setHelpPrompts(const std::vector<HelpPrompt>& prompts);
|
void setHelpPrompts(const std::vector<HelpPrompt>& prompts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -57,6 +58,7 @@ private:
|
||||||
bool mNormalizeNextUpdate;
|
bool mNormalizeNextUpdate;
|
||||||
|
|
||||||
bool mAllowSleep;
|
bool mAllowSleep;
|
||||||
|
bool mRenderedHelpPrompts;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -115,6 +115,16 @@ std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HelpComponent::setOpacity(unsigned char opacity)
|
||||||
|
{
|
||||||
|
GuiComponent::setOpacity(opacity);
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < mGrid->getChildCount(); i++)
|
||||||
|
{
|
||||||
|
mGrid->getChild(i)->setOpacity(opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HelpComponent::render(const Eigen::Affine3f& parentTrans)
|
void HelpComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
void setPrompts(const std::vector<HelpPrompt>& prompts);
|
void setPrompts(const std::vector<HelpPrompt>& prompts);
|
||||||
|
|
||||||
void render(const Eigen::Affine3f& parent) override;
|
void render(const Eigen::Affine3f& parent) override;
|
||||||
|
void setOpacity(unsigned char opacity) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<TextureResource> getIconTexture(const char* name);
|
std::shared_ptr<TextureResource> getIconTexture(const char* name);
|
||||||
|
|
|
@ -44,7 +44,6 @@ void ViewController::goToSystemView(SystemData* system)
|
||||||
systemList->goToSystem(system, false);
|
systemList->goToSystem(system, false);
|
||||||
mCurrentView = systemList;
|
mCurrentView = systemList;
|
||||||
|
|
||||||
updateHelpPrompts();
|
|
||||||
playViewTransition();
|
playViewTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +80,6 @@ void ViewController::goToGameList(SystemData* system)
|
||||||
mState.system = system;
|
mState.system = system;
|
||||||
|
|
||||||
mCurrentView = getGameListView(system);
|
mCurrentView = getGameListView(system);
|
||||||
updateHelpPrompts();
|
|
||||||
playViewTransition();
|
playViewTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,23 +91,36 @@ void ViewController::playViewTransition()
|
||||||
|
|
||||||
if(Settings::getInstance()->getString("TransitionStyle") == "fade")
|
if(Settings::getInstance()->getString("TransitionStyle") == "fade")
|
||||||
{
|
{
|
||||||
// fade animation
|
// fade
|
||||||
auto fadeAnim = [this, target](float t) {
|
// stop whatever's currently playing, leaving mFadeOpacity wherever it is
|
||||||
float fadeStart = lerp<float>(0, 1, t / 0.3f);
|
cancelAnimation(0);
|
||||||
float fadeEnd = lerp<float>(1, 0, (t - 0.7f) / 0.3f);
|
|
||||||
|
|
||||||
if(t <= 0.3f)
|
auto fadeFunc = [this](float t) {
|
||||||
{
|
mFadeOpacity = lerp<float>(0, 1, t);
|
||||||
mFadeOpacity = fadeStart;
|
|
||||||
}else{
|
|
||||||
this->mCamera.translation() = -target;
|
|
||||||
mFadeOpacity = fadeEnd;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
setAnimation(new LambdaAnimation(fadeAnim, 800));
|
|
||||||
|
const static int FADE_DURATION = 240; // fade in/out time
|
||||||
|
const static int FADE_WAIT = 320; // time to wait between in/out
|
||||||
|
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0, [this, fadeFunc, target] {
|
||||||
|
this->mCamera.translation() = -target;
|
||||||
|
updateHelpPrompts();
|
||||||
|
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), FADE_WAIT, nullptr, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// fast-forward animation if we're partway faded
|
||||||
|
if(target == -mCamera.translation())
|
||||||
|
{
|
||||||
|
// not changing screens, so cancel the first half entirely
|
||||||
|
advanceAnimation(0, FADE_DURATION);
|
||||||
|
advanceAnimation(0, FADE_WAIT);
|
||||||
|
advanceAnimation(0, FADE_DURATION - (int)(mFadeOpacity * FADE_DURATION));
|
||||||
|
}else{
|
||||||
|
advanceAnimation(0, (int)(mFadeOpacity * FADE_DURATION));
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
// slide
|
// slide
|
||||||
setAnimation(new MoveCameraAnimation(mCamera, target));
|
setAnimation(new MoveCameraAnimation(mCamera, target));
|
||||||
|
updateHelpPrompts(); // update help prompts immediately
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,6 +278,9 @@ void ViewController::render(const Eigen::Affine3f& parentTrans)
|
||||||
it->second->render(trans);
|
it->second->render(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mWindow->peekGui() == this)
|
||||||
|
mWindow->renderHelpPromptsEarly();
|
||||||
|
|
||||||
// fade out
|
// fade out
|
||||||
if(mFadeOpacity)
|
if(mFadeOpacity)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue