2020-01-27 05:52:21 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-05-13 08:14:52 +00:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-07-16 21:50:22 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-05-21 04:34:35 +00:00
|
|
|
|
using System;
|
2019-05-17 08:15:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
2023-01-24 08:59:25 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-05-17 08:47:28 +00:00
|
|
|
|
using System.Threading;
|
2019-05-23 02:38:13 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-05-21 04:34:35 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2018-07-19 17:07:24 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-05-21 04:34:35 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-01-24 08:59:25 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-18 17:32:15 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-07-19 17:07:24 +00:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2018-07-23 19:38:14 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
using osu.Game.Overlays.Changelog;
|
2021-01-18 07:48:12 +00:00
|
|
|
|
using osuTK.Graphics;
|
2018-07-16 21:50:22 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-01-18 08:13:38 +00:00
|
|
|
|
public partial class ChangelogOverlay : OnlineOverlay<ChangelogHeader>
|
2018-07-16 21:50:22 +00:00
|
|
|
|
{
|
2019-05-23 02:23:24 +00:00
|
|
|
|
public readonly Bindable<APIChangelogBuild> Current = new Bindable<APIChangelogBuild>();
|
|
|
|
|
|
2019-05-17 08:15:51 +00:00
|
|
|
|
private List<APIChangelogBuild> builds;
|
|
|
|
|
|
2020-01-27 05:50:24 +00:00
|
|
|
|
protected List<APIUpdateStream> Streams;
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
2020-01-24 09:24:35 +00:00
|
|
|
|
public ChangelogOverlay()
|
2021-02-18 09:04:41 +00:00
|
|
|
|
: base(OverlayColourScheme.Purple, false)
|
2020-01-24 09:24:35 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 05:18:36 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
|
private void load()
|
2018-07-16 21:50:22 +00:00
|
|
|
|
{
|
2021-01-18 07:48:12 +00:00
|
|
|
|
Header.Build.BindTarget = Current;
|
2019-05-15 08:55:26 +00:00
|
|
|
|
|
2019-05-21 04:34:35 +00:00
|
|
|
|
Current.BindValueChanged(e =>
|
|
|
|
|
{
|
|
|
|
|
if (e.NewValue != null)
|
|
|
|
|
loadContent(new ChangelogSingleBuild(e.NewValue));
|
|
|
|
|
else
|
|
|
|
|
loadContent(new ChangelogListing(builds));
|
|
|
|
|
});
|
2018-07-16 21:50:22 +00:00
|
|
|
|
}
|
2018-07-19 17:07:24 +00:00
|
|
|
|
|
2021-01-18 07:48:12 +00:00
|
|
|
|
protected override ChangelogHeader CreateHeader() => new ChangelogHeader
|
|
|
|
|
{
|
|
|
|
|
ListingSelected = ShowListing,
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-09 09:32:44 +00:00
|
|
|
|
protected override Color4 BackgroundColour => ColourProvider.Background4;
|
2021-01-18 07:48:12 +00:00
|
|
|
|
|
2019-05-23 09:54:42 +00:00
|
|
|
|
public void ShowListing()
|
|
|
|
|
{
|
|
|
|
|
Current.Value = null;
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Show();
|
2019-05-23 09:54:42 +00:00
|
|
|
|
}
|
2019-05-23 02:23:24 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches and shows a specific build from a specific update stream.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="build">Must contain at least <see cref="APIUpdateStream.Name"/> and
|
|
|
|
|
/// <see cref="APIChangelogBuild.Version"/>. If <see cref="APIUpdateStream.DisplayName"/> and
|
|
|
|
|
/// <see cref="APIChangelogBuild.DisplayVersion"/> are specified, the header will instantly display them.</param>
|
|
|
|
|
public void ShowBuild([NotNull] APIChangelogBuild build)
|
|
|
|
|
{
|
2022-12-22 20:27:59 +00:00
|
|
|
|
ArgumentNullException.ThrowIfNull(build);
|
2019-05-23 02:23:24 +00:00
|
|
|
|
|
|
|
|
|
Current.Value = build;
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Show();
|
2019-05-23 09:54:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowBuild([NotNull] string updateStream, [NotNull] string version)
|
|
|
|
|
{
|
2022-12-22 20:27:59 +00:00
|
|
|
|
ArgumentNullException.ThrowIfNull(updateStream);
|
|
|
|
|
ArgumentNullException.ThrowIfNull(version);
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
2023-01-24 08:59:25 +00:00
|
|
|
|
Show();
|
|
|
|
|
|
2019-05-23 09:54:42 +00:00
|
|
|
|
performAfterFetch(() =>
|
|
|
|
|
{
|
|
|
|
|
var build = builds.Find(b => b.Version == version && b.UpdateStream.Name == updateStream)
|
2020-01-27 05:50:24 +00:00
|
|
|
|
?? Streams.Find(s => s.Name == updateStream)?.LatestBuild;
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
|
|
|
|
if (build != null)
|
2019-05-31 04:54:40 +00:00
|
|
|
|
ShowBuild(build);
|
2019-05-23 09:54:42 +00:00
|
|
|
|
});
|
2019-05-23 02:23:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2018-07-22 18:27:50 +00:00
|
|
|
|
{
|
2021-11-18 03:35:47 +00:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2018-07-24 16:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Back:
|
2019-05-21 04:34:35 +00:00
|
|
|
|
if (Current.Value == null)
|
2018-07-24 22:12:05 +00:00
|
|
|
|
{
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Hide();
|
2018-07-24 22:12:05 +00:00
|
|
|
|
}
|
2018-07-24 16:41:47 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-21 04:34:35 +00:00
|
|
|
|
Current.Value = null;
|
2018-07-24 16:41:47 +00:00
|
|
|
|
}
|
2019-05-12 15:36:05 +00:00
|
|
|
|
|
2018-07-24 16:41:47 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-07-22 18:27:50 +00:00
|
|
|
|
|
2018-07-24 16:41:47 +00:00
|
|
|
|
return false;
|
2018-07-19 17:07:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 04:34:35 +00:00
|
|
|
|
protected override void PopIn()
|
2018-07-22 16:35:29 +00:00
|
|
|
|
{
|
2019-05-21 04:34:35 +00:00
|
|
|
|
base.PopIn();
|
2018-07-23 19:38:14 +00:00
|
|
|
|
|
2019-05-23 09:54:42 +00:00
|
|
|
|
if (initialFetchTask == null)
|
|
|
|
|
// fetch and refresh to show listing, if no other request was made via Show methods
|
|
|
|
|
performAfterFetch(() => Current.TriggerChange());
|
2019-05-17 08:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 09:54:42 +00:00
|
|
|
|
private Task initialFetchTask;
|
2019-05-17 08:49:05 +00:00
|
|
|
|
|
2023-01-24 08:59:25 +00:00
|
|
|
|
private void performAfterFetch(Action action)
|
2021-03-13 10:30:40 +00:00
|
|
|
|
{
|
2023-01-24 08:59:25 +00:00
|
|
|
|
Debug.Assert(State.Value == Visibility.Visible);
|
|
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
fetchListing()?.ContinueWith(_ =>
|
|
|
|
|
Schedule(action), TaskContinuationOptions.OnlyOnRanToCompletion);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
|
|
|
|
private Task fetchListing()
|
2019-05-17 08:47:28 +00:00
|
|
|
|
{
|
2019-05-23 09:54:42 +00:00
|
|
|
|
if (initialFetchTask != null)
|
|
|
|
|
return initialFetchTask;
|
|
|
|
|
|
2019-05-23 10:08:44 +00:00
|
|
|
|
return initialFetchTask = Task.Run(async () =>
|
2019-05-17 08:47:28 +00:00
|
|
|
|
{
|
2019-05-23 10:08:44 +00:00
|
|
|
|
var tcs = new TaskCompletionSource<bool>();
|
|
|
|
|
|
2019-05-23 02:38:13 +00:00
|
|
|
|
var req = new GetChangelogRequest();
|
2019-10-31 06:04:13 +00:00
|
|
|
|
|
2019-09-13 08:21:47 +00:00
|
|
|
|
req.Success += res => Schedule(() =>
|
2019-05-23 02:38:13 +00:00
|
|
|
|
{
|
|
|
|
|
// 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));
|
2019-05-17 08:47:28 +00:00
|
|
|
|
|
2019-05-23 02:38:13 +00:00
|
|
|
|
builds = res.Builds;
|
2020-01-27 05:50:24 +00:00
|
|
|
|
Streams = res.Streams;
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
2020-01-27 05:52:21 +00:00
|
|
|
|
Header.Populate(res.Streams);
|
2019-05-14 05:18:36 +00:00
|
|
|
|
|
2019-05-23 09:54:42 +00:00
|
|
|
|
tcs.SetResult(true);
|
2019-09-13 08:21:47 +00:00
|
|
|
|
});
|
2019-10-31 06:04:13 +00:00
|
|
|
|
|
2020-01-03 05:16:33 +00:00
|
|
|
|
req.Failure += e =>
|
2019-10-31 06:04:13 +00:00
|
|
|
|
{
|
|
|
|
|
initialFetchTask = null;
|
2020-01-03 05:16:33 +00:00
|
|
|
|
tcs.SetException(e);
|
2019-10-31 06:04:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
2021-03-08 03:57:16 +00:00
|
|
|
|
await API.PerformAsync(req).ConfigureAwait(false);
|
2019-05-23 09:54:42 +00:00
|
|
|
|
|
2021-03-08 03:57:16 +00:00
|
|
|
|
return tcs.Task;
|
2021-03-13 10:26:38 +00:00
|
|
|
|
}).Unwrap();
|
2019-05-17 08:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 04:54:40 +00:00
|
|
|
|
private CancellationTokenSource loadContentCancellation;
|
2019-05-17 08:47:28 +00:00
|
|
|
|
|
|
|
|
|
private void loadContent(ChangelogContent newContent)
|
|
|
|
|
{
|
2021-01-18 07:48:12 +00:00
|
|
|
|
Content.FadeTo(0.2f, 300, Easing.OutQuint);
|
2019-05-17 08:47:28 +00:00
|
|
|
|
|
2019-05-31 04:54:40 +00:00
|
|
|
|
loadContentCancellation?.Cancel();
|
2019-05-17 08:47:28 +00:00
|
|
|
|
|
|
|
|
|
LoadComponentAsync(newContent, c =>
|
2019-05-15 09:21:06 +00:00
|
|
|
|
{
|
2021-01-18 07:48:12 +00:00
|
|
|
|
Content.FadeIn(300, Easing.OutQuint);
|
2019-05-17 08:47:28 +00:00
|
|
|
|
|
|
|
|
|
c.BuildSelected = ShowBuild;
|
2021-01-18 07:48:12 +00:00
|
|
|
|
Child = c;
|
2019-05-31 04:54:40 +00:00
|
|
|
|
}, (loadContentCancellation = new CancellationTokenSource()).Token);
|
2018-07-19 17:07:24 +00:00
|
|
|
|
}
|
2018-07-16 21:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|