2017-05-24 13:41:51 +08: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;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Online.API.Requests;
|
2017-05-24 13:41:51 +08:00
|
|
|
|
using osu.Game.Overlays.Direct;
|
2017-05-26 13:44:09 +08:00
|
|
|
|
using osu.Game.Overlays.SearchableList;
|
2017-05-26 11:52:01 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-05-24 13:41:51 +08:00
|
|
|
|
|
2017-06-07 21:40:18 +08:00
|
|
|
|
namespace osu.Game.Overlays
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-06-07 21:40:18 +08:00
|
|
|
|
public class DirectOverlay : SearchableListOverlay<DirectTab, DirectSortCriteria, RankStatus>
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
|
|
|
|
private const float panel_padding = 10f;
|
|
|
|
|
|
2017-05-28 13:26:25 +08:00
|
|
|
|
private APIAccess api;
|
|
|
|
|
private RulesetDatabase rulesets;
|
|
|
|
|
|
2017-05-24 13:41:51 +08:00
|
|
|
|
private readonly FillFlowContainer resultCountsContainer;
|
|
|
|
|
private readonly OsuSpriteText resultCountsText;
|
|
|
|
|
private readonly FillFlowContainer<DirectPanel> panels;
|
|
|
|
|
|
2017-06-07 21:40:18 +08:00
|
|
|
|
protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74");
|
2017-05-26 11:52:01 +08:00
|
|
|
|
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71");
|
|
|
|
|
protected override Color4 TrianglesColourDark => OsuColour.FromHex(@"3f5265");
|
|
|
|
|
|
2017-05-26 13:44:09 +08:00
|
|
|
|
protected override SearchableListHeader<DirectTab> CreateHeader() => new Header();
|
2017-06-07 21:40:18 +08:00
|
|
|
|
protected override SearchableListFilterControl<DirectSortCriteria, RankStatus> CreateFilterControl() => new FilterControl();
|
2017-05-26 11:52:01 +08:00
|
|
|
|
|
2017-05-24 13:41:51 +08:00
|
|
|
|
private IEnumerable<BeatmapSetInfo> beatmapSets;
|
|
|
|
|
public IEnumerable<BeatmapSetInfo> BeatmapSets
|
|
|
|
|
{
|
|
|
|
|
get { return beatmapSets; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (beatmapSets?.Equals(value) ?? false) return;
|
|
|
|
|
beatmapSets = value;
|
|
|
|
|
|
2017-05-28 13:26:25 +08:00
|
|
|
|
if (BeatmapSets == null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var p in panels.Children)
|
|
|
|
|
{
|
|
|
|
|
p.FadeOut(200);
|
|
|
|
|
p.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 17:05:05 +08:00
|
|
|
|
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
2017-05-24 13:41:51 +08: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");
|
|
|
|
|
|
2017-05-26 11:52:01 +08:00
|
|
|
|
ScrollFlow.Children = new Drawable[]
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
resultCountsContainer = new FillFlowContainer
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
|
|
|
|
Children = new Drawable[]
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
new OsuSpriteText
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
Text = "Found ",
|
|
|
|
|
TextSize = 15,
|
2017-05-24 13:41:51 +08:00
|
|
|
|
},
|
2017-05-26 11:52:01 +08:00
|
|
|
|
resultCountsText = new OsuSpriteText
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-26 11:52:01 +08:00
|
|
|
|
TextSize = 15,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
2017-05-24 13:41:51 +08:00
|
|
|
|
},
|
2017-05-26 11:52:01 +08:00
|
|
|
|
}
|
2017-05-24 13:41:51 +08:00
|
|
|
|
},
|
2017-05-26 11:52:01 +08:00
|
|
|
|
panels = new FillFlowContainer<DirectPanel>
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-05-26 11:52:01 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(panel_padding),
|
|
|
|
|
Margin = new MarginPadding { Top = 10 },
|
2017-05-24 13:41:51 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-08 17:47:21 +08:00
|
|
|
|
Filter.Search.Current.ValueChanged += text => { if (text != string.Empty) Header.Tabs.Current.Value = DirectTab.Search; };
|
|
|
|
|
((FilterControl)Filter).Ruleset.ValueChanged += ruleset => updateSets();
|
|
|
|
|
Filter.DisplayStyleControl.DisplayStyle.ValueChanged += recreatePanels;
|
|
|
|
|
Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += rankStatus => updateSets();
|
|
|
|
|
|
2017-06-08 17:21:45 +08:00
|
|
|
|
Header.Tabs.Current.ValueChanged += tab =>
|
|
|
|
|
{
|
|
|
|
|
if (tab != DirectTab.Search)
|
|
|
|
|
{
|
|
|
|
|
Filter.Search.Text = lastQuery = string.Empty;
|
|
|
|
|
Filter.Tabs.Current.Value = (DirectSortCriteria)Header.Tabs.Current.Value;
|
|
|
|
|
updateSets();
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-06-08 17:47:21 +08:00
|
|
|
|
|
2017-06-07 22:13:12 +08:00
|
|
|
|
Filter.Search.OnCommit = (sender, text) =>
|
|
|
|
|
{
|
|
|
|
|
lastQuery = Filter.Search.Text;
|
|
|
|
|
updateSets();
|
|
|
|
|
};
|
2017-06-08 17:47:21 +08:00
|
|
|
|
|
2017-06-08 17:21:45 +08:00
|
|
|
|
Filter.Tabs.Current.ValueChanged += sortCriteria =>
|
|
|
|
|
{
|
|
|
|
|
if (Header.Tabs.Current.Value != DirectTab.Search && sortCriteria != (DirectSortCriteria)Header.Tabs.Current.Value)
|
|
|
|
|
Header.Tabs.Current.Value = DirectTab.Search;
|
|
|
|
|
|
|
|
|
|
updateSets();
|
|
|
|
|
};
|
2017-05-24 13:41:51 +08:00
|
|
|
|
|
|
|
|
|
updateResultCounts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-05-28 13:26:25 +08:00
|
|
|
|
private void load(OsuColour colours, APIAccess api, RulesetDatabase rulesets)
|
2017-05-24 13:41:51 +08:00
|
|
|
|
{
|
2017-05-28 13:26:25 +08:00
|
|
|
|
this.api = api;
|
|
|
|
|
this.rulesets = rulesets;
|
2017-05-24 13:41:51 +08:00
|
|
|
|
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;
|
2017-06-24 18:56:35 +08:00
|
|
|
|
panels.ChildrenEnumerable = BeatmapSets.Select(b => displayStyle == PanelDisplayStyle.Grid ? (DirectPanel)new DirectGridPanel(b) { Width = 400 } : new DirectListPanel(b));
|
2017-05-24 13:41:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-28 13:26:25 +08:00
|
|
|
|
private GetBeatmapSetsRequest getSetsRequest;
|
2017-06-08 17:21:45 +08:00
|
|
|
|
private string lastQuery = string.Empty;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
private void updateSets()
|
|
|
|
|
{
|
2017-06-08 17:47:21 +08:00
|
|
|
|
if (!IsLoaded || Header.Tabs.Current.Value == DirectTab.Search && (Filter.Search.Text == string.Empty || lastQuery == string.Empty)) return;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
|
|
|
|
|
BeatmapSets = null;
|
2017-06-07 22:30:52 +08:00
|
|
|
|
ResultAmounts = null;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
getSetsRequest?.Cancel();
|
|
|
|
|
|
2017-06-08 17:31:37 +08:00
|
|
|
|
if (api == null) return;
|
2017-05-28 13:26:25 +08:00
|
|
|
|
|
2017-06-07 22:13:12 +08:00
|
|
|
|
getSetsRequest = new GetBeatmapSetsRequest(lastQuery,
|
2017-06-07 22:00:05 +08:00
|
|
|
|
((FilterControl)Filter).Ruleset.Value,
|
|
|
|
|
Filter.DisplayStyleControl.Dropdown.Current.Value,
|
2017-06-08 17:31:37 +08:00
|
|
|
|
Filter.Tabs.Current.Value); //todo: sort direction (?)
|
2017-06-07 22:00:05 +08:00
|
|
|
|
|
2017-06-07 22:30:52 +08:00
|
|
|
|
getSetsRequest.Success += r =>
|
|
|
|
|
{
|
2017-07-11 12:03:38 +08:00
|
|
|
|
BeatmapSets = r?.Select(response => response.ToBeatmapSet(rulesets));
|
2017-06-07 22:30:52 +08:00
|
|
|
|
|
|
|
|
|
var artists = new List<string>();
|
|
|
|
|
var songs = new List<string>();
|
|
|
|
|
var tags = new List<string>();
|
|
|
|
|
foreach (var s in BeatmapSets)
|
|
|
|
|
{
|
|
|
|
|
artists.Add(s.Metadata.Artist);
|
|
|
|
|
songs.Add(s.Metadata.Title);
|
|
|
|
|
tags.AddRange(s.Metadata.Tags.Split(' '));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultAmounts = new ResultCounts(distinctCount(artists),
|
|
|
|
|
distinctCount(songs),
|
|
|
|
|
distinctCount(tags));
|
|
|
|
|
};
|
2017-05-28 13:26:25 +08:00
|
|
|
|
api.Queue(getSetsRequest);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 22:30:52 +08:00
|
|
|
|
private int distinctCount(List<string> list) => list.Distinct().ToArray().Length;
|
|
|
|
|
|
2017-05-24 13:41:51 +08: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|