mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Improve load and switch logic between views
This commit is contained in:
parent
c5c1896a11
commit
c41ec20236
@ -22,6 +22,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
typeof(StreamBadge),
|
||||
typeof(ChangelogHeader),
|
||||
typeof(ChangelogContent),
|
||||
typeof(ChangelogListing),
|
||||
typeof(ChangelogBuild),
|
||||
typeof(ChangelogContentGroup),
|
||||
typeof(Breadcrumb),
|
||||
typeof(BreadcrumbListing),
|
||||
|
@ -1,14 +1,18 @@
|
||||
// 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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
public class ChangelogBuild : ChangelogContent
|
||||
{
|
||||
private readonly APIChangelogBuild changelogBuild;
|
||||
private APIChangelogBuild changelogBuild;
|
||||
|
||||
public ChangelogBuild(APIChangelogBuild changelogBuild)
|
||||
{
|
||||
@ -16,8 +20,24 @@ namespace osu.Game.Overlays.Changelog
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(CancellationToken? cancellation, IAPIProvider api)
|
||||
{
|
||||
var req = new GetChangelogBuildRequest(changelogBuild.UpdateStream.Name, changelogBuild.Version);
|
||||
bool complete = false;
|
||||
|
||||
req.Success += res =>
|
||||
{
|
||||
changelogBuild = res;
|
||||
complete = true;
|
||||
};
|
||||
|
||||
req.Failure += _ => complete = true;
|
||||
|
||||
api.Queue(req);
|
||||
|
||||
while (!complete && cancellation?.IsCancellationRequested != true)
|
||||
Task.Delay(1);
|
||||
|
||||
var changelogContentGroup = new ChangelogContentGroup(changelogBuild);
|
||||
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
|
||||
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
public class ChangelogContent : FillFlowContainer
|
||||
{
|
||||
public event Action<APIChangelogBuild> BuildSelected;
|
||||
public Action<APIChangelogBuild> BuildSelected;
|
||||
|
||||
public void SelectBuild(APIChangelogBuild build) => BuildSelected?.Invoke(build);
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
@ -24,7 +26,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private BadgeDisplay badges;
|
||||
|
||||
private Container content;
|
||||
private Container<ChangelogContent> content;
|
||||
|
||||
private SampleChannel sampleBack;
|
||||
|
||||
@ -58,7 +60,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
header = new ChangelogHeader(),
|
||||
badges = new BadgeDisplay(),
|
||||
content = new Container
|
||||
content = new Container<ChangelogContent>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
@ -103,7 +105,7 @@ namespace osu.Game.Overlays
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
if (content.Child is ChangelogContent)
|
||||
if (content.Child is ChangelogListing)
|
||||
{
|
||||
State = Visibility.Hidden;
|
||||
}
|
||||
@ -119,30 +121,14 @@ namespace osu.Game.Overlays
|
||||
return false;
|
||||
}
|
||||
|
||||
private void fetchListing()
|
||||
{
|
||||
header.ShowListing();
|
||||
|
||||
var req = new GetChangelogRequest();
|
||||
req.Success += res =>
|
||||
{
|
||||
// remap streams to builds to ensure model equality
|
||||
res.Builds.ForEach(b => b.UpdateStream = res.Streams.Find(s => s.Id == b.UpdateStream.Id));
|
||||
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
|
||||
|
||||
builds = res.Builds;
|
||||
ShowListing();
|
||||
badges.Populate(res.Streams);
|
||||
};
|
||||
|
||||
API.Queue(req);
|
||||
}
|
||||
|
||||
public void ShowListing()
|
||||
{
|
||||
if (content.Children.FirstOrDefault() is ChangelogListing)
|
||||
return;
|
||||
|
||||
header.ShowListing();
|
||||
badges.Current.Value = null;
|
||||
content.Child = new ChangelogListing(builds);
|
||||
loadContent(new ChangelogListing(builds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -162,17 +148,42 @@ namespace osu.Game.Overlays
|
||||
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
|
||||
badges.Current.Value = build.UpdateStream;
|
||||
|
||||
void displayBuild(APIChangelogBuild populatedBuild) =>
|
||||
content.Child = new ChangelogBuild(populatedBuild);
|
||||
loadContent(new ChangelogBuild(build));
|
||||
}
|
||||
|
||||
if (build.Versions != null)
|
||||
displayBuild(build);
|
||||
else
|
||||
private void fetchListing()
|
||||
{
|
||||
var req = new GetChangelogRequest();
|
||||
req.Success += res =>
|
||||
{
|
||||
var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version);
|
||||
req.Success += displayBuild;
|
||||
API.Queue(req);
|
||||
}
|
||||
// remap streams to builds to ensure model equality
|
||||
res.Builds.ForEach(b => b.UpdateStream = res.Streams.Find(s => s.Id == b.UpdateStream.Id));
|
||||
res.Streams.ForEach(s => s.LatestBuild.UpdateStream = res.Streams.Find(s2 => s2.Id == s.LatestBuild.UpdateStream.Id));
|
||||
|
||||
builds = res.Builds;
|
||||
badges.Populate(res.Streams);
|
||||
|
||||
ShowListing();
|
||||
};
|
||||
|
||||
API.Queue(req);
|
||||
}
|
||||
|
||||
private CancellationTokenSource loadContentTask;
|
||||
|
||||
private void loadContent(ChangelogContent newContent)
|
||||
{
|
||||
content.FadeTo(0.2f, 300, Easing.OutQuint);
|
||||
|
||||
loadContentTask?.Cancel();
|
||||
|
||||
LoadComponentAsync(newContent, c =>
|
||||
{
|
||||
content.FadeIn(300, Easing.OutQuint);
|
||||
|
||||
c.BuildSelected = ShowBuild;
|
||||
content.Child = c;
|
||||
}, (loadContentTask = new CancellationTokenSource()).Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user