2017-03-05 04:07:47 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-03-15 03:19:41 +00:00
|
|
|
|
using System;
|
2017-03-16 02:39:09 +00:00
|
|
|
|
using System.Linq;
|
2017-03-16 13:09:35 +00:00
|
|
|
|
using OpenTK;
|
2017-03-16 00:52:31 +00:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-22 23:44:52 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
2017-03-16 12:17:14 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-03-22 23:44:52 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-03-16 12:17:14 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input;
|
2017-03-22 23:44:52 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-05 04:07:47 +00:00
|
|
|
|
|
2017-03-16 00:11:50 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-03-05 04:07:47 +00:00
|
|
|
|
{
|
2017-03-16 00:11:50 +00:00
|
|
|
|
public class OsuTabControl<T> : TabControl<T>
|
2017-03-05 04:07:47 +00:00
|
|
|
|
{
|
2017-03-22 14:32:32 +00:00
|
|
|
|
protected override Dropdown<T> CreateDropdown() => new OsuTabDropdown();
|
2017-03-05 04:07:47 +00:00
|
|
|
|
|
2017-04-03 09:35:33 +00:00
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem(value);
|
2017-03-08 09:19:00 +00:00
|
|
|
|
|
2017-03-22 14:32:32 +00:00
|
|
|
|
protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || Dropdown.Contains(screenSpacePos);
|
2017-03-16 13:09:35 +00:00
|
|
|
|
|
2017-06-09 11:04:29 +00:00
|
|
|
|
private static bool isEnumType => typeof(T).IsEnum;
|
2017-05-11 14:10:19 +00:00
|
|
|
|
|
2017-03-16 07:35:44 +00:00
|
|
|
|
public OsuTabControl()
|
2017-03-08 09:19:00 +00:00
|
|
|
|
{
|
2017-03-23 03:22:31 +00:00
|
|
|
|
TabContainer.Spacing = new Vector2(10f, 0f);
|
|
|
|
|
|
2017-05-11 14:10:19 +00:00
|
|
|
|
if (isEnumType)
|
|
|
|
|
foreach (var val in (T[])Enum.GetValues(typeof(T)))
|
|
|
|
|
AddItem(val);
|
2017-03-08 09:19:00 +00:00
|
|
|
|
}
|
2017-03-16 00:52:31 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == null)
|
|
|
|
|
AccentColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4? accentColour;
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour.GetValueOrDefault(); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
2017-03-22 14:32:32 +00:00
|
|
|
|
var dropDown = Dropdown as OsuTabDropdown;
|
2017-03-16 02:39:09 +00:00
|
|
|
|
if (dropDown != null)
|
|
|
|
|
dropDown.AccentColour = value;
|
2017-03-22 23:57:14 +00:00
|
|
|
|
foreach (var item in TabContainer.Children.OfType<OsuTabItem>())
|
2017-03-16 00:52:31 +00:00
|
|
|
|
item.AccentColour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-16 12:17:14 +00:00
|
|
|
|
|
2017-05-17 08:58:34 +00:00
|
|
|
|
public class OsuTabItem : TabItem<T>
|
2017-03-22 23:44:52 +00:00
|
|
|
|
{
|
2017-05-17 08:58:34 +00:00
|
|
|
|
protected readonly SpriteText Text;
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Box box;
|
2017-03-22 23:44:52 +00:00
|
|
|
|
|
|
|
|
|
private Color4? accentColour;
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour.GetValueOrDefault(); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
if (!Active)
|
2017-05-17 08:58:34 +00:00
|
|
|
|
Text.Colour = value;
|
2017-03-22 23:44:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const float transition_length = 500;
|
|
|
|
|
|
|
|
|
|
private void fadeActive()
|
|
|
|
|
{
|
|
|
|
|
box.FadeIn(transition_length, EasingTypes.OutQuint);
|
2017-05-17 08:58:34 +00:00
|
|
|
|
Text.FadeColour(Color4.White, transition_length, EasingTypes.OutQuint);
|
2017-03-22 23:44:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fadeInactive()
|
|
|
|
|
{
|
|
|
|
|
box.FadeOut(transition_length, EasingTypes.OutQuint);
|
2017-05-17 08:58:34 +00:00
|
|
|
|
Text.FadeColour(AccentColour, transition_length, EasingTypes.OutQuint);
|
2017-03-22 23:44:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (!Active)
|
|
|
|
|
fadeActive();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (!Active)
|
|
|
|
|
fadeInactive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == null)
|
|
|
|
|
AccentColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 09:35:33 +00:00
|
|
|
|
public OsuTabItem(T value) : base(value)
|
2017-03-22 23:44:52 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-17 08:58:34 +00:00
|
|
|
|
Text = new OsuSpriteText
|
2017-04-03 09:35:33 +00:00
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Top = 5, Bottom = 5 },
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-05-11 14:10:19 +00:00
|
|
|
|
Text = (value as Enum)?.GetDescription() ?? value.ToString(),
|
2017-04-03 09:35:33 +00:00
|
|
|
|
TextSize = 14,
|
|
|
|
|
Font = @"Exo2.0-Bold", // Font should only turn bold when active?
|
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 1,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
}
|
2017-03-22 23:44:52 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2017-06-12 09:39:22 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => fadeActive();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => fadeInactive();
|
2017-03-22 23:44:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class OsuTabDropdown : OsuDropdown<T>
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
2017-03-22 14:32:32 +00:00
|
|
|
|
protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
AccentColour = AccentColour,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-22 14:32:32 +00:00
|
|
|
|
protected override DropdownMenuItem<T> CreateMenuItem(string text, T value)
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
2017-03-21 23:55:47 +00:00
|
|
|
|
var item = base.CreateMenuItem(text, value);
|
2017-03-16 12:17:14 +00:00
|
|
|
|
item.ForegroundColourHover = Color4.Black;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 14:32:32 +00:00
|
|
|
|
public OsuTabDropdown()
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
2017-03-22 14:32:32 +00:00
|
|
|
|
DropdownMenu.Anchor = Anchor.TopRight;
|
|
|
|
|
DropdownMenu.Origin = Anchor.TopRight;
|
2017-03-16 12:17:14 +00:00
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
2017-03-22 14:32:32 +00:00
|
|
|
|
DropdownMenu.Background.Colour = Color4.Black.Opacity(0.7f);
|
|
|
|
|
DropdownMenu.MaxHeight = 400;
|
2017-03-16 12:17:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 23:44:52 +00:00
|
|
|
|
protected class OsuTabDropdownHeader : OsuDropdownHeader
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
public override Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return base.AccentColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.AccentColour = value;
|
|
|
|
|
Foreground.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
Foreground.Colour = BackgroundColour;
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
Foreground.Colour = BackgroundColourHover;
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-22 14:32:32 +00:00
|
|
|
|
public OsuTabDropdownHeader()
|
2017-03-16 12:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None;
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.5f);
|
|
|
|
|
|
|
|
|
|
Background.Height = 0.5f;
|
|
|
|
|
Background.CornerRadius = 5;
|
|
|
|
|
Background.Masking = true;
|
|
|
|
|
|
|
|
|
|
Foreground.RelativeSizeAxes = Axes.None;
|
|
|
|
|
Foreground.AutoSizeAxes = Axes.X;
|
|
|
|
|
Foreground.RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Foreground.Margin = new MarginPadding(5);
|
|
|
|
|
|
|
|
|
|
Foreground.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_ellipsis_h,
|
|
|
|
|
TextSize = 14,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Padding = new MarginPadding { Left = 5, Right = 5 };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-05 04:07:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|