1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 12:32:58 +08:00

Basic searching in osu!direct, move BeatmapSetOnlineInfo covers into their own class

This commit is contained in:
DrabWeb 2017-05-28 02:26:25 -03:00
parent ab32e962ca
commit 8745948a01
7 changed files with 150 additions and 9 deletions

View File

@ -50,7 +50,7 @@ namespace osu.Desktop.VisualTests.Tests
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/578332/covers/cover.jpg?1494591390" },
Covers = new BeatmapSetOnlineCovers { Card = @"https://assets.ppy.sh//beatmaps/578332/covers/cover.jpg?1494591390" },
Preview = @"https://b.ppy.sh/preview/578332.mp3",
PlayCount = 97,
FavouriteCount = 72,
@ -76,7 +76,7 @@ namespace osu.Desktop.VisualTests.Tests
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/599627/covers/cover.jpg?1494539318" },
Covers = new BeatmapSetOnlineCovers { Card = @"https://assets.ppy.sh//beatmaps/599627/covers/cover.jpg?1494539318" },
Preview = @"https//b.ppy.sh/preview/599627.mp3",
PlayCount = 3082,
FavouriteCount = 14,
@ -102,7 +102,7 @@ namespace osu.Desktop.VisualTests.Tests
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/513268/covers/cover.jpg?1494502863" },
Covers = new BeatmapSetOnlineCovers { Card = @"https://assets.ppy.sh//beatmaps/513268/covers/cover.jpg?1494502863" },
Preview = @"https//b.ppy.sh/preview/513268.mp3",
PlayCount = 2762,
FavouriteCount = 15,
@ -143,7 +143,7 @@ namespace osu.Desktop.VisualTests.Tests
},
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = new[] { @"https://assets.ppy.sh//beatmaps/586841/covers/cover.jpg?1494052741" },
Covers = new BeatmapSetOnlineCovers { Card = @"https://assets.ppy.sh//beatmaps/586841/covers/cover.jpg?1494052741" },
Preview = @"https//b.ppy.sh/preview/586841.mp3",
PlayCount = 62317,
FavouriteCount = 161,

View File

@ -12,10 +12,10 @@ namespace osu.Game.Database
public class BeatmapSetOnlineInfo
{
/// <summary>
/// The different sizes of cover art for this beatmap: cover, cover@2x, card, card@2x, list, list@2x.
/// The different sizes of cover art for this beatmap.
/// </summary>
[JsonProperty(@"covers")]
public IEnumerable<string> Covers { get; set; }
public BeatmapSetOnlineCovers Covers { get; set; }
/// <summary>
/// A small sample clip of this beatmap's song.
@ -35,4 +35,22 @@ namespace osu.Game.Database
[JsonProperty(@"favourite_count")]
public int FavouriteCount { get; set; }
}
public class BeatmapSetOnlineCovers
{
public string Cover { get; set; }
[JsonProperty(@"cover@2x")]
public string Cover2x { get; set; }
public string Card { get; set; }
[JsonProperty(@"card@2x")]
public string Card2x { get; set; }
public string List { get; set; }
[JsonProperty(@"list@2x")]
public string List2x { get; set; }
}
}

View File

@ -0,0 +1,86 @@
// 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 Newtonsoft.Json;
using osu.Game.Database;
namespace osu.Game.Online.API.Requests
{
public class GetBeatmapSetsRequest : APIRequest<IEnumerable<GetBeatmapSetsResponse>>
{
private readonly string query;
public GetBeatmapSetsRequest(string query)
{
this.query = System.Uri.EscapeDataString(query);
}
protected override string Target => $@"beatmapsets/search?q={query}";
}
public class GetBeatmapSetsResponse : BeatmapMetadata
{
[JsonProperty(@"covers")]
private BeatmapSetOnlineCovers covers { get; set; }
[JsonProperty(@"previewUrl")]
private string preview { get; set; }
[JsonProperty(@"play_count")]
private int playCount { get; set; }
[JsonProperty(@"favourite_count")]
private int favouriteCount { get; set; }
[JsonProperty(@"beatmaps")]
private IEnumerable<GetBeatmapSetsBeatmapResponse> beatmaps { get; set; }
public BeatmapSetInfo ToSetInfo(RulesetDatabase rulesets)
{
return new BeatmapSetInfo
{
Metadata = this,
OnlineInfo = new BeatmapSetOnlineInfo
{
Covers = covers,
Preview = preview,
PlayCount = playCount,
FavouriteCount = favouriteCount,
},
Beatmaps = beatmaps.Select(b => b.ToBeatmap(rulesets)).ToList(),
};
}
private class GetBeatmapSetsBeatmapResponse : BeatmapMetadata
{
[JsonProperty(@"playcount")]
private int playCount { get; set; }
[JsonProperty(@"passcount")]
private int passCount { get; set; }
[JsonProperty(@"mode_int")]
private int ruleset { get; set; }
[JsonProperty(@"difficulty_rating")]
private double starDifficulty { get; set; }
public BeatmapInfo ToBeatmap(RulesetDatabase rulesets)
{
return new BeatmapInfo
{
Metadata = this,
Ruleset = rulesets.GetRuleset(ruleset),
StarDifficulty = starDifficulty,
OnlineInfo = new BeatmapOnlineInfo
{
PlayCount = playCount,
PassCount = passCount,
},
};
}
}
}
}

