2019-01-24 16:43:03 +08: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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-05-17 16:58:34 +08:00
|
|
|
|
using System;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-05-17 16:58:34 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-05-22 16:29:39 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-05-17 16:58:34 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-21 16:03:47 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-05-17 16:58:34 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-06-16 14:58:07 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-05-17 16:58:34 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-26 11:52:01 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
public partial class PageTabControl<T> : OsuTabControl<T>
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new PageTabItem(value);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-26 11:52:01 +08:00
|
|
|
|
public PageTabControl()
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
|
|
|
|
Height = 30;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-12 19:33:30 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
AccentColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class PageTabItem : TabItem<T>, IHasAccentColour
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
2017-05-20 06:50:45 +08:00
|
|
|
|
private const float transition_duration = 100;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-20 06:50:45 +08:00
|
|
|
|
private readonly Box box;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-09 16:01:16 +08:00
|
|
|
|
protected readonly SpriteText Text;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-08-12 19:33:30 +08:00
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
2019-08-12 18:08:15 +08:00
|
|
|
|
{
|
2019-08-12 19:33:30 +08:00
|
|
|
|
get => accentColour;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
box.Colour = accentColour;
|
|
|
|
|
}
|
2019-08-12 18:08:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 16:29:39 +08:00
|
|
|
|
private Sample selectSample = null!;
|
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
|
public PageTabItem(T value)
|
|
|
|
|
: base(value)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 16:58:34 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-06-09 16:01:16 +08:00
|
|
|
|
Text = new OsuSpriteText
|
2017-05-20 03:22:54 +08:00
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 8, Bottom = 8 },
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2019-09-12 10:03:59 +08:00
|
|
|
|
Text = CreateText(),
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 14)
|
2017-05-20 03:22:54 +08:00
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 5,
|
|
|
|
|
Scale = new Vector2(1f, 0f),
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
},
|
2024-05-22 16:29:39 +08:00
|
|
|
|
new HoverSounds(HoverSampleSet.TabSelect)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
};
|
2018-12-29 22:43:19 +08:00
|
|
|
|
|
2020-03-13 12:32:16 +08:00
|
|
|
|
Active.BindValueChanged(active => Text.Font = Text.Font.With(Typeface.Torus, weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium), true);
|
2017-05-17 16:58:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-22 16:29:39 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
selectSample = audio.Samples.Get(@"UI/tabselect-select");
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 14:58:07 +08:00
|
|
|
|
protected virtual LocalisableString CreateText() => (Value as Enum)?.GetLocalisableDescription() ?? Value.ToString();
|
2019-09-12 10:03:59 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
if (!Active.Value)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
slideActive();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
if (!Active.Value)
|
2017-05-17 16:58:34 +08:00
|
|
|
|
slideInactive();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 16:58:34 +08:00
|
|
|
|
private void slideActive()
|
|
|
|
|
{
|
|
|
|
|
box.ScaleTo(new Vector2(1f), transition_duration);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 16:58:34 +08:00
|
|
|
|
private void slideInactive()
|
|
|
|
|
{
|
|
|
|
|
box.ScaleTo(new Vector2(1f, 0f), transition_duration);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-12 17:39:22 +08:00
|
|
|
|
protected override void OnActivated() => slideActive();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-12 17:39:22 +08:00
|
|
|
|
protected override void OnDeactivated() => slideInactive();
|
2024-05-22 16:29:39 +08:00
|
|
|
|
|
|
|
|
|
protected override void OnActivatedByUser() => selectSample.Play();
|
2017-05-17 16:58:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|