mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:35:35 +08:00
Merge pull request #21504 from Feodor0090/skin-fonts
Allow to change font of text elements
This commit is contained in:
commit
e6f17b9a5e
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.ComponentModel;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
@ -115,6 +116,8 @@ namespace osu.Game.Graphics
|
||||
{
|
||||
Venera,
|
||||
Torus,
|
||||
|
||||
[Description("Torus (alternate)")]
|
||||
TorusAlternate,
|
||||
Inter,
|
||||
}
|
||||
|
@ -11,12 +11,11 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
@ -24,10 +23,8 @@ using osu.Game.Resources.Localisation.Web;
|
||||
namespace osu.Game.Skinning.Components
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public partial class BeatmapAttributeText : Container, ISkinnableDrawable
|
||||
public partial class BeatmapAttributeText : FontAdjustableSkinComponent
|
||||
{
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
[SettingSource("Attribute", "The attribute to be displayed.")]
|
||||
public Bindable<BeatmapAttribute> Attribute { get; } = new Bindable<BeatmapAttribute>(BeatmapAttribute.StarRating);
|
||||
|
||||
@ -67,7 +64,6 @@ namespace osu.Game.Skinning.Components
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.Default.With(size: 40)
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -122,6 +118,8 @@ namespace osu.Game.Skinning.Components
|
||||
|
||||
text.Text = LocalisableString.Format(numberedTemplate, args);
|
||||
}
|
||||
|
||||
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
|
||||
}
|
||||
|
||||
public enum BeatmapAttribute
|
||||
|
@ -4,7 +4,7 @@
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
@ -12,17 +12,16 @@ using osu.Game.Graphics.Sprites;
|
||||
namespace osu.Game.Skinning.Components
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public partial class TextElement : Container, ISkinnableDrawable
|
||||
public partial class TextElement : FontAdjustableSkinComponent
|
||||
{
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
[SettingSource("Text", "The text to be displayed.")]
|
||||
public Bindable<string> Text { get; } = new Bindable<string>("Circles!");
|
||||
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public TextElement()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
OsuSpriteText text;
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
text = new OsuSpriteText
|
||||
@ -34,5 +33,7 @@ namespace osu.Game.Skinning.Components
|
||||
};
|
||||
text.Current.BindTo(Text);
|
||||
}
|
||||
|
||||
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
|
||||
}
|
||||
}
|
||||
|
41
osu.Game/Skinning/FontAdjustableSkinComponent.cs
Normal file
41
osu.Game/Skinning/FontAdjustableSkinComponent.cs
Normal file
@ -0,0 +1,41 @@
|
||||
// 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;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
/// <summary>
|
||||
/// A skin component that contains text and allows the user to choose its font.
|
||||
/// </summary>
|
||||
public abstract partial class FontAdjustableSkinComponent : Container, ISkinnableDrawable
|
||||
{
|
||||
public bool UsesFixedAnchor { get; set; }
|
||||
|
||||
[SettingSource("Font", "The font to use.")]
|
||||
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
|
||||
|
||||
/// <summary>
|
||||
/// Implement to apply the user font selection to one or more components.
|
||||
/// </summary>
|
||||
protected abstract void SetFont(FontUsage font);
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Font.BindValueChanged(e =>
|
||||
{
|
||||
// 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);
|
||||
SetFont(f);
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user