From fa508245a1fa50b14a602a758d24581b3c6e9f40 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 26 Jun 2025 07:23:29 +0300 Subject: [PATCH 1/3] Support changing weight in text-based elements --- osu.Game/Graphics/OsuFont.cs | 8 ++ osu.Game/Localisation/FontStrings.cs | 44 +++++++++++ .../SkinnableComponentStrings.cs | 10 +++ .../Skinning/FontAdjustableSkinComponent.cs | 76 +++++++++++++++++-- 4 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 osu.Game/Localisation/FontStrings.cs diff --git a/osu.Game/Graphics/OsuFont.cs b/osu.Game/Graphics/OsuFont.cs index b314c602f5..22a2c9f37b 100644 --- a/osu.Game/Graphics/OsuFont.cs +++ b/osu.Game/Graphics/OsuFont.cs @@ -5,6 +5,8 @@ using System.ComponentModel; using osu.Framework.Graphics.Sprites; +using osu.Framework.Localisation; +using osu.Game.Localisation; namespace osu.Game.Graphics { @@ -177,31 +179,37 @@ namespace osu.Game.Graphics /// /// Equivalent to weight 300. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Light))] Light = 300, /// /// Equivalent to weight 400. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Regular))] Regular = 400, /// /// Equivalent to weight 500. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Medium))] Medium = 500, /// /// Equivalent to weight 600. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.SemiBold))] SemiBold = 600, /// /// Equivalent to weight 700. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Bold))] Bold = 700, /// /// Equivalent to weight 900. /// + [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Black))] Black = 900 } } diff --git a/osu.Game/Localisation/FontStrings.cs b/osu.Game/Localisation/FontStrings.cs new file mode 100644 index 0000000000..72e3f3eaba --- /dev/null +++ b/osu.Game/Localisation/FontStrings.cs @@ -0,0 +1,44 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Localisation; + +namespace osu.Game.Localisation +{ + public static class FontStrings + { + private const string prefix = @"osu.Game.Resources.Localisation.Font"; + + /// + /// "Light" + /// + public static LocalisableString Light => new TranslatableString(getKey(@"light"), @"Light"); + + /// + /// "Regular" + /// + public static LocalisableString Regular => new TranslatableString(getKey(@"regular"), @"Regular"); + + /// + /// "Medium" + /// + public static LocalisableString Medium => new TranslatableString(getKey(@"medium"), @"Medium"); + + /// + /// "Semibold" + /// + public static LocalisableString SemiBold => new TranslatableString(getKey(@"semi_bold"), @"Semibold"); + + /// + /// "Bold" + /// + public static LocalisableString Bold => new TranslatableString(getKey(@"bold"), @"Bold"); + + /// + /// "Black" + /// + public static LocalisableString Black => new TranslatableString(getKey(@"black"), @"Black"); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} diff --git a/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs b/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs index 66abf2bfd5..61d1137e6a 100644 --- a/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs +++ b/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs @@ -79,6 +79,16 @@ namespace osu.Game.Localisation.SkinComponents /// public static LocalisableString TextColourDescription => new TranslatableString(getKey(@"text_colour_description"), @"The colour of the text."); + /// + /// "Text weight" + /// + public static LocalisableString TextWeight => new TranslatableString(getKey(@"text_weight"), @"Text weight"); + + /// + /// "The weight of the text." + /// + public static LocalisableString TextWeightDescription => new TranslatableString(getKey(@"text_weight_description"), @"The weight of the text."); + /// /// "Use relative size" /// diff --git a/osu.Game/Skinning/FontAdjustableSkinComponent.cs b/osu.Game/Skinning/FontAdjustableSkinComponent.cs index 0821edf7fc..1fda31afb7 100644 --- a/osu.Game/Skinning/FontAdjustableSkinComponent.cs +++ b/osu.Game/Skinning/FontAdjustableSkinComponent.cs @@ -1,13 +1,16 @@ // Copyright (c) ppy Pty Ltd . 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,10 @@ namespace osu.Game.Skinning [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))] public Bindable Font { get; } = new Bindable(Typeface.Torus); + [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextWeight), nameof(SkinnableComponentStrings.TextWeightDescription), + SettingControlType = typeof(WeightDropdown))] + public Bindable TextWeight { get; } = new Bindable(FontWeight.Regular); + [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextColour), nameof(SkinnableComponentStrings.TextColourDescription))] public BindableColour4 TextColour { get; } = new BindableColour4(Colour4.White); @@ -35,16 +42,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 + { + public FontAdjustableSkinComponent FontComponent => (FontAdjustableSkinComponent)SettingSourceObject; + protected override OsuDropdown CreateDropdown() => new DropdownControl(this); + + private new partial class DropdownControl : SettingsDropdown.DropdownControl + { + private readonly WeightDropdown settingsDropdown; + + private IBindable 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; + } + } + } + } } } From cd354a0de827a0601d8f78fdd74c6e61d64c55da Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Fri, 27 Jun 2025 00:58:10 +0300 Subject: [PATCH 2/3] Remove font weight localisation --- osu.Game/Graphics/OsuFont.cs | 8 ----- osu.Game/Localisation/FontStrings.cs | 44 ---------------------------- 2 files changed, 52 deletions(-) delete mode 100644 osu.Game/Localisation/FontStrings.cs diff --git a/osu.Game/Graphics/OsuFont.cs b/osu.Game/Graphics/OsuFont.cs index 22a2c9f37b..b314c602f5 100644 --- a/osu.Game/Graphics/OsuFont.cs +++ b/osu.Game/Graphics/OsuFont.cs @@ -5,8 +5,6 @@ using System.ComponentModel; using osu.Framework.Graphics.Sprites; -using osu.Framework.Localisation; -using osu.Game.Localisation; namespace osu.Game.Graphics { @@ -179,37 +177,31 @@ namespace osu.Game.Graphics /// /// Equivalent to weight 300. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Light))] Light = 300, /// /// Equivalent to weight 400. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Regular))] Regular = 400, /// /// Equivalent to weight 500. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Medium))] Medium = 500, /// /// Equivalent to weight 600. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.SemiBold))] SemiBold = 600, /// /// Equivalent to weight 700. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Bold))] Bold = 700, /// /// Equivalent to weight 900. /// - [LocalisableDescription(typeof(FontStrings), nameof(FontStrings.Black))] Black = 900 } } diff --git a/osu.Game/Localisation/FontStrings.cs b/osu.Game/Localisation/FontStrings.cs deleted file mode 100644 index 72e3f3eaba..0000000000 --- a/osu.Game/Localisation/FontStrings.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Localisation; - -namespace osu.Game.Localisation -{ - public static class FontStrings - { - private const string prefix = @"osu.Game.Resources.Localisation.Font"; - - /// - /// "Light" - /// - public static LocalisableString Light => new TranslatableString(getKey(@"light"), @"Light"); - - /// - /// "Regular" - /// - public static LocalisableString Regular => new TranslatableString(getKey(@"regular"), @"Regular"); - - /// - /// "Medium" - /// - public static LocalisableString Medium => new TranslatableString(getKey(@"medium"), @"Medium"); - - /// - /// "Semibold" - /// - public static LocalisableString SemiBold => new TranslatableString(getKey(@"semi_bold"), @"Semibold"); - - /// - /// "Bold" - /// - public static LocalisableString Bold => new TranslatableString(getKey(@"bold"), @"Bold"); - - /// - /// "Black" - /// - public static LocalisableString Black => new TranslatableString(getKey(@"black"), @"Black"); - - private static string getKey(string key) => $@"{prefix}:{key}"; - } -} From 5485abd3a53102c6bca1e3eec790b304cba9fec6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 27 Jun 2025 17:09:29 +0900 Subject: [PATCH 3/3] Remove pointless tooltip I agree that these are pointless and we should probably remove the others and stop wasting localiser's time on these. --- .../Localisation/SkinComponents/SkinnableComponentStrings.cs | 5 ----- osu.Game/Skinning/FontAdjustableSkinComponent.cs | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs b/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs index 61d1137e6a..35ed1ea55c 100644 --- a/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs +++ b/osu.Game/Localisation/SkinComponents/SkinnableComponentStrings.cs @@ -84,11 +84,6 @@ namespace osu.Game.Localisation.SkinComponents /// public static LocalisableString TextWeight => new TranslatableString(getKey(@"text_weight"), @"Text weight"); - /// - /// "The weight of the text." - /// - public static LocalisableString TextWeightDescription => new TranslatableString(getKey(@"text_weight_description"), @"The weight of the text."); - /// /// "Use relative size" /// diff --git a/osu.Game/Skinning/FontAdjustableSkinComponent.cs b/osu.Game/Skinning/FontAdjustableSkinComponent.cs index 1fda31afb7..f2d8c9e440 100644 --- a/osu.Game/Skinning/FontAdjustableSkinComponent.cs +++ b/osu.Game/Skinning/FontAdjustableSkinComponent.cs @@ -24,8 +24,7 @@ namespace osu.Game.Skinning [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))] public Bindable Font { get; } = new Bindable(Typeface.Torus); - [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextWeight), nameof(SkinnableComponentStrings.TextWeightDescription), - SettingControlType = typeof(WeightDropdown))] + [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextWeight), SettingControlType = typeof(WeightDropdown))] public Bindable TextWeight { get; } = new Bindable(FontWeight.Regular); [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.TextColour), nameof(SkinnableComponentStrings.TextColourDescription))]