Skip to content

Commit 94ea003

Browse files
committed
Update game ScrollContainer usage in line with framework changes
See ppy/osu-framework#6467.
1 parent 73adc4d commit 94ea003

17 files changed

+38
-38
lines changed

osu.Game.Tests/Visual/UserInterface/TestSceneSectionsContainer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void step(int scrollIndex)
138138
AddUntilStep("section top is visible", () =>
139139
{
140140
var scrollContainer = container.ChildrenOfType<UserTrackingScrollContainer>().Single();
141-
float sectionPosition = scrollContainer.GetChildPosInContent(container.Children[scrollIndex]);
141+
double sectionPosition = scrollContainer.GetChildPosInContent(container.Children[scrollIndex]);
142142
return scrollContainer.Current < sectionPosition;
143143
});
144144
}

osu.Game/Graphics/Containers/OsuScrollContainer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public OsuScrollContainer(Direction scrollDirection = Direction.Vertical)
5959
/// <param name="extraScroll">An added amount to scroll beyond the requirement to bring the target into view.</param>
6060
public void ScrollIntoView(Drawable d, bool animated = true, float extraScroll = 0)
6161
{
62-
float childPos0 = GetChildPosInContent(d);
63-
float childPos1 = GetChildPosInContent(d, d.DrawSize);
62+
double childPos0 = GetChildPosInContent(d);
63+
double childPos1 = GetChildPosInContent(d, d.DrawSize);
6464

65-
float minPos = Math.Min(childPos0, childPos1);
66-
float maxPos = Math.Max(childPos0, childPos1);
65+
double minPos = Math.Min(childPos0, childPos1);
66+
double maxPos = Math.Max(childPos0, childPos1);
6767

6868
if (minPos < Current || (minPos > Current && d.DrawSize[ScrollDim] > DisplayableContent))
6969
ScrollTo(minPos - extraScroll, animated);

osu.Game/Graphics/Containers/SectionsContainer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void ScrollTo(Drawable target)
208208
private float getScrollTargetForDrawable(Drawable target)
209209
{
210210
// implementation similar to ScrollIntoView but a bit more nuanced.
211-
return scrollContainer.GetChildPosInContent(target) - scrollContainer.DisplayableContent * scroll_y_centre;
211+
return (float)(scrollContainer.GetChildPosInContent(target) - scrollContainer.DisplayableContent * scroll_y_centre);
212212
}
213213

214214
public void ScrollToTop() => scrollContainer.ScrollTo(0);
@@ -259,7 +259,7 @@ protected override void UpdateAfterChildren()
259259
updateSectionsMargin();
260260
}
261261

262-
float currentScroll = scrollContainer.Current;
262+
float currentScroll = (float)scrollContainer.Current;
263263

