mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22: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.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
@ -63,6 +64,8 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
{
|
{
|
||||||
private Bindable<string> frameworkLocale = null!;
|
private Bindable<string> frameworkLocale = null!;
|
||||||
|
|
||||||
|
private ScheduledDelegate? updateSelectedDelegate;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(FrameworkConfigManager frameworkConfig)
|
private void load(FrameworkConfigManager frameworkConfig)
|
||||||
{
|
{
|
||||||
@ -82,11 +85,20 @@ namespace osu.Game.Overlays.FirstRunSetup
|
|||||||
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
|
if (!LanguageExtensions.TryParseCultureCode(locale.NewValue, out var language))
|
||||||
language = Language.en;
|
language = Language.en;
|
||||||
|
|
||||||
foreach (var c in Children.OfType<LanguageButton>())
|
// Changing language may cause a short period of blocking the UI thread while the new glyphs are loaded.
|
||||||
c.Selected = c.Language == language;
|
// 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);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSelectedStates(Language language)
|
||||||
|
{
|
||||||
|
foreach (var c in Children.OfType<LanguageButton>())
|
||||||
|
c.Selected = c.Language == language;
|
||||||
|
}
|
||||||
|
|
||||||
private class LanguageButton : OsuClickableContainer
|
private class LanguageButton : OsuClickableContainer
|
||||||
{
|
{
|
||||||
public readonly Language Language;
|
public readonly Language Language;
|
||||||
|
Loading…
Reference in New Issue
Block a user