2022-04-06 16:42:10 +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.
|
|
|
|
|
2022-07-13 22:15:25 +08:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2022-04-26 15:22:41 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-07-13 22:15:25 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Extensions;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-07-13 22:15:25 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-04-26 15:22:41 +08:00
|
|
|
using osu.Framework.Localisation;
|
2022-07-14 13:40:25 +08:00
|
|
|
using osu.Framework.Threading;
|
2022-07-13 22:15:25 +08:00
|
|
|
using osu.Game.Extensions;
|
2022-04-18 14:20:54 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-04-06 16:42:10 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-07-13 22:15:25 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-04-19 12:52:55 +08:00
|
|
|
using osu.Game.Localisation;
|
2022-11-21 06:18:19 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
2022-07-13 22:15:25 +08:00
|
|
|
using osuTK;
|
2022-04-06 16:42:10 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.FirstRunSetup
|
|
|
|
{
|
2022-04-26 15:22:41 +08:00
|
|
|
[LocalisableDescription(typeof(FirstRunSetupOverlayStrings), nameof(FirstRunSetupOverlayStrings.WelcomeTitle))]
|
2022-04-06 16:42:10 +08:00
|
|
|
public partial class ScreenWelcome : FirstRunSetupScreen
|
|
|
|
{
|
2022-04-26 15:22:41 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-11-21 06:18:19 +08:00
|
|
|
private void load(FrameworkConfigManager frameworkConfig)
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
2022-04-19 15:37:29 +08:00
|
|
|
Content.Children = new Drawable[]
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
2022-07-13 22:22:50 +08:00
|
|
|
new GridContainer
|
2022-04-06 16:42:10 +08:00
|
|
|
{
|
2022-04-19 15:37:29 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-07-13 22:22:50 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
// Avoid height changes when changing language.
|
|
|
|
new Dimension(GridSizeMode.AutoSize, minSize: 100),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
|
|
|
{
|
|
|
|
Text = FirstRunSetupOverlayStrings.WelcomeDescription,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-04-06 16:42:10 +08:00
|
|
|
},
|
2022-11-21 06:18:19 +08:00
|
|
|
new SettingsCheckbox
|
|
|
|
{
|
|
|
|
LabelText = GeneralSettingsStrings.PreferOriginalMetadataLanguage,
|
|
|
|
Current = frameworkConfig.GetBindable<bool>(FrameworkSetting.ShowUnicode)
|
|
|
|
},
|
2022-07-13 22:15:25 +08:00
|
|
|
new LanguageSelectionFlow
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
}
|
2022-04-06 16:42:10 +08:00
|
|
|
};
|
|
|
|
}
|
2022-07-13 22:15:25 +08:00
|
|
|
|
|
|
|
private partial class LanguageSelectionFlow : FillFlowContainer
|
|
|
|
{
|
|
|
|
private Bindable<string> frameworkLocale = null!;
|
2022-11-11 05:56:24 +08:00
|
|
|
private IBindable<LocalisationParameters> localisationParameters = null!;
|
2022-07-13 22:15:25 +08:00
|
|
|
|
2022-07-14 13:40:25 +08:00
|
|
|
private ScheduledDelegate? updateSelectedDelegate;
|
|
|
|
|
2022-07-13 22:15:25 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2022-11-11 05:56:24 +08:00
|
|
|
private void load(FrameworkConfigManager frameworkConfig, LocalisationManager localisation)
|
2022-07-13 22:15:25 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Full;
|
|
|
|
Spacing = new Vector2(5);
|
|
|
|
|
|
|
|
ChildrenEnumerable = Enum.GetValues(typeof(Language))
|
|
|
|
.Cast<Language>()
|
|
|
|
.Select(l => new LanguageButton(l)
|
|
|
|
{
|
|
|
|
Action = () => frameworkLocale.Value = l.ToCultureCode()
|
|
|
|
});
|
|
|
|
|
|
|
|
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
2022-11-11 05:56:24 +08:00
|
|
|
|
|
|
|
localisationParameters = localisation.CurrentParameters.GetBoundCopy();
|
|
|
|
localisationParameters.BindValueChanged(p =>
|
2022-07-13 22:15:25 +08:00
|
|
|
{
|
2022-11-11 05:56:24 +08:00
|
|
|
var language = LanguageExtensions.GetLanguageFor(frameworkLocale.Value, p.NewValue);
|
2022-07-13 22:15:25 +08:00
|
|
|
|
2022-07-14 13:40:25 +08:00
|
|
|
// 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);
|
2022-07-13 22:15:25 +08:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:40:25 +08:00
|
|
|
private void updateSelectedStates(Language language)
|
|
|
|
{
|
|
|
|
foreach (var c in Children.OfType<LanguageButton>())
|
|
|
|
c.Selected = c.Language == language;
|
|
|
|
}
|
|
|
|
|
2022-07-13 22:15:25 +08:00
|
|
|
private partial class LanguageButton : OsuClickableContainer
|
|
|
|
{
|
|
|
|
public readonly Language Language;
|
|
|
|
|
|
|
|
private Box backgroundBox = null!;
|
|
|
|
|
|
|
|
private OsuSpriteText text = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
private bool selected;
|
|
|
|
|
|
|
|
public bool Selected
|
|
|
|
{
|
|
|
|
get => selected;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (selected == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
selected = value;
|
|
|
|
|
2022-07-14 13:31:59 +08:00
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
2022-07-13 22:15:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public LanguageButton(Language language)
|
|
|
|
{
|
|
|
|
Language = language;
|
|
|
|
|
|
|
|
Size = new Vector2(160, 50);
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
backgroundBox = new Box
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
Colour = colourProvider.Background5,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Colour = colourProvider.Light1,
|
|
|
|
Text = Language.GetDescription(),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-14 13:31:59 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
2022-07-13 22:15:25 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
if (!selected)
|
|
|
|
updateState();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
if (!selected)
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
if (selected)
|
|
|
|
{
|
2022-07-14 13:47:25 +08:00
|
|
|
const double selected_duration = 1000;
|
|
|
|
|
|
|
|
backgroundBox.FadeTo(1, selected_duration, Easing.OutQuint);
|
|
|
|
backgroundBox.FadeColour(colourProvider.Background2, selected_duration, Easing.OutQuint);
|
|
|
|
text.FadeColour(colourProvider.Content1, selected_duration, Easing.OutQuint);
|
|
|
|
text.ScaleTo(1.2f, selected_duration, Easing.OutQuint);
|
2022-07-13 22:15:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-14 13:47:25 +08:00
|
|
|
const double duration = 500;
|
|
|
|
|
|
|
|
backgroundBox.FadeTo(IsHovered ? 1 : 0, duration, Easing.OutQuint);
|
|
|
|
backgroundBox.FadeColour(colourProvider.Background5, duration, Easing.OutQuint);
|
|
|
|
text.FadeColour(colourProvider.Light1, duration, Easing.OutQuint);
|
|
|
|
text.ScaleTo(1, duration, Easing.OutQuint);
|
2022-07-13 22:15:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-06 16:42:10 +08:00
|
|
|
}
|
|
|
|
}
|