osu/osu.Game/Screens/OnlinePlay/Header.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
3.6 KiB
C#
Raw Normal View History

// 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.
2018-05-15 23:34:14 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
2020-06-25 12:58:40 +00:00
using Humanizer;
2021-08-12 07:52:30 +00:00
using JetBrains.Annotations;
2018-05-15 23:34:14 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2020-09-03 07:28:14 +00:00
using osu.Game.Overlays;
using osuTK;
2018-05-15 23:34:14 +00:00
namespace osu.Game.Screens.OnlinePlay
2018-05-15 23:34:14 +00:00
{
public class Header : Container
{
2020-06-25 13:22:24 +00:00
public const float HEIGHT = 80;
2018-05-15 23:34:14 +00:00
2021-08-12 07:52:30 +00:00
private readonly ScreenStack stack;
private readonly MultiHeaderTitle title;
public Header(string mainTitle, ScreenStack stack)
2018-05-15 23:34:14 +00:00
{
2021-08-12 07:52:30 +00:00
this.stack = stack;
2018-05-15 23:34:14 +00:00
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
2021-08-12 07:52:30 +00:00
Padding = new MarginPadding { Left = WaveOverlayContainer.WIDTH_PADDING };
2018-05-15 23:34:14 +00:00
2021-08-12 07:52:30 +00:00
Child = title = new MultiHeaderTitle(mainTitle)
2018-05-15 23:34:14 +00:00
{
2021-08-12 07:52:30 +00:00
Anchor = Anchor.CentreLeft,
2021-08-12 09:02:00 +00:00
Origin = Anchor.CentreLeft,
2018-05-15 23:34:14 +00:00
};
// unnecessary to unbind these as this header has the same lifetime as the screen stack we are attaching to.
2022-06-24 12:25:23 +00:00
stack.ScreenPushed += (_, _) => updateSubScreenTitle();
stack.ScreenExited += (_, _) => updateSubScreenTitle();
2018-05-15 23:34:14 +00:00
}
2021-08-12 07:52:30 +00:00
private void updateSubScreenTitle() => title.Screen = stack.CurrentScreen as IOnlinePlaySubScreen;
2020-06-25 12:58:40 +00:00
private class MultiHeaderTitle : CompositeDrawable
2019-03-11 17:37:36 +00:00
{
private const float spacing = 6;
2020-06-25 12:58:40 +00:00
private readonly OsuSpriteText dot;
private readonly OsuSpriteText pageTitle;
2021-08-12 07:52:30 +00:00
[CanBeNull]
public IOnlinePlaySubScreen Screen
{
2021-08-12 07:52:30 +00:00
set => pageTitle.Text = value?.ShortTitle.Titleize() ?? string.Empty;
}
public MultiHeaderTitle(string mainTitle)
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(spacing, 0),
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
2020-06-25 12:58:40 +00:00
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.TorusAlternate.With(size: 24),
Text = mainTitle
},
2020-06-25 12:58:40 +00:00
dot = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.TorusAlternate.With(size: 24),
2020-06-25 12:58:40 +00:00
Text = "·"
},
2020-06-25 12:58:40 +00:00
pageTitle = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.TorusAlternate.With(size: 24),
2020-06-25 12:58:40 +00:00
Text = "Lounge"
}
}
},
};
}
2019-03-11 17:37:36 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2020-06-25 12:58:40 +00:00
pageTitle.Colour = dot.Colour = colours.Yellow;
2019-03-11 17:37:36 +00:00
}
}
2018-05-15 23:34:14 +00:00
}
}