1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 20:53:00 +08:00

Don't depend on parent sizing

This commit is contained in:
David Zhao 2019-07-25 17:32:21 +09:00
parent c4bed0e6d2
commit 97eb5293a8
4 changed files with 28 additions and 26 deletions

View File

@ -426,19 +426,18 @@ namespace osu.Game.Screens.Select
if (!scrollPositionCache.IsValid)
updateScrollPosition();
// The draw positions of individual sets extend beyond the size of the carousel and into its parent
// As a result, this should use the Parent's draw height instead.
float drawHeight = Parent.DrawHeight;
// The draw positions of individual sets extend beyond the size of the carousel and into the footer and header.
float visibleHeight = DrawHeight + SongSelect.FOOTER_HEIGHT + SongSelect.FILTER_CONTROL_HEIGHT;
// Remove all items that should no longer be on-screen
scrollableContent.RemoveAll(p => p.Y < Current - p.DrawHeight || p.Y > Current + drawHeight || !p.IsPresent);
scrollableContent.RemoveAll(p => p.Y < Current - p.DrawHeight || p.Y > Current + visibleHeight || !p.IsPresent);
// Find index range of all items that should be on-screen
Trace.Assert(Items.Count == yPositions.Count);
int firstIndex = yPositions.BinarySearch(Current - DrawableCarouselItem.MAX_HEIGHT - Parent.Padding.Top);
int firstIndex = yPositions.BinarySearch(Current - DrawableCarouselItem.MAX_HEIGHT - SongSelect.FILTER_CONTROL_HEIGHT);
if (firstIndex < 0) firstIndex = ~firstIndex;
int lastIndex = yPositions.BinarySearch(Current + drawHeight + Parent.Padding.Bottom);
int lastIndex = yPositions.BinarySearch(Current + visibleHeight + SongSelect.FOOTER_HEIGHT);
if (lastIndex < 0) lastIndex = ~lastIndex;
int notVisibleCount = 0;
@ -490,7 +489,7 @@ namespace osu.Game.Screens.Select
// Update externally controlled state of currently visible items
// (e.g. x-offset and opacity).
float halfHeight = drawHeight / 2;
float halfHeight = visibleHeight / 2;
foreach (DrawableCarouselItem p in scrollableContent.Children)
updateItem(p, halfHeight);
}
@ -546,7 +545,8 @@ namespace osu.Game.Screens.Select
yPositions.Clear();
float currentY = DrawHeight / 2;
float visibleHeight = DrawHeight + SongSelect.FOOTER_HEIGHT + SongSelect.FILTER_CONTROL_HEIGHT;
float currentY = visibleHeight / 2;
DrawableCarouselBeatmapSet lastSet = null;
scrollTarget = null;
@ -600,7 +600,7 @@ namespace osu.Game.Screens.Select
currentY += d.DrawHeight + 5;
}
currentY += DrawHeight / 2;
currentY += visibleHeight / 2;
scrollableContent.Height = currentY;
if (BeatmapSetsLoaded && (selectedBeatmapSet == null || selectedBeatmap == null || selectedBeatmapSet.State.Value != CarouselItemState.Selected))
@ -641,19 +641,19 @@ namespace osu.Game.Screens.Select
/// the current scroll position.
/// </summary>
/// <param name="p">The item to be updated.</param>
/// <param name="parentHalfHeight">Half the draw height of the carousel container's parent.</param>
private void updateItem(DrawableCarouselItem p, float parentHalfHeight)
/// <param name="halfHeight">Half the draw height of the carousel container's parent.</param>
private void updateItem(DrawableCarouselItem p, float halfHeight)
{
var height = p.IsPresent ? p.DrawHeight : 0;
// The actual Y position of the item needs to be offset by any potential padding set by the container's parent.
float itemDrawY = p.Position.Y - Current + Parent.Padding.Top + height / 2;
float dist = Math.Abs(1f - itemDrawY / parentHalfHeight);
float itemDrawY = p.Position.Y + SongSelect.FILTER_CONTROL_HEIGHT - Current + height / 2;
float dist = Math.Abs(1f - itemDrawY / halfHeight);
// Setting the origin position serves as an additive position on top of potential
// local transformation we may want to apply (e.g. when a item gets selected, we
// may want to smoothly transform it leftwards.)
p.OriginPosition = new Vector2(-offsetX(dist, parentHalfHeight), 0);
p.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0);
// We are applying a multiplicative alpha (which is internally done by nesting an
// additional container and setting that container's alpha) such that we can

View File

@ -14,7 +14,6 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Select.Filter;
using Container = osu.Framework.Graphics.Containers.Container;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osu.Game.Rulesets;

View File

@ -62,10 +62,6 @@ namespace osu.Game.Screens.Select
public Footer()
{
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Children = new Drawable[]
{
new Box

View File

@ -43,9 +43,10 @@ namespace osu.Game.Screens.Select
{
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245);
public const float FILTER_CONTROL_HEIGHT = 100;
public const float FOOTER_HEIGHT = 50;
protected const float BACKGROUND_BLUR = 20;
private const float left_area_padding = 20;
private const float filter_control_height = 100;
public readonly FilterControl FilterControl;
@ -122,7 +123,7 @@ namespace osu.Game.Screens.Select
Size = new Vector2(wedged_container_size.X, 1),
Padding = new MarginPadding
{
Bottom = Footer.HEIGHT,
Bottom = FOOTER_HEIGHT,
Top = wedged_container_size.Y + left_area_padding,
Left = left_area_padding,
Right = left_area_padding * 2,
@ -153,8 +154,8 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Top = filter_control_height,
Bottom = Footer.HEIGHT
Top = FILTER_CONTROL_HEIGHT,
Bottom = FOOTER_HEIGHT
},
Child = Carousel = new BeatmapCarousel
{
@ -170,7 +171,7 @@ namespace osu.Game.Screens.Select
FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = filter_control_height,
Height = FILTER_CONTROL_HEIGHT,
FilterChanged = c => Carousel.Filter(c),
Background = { Width = 2 },
Exit = () =>
@ -209,7 +210,7 @@ namespace osu.Game.Screens.Select
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Bottom = Footer.HEIGHT },
Margin = new MarginPadding { Bottom = FOOTER_HEIGHT },
Children = new Drawable[]
{
BeatmapOptions = new BeatmapOptionsOverlay(),
@ -221,7 +222,13 @@ namespace osu.Game.Screens.Select
}
}
},
Footer = new Footer()
Footer = new Footer
{
RelativeSizeAxes = Axes.X,
Height = FOOTER_HEIGHT,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
}
});
}