From a67ee27815d0396e08b0dafe652786ca99763213 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 15 Nov 2020 11:30:43 +0100 Subject: [PATCH] Fixed a cosmetic navigation issue in SystemView. --- es-app/src/views/SystemView.cpp | 28 +++++++++++++++++++++++----- es-app/src/views/SystemView.h | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index bc26373d6..6fa50b073 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -30,6 +30,7 @@ SystemView::SystemView( Window* window) : IList (window, LIST_SCROLL_STYLE_SLOW, LIST_ALWAYS_LOOP), + mPreviousScrollVelocity(0), mViewNeedsReload(true), mSystemInfo(window, "SYSTEM INFO", Font::get(FONT_SIZE_SMALL), 0x33333300, ALIGN_CENTER) { @@ -249,13 +250,10 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) updateHelpPrompts(); float startPos = mCamOffset; - float posMax = static_cast(mEntries.size()); float target = static_cast(mCursor); - // What's the shortest way to get to our target? - // It's one of these... - + // Find the shortest path to the target. float endPos = target; // Directly. float dist = fabs(endPos - startPos); @@ -264,8 +262,18 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) if (fabs(target - posMax - startPos - mScrollVelocity) < dist) endPos = target - posMax; // Loop around the start (max - 1 -> -1). - // Animate mSystemInfo's opacity (fade out, wait, fade back in). + // This logic is only needed when there are two game systems, to prevent ugly jumps back + // an forth when selecting the same direction rapidly several times in a row. + if (posMax == 2) { + if (mPreviousScrollVelocity == 0) + mPreviousScrollVelocity = mScrollVelocity; + else if (mScrollVelocity < 0 && startPos < endPos) + mPreviousScrollVelocity = -1; + else if (mScrollVelocity > 0 && startPos > endPos) + mPreviousScrollVelocity = 1; + } + // Animate mSystemInfo's opacity (fade out, wait, fade back in). cancelAnimation(1); cancelAnimation(2); @@ -279,6 +287,16 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) Math::lerp(infoStartOpacity, 0.f, t) * 255)); }, static_cast(infoStartOpacity * (goFast ? 10 : 150))); + // To prevent ugly jumps with two systems when quickly repeating the same direction. + if (mPreviousScrollVelocity != 0 && posMax == 2 && + mScrollVelocity == mPreviousScrollVelocity ) { + if (fabs(endPos - startPos) < 0.5 || fabs(endPos - startPos) > 1.5) { + (mScrollVelocity < 0) ? endPos -= 1 : endPos += 1; + (mCursor == 0) ? mCursor = 1 : mCursor = 0; + return; + } + } + std::pair gameCount = getSelected()->getDisplayedGameCount(); // Also change the text after we've fully faded out. diff --git a/es-app/src/views/SystemView.h b/es-app/src/views/SystemView.h index 2e2069fc8..42c4708ca 100644 --- a/es-app/src/views/SystemView.h +++ b/es-app/src/views/SystemView.h @@ -93,6 +93,7 @@ private: float mExtrasCamOffset; float mExtrasFadeOpacity; + int mPreviousScrollVelocity; bool mViewNeedsReload; bool mShowing; };