osu/osu.Game/Overlays/DirectOverlay.cs

150 lines
5.5 KiB
C#
Raw Normal View History

2017-05-24 05:41:51 +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
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Direct;
2017-05-26 05:44:09 +00:00
using osu.Game.Overlays.SearchableList;
using OpenTK.Graphics;
2017-05-24 05:41:51 +00:00
namespace osu.Game.Overlays
{
2017-06-01 00:29:50 +00:00
public class DirectOverlay : SearchableListOverlay<DirectTab, DirectSortCritera, RankStatus>
2017-05-24 05:41:51 +00:00
{
private const float panel_padding = 10f;
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
private readonly FillFlowContainer<DirectPanel> panels;
protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74");
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71");
protected override Color4 TrianglesColourDark => OsuColour.FromHex(@"3f5265");
2017-05-26 05:44:09 +00:00
protected override SearchableListHeader<DirectTab> CreateHeader() => new Header();
2017-06-01 00:29:50 +00:00
protected override SearchableListFilterControl<DirectSortCritera, RankStatus> CreateFilterControl() => new FilterControl();
2017-05-24 05:41:51 +00:00
private IEnumerable<BeatmapSetInfo> beatmapSets;
public IEnumerable<BeatmapSetInfo> BeatmapSets
{
get { return beatmapSets; }
set
{
if (beatmapSets?.Equals(value) ?? false) return;
beatmapSets = value;
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
2017-05-24 05:41:51 +00:00
}
}
private ResultCounts resultAmounts;
public ResultCounts ResultAmounts
{
get { return resultAmounts; }
set
{
if (value == ResultAmounts) return;
resultAmounts = value;
updateResultCounts();
}
}
public DirectOverlay()
{
RelativeSizeAxes = Axes.Both;
// osu!direct colours are not part of the standard palette
FirstWaveColour = OsuColour.FromHex(@"19b0e2");
SecondWaveColour = OsuColour.FromHex(@"2280a2");
ThirdWaveColour = OsuColour.FromHex(@"005774");
FourthWaveColour = OsuColour.FromHex(@"003a4e");
ScrollFlow.Children = new Drawable[]
2017-05-24 05:41:51 +00:00
{
resultCountsContainer = new FillFlowContainer
2017-05-24 05:41:51 +00:00
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Top = 5 },
Children = new Drawable[]
2017-05-24 05:41:51 +00:00
{
new OsuSpriteText
2017-05-24 05:41:51 +00:00
{
Text = "Found ",
TextSize = 15,
2017-05-24 05:41:51 +00:00
},
resultCountsText = new OsuSpriteText
2017-05-24 05:41:51 +00:00
{
TextSize = 15,
Font = @"Exo2.0-Bold",
2017-05-24 05:41:51 +00:00
},
}
2017-05-24 05:41:51 +00:00
},
panels = new FillFlowContainer<DirectPanel>
2017-05-24 05:41:51 +00:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(panel_padding),
Margin = new MarginPadding { Top = 10 },
2017-05-24 05:41:51 +00:00
},
};
Header.Tabs.Current.ValueChanged += tab => { if (tab != DirectTab.Search) Filter.Search.Text = string.Empty; };
Filter.Search.Current.ValueChanged += text => { if (text != string.Empty) Header.Tabs.Current.Value = DirectTab.Search; };
Filter.DisplayStyleControl.DisplayStyle.ValueChanged += recreatePanels;
2017-05-24 05:41:51 +00:00
updateResultCounts();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
resultCountsContainer.Colour = colours.Yellow;
}
private void updateResultCounts()
{
resultCountsContainer.FadeTo(ResultAmounts == null ? 0f : 1f, 200, EasingTypes.Out);
if (ResultAmounts == null) return;
resultCountsText.Text = pluralize("Artist", ResultAmounts.Artists) + ", " +
pluralize("Song", ResultAmounts.Songs) + ", " +
pluralize("Tag", ResultAmounts.Tags);
}
private string pluralize(string prefix, int value)
{
return $@"{value} {prefix}" + (value == 1 ? string.Empty : @"s");
}
private void recreatePanels(PanelDisplayStyle displayStyle)
{
if (BeatmapSets == null) return;
panels.Children = BeatmapSets.Select(b => displayStyle == PanelDisplayStyle.Grid ? (DirectPanel)new DirectGridPanel(b) { Width = 400 } : new DirectListPanel(b));
}
2017-05-31 08:22:54 +00:00
2017-05-24 05:41:51 +00:00
public class ResultCounts
{
public readonly int Artists;
public readonly int Songs;
public readonly int Tags;
public ResultCounts(int artists, int songs, int tags)
{
Artists = artists;
Songs = songs;
Tags = tags;
}
}
}
}