2020-01-27 13:52:21 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-05-13 16:14:52 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-07-17 05:50:22 +08:00
|
|
|
|
|
2019-05-21 12:34:35 +08:00
|
|
|
|
using System;
|
2019-05-17 16:15:51 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-05-17 16:47:28 +08:00
|
|
|
|
using System.Threading;
|
2019-05-23 10:38:13 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-05-21 12:34:35 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-07-24 05:15:14 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2019-05-21 12:34:35 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-07-17 05:50:22 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-07-19 01:32:15 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2018-07-24 03:38:14 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-07-17 05:50:22 +08:00
|
|
|
|
using osu.Game.Overlays.Changelog;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2019-05-14 13:18:36 +08:00
|
|
|
|
public class ChangelogOverlay : FullscreenOverlay
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
2019-05-23 10:23:24 +08:00
|
|
|
|
public readonly Bindable<APIChangelogBuild> Current = new Bindable<APIChangelogBuild>();
|
|
|
|
|
|
2020-01-27 13:50:24 +08:00
|
|
|
|
protected ChangelogHeader Header;
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2019-05-17 16:47:28 +08:00
|
|
|
|
private Container<ChangelogContent> content;
|
2018-07-23 00:35:29 +08:00
|
|
|
|
|
2018-07-25 00:41:47 +08:00
|
|
|
|
private SampleChannel sampleBack;
|
|
|
|
|
|
2019-05-17 16:15:51 +08:00
|
|
|
|
private List<APIChangelogBuild> builds;
|
|
|
|
|
|
2020-01-27 13:50:24 +08:00
|
|
|
|
protected List<APIUpdateStream> Streams;
|
2019-05-23 17:54:42 +08:00
|
|
|
|
|
2020-01-24 17:24:35 +08:00
|
|
|
|
public ChangelogOverlay()
|
|
|
|
|
: base(OverlayColourScheme.Purple)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 13:18:36 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-21 21:41:52 +08:00
|
|
|
|
private void load(AudioManager audio)
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-02-21 21:41:52 +08:00
|
|
|
|
Colour = ColourProvider.Background4,
|
2018-07-17 05:50:22 +08:00
|
|
|
|
},
|
2020-04-13 17:23:28 +08:00
|
|
|
|
new OverlayScrollContainer
|
2018-07-17 05:50:22 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ScrollbarVisible = false,
|
|
|
|
|
Child = new ReverseChildIDFillFlowContainer<Drawable>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-01-27 13:50:24 +08:00
|
|
|
|
Header = new ChangelogHeader
|
2019-05-21 11:52:50 +08:00
|
|
|
|
{
|
|
|
|
|
ListingSelected = ShowListing,
|
|
|
|
|
},
|
2019-05-17 16:47:28 +08:00
|
|
|
|
content = new Container<ChangelogContent>
|
2019-05-17 16:15:51 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
}
|
2018-07-17 05:50:22 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2019-05-15 16:55:26 +08:00
|
|
|
|
|
2019-06-04 10:04:28 +08:00
|
|
|
|
sampleBack = audio.Samples.Get(@"UI/generic-select-soft");
|
2018-07-19 01:32:15 +08:00
|
|
|
|
|
2020-02-04 05:43:04 +08:00
|
|
|
|
Header.Build.BindTo(Current);
|
2018-07-17 05:50:22 +08:00
|
|
|
|
|
2019-05-21 12:34:35 +08:00
|
|
|
|
Current.BindValueChanged(e =>
|
|
|
|
|
{
|
|
|
|
|
if (e.NewValue != null)
|
|
|
|
|
loadContent(new ChangelogSingleBuild(e.NewValue));
|
|
|
|
|
else
|
|
|
|
|
loadContent(new ChangelogListing(builds));
|
|
|
|
|
});
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
2018-07-20 01:07:24 +08:00
|
|
|
|
|
2019-05-23 17:54:42 +08:00
|
|
|
|
public void ShowListing()
|
|
|
|
|
{
|
|
|
|
|
Current.Value = null;
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2019-05-23 17:54:42 +08:00
|
|
|
|
}
|
2019-05-23 10:23:24 +08: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)
|
|
|
|
|
{
|
|
|
|
|
if (build == null) throw new ArgumentNullException(nameof(build));
|
|
|
|
|
|
|
|
|
|
Current.Value = build;
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2019-05-23 17:54:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowBuild([NotNull] string updateStream, [NotNull] string version)
|
|
|
|
|
{
|
|
|
|
|
if (updateStream == null) throw new ArgumentNullException(nameof(updateStream));
|
|
|
|
|
if (version == null) throw new ArgumentNullException(nameof(version));
|
|
|
|
|
|
|
|
|
|
performAfterFetch(() =>
|
|
|
|
|
{
|
|
|
|
|
var build = builds.Find(b => b.Version == version && b.UpdateStream.Name == updateStream)
|
2020-01-27 13:50:24 +08:00
|
|
|
|
?? Streams.Find(s => s.Name == updateStream)?.LatestBuild;
|
2019-05-23 17:54:42 +08:00
|
|
|
|
|
|
|
|
|
if (build != null)
|
2019-05-31 12:54:40 +08:00
|
|
|
|
ShowBuild(build);
|
2019-05-23 17:54:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Show();
|
2019-05-23 10:23:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 00:41:47 +08:00
|
|
|
|
public override bool OnPressed(GlobalAction action)
|
2018-07-23 02:27:50 +08:00
|
|
|
|
{
|
2018-07-25 00:41:47 +08:00
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Back:
|
2019-05-21 12:34:35 +08:00
|
|
|
|
if (Current.Value == null)
|
2018-07-25 06:12:05 +08:00
|
|
|
|
{
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Hide();
|
2018-07-25 06:12:05 +08:00
|
|
|
|
}
|
2018-07-25 00:41:47 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-21 12:34:35 +08:00
|
|
|
|
Current.Value = null;
|
2018-07-25 00:41:47 +08:00
|
|
|
|
sampleBack?.Play();
|
|
|
|
|
}
|
2019-05-12 23:36:05 +08:00
|
|
|
|
|
2018-07-25 00:41:47 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-07-23 02:27:50 +08:00
|
|
|
|
|
2018-07-25 00:41:47 +08:00
|
|
|
|
return false;
|
2018-07-20 01:07:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 12:34:35 +08:00
|
|
|
|
protected override void PopIn()
|
2018-07-23 00:35:29 +08:00
|
|
|
|
{
|
2019-05-21 12:34:35 +08:00
|
|
|
|
base.PopIn();
|
2018-07-24 03:38:14 +08:00
|
|
|
|
|
2019-05-23 17:54:42 +08: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 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 17:54:42 +08:00
|
|
|
|
private Task initialFetchTask;
|
2019-05-17 16:49:05 +08:00
|
|
|
|
|
2020-01-02 18:19:00 +08:00
|
|
|
|
private void performAfterFetch(Action action) => fetchListing()?.ContinueWith(_ =>
|
|
|
|
|
Schedule(action), TaskContinuationOptions.OnlyOnRanToCompletion);
|
2019-05-23 17:54:42 +08:00
|
|
|
|
|
|
|
|
|
private Task fetchListing()
|
2019-05-17 16:47:28 +08:00
|
|
|
|
{
|
2019-05-23 17:54:42 +08:00
|
|
|
|
if (initialFetchTask != null)
|
|
|
|
|
return initialFetchTask;
|
|
|
|
|
|
2019-05-23 18:08:44 +08:00
|
|
|
|
return initialFetchTask = Task.Run(async () =>
|
2019-05-17 16:47:28 +08:00
|
|
|
|
{
|
2019-05-23 18:08:44 +08:00
|
|
|
|
var tcs = new TaskCompletionSource<bool>();
|
|
|
|
|
|
2019-05-23 10:38:13 +08:00
|
|
|
|
var req = new GetChangelogRequest();
|
2019-10-31 14:04:13 +08:00
|
|
|
|
|
2019-09-13 16:21:47 +08:00
|
|
|
|
req.Success += res => Schedule(() =>
|
2019-05-23 10:38:13 +08: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 16:47:28 +08:00
|
|
|
|
|
2019-05-23 10:38:13 +08:00
|
|
|
|
builds = res.Builds;
|
2020-01-27 13:50:24 +08:00
|
|
|
|
Streams = res.Streams;
|
2019-05-23 17:54:42 +08:00
|
|
|
|
|
2020-01-27 13:52:21 +08:00
|
|
|
|
Header.Populate(res.Streams);
|
2019-05-14 13:18:36 +08:00
|
|
|
|
|
2019-05-23 17:54:42 +08:00
|
|
|
|
tcs.SetResult(true);
|
2019-09-13 16:21:47 +08:00
|
|
|
|
});
|
2019-10-31 14:04:13 +08:00
|
|
|
|
|
2020-01-03 13:16:33 +08:00
|
|
|
|
req.Failure += e =>
|
2019-10-31 14:04:13 +08:00
|
|
|
|
{
|
|
|
|
|
initialFetchTask = null;
|
2020-01-03 13:16:33 +08:00
|
|
|
|
tcs.SetException(e);
|
2019-10-31 14:04:13 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-11-29 19:03:14 +08:00
|
|
|
|
await API.PerformAsync(req);
|
2019-05-23 17:54:42 +08:00
|
|
|
|
|
2019-05-23 18:08:44 +08:00
|
|
|
|
await tcs.Task;
|
|
|
|
|
});
|
2019-05-17 16:47:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 12:54:40 +08:00
|
|
|
|
private CancellationTokenSource loadContentCancellation;
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
private void loadContent(ChangelogContent newContent)
|
|
|
|
|
{
|
|
|
|
|
content.FadeTo(0.2f, 300, Easing.OutQuint);
|
|
|
|
|
|
2019-05-31 12:54:40 +08:00
|
|
|
|
loadContentCancellation?.Cancel();
|
2019-05-17 16:47:28 +08:00
|
|
|
|
|
|
|
|
|
LoadComponentAsync(newContent, c =>
|
2019-05-15 17:21:06 +08:00
|
|
|
|
{
|
2019-05-17 16:47:28 +08:00
|
|
|
|
content.FadeIn(300, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
c.BuildSelected = ShowBuild;
|
|
|
|
|
content.Child = c;
|
2019-05-31 12:54:40 +08:00
|
|
|
|
}, (loadContentCancellation = new CancellationTokenSource()).Token);
|
2018-07-20 01:07:24 +08:00
|
|
|
|
}
|
2018-07-17 05:50:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|