mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Improve load and switch logic between views
This commit is contained in:
@ -22,6 +22,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
typeof(StreamBadge),
|
typeof(StreamBadge),
|
||||||
typeof(ChangelogHeader),
|
typeof(ChangelogHeader),
|
||||||
typeof(ChangelogContent),
|
typeof(ChangelogContent),
|
||||||
|
typeof(ChangelogListing),
|
||||||
|
typeof(ChangelogBuild),
|
||||||
typeof(ChangelogContentGroup),
|
typeof(ChangelogContentGroup),
|
||||||
typeof(Breadcrumb),
|
typeof(Breadcrumb),
|
||||||
typeof(BreadcrumbListing),
|
typeof(BreadcrumbListing),
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// 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.Framework.Allocation;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog
|
namespace osu.Game.Overlays.Changelog
|
||||||
{
|
{
|
||||||
public class ChangelogBuild : ChangelogContent
|
public class ChangelogBuild : ChangelogContent
|
||||||
{
|
{
|
||||||
private readonly APIChangelogBuild changelogBuild;
|
private APIChangelogBuild changelogBuild;
|
||||||
|
|
||||||
public ChangelogBuild(APIChangelogBuild changelogBuild)
|
public ChangelogBuild(APIChangelogBuild changelogBuild)
|
||||||
{
|
{
|
||||||
@ -16,8 +20,24 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[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);
|
var changelogContentGroup = new ChangelogContentGroup(changelogBuild);
|
||||||
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
|
changelogContentGroup.GenerateText(changelogBuild.ChangelogEntries);
|
||||||
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
|
changelogContentGroup.UpdateChevronTooltips(changelogBuild.Versions.Previous?.DisplayVersion,
|
||||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
{
|
{
|
||||||
public class ChangelogContent : FillFlowContainer
|
public class ChangelogContent : FillFlowContainer
|
||||||
{
|
{
|
||||||
public event Action<APIChangelogBuild> BuildSelected;
|
public Action<APIChangelogBuild> BuildSelected;
|
||||||
|
|
||||||
public void SelectBuild(APIChangelogBuild build) => BuildSelected?.Invoke(build);
|
public void SelectBuild(APIChangelogBuild build) => BuildSelected?.Invoke(build);
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
@ -24,7 +26,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private BadgeDisplay badges;
|
private BadgeDisplay badges;
|
||||||
|
|
||||||
private Container content;
|
private Container<ChangelogContent> content;
|
||||||
|
|
||||||
private SampleChannel sampleBack;
|
private SampleChannel sampleBack;
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
header = new ChangelogHeader(),
|
header = new ChangelogHeader(),
|
||||||
badges = new BadgeDisplay(),
|
badges = new BadgeDisplay(),
|
||||||
content = new Container
|
content = new Container<ChangelogContent>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -103,7 +105,7 @@ namespace osu.Game.Overlays
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case GlobalAction.Back:
|
case GlobalAction.Back:
|
||||||
if (content.Child is ChangelogContent)
|
if (content.Child is ChangelogListing)
|
||||||
{
|
{
|
||||||
State = Visibility.Hidden;
|
State = Visibility.Hidden;
|
||||||
}
|
}
|
||||||
@ -119,30 +121,14 @@ namespace osu.Game.Overlays
|
|||||||
return false;
|
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()
|
public void ShowListing()
|
||||||
{
|
{
|
||||||
|
if (content.Children.FirstOrDefault() is ChangelogListing)
|
||||||
|
return;
|
||||||
|
|
||||||
header.ShowListing();
|
header.ShowListing();
|
||||||
badges.Current.Value = null;
|
badges.Current.Value = null;
|
||||||
content.Child = new ChangelogListing(builds);
|
loadContent(new ChangelogListing(builds));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -162,17 +148,42 @@ namespace osu.Game.Overlays
|
|||||||
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
|
header.ShowBuild(build.UpdateStream.DisplayName, build.DisplayVersion);
|
||||||
badges.Current.Value = build.UpdateStream;
|
badges.Current.Value = build.UpdateStream;
|
||||||
|
|
||||||
void displayBuild(APIChangelogBuild populatedBuild) =>
|
loadContent(new ChangelogBuild(build));
|
||||||
content.Child = new ChangelogBuild(populatedBuild);
|
}
|
||||||
|
|
||||||
if (build.Versions != null)
|
private void fetchListing()
|
||||||
displayBuild(build);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
var req = new GetChangelogBuildRequest(build.UpdateStream.Name, build.Version);
|
var req = new GetChangelogRequest();
|
||||||
req.Success += displayBuild;
|
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;
|
||||||
|
badges.Populate(res.Streams);
|
||||||
|
|
||||||
|
ShowListing();
|
||||||
|
};
|
||||||
|
|
||||||
API.Queue(req);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user