mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 16:32:54 +08:00
Fix button selection animation not playing smoothly when new glyphs are loaded
This commit is contained in:
parent
5c6b4e498d
commit
5dff48a1e0
@ -12,6 +12,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -63,6 +64,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
{
|
||||
private Bindable<string> frameworkLocale = null!;
|
||||
|
||||
private ScheduledDelegate? updateSelectedDelegate;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkConfigManager frameworkConfig)
|
||||
{
|
||||
@ -82,11 +85,20 @@ namespace osu.Game.Overlays.FirstRunSetup
|
||||
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
|
||||
language = Language.en;
|
||||
|
||||
foreach (var c in Children.OfType<LanguageButton>())
|
||||
c.Selected = c.Language == language;
|
||||
// Changing language may cause a short period of blocking the UI thread while the new glyphs are loaded.
|
||||
// Scheduling ensures the button animation plays smoothly after any blocking operation completes.
|
||||
// Note that a delay is required (the alternative would be a double-schedule; delay feels better).
|
||||
updateSelectedDelegate?.Cancel();
|
||||
updateSelectedDelegate = Scheduler.AddDelayed(() => updateSelectedStates(language), 50);
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void updateSelectedStates(Language language)
|
||||
{
|
||||
foreach (var c in Children.OfType<LanguageButton>())
|
||||
c.Selected = c.Language == language;
|
||||
}
|
||||
|
||||
private class LanguageButton : OsuClickableContainer
|
||||
{
|
||||
public readonly Language Language;
|
||||
|
Loading…
Reference in New Issue
Block a user