Rearrange things somewhat

This commit is contained in:
Drew DeVault
2017-03-15 20:11:50 -04:00
parent cac6c42aac
commit 3aecbf5739
8 changed files with 40 additions and 35 deletions

View File

@ -0,0 +1,24 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics.UserInterface.Tab;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabControl<T> : TabControl<T>
{
protected override TabDropDownMenu<T> CreateDropDownMenu() => new OsuTabDropDownMenu<T>();
protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem<T> { Value = value };
public OsuTabControl(float offset = 0) : base(offset)
{
if (!typeof(T).IsEnum)
throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument");
foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddTab(val);
}
}
}

View File

@ -0,0 +1,30 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Game.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropDownHeader : TabDropDownHeader
{
protected override string Label { get; set; }
public OsuTabDropDownHeader()
{
Foreground.Children = new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
TextSize = 14,
Margin = new MarginPadding{ Top = 6, Bottom = 4 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
};
}
}
}

View File

@ -0,0 +1,56 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Game.Graphics;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropDownMenu<T> : TabDropDownMenu<T>
{
public override float HeaderWidth => 14;
public override float HeaderHeight => 24;
protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader();
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) => new OsuTabDropDownMenuItem<T>(key, value);
public OsuTabDropDownMenu()
{
MaxDropDownHeight = int.MaxValue;
ContentContainer.CornerRadius = 4;
ContentBackground.Colour = Color4.Black.Opacity(0.9f);
ScrollContainer.ScrollDraggerVisible = false;
DropDownItemsContainer.Padding = new MarginPadding { Left = 5, Bottom = 7, Right = 5, Top = 7 };
}
protected override void AnimateOpen()
{
ContentContainer.FadeIn(300, EasingTypes.OutQuint);
}
protected override void AnimateClose()
{
ContentContainer.FadeOut(300, EasingTypes.OutQuint);
}
protected override void UpdateContentHeight()
{
ContentContainer.ResizeTo(new Vector2(1, State == DropDownMenuState.Opened ? ContentHeight : 0), 300, EasingTypes.OutQuint);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Header.Colour = typeof(T) == typeof(SortMode) ? colours.GreenLight : colours.Blue;
}
}
}

View File

@ -0,0 +1,52 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using OpenTK.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabDropDownMenuItem<T> : DropDownMenuItem<T>
{
public OsuTabDropDownMenuItem(string text, T value) : base(text, value)
{
Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4 };
Foreground.Margin = new MarginPadding { Left = 7 };
Masking = true;
CornerRadius = 6;
Foreground.Add(new OsuSpriteText
{
Text = text,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = Color4.Black.Opacity(0f);
ForegroundColourHover = Color4.Black;
ForegroundColourSelected = Color4.Black;
if (typeof(T) == typeof(SortMode))
{
BackgroundColourHover = colours.GreenLight;
BackgroundColourSelected = colours.GreenLight;
}
else
{
BackgroundColourHover = colours.Blue;
BackgroundColourSelected = colours.Blue;
}
}
}
}

View File

@ -0,0 +1,111 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTabItem<T> : TabItem<T>
{
private SpriteText text;
private Box box;
private Color4 fadeColour;
public new T Value
{
get { return base.Value; }
set
{
base.Value = value;
text.Text = (value as Enum)?.GetDescription();
}
}
public override bool Active
{
get { return base.Active; }
set
{
if (value)
fadeActive();
else
fadeInactive();
base.Active = value;
}
}
private void fadeActive()
{
box.FadeIn(300);
text.FadeColour(Color4.White, 300);
}
private void fadeInactive()
{
box.FadeOut(300);
text.FadeColour(fadeColour, 300);
}
protected override bool OnHover(InputState state) {
if (!Active)
fadeActive();
return true;
}
protected override void OnHoverLost(InputState state) {
if (!Active)
fadeInactive();
}
public OsuTabItem()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
text = new OsuSpriteText
{
Margin = new MarginPadding(5),
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,
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (typeof(T) == typeof(SortMode))
{
fadeColour = colours.GreenLight;
if (!Active)
text.Colour = colours.GreenLight;
}
else
{
fadeColour = colours.Blue;
if (!Active)
text.Colour = colours.Blue;
}
}
}
}