1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 20:56:12 +08:00

Add FilterControl and FilterTabControl

This commit is contained in:
Kelvin 2017-03-04 20:07:47 -08:00
parent 1317198628
commit 2629f78afc
13 changed files with 397 additions and 197 deletions

@ -1 +1 @@
Subproject commit 4f9ed4e703777ede98737c7e2af31efa4694c395
Subproject commit 51f2b9b37f38cd349a3dd728a78f8fffcb3a54f5

View File

@ -8,6 +8,7 @@ using osu.Framework.MathUtils;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
namespace osu.Desktop.VisualTests.Tests
{
@ -39,10 +40,10 @@ namespace osu.Desktop.VisualTests.Tests
Add(songSelect = new PlaySongSelect());
AddButton(@"Sort by Artist", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Artist; });
AddButton(@"Sort by Title", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Title; });
AddButton(@"Sort by Author", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Author; });
AddButton(@"Sort by Difficulty", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Difficulty; });
AddButton(@"Sort by Artist", delegate { songSelect.Filter.Sort = SortMode.Artist; });
AddButton(@"Sort by Title", delegate { songSelect.Filter.Sort = SortMode.Title; });
AddButton(@"Sort by Author", delegate { songSelect.Filter.Sort = SortMode.Author; });
AddButton(@"Sort by Difficulty", delegate { songSelect.Filter.Sort = SortMode.Difficulty; });
}
protected override void Dispose(bool isDisposing)

View File

