mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 08:12:56 +08:00
Add loading spinner
This commit is contained in:
parent
44dd7d65be
commit
4fd5ff61eb
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
@ -18,19 +19,52 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
public class TestSceneTimeshiftResultsScreen : ScreenTestScene
|
public class TestSceneTimeshiftResultsScreen : ScreenTestScene
|
||||||
{
|
{
|
||||||
|
private bool roomsReceived;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup() => Schedule(() =>
|
||||||
|
{
|
||||||
|
roomsReceived = false;
|
||||||
|
bindHandler();
|
||||||
|
});
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestShowResultsWithScore()
|
public void TestShowResultsWithScore()
|
||||||
{
|
{
|
||||||
createResults(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
createResults(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||||
|
AddWaitStep("wait for display", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestShowResultsNullScore()
|
public void TestShowResultsNullScore()
|
||||||
{
|
{
|
||||||
createResults(null);
|
createResults(null);
|
||||||
|
AddWaitStep("wait for display", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestShowResultsNullScoreWithDelay()
|
||||||
|
{
|
||||||
|
AddStep("bind delayed handler", () => bindHandler(3000));
|
||||||
|
createResults(null);
|
||||||
|
AddUntilStep("wait for rooms to be received", () => roomsReceived);
|
||||||
|
AddWaitStep("wait for display", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createResults(ScoreInfo score)
|
private void createResults(ScoreInfo score)
|
||||||
|
{
|
||||||
|
AddStep("load results", () =>
|
||||||
|
{
|
||||||
|
LoadScreen(new TimeshiftResultsScreen(score, 1, new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
||||||
|
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindHandler(double delay = 0)
|
||||||
{
|
{
|
||||||
var roomScores = new List<RoomScore>();
|
var roomScores = new List<RoomScore>();
|
||||||
|
|
||||||
@ -61,26 +95,31 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AddStep("bind request handler", () => ((DummyAPIAccess)API).HandleRequest = request =>
|
((DummyAPIAccess)API).HandleRequest = request =>
|
||||||
{
|
{
|
||||||
switch (request)
|
switch (request)
|
||||||
{
|
{
|
||||||
case GetRoomPlaylistScoresRequest r:
|
case GetRoomPlaylistScoresRequest r:
|
||||||
r.TriggerSuccess(new RoomPlaylistScores { Scores = roomScores });
|
if (delay == 0)
|
||||||
|
success();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromMilliseconds(delay));
|
||||||
|
Schedule(success);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void success()
|
||||||
|
{
|
||||||
|
r.TriggerSuccess(new RoomPlaylistScores { Scores = roomScores });
|
||||||
|
roomsReceived = true;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
AddStep("load results", () =>
|
|
||||||
{
|
|
||||||
LoadScreen(new TimeshiftResultsScreen(score, 1, new PlaylistItem
|
|
||||||
{
|
|
||||||
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
|
|
||||||
Ruleset = { Value = new OsuRuleset().RulesetInfo }
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
AddWaitStep("wait for display", 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
@ -17,6 +21,8 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
private readonly int roomId;
|
private readonly int roomId;
|
||||||
private readonly PlaylistItem playlistItem;
|
private readonly PlaylistItem playlistItem;
|
||||||
|
|
||||||
|
private LoadingSpinner loadingLayer;
|
||||||
|
|
||||||
public TimeshiftResultsScreen(ScoreInfo score, int roomId, PlaylistItem playlistItem, bool allowRetry = true)
|
public TimeshiftResultsScreen(ScoreInfo score, int roomId, PlaylistItem playlistItem, bool allowRetry = true)
|
||||||
: base(score, allowRetry)
|
: base(score, allowRetry)
|
||||||
{
|
{
|
||||||
@ -24,10 +30,31 @@ namespace osu.Game.Screens.Multi.Ranking
|
|||||||
this.playlistItem = playlistItem;
|
this.playlistItem = playlistItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
AddInternal(loadingLayer = new LoadingLayer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
X = -10,
|
||||||
|
State = { Value = Score == null ? Visibility.Visible : Visibility.Hidden },
|
||||||
|
Padding = new MarginPadding { Bottom = TwoLayerButton.SIZE_EXTENDED.Y }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
||||||
{
|
{
|
||||||
var req = new GetRoomPlaylistScoresRequest(roomId, playlistItem.ID);
|
var req = new GetRoomPlaylistScoresRequest(roomId, playlistItem.ID);
|
||||||
req.Success += r => scoresCallback?.Invoke(r.Scores.Where(s => s.ID != Score?.OnlineScoreID).Select(s => s.CreateScoreInfo(playlistItem)));
|
|
||||||
|
req.Success += r =>
|
||||||
|
{
|
||||||
|
scoresCallback?.Invoke(r.Scores.Where(s => s.ID != Score?.OnlineScoreID).Select(s => s.CreateScoreInfo(playlistItem)));
|
||||||
|
loadingLayer.Hide();
|
||||||
|
};
|
||||||
|
|
||||||
|
req.Failure += _ => loadingLayer.Hide();
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user