-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add support for displaying "system title" on main menu #26172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d9299a8
Implement visual appearance of "system title" message in main menu
bdach a3f720b
Retrieve system title from online source
bdach ac44913
CodeFileSanity does not like records in standalone files
bdach ef39759
More code quality inspections
bdach 93a8afe
Add very simple cache-busting (30 minutes)
peppy c70e7d3
Adjust animation and add delay to URL open
peppy 289e0f0
Add flash on click
peppy 481a251
Use `HandleLink` to allow potentially opening wiki or otherwise
peppy 972234b
Move re-schedule inside continuation
peppy 0ea62d0
Add initial additive blending on fade in
peppy 6684987
Reduce refresh interval slightly
peppy be3fc45
Merge branch 'master' into system-title-basic
peppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Testing; | ||
using osu.Game.Online.API.Requests.Responses; | ||
using osu.Game.Screens.Menu; | ||
|
||
namespace osu.Game.Tests.Visual.Menus | ||
{ | ||
public partial class TestSceneMainMenu : OsuGameTestScene | ||
{ | ||
[Test] | ||
public void TestSystemTitle() | ||
{ | ||
AddStep("set system title", () => Game.ChildrenOfType<SystemTitle>().Single().Current.Value = new APISystemTitle | ||
{ | ||
Image = @"https://assets.ppy.sh/main-menu/project-loved-2@2x.png", | ||
Url = @"https://osu.ppy.sh/home/news/2023-12-21-project-loved-december-2023", | ||
}); | ||
AddStep("set another title", () => Game.ChildrenOfType<SystemTitle>().Single().Current.Value = new APISystemTitle | ||
{ | ||
Image = @"https://assets.ppy.sh/main-menu/wf2023-vote@2x.png", | ||
Url = @"https://osu.ppy.sh/community/contests/189", | ||
}); | ||
AddStep("unset system title", () => Game.ChildrenOfType<SystemTitle>().Single().Current.Value = null); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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; | ||
using osu.Game.Online.API.Requests.Responses; | ||
|
||
namespace osu.Game.Online.API.Requests | ||
{ | ||
public class GetSystemTitleRequest : OsuJsonWebRequest<APISystemTitle> | ||
{ | ||
public GetSystemTitleRequest() | ||
: base($@"https://assets.ppy.sh/lazer-status.json?{DateTimeOffset.UtcNow.ToUnixTimeSeconds() / 1800}") | ||
{ | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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; | ||
using Newtonsoft.Json; | ||
|
||
namespace osu.Game.Online.API.Requests.Responses | ||
{ | ||
public class APISystemTitle : IEquatable<APISystemTitle> | ||
{ | ||
[JsonProperty(@"image")] | ||
public string Image { get; set; } = string.Empty; | ||
|
||
[JsonProperty(@"url")] | ||
public string Url { get; set; } = string.Empty; | ||
|
||
public bool Equals(APISystemTitle? other) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
|
||
return Image == other.Image && Url == other.Url; | ||
} | ||
|
||
public override bool Equals(object? obj) => obj is APISystemTitle other && Equals(other); | ||
|
||
// ReSharper disable NonReadonlyMemberInGetHashCode | ||
public override int GetHashCode() => HashCode.Combine(Image, Url); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// 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; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
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.Threading; | ||
using osu.Game.Graphics.Containers; | ||
using osu.Game.Online.API.Requests; | ||
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; | ||
|
||
private ScheduledDelegate? openUrlAction; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(OsuGame? game) | ||
{ | ||
Anchor = Anchor.BottomCentre; | ||
Origin = Anchor.BottomCentre; | ||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChild = content = new OsuClickableContainer | ||
{ | ||
AutoSizeAxes = Axes.Both, | ||
Action = () => | ||
{ | ||
currentImage?.Flash(); | ||
|
||
// Delay slightly to allow animation to play out. | ||
openUrlAction?.Cancel(); | ||
openUrlAction = Scheduler.AddDelayed(() => | ||
{ | ||
if (!string.IsNullOrEmpty(Current.Value?.Url)) | ||
game?.HandleLink(Current.Value.Url); | ||
}, 250); | ||
} | ||
}; | ||
} | ||
|
||
protected override bool OnHover(HoverEvent e) | ||
{ | ||
content.ScaleTo(1.05f, 2000, Easing.OutQuint); | ||
return base.OnHover(e); | ||
} | ||
|
||
protected override void OnHoverLost(HoverLostEvent e) | ||
{ | ||
content.ScaleTo(1f, 500, Easing.OutQuint); | ||
base.OnHoverLost(e); | ||
} | ||
|
||
protected override bool OnMouseDown(MouseDownEvent e) | ||
{ | ||
content.ScaleTo(0.95f, 500, Easing.OutQuint); | ||
return base.OnMouseDown(e); | ||
} | ||
|
||
protected override void OnMouseUp(MouseUpEvent e) | ||
{ | ||
content | ||
.ScaleTo(0.95f) | ||
.ScaleTo(1, 500, Easing.OutElastic); | ||
base.OnMouseUp(e); | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
Current.BindValueChanged(_ => loadNewImage(), true); | ||
|
||
checkForUpdates(); | ||
} | ||
|
||
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; | ||
|
||
Scheduler.AddDelayed(checkForUpdates, TimeSpan.FromMinutes(5).TotalMilliseconds); | ||
}); | ||
} | ||
|
||
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.Equals(Current.Value)) | ||
loaded.Dispose(); | ||
|
||
content.Add(currentImage = loaded); | ||
}, (cancellationTokenSource ??= new CancellationTokenSource()).Token); | ||
} | ||
|
||
[LongRunningLoad] | ||
private partial class SystemTitleImage : CompositeDrawable | ||
{ | ||
public readonly APISystemTitle SystemTitle; | ||
|
||
private Sprite flash = null!; | ||
|
||
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; | ||
|
||
AutoSizeAxes = Axes.Both; | ||
|
||
InternalChildren = new Drawable[] | ||
{ | ||
new Sprite { Texture = texture }, | ||
flash = new Sprite | ||
{ | ||
Texture = texture, | ||
Blending = BlendingParameters.Additive, | ||
}, | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
this.FadeInFromZero(500, Easing.OutQuint); | ||
flash.FadeOutFromOne(4000, Easing.OutQuint); | ||
} | ||
|
||
public Drawable Flash() | ||
{ | ||
flash.FadeInFromZero(50) | ||
.Then() | ||
.FadeOut(500, Easing.OutQuint); | ||
|
||
return this; | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This excursion is to prevent the version display on the bottom and the system title stepping on each other.