1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-04 06:12:57 +08:00

Apply nullability to GameplayMenuOverlay and use TextFlowContainer for text

This commit is contained in:
Dean Herbert 2023-05-24 17:58:48 +09:00
parent 8ada8b1c8c
commit 456f3005d6

View File

@ -1,12 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Humanizer;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -20,6 +17,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Rulesets.UI;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -38,8 +36,8 @@ namespace osu.Game.Screens.Play
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
public Action OnRetry; public Action? OnRetry;
public Action OnQuit; public Action? OnQuit;
/// <summary> /// <summary>
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered. /// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
@ -53,10 +51,13 @@ namespace osu.Game.Screens.Play
public abstract string Header { get; } public abstract string Header { get; }
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons; protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons = null!;
public IReadOnlyList<DialogButton> Buttons => InternalButtons; public IReadOnlyList<DialogButton> Buttons => InternalButtons;
private FillFlowContainer retryCounterContainer; private TextFlowContainer playInfoText = null!;
[Resolved]
private GlobalActionContainer globalAction { get; set; } = null!;
protected GameplayMenuOverlay() protected GameplayMenuOverlay()
{ {
@ -83,29 +84,14 @@ namespace osu.Game.Screens.Play
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{
new FillFlowContainer
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
Text = Header, Text = Header,
Font = OsuFont.GetFont(size: 30), Font = OsuFont.GetFont(size: 48),
Spacing = new Vector2(5, 0),
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Colour = colours.Yellow, Colour = colours.Yellow,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
},
}
}, },
InternalButtons = new SelectionCycleFillFlowContainer<DialogButton> InternalButtons = new SelectionCycleFillFlowContainer<DialogButton>
{ {
@ -122,10 +108,11 @@ namespace osu.Game.Screens.Play
Radius = 50 Radius = 50
}, },
}, },
retryCounterContainer = new FillFlowContainer playInfoText = new OsuTextFlowContainer(cp => cp.Font = OsuFont.GetFont(size: 18))
{ {
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
TextAnchor = Anchor.TopCentre,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
} }
} }
@ -147,7 +134,8 @@ namespace osu.Game.Screens.Play
return; return;
retries = value; retries = value;
if (retryCounterContainer != null)
if (IsLoaded)
updateRetryCount(); updateRetryCount();
} }
} }
@ -160,7 +148,7 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseMove(MouseMoveEvent e) => true; protected override bool OnMouseMove(MouseMoveEvent e) => true;
protected void AddButton(string text, Color4 colour, Action action) protected void AddButton(string text, Color4 colour, Action? action)
{ {
var button = new Button var button = new Button
{ {
@ -212,30 +200,9 @@ namespace osu.Game.Screens.Play
// "You've retried 1,065 times in this session" // "You've retried 1,065 times in this session"
// "You've retried 1 time in this session" // "You've retried 1 time in this session"
retryCounterContainer.Children = new Drawable[] playInfoText.Clear();
{ playInfoText.AddText("Retry count: ");
new OsuSpriteText playInfoText.AddText(retries.ToString(), cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
{
Text = "You've retried ",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
Font = OsuFont.GetFont(size: 18),
},
new OsuSpriteText
{
Text = "time".ToQuantity(retries),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
},
new OsuSpriteText
{
Text = " in this session",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
Font = OsuFont.GetFont(size: 18),
}
};
} }
private partial class Button : DialogButton private partial class Button : DialogButton
@ -250,9 +217,6 @@ namespace osu.Game.Screens.Play
} }
} }
[Resolved]
private GlobalActionContainer globalAction { get; set; }
protected override bool Handle(UIEvent e) protected override bool Handle(UIEvent e)
{ {
switch (e) switch (e)