1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 08:27:49 +08:00

Adjust online play header to be reusable for new daily challenge screen

This commit is contained in:
Bartłomiej Dach 2024-05-30 12:02:16 +02:00
parent 19f39ca1b6
commit d80f09e0c0
No known key found for this signature in database

View File

@ -1,13 +1,11 @@
// 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.
#nullable disable
using Humanizer;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
@ -20,10 +18,10 @@ namespace osu.Game.Screens.OnlinePlay
{
public const float HEIGHT = 80;
private readonly ScreenStack stack;
private readonly ScreenStack? stack;
private readonly MultiHeaderTitle title;
public Header(string mainTitle, ScreenStack stack)
public Header(LocalisableString mainTitle, ScreenStack? stack)
{
this.stack = stack;
@ -37,12 +35,15 @@ namespace osu.Game.Screens.OnlinePlay
Origin = Anchor.CentreLeft,
};
// unnecessary to unbind these as this header has the same lifetime as the screen stack we are attaching to.
stack.ScreenPushed += (_, _) => updateSubScreenTitle();
stack.ScreenExited += (_, _) => updateSubScreenTitle();
if (stack != null)
{
// unnecessary to unbind these as this header has the same lifetime as the screen stack we are attaching to.
stack.ScreenPushed += (_, _) => updateSubScreenTitle();
stack.ScreenExited += (_, _) => updateSubScreenTitle();
}
}
private void updateSubScreenTitle() => title.Screen = stack.CurrentScreen as IOnlinePlaySubScreen;
private void updateSubScreenTitle() => title.Screen = stack?.CurrentScreen as IOnlinePlaySubScreen;
private partial class MultiHeaderTitle : CompositeDrawable
{
@ -51,13 +52,16 @@ namespace osu.Game.Screens.OnlinePlay
private readonly OsuSpriteText dot;
private readonly OsuSpriteText pageTitle;
[CanBeNull]
public IOnlinePlaySubScreen Screen
public IOnlinePlaySubScreen? Screen
{
set => pageTitle.Text = value?.ShortTitle.Titleize() ?? string.Empty;
set
{
pageTitle.Text = value?.ShortTitle.Titleize() ?? default(LocalisableString);
dot.Alpha = pageTitle.Text == default ? 0 : 1;
}
}
public MultiHeaderTitle(string mainTitle)
public MultiHeaderTitle(LocalisableString mainTitle)
{
AutoSizeAxes = Axes.Both;
@ -82,14 +86,14 @@ namespace osu.Game.Screens.OnlinePlay
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.TorusAlternate.With(size: 24),
Text = "·"
Text = "·",
Alpha = 0,
},
pageTitle = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.TorusAlternate.With(size: 24),
Text = "Lounge"
}
}
},