2023-12-28 06:07:17 +08:00
|
|
|
// 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.
|
|
|
|
|
2023-12-28 06:31:14 +08:00
|
|
|
using System;
|
2023-12-28 06:07:17 +08:00
|
|
|
using System.Threading;
|
2023-12-28 06:31:14 +08:00
|
|
|
using System.Threading.Tasks;
|
2023-12-28 06:07:17 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Framework.Platform;
|
2023-12-28 06:31:14 +08:00
|
|
|
using osu.Game.Online.API.Requests;
|
2023-12-28 06:07:17 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
|
|
|
public partial class SystemTitle : CompositeDrawable
|
|
|
|
{
|
|
|
|
internal Bindable<APISystemTitle?> Current { get; } = new Bindable<APISystemTitle?>();
|
|
|
|
|
|
|
|
private Container content = null!;
|
|
|
|
private CancellationTokenSource? cancellationTokenSource;
|
|
|
|
private SystemTitleImage? currentImage;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost? gameHost)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
Origin = Anchor.BottomCentre;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChild = content = new ClickableContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(Current.Value?.Url))
|
|
|
|
gameHost?.OpenUrlExternally(Current.Value.Url);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
content.ScaleTo(1.1f, 500, Easing.OutBounce);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
content.ScaleTo(1f, 500, Easing.OutBounce);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Current.BindValueChanged(_ => loadNewImage(), true);
|
2023-12-28 06:31:14 +08:00
|
|
|
|
|
|
|
checkForUpdates();
|
|
|
|
Scheduler.AddDelayed(checkForUpdates, TimeSpan.FromMinutes(15).TotalMilliseconds, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkForUpdates()
|
|
|
|
{
|
|
|
|
var request = new GetSystemTitleRequest();
|
|
|
|
Task.Run(() => request.Perform())
|
|
|
|
.ContinueWith(r =>
|
|
|
|
{
|
|
|
|
if (r.IsCompletedSuccessfully)
|
|
|
|
Schedule(() => Current.Value = request.ResponseObject);
|
|
|
|
|
|
|
|
// if the request failed, "observe" the exception.
|
|
|
|
// it isn't very important why this failed, as it's only for display.
|
|
|
|
// the inner error will be logged by framework mechanisms anyway.
|
|
|
|
if (r.IsFaulted)
|
|
|
|
_ = r.Exception;
|
|
|
|
});
|
2023-12-28 06:07:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadNewImage()
|
|
|
|
{
|
|
|
|
cancellationTokenSource?.Cancel();
|
|
|
|
cancellationTokenSource = null;
|
|
|
|
currentImage?.FadeOut(500, Easing.OutQuint).Expire();
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Current.Value?.Image))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LoadComponentAsync(new SystemTitleImage(Current.Value), loaded =>
|
|
|
|
{
|
|
|
|
if (loaded.SystemTitle != Current.Value)
|
|
|
|
loaded.Dispose();
|
|
|
|
|
|
|
|
loaded.FadeInFromZero(500, Easing.OutQuint);
|
|
|
|
content.Add(currentImage = loaded);
|
|
|
|
}, (cancellationTokenSource ??= new CancellationTokenSource()).Token);
|
|
|
|
}
|
|
|
|
|
|
|
|
[LongRunningLoad]
|
|
|
|
private partial class SystemTitleImage : Sprite
|
|
|
|
{
|
|
|
|
public readonly APISystemTitle SystemTitle;
|
|
|
|
|
|
|
|
public SystemTitleImage(APISystemTitle systemTitle)
|
|
|
|
{
|
|
|
|
SystemTitle = systemTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(LargeTextureStore textureStore)
|
|
|
|
{
|
|
|
|
var texture = textureStore.Get(SystemTitle.Image);
|
|
|
|
if (SystemTitle.Image.Contains(@"@2x"))
|
|
|
|
texture.ScaleAdjust *= 2;
|
|
|
|
Texture = texture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|