@ -11,7 +11,7 @@ namespace osu.Game.Graphics.UserInterface
{
public class OsuDropDownMenu<U> : DropDownMenu<U>
{
protected override DropDownHeader CreateHeader() => new OsuDropDownHeader();
protected override BasicDropDownHeader CreateHeader() => new OsuDropDownHeader();
public OsuDropDownMenu()
{

View File

@ -15,6 +15,7 @@ using OpenTK.Input;
using System.Collections;
using osu.Framework.MathUtils;
using System.Diagnostics;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select
{
@ -157,21 +158,21 @@ namespace osu.Game.Screens.Select
ScrollTo(selectedY, animated);
}
public void Sort(FilterControl.SortMode mode)
public void Sort(SortMode mode)
{
List<BeatmapGroup> sortedGroups = new List<BeatmapGroup>(groups);
switch (mode)
{
case FilterControl.SortMode.Artist:
case SortMode.Artist:
sortedGroups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Artist, y.BeatmapSet.Metadata.Artist, StringComparison.InvariantCultureIgnoreCase));
break;
case FilterControl.SortMode.Title:
case SortMode.Title:
sortedGroups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Title, y.BeatmapSet.Metadata.Title, StringComparison.InvariantCultureIgnoreCase));
break;
case FilterControl.SortMode.Author:
case SortMode.Author:
sortedGroups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Author, y.BeatmapSet.Metadata.Author, StringComparison.InvariantCultureIgnoreCase));
break;
case FilterControl.SortMode.Difficulty:
case SortMode.Difficulty:
sortedGroups.Sort((x, y) =>
{
float xAverage = 0, yAverage = 0;

View File

@ -0,0 +1,42 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using System.ComponentModel;
namespace osu.Game.Screens.Select.Filter
{
public enum GroupMode
{
None = 0,
[Description("All")]
All,
[Description("Artist")]
Artist,
[Description("Author")]
Author,
[Description("BPM")]
BPM,
[Description("Collections")]
Collections,
[Description("Date Added")]
DateAdded,
[Description("Difficulty")]
Difficulty,
[Description("Favorites")]
Favorites,
[Description("Length")]
Length,
[Description("My Maps")]
MyMaps,
[Description("No Grouping")]
NoGrouping,
[Description("Rank Achieved")]
RankAchieved,
[Description("Ranked Status")]
RankedStatus,
[Description("Recently Played")]
RecentlyPlayed,
[Description("Title")]
Title
}
}

View File

@ -0,0 +1,28 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using System.ComponentModel;
namespace osu.Game.Screens.Select.Filter
{
public enum SortMode
{
None = 0,
[Description("Artist")]
Artist,
[Description("Author")]
Author,
[Description("BPM")]
BPM,
[Description("Date Added")]
DateAdded,
[Description("Difficulty")]
Difficulty,
[Description("Length")]
Length,
[Description("Rank Achieved")]
RankAchieved,
[Description("Title")]
Title
}
}

View File

@ -2,16 +2,19 @@
// 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;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select.Filter;
using osu.Game.Screens.Select.Tab;
using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Screens.Select
{
@ -23,7 +26,8 @@ namespace osu.Game.Screens.Select
private SortMode sort = SortMode.Title;
public SortMode Sort {
get { return sort; }
set {
set
{
if (sort != value)
{
sort = value;
@ -36,7 +40,7 @@ namespace osu.Game.Screens.Select
private SearchTextBox searchTextBox;
public FilterControl()
public FilterControl(float height)
{
Children = new Drawable[]
{
@ -44,7 +48,8 @@ namespace osu.Game.Screens.Select
{
Colour = Color4.Black,
Alpha = 0.8f,
RelativeSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X,
Height = height
},
new FillFlowContainer
{
@ -57,7 +62,8 @@ namespace osu.Game.Screens.Select
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
searchTextBox = new SearchTextBox {
searchTextBox = new SearchTextBox
{
RelativeSizeAxes = Axes.X,
OnChange = (sender, newText) =>
{
@ -83,97 +89,20 @@ namespace osu.Game.Screens.Select
searchTextBox.HoldFocus = true;
}
private class TabItem : ClickableContainer
private class GroupSortTabs : Container
{
public string Text
{
get { return text.Text; }
set { text.Text = value; }
}
private TabControl<GroupMode> groupTabs;
private TabControl<SortMode> sortTabs;
private void fadeActive()
public GroupSortTabs()
{
box.FadeIn(300);
text.FadeColour(Color4.White, 300);
}
private void fadeInactive()
{
box.FadeOut(300);
text.FadeColour(fadeColour, 300);
}
private bool active;
public bool Active
{
get { return active; }
set
{
active = value;
if (active)
fadeActive();
else
fadeInactive();
}
}
private SpriteText text;
private Box box;
private Color4 fadeColour;
protected override bool OnHover(InputState state)
{
if (!active)
fadeActive();
return true;
}
protected override void OnHoverLost(InputState state)
{
if (!active)
fadeInactive();
}
public TabItem()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
text = new OsuSpriteText
{
Margin = new MarginPadding(5),
TextSize = 14,
Font = @"Exo2.0-Bold",
},
box = new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Alpha = 0,
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
};
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
text.Colour = colours.Blue;
fadeColour = colours.Blue;
}
}
private class GroupSortTabs : Container
{
private TextAwesome groupsEllipsis, sortEllipsis;
private SpriteText sortLabel;
public GroupSortTabs()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
{
new Box
@ -181,110 +110,34 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = OsuColour.Gray(80),
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Position = new Vector2(0, 23)
},
new FillFlowContainer
groupTabs = new FilterTabControl<GroupMode>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
new TabItem
{
Text = "All",
Active = true,
},
new TabItem
{
Text = "Recently Played",
Active = false,
},
new TabItem
{
Text = "Collections",
Active = false,
},
groupsEllipsis = new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
Origin = Anchor.TopLeft,
TextSize = 14,
Margin = new MarginPadding { Top = 5, Bottom = 5 },
}
}
Width = 210
},
new FillFlowContainer
sortTabs = new FilterTabControl<SortMode>
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Origin = Anchor.TopRight,
Width = 180,
Anchor = Anchor.TopRight,
Children = new Drawable[]
{
sortLabel = new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = "Sort results by",
TextSize = 14,
Margin = new MarginPadding { Top = 5, Bottom = 5 },
},
new TabItem
{
Text = "Artist",
Active = true,
},
sortEllipsis = new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
Origin = Anchor.TopLeft,
TextSize = 14,
Margin = new MarginPadding { Top = 5, Bottom = 5 },
}
}
},
Origin = Anchor.TopRight
}
};
sortTabs.Prefix.Children = new Drawable[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = "Sort results by",
TextSize = 14,
Margin = new MarginPadding { Top = 5, Bottom = 5 },
}
};
groupTabs.Pin(GroupMode.All);
groupTabs.Pin(GroupMode.RecentlyPlayed);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
groupsEllipsis.Colour = colours.Blue;
sortLabel.Colour = colours.GreenLight;
sortEllipsis.Colour = colours.GreenLight;
}
}
public enum SortMode
{
Artist,
BPM,
Author,
DateAdded,
Difficulty,
Length,
RankAchieved,
Title
}
public enum GroupMode
{
NoGrouping,
Artist,
BPM,
Author,
DateAdded,
Difficulty,
Length,
RankAchieved,
Title,
Collections,
Favorites,
MyMaps,
RankedStatus,
RecentlyPlayed
}
}
}

View File

