1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 21:52:54 +08:00

Update HUDOverlay logic to add automatic layout for bottom-aligned components

This commit is contained in:
Dean Herbert 2021-05-17 18:26:30 +09:00
parent da0913ca2d
commit 0c433cda86

View File

@ -35,8 +35,12 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public float TopScoringElementsHeight { get; private set; } public float TopScoringElementsHeight { get; private set; }
/// <summary>
/// The total height of all the bottom of screen scoring elements.
/// </summary>
public float BottomScoringElementsHeight { get; private set; }
public readonly KeyCounterDisplay KeyCounter; public readonly KeyCounterDisplay KeyCounter;
public readonly SongProgress Progress;
public readonly ModDisplay ModDisplay; public readonly ModDisplay ModDisplay;
public readonly HoldForMenuButton HoldToQuit; public readonly HoldForMenuButton HoldToQuit;
public readonly PlayerSettingsOverlay PlayerSettingsOverlay; public readonly PlayerSettingsOverlay PlayerSettingsOverlay;
@ -59,8 +63,6 @@ namespace osu.Game.Screens.Play
private static bool hasShownNotificationOnce; private static bool hasShownNotificationOnce;
public Action<double> RequestSeek;
private readonly FillFlowContainer bottomRightElements; private readonly FillFlowContainer bottomRightElements;
private readonly FillFlowContainer topRightElements; private readonly FillFlowContainer topRightElements;
@ -85,45 +87,22 @@ namespace osu.Game.Screens.Play
visibilityContainer = new Container visibilityContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new GridContainer Children = new Drawable[]
{ {
RelativeSizeAxes = Axes.Both, mainComponents = new SkinnableTargetContainer(SkinnableTarget.MainHUDComponents)
Content = new[]
{ {
new Drawable[] RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{ {
new Container // still need to be migrated; a bit more involved.
{ new HitErrorDisplay(this.drawableRuleset?.FirstAvailableHitWindows),
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
mainComponents = new SkinnableTargetContainer(SkinnableTarget.MainHUDComponents)
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
// still need to be migrated; a bit more involved.
new HitErrorDisplay(this.drawableRuleset?.FirstAvailableHitWindows),
}
},
}
},
},
new Drawable[]
{
Progress = CreateProgress(),
} }
}, },
RowDimensions = new[] }
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
}
},
}, },
topRightElements = new FillFlowContainer topRightElements = new FillFlowContainer
{ {
@ -164,10 +143,6 @@ namespace osu.Game.Screens.Play
if (drawableRuleset != null) if (drawableRuleset != null)
{ {
BindDrawableRuleset(drawableRuleset); BindDrawableRuleset(drawableRuleset);
Progress.Objects = drawableRuleset.Objects;
Progress.RequestSeek = time => RequestSeek(time);
Progress.ReferenceClock = drawableRuleset.FrameStableClock;
} }
ModDisplay.Current.Value = mods; ModDisplay.Current.Value = mods;
@ -206,26 +181,43 @@ namespace osu.Game.Screens.Play
{ {
base.Update(); base.Update();
Vector2 lowestScreenSpace = Vector2.Zero; Vector2? lowestTopScreenSpace = null;
Vector2? highestBottomScreenSpace = null;
// LINQ cast can be removed when IDrawable interface includes Anchor / RelativeSizeAxes. // LINQ cast can be removed when IDrawable interface includes Anchor / RelativeSizeAxes.
foreach (var element in mainComponents.Components.Cast<Drawable>()) foreach (var element in mainComponents.Components.Cast<Drawable>())
{ {
// for now align top-right components with the bottom-edge of the lowest top-anchored hud element. // for now align top-right components with the bottom-edge of the lowest top-anchored hud element.
if (!element.Anchor.HasFlagFast(Anchor.TopRight) && !element.RelativeSizeAxes.HasFlagFast(Axes.X)) if (!element.RelativeSizeAxes.HasFlagFast(Axes.X))
continue; continue;
// health bars are excluded for the sake of hacky legacy skins which extend the health bar to take up the full screen area. if (element.Anchor.HasFlagFast(Anchor.TopRight))
if (element is LegacyHealthDisplay) {
continue; // health bars are excluded for the sake of hacky legacy skins which extend the health bar to take up the full screen area.
if (element is LegacyHealthDisplay)
continue;
var bottomRight = element.ScreenSpaceDrawQuad.BottomRight; var bottomRight = element.ScreenSpaceDrawQuad.BottomRight;
if (bottomRight.Y > lowestScreenSpace.Y) if (lowestTopScreenSpace == null || bottomRight.Y > lowestTopScreenSpace.Value.Y)
lowestScreenSpace = bottomRight; lowestTopScreenSpace = bottomRight;
}
else if (element.Anchor.HasFlagFast(Anchor.y2))
{
var topLeft = element.ScreenSpaceDrawQuad.TopLeft;
if (highestBottomScreenSpace == null || topLeft.Y < highestBottomScreenSpace.Value.Y)
highestBottomScreenSpace = topLeft;
}
} }
topRightElements.Y = TopScoringElementsHeight = ToLocalSpace(lowestScreenSpace).Y; if (lowestTopScreenSpace.HasValue)
bottomRightElements.Y = -Progress.Height; topRightElements.Y = TopScoringElementsHeight = ToLocalSpace(lowestTopScreenSpace.Value).Y;
else
topRightElements.Y = 0;
if (highestBottomScreenSpace.HasValue)
bottomRightElements.Y = BottomScoringElementsHeight = -(DrawHeight - ToLocalSpace(highestBottomScreenSpace.Value).Y);
else
bottomRightElements.Y = 0;
} }
private void updateVisibility() private void updateVisibility()
@ -281,8 +273,6 @@ namespace osu.Game.Screens.Play
(drawableRuleset as ICanAttachKeyCounter)?.Attach(KeyCounter); (drawableRuleset as ICanAttachKeyCounter)?.Attach(KeyCounter);
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded); replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
Progress.BindDrawableRuleset(drawableRuleset);
} }
protected FailingLayer CreateFailingLayer() => new FailingLayer protected FailingLayer CreateFailingLayer() => new FailingLayer
@ -296,13 +286,6 @@ namespace osu.Game.Screens.Play
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
}; };
protected SongProgress CreateProgress() => new SongProgress
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
};
protected HoldForMenuButton CreateHoldForMenuButton() => new HoldForMenuButton protected HoldForMenuButton CreateHoldForMenuButton() => new HoldForMenuButton
{ {
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,