264264
if (currentScroll != lastKnownScroll)
265265
{

osu.Game/Graphics/Containers/UserTrackingScrollContainer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public UserTrackingScrollContainer(Direction direction)
3535
{
3636
}
3737

38-
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
38+
protected override void OnUserScroll(double value, bool animated = true, double? distanceDecay = default)
3939
{
4040
UserScrolling = true;
4141
base.OnUserScroll(value, animated, distanceDecay);
@@ -53,7 +53,7 @@ protected override void ScrollFromMouseEvent(MouseEvent e)
5353
base.ScrollFromMouseEvent(e);
5454
}
5555

56-
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
56+
public new void ScrollTo(double value, bool animated = true, double? distanceDecay = null)
5757
{
5858
UserScrolling = false;
5959
base.ScrollTo(value, animated, distanceDecay);

osu.Game/Online/Leaderboards/Leaderboard.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ protected override void UpdateAfterChildren()
375375
{
376376
base.UpdateAfterChildren();
377377

378-
float fadeBottom = scrollContainer.Current + scrollContainer.DrawHeight;
379-
float fadeTop = scrollContainer.Current + LeaderboardScore.HEIGHT;
378+
float fadeBottom = (float)(scrollContainer.Current + scrollContainer.DrawHeight);
379+
float fadeTop = (float)(scrollContainer.Current + LeaderboardScore.HEIGHT);
380380

381381
if (!scrollContainer.IsScrolledToEnd())
382382
fadeBottom -= LeaderboardScore.HEIGHT;

osu.Game/Overlays/Chat/ChannelScrollContainer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ protected override void UpdateAfterChildren()
4141

4242
#region Scroll handling
4343

44-
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = null)
44+
protected override void OnUserScroll(double value, bool animated = true, double? distanceDecay = null)
4545
{
4646
base.OnUserScroll(value, animated, distanceDecay);
4747
updateTrackState();
4848
}
4949

50-
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
50+
public new void ScrollTo(double value, bool animated = true, double? distanceDecay = null)
5151
{
5252
base.ScrollTo(value, animated, distanceDecay);
5353
updateTrackState();

osu.Game/Overlays/Chat/DrawableChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void processMessageHighlighting() => SchedulerAfterChildren.AddOnce(() =
117117
if (chatLine == null)
118118
return;
119119

120-
float center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2;
120+
double center = scroll.GetChildPosInContent(chatLine, chatLine.DrawSize / 2) - scroll.DisplayableContent / 2;
121121
scroll.ScrollTo(Math.Clamp(center, 0, scroll.ScrollableExtent));
122122
chatLine.Highlight();
123123

osu.Game/Overlays/Mods/ModSelectOverlay.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,13 @@ protected override void Update()
710710

711711
// the bounds below represent the horizontal range of scroll items to be considered fully visible/active, in the scroll's internal coordinate space.
712712
// note that clamping is applied to the left scroll bound to ensure scrolling past extents does not change the set of active columns.
713-
float leftVisibleBound = Math.Clamp(Current, 0, ScrollableExtent);
714-
float rightVisibleBound = leftVisibleBound + DrawWidth;
713+
double leftVisibleBound = Math.Clamp(Current, 0, ScrollableExtent);
714+
double rightVisibleBound = leftVisibleBound + DrawWidth;
715715

716716
// if a movement is occurring at this time, the bounds below represent the full range of columns that the scroll movement will encompass.
717717
// this will be used to ensure that columns do not change state from active to inactive back and forth until they are fully scrolled past.
718-
float leftMovementBound = Math.Min(Current, Target);
719-
float rightMovementBound = Math.Max(Current, Target) + DrawWidth;
718+
double leftMovementBound = Math.Min(Current, Target);
719+
double rightMovementBound = Math.Max(Current, Target) + DrawWidth;
720720

721721
foreach (var column in Child)
722722
{

osu.Game/Overlays/NewsOverlay.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected override void UpdateAfterChildren()
136136
{
137137
base.UpdateAfterChildren();
138138
sidebarContainer.Height = DrawHeight;
139-
sidebarContainer.Y = Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
139+
sidebarContainer.Y = (float)Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
140140
}
141141

142142
private void loadListing(int? year = null)

osu.Game/Overlays/OnlineOverlay.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected override void UpdateAfterChildren()
8888
base.UpdateAfterChildren();
8989

9090
// don't block header by applying padding equal to the visible header height
91-
loadingContainer.Padding = new MarginPadding { Top = Math.Max(0, Header.Height - ScrollFlow.Current) };
91+
loadingContainer.Padding = new MarginPadding { Top = (float)Math.Max(0, Header.Height - ScrollFlow.Current) };
9292
}
9393
}
9494
}

osu.Game/Overlays/OverlayScrollContainer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public partial class OverlayScrollContainer : UserTrackingScrollContainer
3535

3636
public ScrollBackButton Button { get; private set; }
3737

38-
private readonly Bindable<float?> lastScrollTarget = new Bindable<float?>();
38+
private readonly Bindable<double?> lastScrollTarget = new Bindable<double?>();
3939

4040
[BackgroundDependencyLoader]
4141
private void load()
@@ -63,7 +63,7 @@ protected override void UpdateAfterChildren()
6363
Button.State = Target > button_scroll_position || lastScrollTarget.Value != null ? Visibility.Visible : Visibility.Hidden;
6464
}
6565

66-
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
66+
protected override void OnUserScroll(double value, bool animated = true, double? distanceDecay = default)
6767
{
6868
base.OnUserScroll(value, animated, distanceDecay);
6969

@@ -112,7 +112,7 @@ public Visibility State
112112
private readonly Box background;
113113
private readonly SpriteIcon spriteIcon;
114114

115-
public Bindable<float?> LastScrollTarget = new Bindable<float?>();
115+
public Bindable<double?> LastScrollTarget = new Bindable<double?>();
116116

117117
protected override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverSounds();
118118

osu.Game/Overlays/WikiOverlay.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected override void UpdateAfterChildren()
100100
if (articlePage != null)
101101
{
102102
articlePage.SidebarContainer.Height = DrawHeight;
103-
articlePage.SidebarContainer.Y = Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
103+
articlePage.SidebarContainer.Y = (float)Math.Clamp(ScrollFlow.Current - Header.DrawHeight, 0, Math.Max(ScrollFlow.ScrollContent.DrawHeight - DrawHeight - Header.DrawHeight, 0));
104104
}
105105
}
106106

osu.Game/Screens/Edit/Compose/Components/Timeline/Timeline.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public bool AlwaysShowControlPoints
5555
/// <summary>
5656
/// The timeline's scroll position in the last frame.
5757
/// </summary>
58-
private float lastScrollPosition;
58+
private double lastScrollPosition;
5959

6060
/// <summary>
6161
/// The track time in the last frame.
@@ -322,7 +322,7 @@ private void endUserDrag()
322322
/// </summary>
323323
public double VisibleRange => editorClock.TrackLength / Zoom;
324324

325-
public double TimeAtPosition(float x)
325+
public double TimeAtPosition(double x)
326326
{
327327
return x / Content.DrawWidth * editorClock.TrackLength;
328328
}

osu.Game/Screens/Edit/Compose/Components/Timeline/ZoomableScrollContainer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private void setZoomTarget(float newZoom, float? focusPoint = null)
182182
}
183183

