From c1438464cdf59e5e8f827a3d4af07321fb1acdb0 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 12 Jun 2020 21:24:14 +0200 Subject: [PATCH] fixed swiping back and forth causing issues sometimes --- TouchyTickets/Ui.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index 0ef8f8c..8e60000 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -338,14 +338,18 @@ namespace TouchyTickets { } else if (!this.finishingSwipe && this.swipeProgress != 0 && !MlemGame.Input.TouchState.Any()) { // if we're not dragging or holding, we need to move back to our current ui this.swipeProgress -= Math.Sign(this.swipeProgress) * 0.03F; - if (this.swipeProgress.Equals(0, 0.03F)) - this.ResetSwipe(); + if (this.swipeProgress.Equals(0, 0.03F)) { + this.currentUi.Root.Transform = Matrix.Identity; + this.finishingSwipe = false; + this.swipeProgress = 0; + } } + var next = -1; if (this.swipeProgress != 0) { // actual swipe reaction logic var curr = Array.IndexOf(this.swipeRelations, this.currentUi); - var next = curr + Math.Sign(this.swipeProgress); + next = curr + Math.Sign(this.swipeProgress); if (next >= 0 && next < this.swipeRelations.Length) { this.swipeRelations[next].IsHidden = false; // if we've swiped a bit, we count this as a success and move to the next ui @@ -357,7 +361,9 @@ namespace TouchyTickets { // we're done with the swipe, so switch the active ui if (this.swipeProgress.Equals(Math.Sign(this.swipeProgress), 0.05F)) { this.currentUi = this.swipeRelations[next]; - this.ResetSwipe(); + this.currentUi.Root.Transform = Matrix.Identity; + this.finishingSwipe = false; + this.swipeProgress = 0; } } } else { @@ -370,6 +376,8 @@ namespace TouchyTickets { if (next >= 0 && next < this.swipeRelations.Length) this.swipeRelations[next].Root.Transform = Matrix.CreateTranslation((Math.Sign(this.swipeProgress) - this.swipeProgress) * this.swipeRelations[next].DisplayArea.Width, 0, 0); } + for (var i = 0; i < this.swipeRelations.Length; i++) + this.swipeRelations[i].IsHidden = i != next && this.swipeRelations[i] != this.currentUi; } } @@ -410,15 +418,6 @@ namespace TouchyTickets { this.uiSystem.Remove(splash.Root.Name); } - private void ResetSwipe() { - this.finishingSwipe = false; - this.swipeProgress = 0; - foreach (var element in this.swipeRelations) { - element.IsHidden = element != this.currentUi; - element.Root.Transform = Matrix.Identity; - } - } - private void FadeUi(bool fadeOut, Action after = null) { IEnumerator Impl() { // disable input handling during fade