mirror of
https://github.com/ppy/osu.git
synced 2026-05-18 21:52:57 +08:00
Merge pull request #33888 from frenzibyte/font-weight
Allow changing weight in `TextElement` and similar skin elements
This commit is contained in:
@@ -79,6 +79,11 @@ namespace osu.Game.Localisation.SkinComponents
|
||||
/// </summary>
|
||||
public static LocalisableString TextColourDescription => new TranslatableString(getKey(@"text_colour_description"), @"The colour of the text.");
|
||||
|
||||
/// <summary>
|
||||
/// "Text weight"
|
||||
/// </summary>
|
||||
public static LocalisableString TextWeight => new TranslatableString(getKey(@"text_weight"), @"Text weight");
|
||||
|
||||
/// <summary>
|
||||
/// "Use relative size"
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// 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 System.Linq;
|
||||
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.UserInterface;
|
||||
using osu.Game.Localisation.SkinComponents;
|
||||
using osu.Game.Overlays.Settings;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
@@ -21,6 +24,9 @@ namespace osu.Game.Skinning
|
||||
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
|
||||
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
|
||||
|
||||
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextWeight), SettingControlType = typeof(WeightDropdown))]
|
||||
public Bindable<FontWeight> TextWeight { get; } = new Bindable<FontWeight>(FontWeight.Regular);
|
||||
|
||||
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextColour), nameof(SkinnableComponentStrings.TextColourDescription))]
|
||||
public BindableColour4 TextColour { get; } = new BindableColour4(Colour4.White);
|
||||
|
||||
@@ -35,16 +41,69 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
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);
|
||||
Font.BindValueChanged(_ => updateFont());
|
||||
TextWeight.BindValueChanged(_ => updateFont(), true);
|
||||
|
||||
TextColour.BindValueChanged(e => SetTextColour(e.NewValue), true);
|
||||
}
|
||||
|
||||
private void updateFont() => SetFont(OsuFont.GetFont(Font.Value, weight: TextWeight.Value));
|
||||
|
||||
private partial class WeightDropdown : SettingsDropdown<FontWeight>
|
||||
{
|
||||
public FontAdjustableSkinComponent FontComponent => (FontAdjustableSkinComponent)SettingSourceObject;
|
||||
protected override OsuDropdown<FontWeight> CreateDropdown() => new DropdownControl(this);
|
||||
|
||||
private new partial class DropdownControl : SettingsDropdown<FontWeight>.DropdownControl
|
||||
{
|
||||
private readonly WeightDropdown settingsDropdown;
|
||||
|
||||
private IBindable<Typeface> font = null!;
|
||||
|
||||
public DropdownControl(WeightDropdown settingsDropdown)
|
||||
{
|
||||
this.settingsDropdown = settingsDropdown;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
font = settingsDropdown.FontComponent.Font.GetBoundCopy();
|
||||
font.BindValueChanged(_ => updateItems(), true);
|
||||
}
|
||||
|
||||
private void updateItems()
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
switch (font.Value)
|
||||
{
|
||||
case Typeface.Venera:
|
||||
AddDropdownItem(FontWeight.Light);
|
||||
AddDropdownItem(FontWeight.Bold);
|
||||
AddDropdownItem(FontWeight.Black);
|
||||
|
||||
Current.Default = FontWeight.Bold;
|
||||
|
||||
if (!Items.Contains(Current.Value))
|
||||
Current.SetDefault();
|
||||
break;
|
||||
|
||||
default:
|
||||
AddDropdownItem(FontWeight.Light);
|
||||
AddDropdownItem(FontWeight.Regular);
|
||||
AddDropdownItem(FontWeight.SemiBold);
|
||||
AddDropdownItem(FontWeight.Bold);
|
||||
|
||||
Current.Default = FontWeight.Regular;
|
||||
|
||||
if (!Items.Contains(Current.Value))
|
||||
Current.SetDefault();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user