1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-15 11:47:18 +08:00

Sort on SortTabs ValueChanged

This commit is contained in:
Kelvin 2017-03-14 20:19:41 -07:00
parent 755fb260db
commit 20e2e7a8c8
5 changed files with 79 additions and 76 deletions

View File

@ -7,7 +7,6 @@ namespace osu.Game.Screens.Select.Filter
{
public enum GroupMode
{
None = 0,
[Description("All")]
All,
[Description("Artist")]

View File

@ -7,7 +7,6 @@ namespace osu.Game.Screens.Select.Filter
{
public enum SortMode
{
None = 0,
[Description("Artist")]
Artist,
[Description("Author")]

View File

@ -2,9 +2,9 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
@ -36,6 +36,23 @@ namespace osu.Game.Screens.Select
}
}
private GroupMode group = GroupMode.All;
public GroupMode Group {
get { return group; }
set
{
if (group != value)
{
group = value;
FilterChanged?.Invoke();
}
}
}
private TabControl<GroupMode> groupTabs;
private TabControl<SortMode> sortTabs;
private OsuSpriteText spriteText;
public Action Exit;
private SearchTextBox searchTextBox;
@ -72,10 +89,61 @@ namespace osu.Game.Screens.Select
},
Exit = () => Exit?.Invoke(),
},
new GroupSortTabs()
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = OsuColour.Gray(80),
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Position = new Vector2(0, 23)
},
groupTabs = new FilterTabControl<GroupMode>
{
Width = 230,
AutoSort = true
},
new Container
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Children = new Drawable[]
{
spriteText = new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = "Sort results by",
TextSize = 14,
Margin = new MarginPadding
{
Top = 5,
Bottom = 5
},
},
sortTabs = new FilterTabControl<SortMode>(87)
{
Width = 191,
AutoSort = true
}
}
}
}
}
}
}
};
groupTabs.PinTab(GroupMode.All);
groupTabs.PinTab(GroupMode.RecentlyPlayed);
groupTabs.ValueChanged += (sender, value) => Group = value;
sortTabs.ValueChanged += (sender, value) => Sort = value;
}
public void Deactivate()
@ -89,66 +157,10 @@ namespace osu.Game.Screens.Select
searchTextBox.HoldFocus = true;
}
private class GroupSortTabs : Container
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
private TabControl<GroupMode> groupTabs;
private TabControl<SortMode> sortTabs;
private OsuSpriteText spriteText;
public GroupSortTabs()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = OsuColour.Gray(80),
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Position = new Vector2(0, 23)
},
groupTabs = new FilterTabControl<GroupMode>
{
Width = 230,
AutoSort = true
},
new Container
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Children = new Drawable[]
{
spriteText = new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = "Sort results by",
TextSize = 14,
Margin = new MarginPadding
{
Top = 5,
Bottom = 5
},
},
sortTabs = new FilterTabControl<SortMode>(87)
{
Width = 191,
AutoSort = true
}
}
}
};
groupTabs.PinTab(GroupMode.All);
groupTabs.PinTab(GroupMode.RecentlyPlayed);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours) {
spriteText.Colour = colours.GreenLight;
}
spriteText.Colour = colours.GreenLight;
}
}
}

View File

@ -1,6 +1,7 @@
// 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.Screens.Select.Tab
@ -13,6 +14,11 @@ namespace osu.Game.Screens.Select.Tab
public FilterTabControl(float offset = 0) : base(offset)
{
if (!typeof(T).IsEnum)
throw new InvalidOperationException("FilterTabControl only supports enums as the generic type argument");
foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddTab(val);
}
}
}

View File

@ -34,19 +34,6 @@ namespace osu.Game.Screens.Select.Tab
ContentBackground.Colour = Color4.Black.Opacity(0.9f);
ScrollContainer.ScrollDraggerVisible = false;
DropDownItemsContainer.Padding = new MarginPadding { Left = 5, Bottom = 7, Right = 5, Top = 7 };
if (!typeof(T).IsEnum)
throw new InvalidOperationException("TabControl only supports enums as the generic type argument");
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, T>>();
foreach (var val in (T[])Enum.GetValues(typeof(T)))
{
if (!val.Equals(default(T)))
items.Add(new KeyValuePair<string, T>((val as Enum)?.GetDescription(), val));
}
Items = items;
// TODO: ValueChanged Handling
}
protected override void AnimateOpen()