@ -0,0 +1,14 @@
// 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.UserInterface.Tab;
namespace osu.Game.Screens.Select.Tab
{
public class FilterTabControl<T> : TabControl<T>
{
protected override TabDropDownMenu<T> CreateDropDownMenu() => new FilterTabDropDownMenu<T>();
protected override TabItem<T> CreateTabItem(T value) => new FilterTabItem<T> { Value = value };
}
}

View File

@ -0,0 +1,40 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
namespace osu.Game.Screens.Select.Tab
{
public class FilterTabDropDownHeader : BasicDropDownHeader
{
protected override string Label { get; set; }
private TextAwesome ellipses;
public FilterTabDropDownHeader()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
ellipses = new TextAwesome
{
Icon = FontAwesome.fa_ellipsis_h,
TextSize = 14,
Margin = new MarginPadding{ Top = 6, Bottom = 4 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
ellipses.Colour = colours.Blue;
}
}
}

View File

@ -0,0 +1,70 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface.Tab;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Select.Tab
{
public class FilterTabDropDownMenu<T> : TabDropDownMenu<T>
{
protected override BasicDropDownHeader CreateHeader() => new FilterTabDropDownHeader();
protected override IEnumerable<DropDownMenuItem<T>> GetDropDownItems(IEnumerable<KeyValuePair<string, T>> values)
=> values.Select(v => new FilterTabDropDownMenuItem<T>(v.Key, v.Value));
public FilterTabDropDownMenu()
{
ContentContainer.CornerRadius = 4;
MaxDropDownHeight = int.MaxValue;
ContentBackground.Colour = Color4.Black.Opacity(0.5f);
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()
{
ContentContainer.FadeIn(300, EasingTypes.OutQuint);
}
protected override void AnimateClose()
{
ContentContainer.FadeOut(300, EasingTypes.OutQuint);
}
protected override void UpdateContentHeight()
{
if (State == DropDownMenuState.Opened)
ContentContainer.ResizeTo(new Vector2(1, ContentHeight), 300, EasingTypes.OutQuint);
else
ContentContainer.ResizeTo(new Vector2(1, 0), 300, EasingTypes.OutQuint);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours) {
//Colour = colours.White;
//SelectedItem.Colour = colours.Blue;
}
}
}

View File

@ -0,0 +1,39 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/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;
namespace osu.Game.Screens.Select.Tab
{
public class FilterTabDropDownMenuItem<T> : DropDownMenuItem<T>
{
public FilterTabDropDownMenuItem(string text, T value) : base(text, value)
{
Foreground.Padding = new MarginPadding(5);
Background.Colour = Color4.Red;
Foreground.Margin = new MarginPadding { Left = 7 };
Foreground.Add(new OsuSpriteText
{
Text = text,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = Color4.Black.Opacity(0.8f);
BackgroundColourHover = new Color4(124, 200, 253, 255);
BackgroundColourSelected = new Color4(124, 200, 253, 255);
//BackgroundColourSelected = new Color4(163, 196, 36, 255); // Green
}
}
}

View File

@ -0,0 +1,105 @@
// 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.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 OpenTK.Graphics;
namespace osu.Game.Screens.Select.Tab
{
public class FilterTabItem<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 FilterTabItem()
{
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,
}
};
}
// TODO: Remove this (for debugging)
public override string ToString() {
return Value.ToString();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
fadeColour = colours.Blue;
text.Colour = colours.Blue;
}
}
}

View File

@ -84,6 +84,11 @@
<Compile Include="Graphics\UserInterface\OsuPasswordTextBox.cs" />
<Compile Include="Graphics\UserInterface\OsuSliderBar.cs" />
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
<Compile Include="Screens\Select\Tab\FilterTabControl.cs" />
<Compile Include="Screens\Select\Tab\FilterTabDropDownMenu.cs" />
<Compile Include="Screens\Select\Tab\FilterTabItem.cs" />
<Compile Include="Screens\Select\Tab\FilterTabDropDownHeader.cs" />
<Compile Include="Screens\Select\Tab\FilterTabDropDownMenuItem.cs" />
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />
<Compile Include="Input\Handlers\ReplayInputHandler.cs" />
<Compile Include="IO\Legacy\ILegacySerializable.cs" />
@ -175,6 +180,8 @@
<Compile Include="Screens\Play\SkipButton.cs" />
<Compile Include="Modes\UI\StandardComboCounter.cs" />
<Compile Include="Screens\Select\CarouselContainer.cs" />
<Compile Include="Screens\Select\Filter\GroupMode.cs" />
<Compile Include="Screens\Select\Filter\SortMode.cs" />
<Compile Include="Screens\Select\MatchSongSelect.cs" />
<Compile Include="Screens\OsuGameScreen.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapGroup.cs" />