2019-12-28 01:57:41 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
2020-10-28 08:19:01 +00:00
|
|
|
|
using System;
|
2020-01-21 03:03:48 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2020-01-15 19:41:22 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-02-03 17:20:35 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-10-28 08:19:01 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
2020-01-03 06:01:42 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-21 03:00:12 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-12-31 15:12:03 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-01-03 06:01:42 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2020-01-21 03:00:12 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2019-12-31 15:12:03 +00:00
|
|
|
|
|
2019-12-28 01:57:41 +00:00
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2020-01-21 03:00:12 +00:00
|
|
|
|
/// <summary>
|
2020-01-24 07:24:44 +00:00
|
|
|
|
/// An overlay header which contains a <see cref="OsuTabControl{T}"/>.
|
2020-01-21 03:00:12 +00:00
|
|
|
|
/// </summary>
|
2020-01-24 07:24:44 +00:00
|
|
|
|
/// <typeparam name="T">The type of item to be represented by tabs.</typeparam>
|
2020-02-03 21:43:04 +00:00
|
|
|
|
public abstract class TabControlOverlayHeader<T> : OverlayHeader, IHasCurrentValue<T>
|
2019-12-28 01:57:41 +00:00
|
|
|
|
{
|
2020-01-21 03:00:12 +00:00
|
|
|
|
protected OsuTabControl<T> TabControl;
|
2019-12-31 15:12:03 +00:00
|
|
|
|
|
2020-03-26 14:43:48 +00:00
|
|
|
|
private readonly Box controlBackground;
|
2020-07-21 17:02:22 +00:00
|
|
|
|
private readonly Container tabControlContainer;
|
2020-02-03 21:43:04 +00:00
|
|
|
|
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
|
|
|
|
|
|
|
|
|
public Bindable<T> Current
|
|
|
|
|
{
|
|
|
|
|
get => current.Current;
|
|
|
|
|
set => current.Current = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-21 17:02:22 +00:00
|
|
|
|
protected new float ContentSidePadding
|
|
|
|
|
{
|
|
|
|
|
get => base.ContentSidePadding;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.ContentSidePadding = value;
|
|
|
|
|
tabControlContainer.Padding = new MarginPadding { Horizontal = value };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-26 13:35:07 +00:00
|
|
|
|
protected TabControlOverlayHeader()
|
2020-01-15 19:41:22 +00:00
|
|
|
|
{
|
2020-01-21 03:00:12 +00:00
|
|
|
|
HeaderInfo.Add(new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
controlBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2020-07-21 17:02:22 +00:00
|
|
|
|
tabControlContainer = new Container
|
2020-02-03 17:20:35 +00:00
|
|
|
|
{
|
2020-07-21 17:02:22 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = ContentSidePadding },
|
|
|
|
|
Child = TabControl = CreateTabControl().With(control =>
|
|
|
|
|
{
|
|
|
|
|
control.Current = Current;
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-01-21 03:00:12 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2020-01-15 19:41:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-01-24 09:33:34 +00:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2020-01-15 19:41:22 +00:00
|
|
|
|
{
|
2020-01-26 13:35:07 +00:00
|
|
|
|
controlBackground.Colour = colourProvider.Dark4;
|
2020-01-15 19:41:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 03:03:48 +00:00
|
|
|
|
[NotNull]
|
2020-01-21 03:00:12 +00:00
|
|
|
|
protected virtual OsuTabControl<T> CreateTabControl() => new OverlayHeaderTabControl();
|
|
|
|
|
|
2020-01-07 21:41:52 +00:00
|
|
|
|
public class OverlayHeaderTabControl : OverlayTabControl<T>
|
2020-01-03 06:01:42 +00:00
|
|
|
|
{
|
2020-03-26 14:43:48 +00:00
|
|
|
|
private const float bar_height = 1;
|
|
|
|
|
|
2020-01-03 06:01:42 +00:00
|
|
|
|
public OverlayHeaderTabControl()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None;
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
2020-03-26 14:43:48 +00:00
|
|
|
|
Height = 47;
|
|
|
|
|
BarHeight = bar_height;
|
2020-01-03 06:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-21 03:00:12 +00:00
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new OverlayHeaderTabItem(value);
|
2020-01-03 06:01:42 +00:00
|
|
|
|
|
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private class OverlayHeaderTabItem : OverlayTabItem
|
|
|
|
|
{
|
2020-01-07 21:41:52 +00:00
|
|
|
|
public OverlayHeaderTabItem(T value)
|
2020-01-03 06:01:42 +00:00
|
|
|
|
: base(value)
|
|
|
|
|
{
|
2021-06-16 06:58:07 +00:00
|
|
|
|
if (!(Value is Enum enumValue))
|
|
|
|
|
Text.Text = Value.ToString().ToLower();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var localisableDescription = enumValue.GetLocalisableDescription();
|
2021-10-27 04:04:41 +00:00
|
|
|
|
string nonLocalisableDescription = enumValue.GetDescription();
|
2021-06-16 06:58:07 +00:00
|
|
|
|
|
|
|
|
|
// If localisable == non-localisable, then we must have a basic string, so .ToLower() is used.
|
|
|
|
|
Text.Text = localisableDescription.Equals(nonLocalisableDescription)
|
|
|
|
|
? nonLocalisableDescription.ToLower()
|
|
|
|
|
: localisableDescription;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 06:01:42 +00:00
|
|
|
|
Text.Font = OsuFont.GetFont(size: 14);
|
2020-03-26 14:43:48 +00:00
|
|
|
|
Text.Margin = new MarginPadding { Vertical = 16.5f }; // 15px padding + 1.5px line-height difference compensation
|
|
|
|
|
Bar.Margin = new MarginPadding { Bottom = bar_height };
|
2020-01-03 06:01:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-28 01:57:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|