Fixed a reverse scrolling issue in CarouselComponent.

This commit is contained in:
Leon Styhre 2022-02-09 00:05:06 +01:00
parent d1cbbad8ee
commit 03f8e020c3
3 changed files with 29 additions and 17 deletions

View file

@ -32,6 +32,7 @@ namespace
SystemView::SystemView()
: mCamOffset {0.0f}
, mFadeOpacity {0.0f}
, mPreviousScrollVelocity {0}
, mUpdatedGameCount {false}
, mViewNeedsReload {true}
, mLegacyMode {false}
@ -240,6 +241,20 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
if (fabs(target - posMax - startPos - scrollVelocity) < dist)
endPos = target - posMax; // Loop around the start (max - 1 -> -1).
// Make sure transitions do not animate in reverse.
bool changedDirection {false};
if (mPreviousScrollVelocity != 0 && mPreviousScrollVelocity != scrollVelocity)
changedDirection = true;
if (!changedDirection && scrollVelocity > 0 && endPos < startPos)
endPos = endPos + posMax;
if (!changedDirection && scrollVelocity < 0 && endPos > startPos)
endPos = endPos - posMax;
if (scrollVelocity != 0)
mPreviousScrollVelocity = scrollVelocity;
std::string transition_style {Settings::getInstance()->getString("TransitionStyle")};
Animation* anim;

View file

@ -90,6 +90,7 @@ private:
float mCamOffset;
float mFadeOpacity;
int mPreviousScrollVelocity;
bool mUpdatedGameCount;
bool mViewNeedsReload;

View file

@ -435,23 +435,19 @@ void CarouselComponent::onCursorChanged(const CursorState& state)
if (fabs(target - posMax - startPos - mScrollVelocity) < dist)
endPos = target - posMax; // Loop around the start (max - 1 -> -1).
// 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;
}
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;
}
}
// Make sure there are no reverse jumps between logos.
bool changedDirection {false};
if (mPreviousScrollVelocity != 0 && mPreviousScrollVelocity != mScrollVelocity)
changedDirection = true;
if (!changedDirection && mScrollVelocity > 0 && endPos < startPos)
endPos = endPos + posMax;
if (!changedDirection && mScrollVelocity < 0 && endPos > startPos)
endPos = endPos - posMax;
if (mScrollVelocity != 0)
mPreviousScrollVelocity = mScrollVelocity;
// No need to animate transition, we're not going anywhere (probably mEntries.size() == 1).
if (endPos == mCamOffset)