View File

@ -98,8 +98,8 @@ namespace osu.Game.Overlays.Direct
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (set.OnlineInfo?.Covers.FirstOrDefault() != null)
Texture = textures.Get(set.OnlineInfo.Covers.First());
if (set.OnlineInfo?.Covers?.Card != null)
Texture = textures.Get(set.OnlineInfo.Covers.Card);
}
}
}

View File

@ -129,6 +129,8 @@ namespace osu.Game.Overlays.Direct
protected override Color4 BackgroundUnfocused => backgroundColour;
protected override Color4 BackgroundFocused => backgroundColour;
protected override bool AllowCommit => true;
private Color4 backgroundColour;
[BackgroundDependencyLoader]

View File

@ -13,6 +13,8 @@ using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.Direct;
using Container = osu.Framework.Graphics.Containers.Container;
@ -24,6 +26,9 @@ namespace osu.Game.Overlays
public static readonly int WIDTH_PADDING = 80;
private const float panel_padding = 10f;
private APIAccess api;
private RulesetDatabase rulesets;
private readonly FilterControl filter;
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
@ -38,6 +43,17 @@ namespace osu.Game.Overlays
if (beatmapSets?.Equals(value) ?? false) return;
beatmapSets = value;
if (BeatmapSets == null)
{
foreach (var p in panels.Children)
{
p.FadeOut(200);
p.Expire();
}
return;
}
recreatePanels(filter.DisplayStyle.Value);
}
}
@ -155,14 +171,17 @@ namespace osu.Game.Overlays
filter.Search.Exit = Hide;
filter.Search.Current.ValueChanged += text => { if (text != string.Empty) header.Tabs.Current.Value = DirectTab.Search; };
filter.Search.OnCommit = (sender, text) => updateSets();
filter.DisplayStyle.ValueChanged += recreatePanels;
updateResultCounts();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, APIAccess api, RulesetDatabase rulesets)
{
this.api = api;
this.rulesets = rulesets;
resultCountsContainer.Colour = colours.Yellow;
}
@ -187,6 +206,21 @@ namespace osu.Game.Overlays
panels.Children = BeatmapSets.Select(b => displayStyle == PanelDisplayStyle.Grid ? (DirectPanel)new DirectGridPanel(b) { Width = 400 } : new DirectListPanel(b));
}
private GetBeatmapSetsRequest getSetsRequest;
private void updateSets()
{
if (!IsLoaded) return;
BeatmapSets = null;
getSetsRequest?.Cancel();
if (api == null || filter.Search.Text == string.Empty) return;
getSetsRequest = new GetBeatmapSetsRequest(filter.Search.Text);
getSetsRequest.Success += r => BeatmapSets = r?.Select(response => response.ToSetInfo(rulesets));
api.Queue(getSetsRequest);
}
protected override bool OnFocus(InputState state)
{
filter.Search.TriggerFocus();

View File

@ -450,6 +450,7 @@
<Compile Include="Graphics\Containers\ReverseDepthFillFlowContainer.cs" />
<Compile Include="Database\RankStatus.cs" />
<Compile Include="Database\BeatmapSetOnlineInfo.cs" />
<Compile Include="Online\API\Requests\GetBeatmapSetsRequest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">