From d80f09e0c0f90b163c3f271e75cdcfc97abd8e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 30 May 2024 12:02:16 +0200 Subject: [PATCH] Adjust online play header to be reusable for new daily challenge screen --- osu.Game/Screens/OnlinePlay/Header.cs | 34 +++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Header.cs b/osu.Game/Screens/OnlinePlay/Header.cs index 4c4851c3ac..860042fd37 100644 --- a/osu.Game/Screens/OnlinePlay/Header.cs +++ b/osu.Game/Screens/OnlinePlay/Header.cs @@ -1,13 +1,11 @@ // Copyright (c) ppy Pty Ltd . 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" } } },