2022-12-04 03:44:54 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Bindables;
|
2024-08-06 17:06:08 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-12-04 03:44:54 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics;
|
2023-02-03 14:34:57 +08:00
|
|
|
using osu.Game.Localisation.SkinComponents;
|
2022-12-04 03:44:54 +08:00
|
|
|
|
2023-01-26 15:04:56 +08:00
|
|
|
namespace osu.Game.Skinning
|
2022-12-04 03:44:54 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2023-01-26 15:05:07 +08:00
|
|
|
/// A skin component that contains text and allows the user to choose its font.
|
2022-12-04 03:44:54 +08:00
|
|
|
/// </summary>
|
2023-02-15 15:01:26 +08:00
|
|
|
public abstract partial class FontAdjustableSkinComponent : Container, ISerialisableDrawable
|
2022-12-04 03:44:54 +08:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2023-02-03 15:02:16 +08:00
|
|
|
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
|
2022-12-04 04:32:17 +08:00
|
|
|
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
|
2022-12-04 03:44:54 +08:00
|
|
|
|
2024-09-20 22:50:17 +08:00
|
|
|
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextColour), nameof(SkinnableComponentStrings.TextColourDescription))]
|
|
|
|
public BindableColour4 TextColour { get; } = new BindableColour4(Colour4.White);
|
2024-08-06 17:06:08 +08:00
|
|
|
|
2023-01-26 15:05:07 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Implement to apply the user font selection to one or more components.
|
|
|
|
/// </summary>
|
2022-12-04 03:44:54 +08:00
|
|
|
protected abstract void SetFont(FontUsage font);
|
|
|
|
|
2024-09-20 22:50:17 +08:00
|
|
|
protected abstract void SetTextColour(Colour4 textColour);
|
2024-08-06 17:06:08 +08:00
|
|
|
|
2022-12-04 03:44:54 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2023-01-26 15:05:07 +08:00
|
|
|
|
2022-12-04 03:44:54 +08:00
|
|
|
Font.BindValueChanged(e =>
|
|
|
|
{
|
2023-01-26 15:05:07 +08:00
|
|
|
// We only have bold weight for venera, so let's force that.
|
|
|
|
FontWeight fontWeight = e.NewValue == Typeface.Venera ? FontWeight.Bold : FontWeight.Regular;
|
|
|
|
|
|
|
|
FontUsage f = OsuFont.GetFont(e.NewValue, weight: fontWeight);
|
2022-12-04 03:44:54 +08:00
|
|
|
SetFont(f);
|
|
|
|
}, true);
|
2024-08-06 17:06:08 +08:00
|
|
|
|
2024-09-20 22:50:17 +08:00
|
|
|
TextColour.BindValueChanged(e => SetTextColour(e.NewValue), true);
|
2022-12-04 03:44:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|