184184
private void transformZoomTo(float newZoom, float focusPoint, double duration = 0, Easing easing = Easing.None)
185-
=> this.TransformTo(this.PopulateTransform(new TransformZoom(focusPoint, zoomedContent.DrawWidth, Current), newZoom, duration, easing));
185+
=> this.TransformTo(this.PopulateTransform(new TransformZoom(focusPoint, zoomedContent.DrawWidth, (float)Current), newZoom, duration, easing));
186186

187187
/// <summary>
188188
/// Invoked when <see cref="Zoom"/> has changed.

osu.Game/Screens/Play/HUD/GameplayLeaderboard.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ protected override void Update()
114114

115115
if (requiresScroll && TrackedScore != null)
116116
{
117-
float scrollTarget = scroll.GetChildPosInContent(TrackedScore) + TrackedScore.DrawHeight / 2 - scroll.DrawHeight / 2;
117+
double scrollTarget = scroll.GetChildPosInContent(TrackedScore) + TrackedScore.DrawHeight / 2 - scroll.DrawHeight / 2;
118118

119119
scroll.ScrollTo(scrollTarget);
120120
}
121121

122122
const float panel_height = GameplayLeaderboardScore.PANEL_HEIGHT;
123123

124-
float fadeBottom = scroll.Current + scroll.DrawHeight;
125-
float fadeTop = scroll.Current + panel_height;
124+
float fadeBottom = (float)(scroll.Current + scroll.DrawHeight);
125+
float fadeTop = (float)(scroll.Current + panel_height);
126126

127127
if (scroll.IsScrolledToStart()) fadeTop -= panel_height;
128128
if (!scroll.IsScrolledToEnd()) fadeBottom -= panel_height;

osu.Game/Screens/Ranking/ScorePanelList.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private IEnumerable<ScorePanelTrackingContainer> applySorting(IEnumerable<Drawab
334334

335335
private partial class Scroll : OsuScrollContainer
336336
{
337-
public new float Target => base.Target;
337+
public new double Target => base.Target;
338338

339339
public Scroll()
340340
: base(Direction.Horizontal)
@@ -344,7 +344,7 @@ public Scroll()
344344
/// <summary>
345345
/// The target that will be scrolled to instantaneously next frame.
346346
/// </summary>
347-
public float? InstantScrollTarget;
347+
public double? InstantScrollTarget;
348348

349349
protected override void UpdateAfterChildren()
350350
{

osu.Game/Screens/Select/BeatmapCarousel.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,12 @@ private void select(CarouselItem? item)
611611
/// <summary>
612612
/// The position of the lower visible bound with respect to the current scroll position.
613613
/// </summary>
614-
private float visibleBottomBound => Scroll.Current + DrawHeight + BleedBottom;
614+
private float visibleBottomBound => (float)(Scroll.Current + DrawHeight + BleedBottom);
615615

616616
/// <summary>
617617
/// The position of the upper visible bound with respect to the current scroll position.
618618
/// </summary>
619-
private float visibleUpperBound => Scroll.Current - BleedTop;
619+
private float visibleUpperBound => (float)(Scroll.Current - BleedTop);
620620

621621
public void FlushPendingFilterOperations()
622622
{
@@ -1006,7 +1006,7 @@ private void updateScrollPosition()
10061006
// we take the difference in scroll height and apply to all visible panels.
10071007
// this avoids edge cases like when the visible panels is reduced suddenly, causing ScrollContainer
10081008
// to enter clamp-special-case mode where it animates completely differently to normal.
1009-
float scrollChange = scrollTarget.Value - Scroll.Current;
1009+
float scrollChange = (float)(scrollTarget.Value - Scroll.Current);
10101010
Scroll.ScrollTo(scrollTarget.Value, false);
10111011
foreach (var i in Scroll)
10121012
i.Y += scrollChange;
@@ -1217,20 +1217,20 @@ public PaddedScrollbar()
12171217
private const float top_padding = 10;
12181218
private const float bottom_padding = 70;
12191219

1220-
protected override float ToScrollbarPosition(float scrollPosition)
1220+
protected override float ToScrollbarPosition(double scrollPosition)
12211221
{
12221222
if (Precision.AlmostEquals(0, ScrollableExtent))
12231223
return 0;
12241224

1225-
return top_padding + (ScrollbarMovementExtent - (top_padding + bottom_padding)) * (scrollPosition / ScrollableExtent);
1225+
return (float)(top_padding + (ScrollbarMovementExtent - (top_padding + bottom_padding)) * (scrollPosition / ScrollableExtent));
12261226
}
12271227

12281228
protected override float FromScrollbarPosition(float scrollbarPosition)
12291229
{
12301230
if (Precision.AlmostEquals(0, ScrollbarMovementExtent))
12311231
return 0;
12321232

1233-
return ScrollableExtent * ((scrollbarPosition - top_padding) / (ScrollbarMovementExtent - (top_padding + bottom_padding)));
1233+
return (float)(ScrollableExtent * ((scrollbarPosition - top_padding) / (ScrollbarMovementExtent - (top_padding + bottom_padding))));
12341234
}
12351235
}
12361236
}

0 commit comments

Comments
 (0)