osu/osu.Game/Screens/Multi/Header.cs

160 lines
5.3 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
2020-06-25 12:58:40 +00:00
using Humanizer;
2018-05-15 23:34:14 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2018-05-15 23:34:14 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2020-06-25 12:58:40 +00:00
using osu.Framework.Graphics.UserInterface;
2018-05-15 23:34:14 +00:00
using osu.Framework.Screens;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.SearchableList;
using osu.Game.Graphics.Sprites;
using osuTK;
2018-11-20 07:51:59 +00:00
using osuTK.Graphics;
2018-05-15 23:34:14 +00:00
namespace osu.Game.Screens.Multi
{
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
2019-01-23 11:52:00 +00:00
public Header(ScreenStack stack)
2018-05-15 23:34:14 +00:00
{
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
2020-06-25 12:58:40 +00:00
HeaderBreadcrumbControl breadcrumbs;
MultiHeaderTitle title;
2018-05-15 23:34:14 +00:00
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
2020-06-25 12:58:40 +00:00
Colour = Color4Extensions.FromHex(@"#1f1921"),
2018-05-15 23:34:14 +00:00
},
new Container
{
2020-06-25 12:58:40 +00:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2018-05-15 23:34:14 +00:00
RelativeSizeAxes = Axes.Both,
2020-06-25 12:58:40 +00:00
Padding = new MarginPadding { Left = SearchableListOverlay.WIDTH_PADDING + OsuScreen.HORIZONTAL_OVERFLOW_PADDING },
2018-05-15 23:34:14 +00:00
Children = new Drawable[]
{
2019-03-11 17:37:36 +00:00
title = new MultiHeaderTitle
2018-05-15 23:34:14 +00:00
{
Anchor = Anchor.CentreLeft,
2020-06-25 13:22:24 +00:00
Origin = Anchor.BottomLeft,
2018-05-15 23:34:14 +00:00
},
2019-01-23 11:52:00 +00:00
breadcrumbs = new HeaderBreadcrumbControl(stack)
2018-05-15 23:34:14 +00:00
{
Anchor = Anchor.BottomLeft,
2020-06-25 12:58:40 +00:00
Origin = Anchor.BottomLeft
}
2018-05-15 23:34:14 +00:00
},
},
};
2019-03-11 17:37:36 +00:00
breadcrumbs.Current.ValueChanged += screen =>
{
2019-03-11 17:37:36 +00:00
if (screen.NewValue is IMultiplayerSubScreen multiScreen)
title.Screen = multiScreen;
};
2018-05-15 23:34:14 +00:00
breadcrumbs.Current.TriggerChange();
}
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;
public IMultiplayerSubScreen Screen
{
2020-06-25 12:58:40 +00:00
set => pageTitle.Text = value.ShortTitle.Titleize();
}
public MultiHeaderTitle()
{
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.Centre,
Origin = Anchor.Centre,
2020-06-25 12:58:40 +00:00
Font = OsuFont.GetFont(size: 24),
Text = "Multiplayer"
},
2020-06-25 12:58:40 +00:00
dot = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-06-25 12:58:40 +00:00
Font = OsuFont.GetFont(size: 24),
Text = "·"
},
2020-06-25 12:58:40 +00:00
pageTitle = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-06-25 12:58:40 +00:00
Font = OsuFont.GetFont(size: 24),
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-17 09:19:55 +00:00
private class HeaderBreadcrumbControl : ScreenBreadcrumbControl
{
2019-01-23 11:52:00 +00:00
public HeaderBreadcrumbControl(ScreenStack stack)
: base(stack)
2018-05-17 09:19:55 +00:00
{
2020-06-25 12:58:40 +00:00
RelativeSizeAxes = Axes.X;
StripColour = Color4.Transparent;
2018-05-17 09:19:55 +00:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2020-06-25 12:58:40 +00:00
AccentColour = Color4Extensions.FromHex("#e35c99");
}
protected override TabItem<IScreen> CreateTabItem(IScreen value) => new HeaderBreadcrumbTabItem(value)
{
AccentColour = AccentColour
};
private class HeaderBreadcrumbTabItem : BreadcrumbTabItem
{
public HeaderBreadcrumbTabItem(IScreen value)
: base(value)
{
Bar.Colour = Color4.Transparent;
}
2018-05-17 09:19:55 +00:00
}
}
2018-05-15 23:34:14 +00:00
}
}