mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Add Favourite Beatmaps section in UserProfileOverlay
This commit is contained in:
parent
7fa3ac8cf2
commit
761d885167
30
osu.Game/Online/API/Requests/GetUserBeatmapsRequest.cs
Normal file
30
osu.Game/Online/API/Requests/GetUserBeatmapsRequest.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests
|
||||||
|
{
|
||||||
|
public class GetUserBeatmapsRequest : APIRequest<List<GetBeatmapSetsResponse>>
|
||||||
|
{
|
||||||
|
private readonly long userId;
|
||||||
|
private readonly BeatmapSetType type;
|
||||||
|
private readonly int offset;
|
||||||
|
|
||||||
|
public GetUserBeatmapsRequest(long userId, BeatmapSetType type, int offset = 0)
|
||||||
|
{
|
||||||
|
this.userId = userId;
|
||||||
|
this.type = type;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => $@"users/{userId}/beatmapsets/{type.ToString().ToLower()}?offset={offset}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum BeatmapSetType
|
||||||
|
{
|
||||||
|
Most_Played,
|
||||||
|
Favourite,
|
||||||
|
Ranked_And_Approved
|
||||||
|
}
|
||||||
|
}
|
@ -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 OpenTK;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Overlays.Direct;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Sections.Beatmaps
|
||||||
|
{
|
||||||
|
public class PaginatedBeatmapContainer : PaginatedContainer
|
||||||
|
{
|
||||||
|
private const float panel_padding = 10f;
|
||||||
|
|
||||||
|
private readonly BeatmapSetType type;
|
||||||
|
private string header;
|
||||||
|
|
||||||
|
private DirectPanel playing;
|
||||||
|
|
||||||
|
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user, string header, string missing)
|
||||||
|
: base(user, header, missing)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.header = header;
|
||||||
|
|
||||||
|
ItemsPerPage = 6;
|
||||||
|
|
||||||
|
ItemsContainer.Spacing = new Vector2(panel_padding);
|
||||||
|
ItemsContainer.Margin = new MarginPadding { Bottom = panel_padding };
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ShowMore()
|
||||||
|
{
|
||||||
|
base.ShowMore();
|
||||||
|
|
||||||
|
var req = new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
|
||||||
|
|
||||||
|
req.Success += sets =>
|
||||||
|
{
|
||||||
|
ShowMoreButton.FadeTo(sets.Count == ItemsPerPage ? 1 : 0);
|
||||||
|
ShowMoreLoading.Hide();
|
||||||
|
|
||||||
|
if (!sets.Any()) return;
|
||||||
|
|
||||||
|
MissingText.Hide();
|
||||||
|
|
||||||
|
foreach (var s in sets)
|
||||||
|
{
|
||||||
|
var panel = new DirectGridPanel(s.ToBeatmapSet(Rulesets)) { Width = 400 };
|
||||||
|
ItemsContainer.Add(panel);
|
||||||
|
|
||||||
|
panel.PreviewPlaying.ValueChanged += newValue =>
|
||||||
|
{
|
||||||
|
if (newValue)
|
||||||
|
{
|
||||||
|
if (playing != null && playing != panel)
|
||||||
|
playing.PreviewPlaying.Value = false;
|
||||||
|
playing = panel;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Api.Queue(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Overlays.Profile.Sections.Beatmaps;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections
|
namespace osu.Game.Overlays.Profile.Sections
|
||||||
{
|
{
|
||||||
public class BeatmapsSection : ProfileSection
|
public class BeatmapsSection : ProfileSection
|
||||||
@ -8,5 +11,13 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
public override string Title => "Beatmaps";
|
public override string Title => "Beatmaps";
|
||||||
|
|
||||||
public override string Identifier => "beatmaps";
|
public override string Identifier => "beatmaps";
|
||||||
|
|
||||||
|
public BeatmapsSection()
|
||||||
|
{
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
new PaginatedBeatmapContainer(BeatmapSetType.Favourite, User, "Favourite Beatmaps", "None... yet."),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
|
|
||||||
public HistoricalSection()
|
public HistoricalSection()
|
||||||
{
|
{
|
||||||
Child = new PaginatedScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)");
|
Child = new PaginatedScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)", "No performance records. :(");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
109
osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs
Normal file
109
osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Sections
|
||||||
|
{
|
||||||
|
public class PaginatedContainer : FillFlowContainer
|
||||||
|
{
|
||||||
|
protected readonly FillFlowContainer ItemsContainer;
|
||||||
|
protected readonly OsuHoverContainer ShowMoreButton;
|
||||||
|
protected readonly LoadingAnimation ShowMoreLoading;
|
||||||
|
protected readonly OsuSpriteText MissingText;
|
||||||
|
|
||||||
|
protected int VisiblePages;
|
||||||
|
protected int ItemsPerPage;
|
||||||
|
|
||||||
|
protected readonly Bindable<User> User = new Bindable<User>();
|
||||||
|
|
||||||
|
protected APIAccess Api;
|
||||||
|
protected RulesetStore Rulesets;
|
||||||
|
|
||||||
|
public PaginatedContainer(Bindable<User> user, string header, string missing)
|
||||||
|
{
|
||||||
|
User.BindTo(user);
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
Direction = FillDirection.Vertical;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
TextSize = 15,
|
||||||
|
Text = header,
|
||||||
|
Font = "Exo2.0-RegularItalic",
|
||||||
|
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
||||||
|
},
|
||||||
|
ItemsContainer = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
},
|
||||||
|
ShowMoreButton = new OsuHoverContainer
|
||||||
|
{
|
||||||
|
Alpha = 0,
|
||||||
|
Action = ShowMore,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Child = new OsuSpriteText
|
||||||
|
{
|
||||||
|
TextSize = 14,
|
||||||
|
Text = "show more",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ShowMoreLoading = new LoadingAnimation
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Size = new Vector2(14),
|
||||||
|
},
|
||||||
|
MissingText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
TextSize = 14,
|
||||||
|
Text = missing
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(APIAccess api, RulesetStore rulesets)
|
||||||
|
{
|
||||||
|
Api = api;
|
||||||
|
Rulesets = rulesets;
|
||||||
|
|
||||||
|
User.ValueChanged += onUserChanged;
|
||||||
|
User.TriggerChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onUserChanged(User newUser)
|
||||||
|
{
|
||||||
|
VisiblePages = 0;
|
||||||
|
ItemsContainer.Clear();
|
||||||
|
ShowMoreButton.Hide();
|
||||||
|
MissingText.Show();
|
||||||
|
|
||||||
|
if (newUser != null)
|
||||||
|
ShowMore();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void ShowMore()
|
||||||
|
{
|
||||||
|
ShowMoreLoading.Show();
|
||||||
|
ShowMoreButton.Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,130 +1,49 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using OpenTK;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||||
{
|
{
|
||||||
public class PaginatedScoreContainer : FillFlowContainer
|
public class PaginatedScoreContainer : PaginatedContainer
|
||||||
{
|
{
|
||||||
private readonly FillFlowContainer<DrawableScore> scoreContainer;
|
|
||||||
private readonly OsuSpriteText missing;
|
|
||||||
private readonly OsuHoverContainer showMoreButton;
|
|
||||||
private readonly LoadingAnimation showMoreLoading;
|
|
||||||
|
|
||||||
private readonly bool includeWeight;
|
private readonly bool includeWeight;
|
||||||
private readonly ScoreType type;
|
private readonly ScoreType type;
|
||||||
private int visiblePages;
|
|
||||||
|
|
||||||
private readonly Bindable<User> user = new Bindable<User>();
|
public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string header, string missing, bool includeWeight = false)
|
||||||
|
: base(user, header, missing)
|
||||||
private RulesetStore rulesets;
|
|
||||||
private APIAccess api;
|
|
||||||
|
|
||||||
public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string header, bool includeWeight = false)
|
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.includeWeight = includeWeight;
|
this.includeWeight = includeWeight;
|
||||||
this.user.BindTo(user);
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
ItemsPerPage = 5;
|
||||||
AutoSizeAxes = Axes.Y;
|
|
||||||
Direction = FillDirection.Vertical;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
ItemsContainer.Direction = FillDirection.Vertical;
|
||||||
{
|
|
||||||
new OsuSpriteText
|
|
||||||
{
|
|
||||||
TextSize = 15,
|
|
||||||
Text = header,
|
|
||||||
Font = "Exo2.0-RegularItalic",
|
|
||||||
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
|
||||||
},
|
|
||||||
scoreContainer = new FillFlowContainer<DrawableScore>
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Direction = FillDirection.Vertical,
|
|
||||||
},
|
|
||||||
showMoreButton = new OsuHoverContainer
|
|
||||||
{
|
|
||||||
Alpha = 0,
|
|
||||||
Action = showMore,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Child = new OsuSpriteText
|
|
||||||
{
|
|
||||||
TextSize = 14,
|
|
||||||
Text = "show more",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
showMoreLoading = new LoadingAnimation
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Size = new Vector2(14),
|
|
||||||
},
|
|
||||||
missing = new OsuSpriteText
|
|
||||||
{
|
|
||||||
TextSize = 14,
|
|
||||||
Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override void ShowMore()
|
||||||
private void load(APIAccess api, RulesetStore rulesets)
|
|
||||||
{
|
{
|
||||||
this.api = api;
|
base.ShowMore();
|
||||||
this.rulesets = rulesets;
|
|
||||||
|
|
||||||
user.ValueChanged += user_ValueChanged;
|
var req = new GetUserScoresRequest(User.Value.Id, type, VisiblePages++ * ItemsPerPage);
|
||||||
user.TriggerChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void user_ValueChanged(User newUser)
|
|
||||||
{
|
|
||||||
visiblePages = 0;
|
|
||||||
scoreContainer.Clear();
|
|
||||||
showMoreButton.Hide();
|
|
||||||
missing.Show();
|
|
||||||
|
|
||||||
if (newUser != null)
|
|
||||||
showMore();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showMore()
|
|
||||||
{
|
|
||||||
var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5);
|
|
||||||
|
|
||||||
showMoreLoading.Show();
|
|
||||||
showMoreButton.Hide();
|
|
||||||
|
|
||||||
req.Success += scores =>
|
req.Success += scores =>
|
||||||
{
|
{
|
||||||
foreach (var s in scores)
|
foreach (var s in scores)
|
||||||
s.ApplyRuleset(rulesets.GetRuleset(s.OnlineRulesetID));
|
s.ApplyRuleset(Rulesets.GetRuleset(s.OnlineRulesetID));
|
||||||
|
|
||||||
showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0);
|
ShowMoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0);
|
||||||
showMoreLoading.Hide();
|
ShowMoreLoading.Hide();
|
||||||
|
|
||||||
if (!scores.Any()) return;
|
if (!scores.Any()) return;
|
||||||
|
|
||||||
missing.Hide();
|
MissingText.Hide();
|
||||||
|
|
||||||
foreach (OnlineScore score in scores)
|
foreach (OnlineScore score in scores)
|
||||||
{
|
{
|
||||||
@ -133,7 +52,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null);
|
drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, ItemsContainer.Count) : (double?)null);
|
||||||
break;
|
break;
|
||||||
case ScoreType.Recent:
|
case ScoreType.Recent:
|
||||||
drawableScore = new DrawableTotalScore(score);
|
drawableScore = new DrawableTotalScore(score);
|
||||||
@ -143,11 +62,11 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
|||||||
drawableScore.RelativeSizeAxes = Axes.X;
|
drawableScore.RelativeSizeAxes = Axes.X;
|
||||||
drawableScore.Height = 60;
|
drawableScore.Height = 60;
|
||||||
|
|
||||||
scoreContainer.Add(drawableScore);
|
ItemsContainer.Add(drawableScore);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
api.Queue(req);
|
Api.Queue(req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new PaginatedScoreContainer(ScoreType.Best, User, "Best Performance", true),
|
new PaginatedScoreContainer(ScoreType.Best, User, "Best Performance", "No performance records. :(", true),
|
||||||
new PaginatedScoreContainer(ScoreType.Firsts, User, "First Place Ranks"),
|
new PaginatedScoreContainer(ScoreType.Firsts, User, "First Place Ranks", "No awesome performance records yet. :("),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ namespace osu.Game.Overlays
|
|||||||
new RanksSection(),
|
new RanksSection(),
|
||||||
//new MedalsSection(),
|
//new MedalsSection(),
|
||||||
new HistoricalSection(),
|
new HistoricalSection(),
|
||||||
//new BeatmapsSection(),
|
new BeatmapsSection(),
|
||||||
//new KudosuSection()
|
//new KudosuSection()
|
||||||
};
|
};
|
||||||
tabs = new ProfileTabControl
|
tabs = new ProfileTabControl
|
||||||
|
@ -279,6 +279,9 @@
|
|||||||
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
|
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
|
||||||
<Compile Include="Online\API\Requests\GetBeatmapSetRequest.cs" />
|
<Compile Include="Online\API\Requests\GetBeatmapSetRequest.cs" />
|
||||||
<Compile Include="Online\API\Requests\GetBeatmapSetsResponse.cs" />
|
<Compile Include="Online\API\Requests\GetBeatmapSetsResponse.cs" />
|
||||||
|
<Compile Include="Online\API\Requests\GetUserBeatmapsRequest.cs" />
|
||||||
|
<Compile Include="Overlays\Profile\Sections\Beatmaps\PaginatedBeatmapContainer.cs" />
|
||||||
|
<Compile Include="Overlays\Profile\Sections\PaginatedContainer.cs" />
|
||||||
<Compile Include="Overlays\Profile\Sections\Ranks\DrawablePerformanceScore.cs" />
|
<Compile Include="Overlays\Profile\Sections\Ranks\DrawablePerformanceScore.cs" />
|
||||||
<Compile Include="Overlays\Profile\Sections\Ranks\PaginatedScoreContainer.cs" />
|
<Compile Include="Overlays\Profile\Sections\Ranks\PaginatedScoreContainer.cs" />
|
||||||
<Compile Include="Overlays\Profile\Sections\Ranks\DrawableTotalScore.cs" />
|
<Compile Include="Overlays\Profile\Sections\Ranks\DrawableTotalScore.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user