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

Populate users centrally, using the correct ruleset

This commit is contained in:
Dean Herbert 2019-11-11 17:39:48 +09:00
parent 702a1c496b
commit 5d96e6d90a
2 changed files with 33 additions and 25 deletions

View File

@ -12,7 +12,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Overlays.Settings;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
@ -24,7 +23,7 @@ namespace osu.Game.Tournament.Screens.Editors
public class TeamEditorScreen : TournamentEditorScreen<TeamEditorScreen.TeamRow, TournamentTeam>
{
[Resolved]
private Framework.Game game { get; set; }
private TournamentGameBase game { get; set; }
protected override BindableList<TournamentTeam> Storage => LadderInfo.Teams;
@ -198,6 +197,9 @@ namespace osu.Game.Tournament.Screens.Editors
[Resolved]
protected IAPIProvider API { get; private set; }
[Resolved]
private TournamentGameBase game { get; set; }
private readonly Bindable<string> userId = new Bindable<string>();
private readonly Container drawableContainer;
@ -280,25 +282,7 @@ namespace osu.Game.Tournament.Screens.Editors
return;
}
var req = new GetUserRequest(user.Id);
req.Success += res =>
{
// TODO: this should be done in a better way.
user.Username = res.Username;
user.Country = res.Country;
user.Cover = res.Cover;
updatePanel();
};
req.Failure += _ =>
{
user.Id = 1;
updatePanel();
};
API.Queue(req);
game.PopulateUser(user, updatePanel, updatePanel);
}, true);
}

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Drawing;
using System.IO;
using System.Linq;
@ -21,11 +22,13 @@ using osu.Game.Graphics;
using osu.Game.Online.API.Requests;
using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models;
using osu.Game.Users;
using osuTK.Graphics;
using osuTK.Input;
namespace osu.Game.Tournament
{
[Cached(typeof(TournamentGameBase))]
public abstract class TournamentGameBase : OsuGameBase
{
private const string bracket_filename = "bracket.json";
@ -197,10 +200,7 @@ namespace osu.Game.Tournament
foreach (var p in t.Players)
if (string.IsNullOrEmpty(p.Username))
{
var req = new GetUserRequest(p.Id);
req.Perform(API);
p.Username = req.Result.Username;
PopulateUser(p);
addedInfo = true;
}
@ -228,6 +228,30 @@ namespace osu.Game.Tournament
return addedInfo;
}
public void PopulateUser(User user, Action success = null, Action failure = null)
{
var req = new GetUserRequest(user.Id, Ruleset.Value);
req.Success += res =>
{
user.Username = res.Username;
user.Statistics = res.Statistics;
user.Username = res.Username;
user.Country = res.Country;
user.Cover = res.Cover;
success?.Invoke();
};
req.Failure += _ =>
{
user.Id = 1;
failure?.Invoke();
};
API.Queue(req);
}
protected override void LoadComplete()
{
MenuCursorContainer.Cursor.AlwaysPresent = true; // required for tooltip display