Skip to content

Commit 14cb455

Browse files
committed
fix currently selected map not being scrolled to when entering songselect + add an animation
1 parent 3c24c15 commit 14cb455

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

fluXis/Screens/Select/List/MapList.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using fluXis.Database.Maps;
@@ -27,6 +28,7 @@ public partial class MapList : FluXisScrollContainer, ISelectionManager
2728
private List<IListItem> items { get; } = new();
2829

2930
private bool bulkInserting;
31+
private bool entering = true;
3032

3133
public MapList(Bindable<MapUtils.SortingMode> sorting)
3234
{
@@ -141,6 +143,12 @@ protected override void Update()
141143
}
142144

143145
Content.Height = pos;
146+
147+
if (pos > 0 && entering)
148+
{
149+
entering = false;
150+
Schedule(() => ScheduleAfterChildren(scrollEnter));
151+
}
144152
}
145153

146154
public void Sort()
@@ -163,17 +171,36 @@ public void ScrollToSelected(bool smooth = true)
163171
ScrollToItem(selected, smooth);
164172
}
165173

174+
private void scrollEnter()
175+
{
176+
var selected = items.FirstOrDefault(c => c.State.Value == SelectedState.Selected);
177+
178+
if (selected != null)
179+
{
180+
var position = getScrollPosition(selected);
181+
var start = Math.Max(position - 800, 0);
182+
ScrollTo(start, false);
183+
ScrollTo(position);
184+
}
185+
}
186+
166187
public void ScrollToItem(IListItem item, bool smooth = true)
188+
{
189+
var pos = getScrollPosition(item);
190+
ScrollTo(pos, smooth);
191+
}
192+
193+
private double getScrollPosition(IListItem item)
167194
{
168195
var top = item.ScrollPosition;
169196
var center = top + item.ScrollSize / 2;
170197

171198
if (center < DisplayableContent / 2)
172-
ScrollTo(0, smooth);
173-
else if (center > ScrollableExtent + DisplayableContent / 2)
174-
ScrollToEnd(smooth);
175-
else
176-
ScrollTo(center - DisplayableContent / 2, smooth);
199+
return 0;
200+
if (center > ScrollableExtent + DisplayableContent / 2)
201+
return ScrollableExtent;
202+
203+
return center - DisplayableContent / 2;
177204
}
178205

179206
public RealmMap CurrentMap => MapBindable.Value;

fluXis/Screens/Select/SelectScreen.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ protected override void LoadComplete()
214214

215215
mapList.FadeIn(500);
216216
loadingIcon.FadeOut(500);
217-
218-
mapList.ScrollToSelected(false);
219217
});
220218
});
221219
}

0 commit comments

Comments
 (0)