1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 03:33:20 +08:00

Add colour customisation to skin components

This commit is contained in:
Daniel Cios 2024-08-06 11:06:08 +02:00
parent 6ec3f715d2
commit e81e356d59
9 changed files with 53 additions and 1 deletions

View File

@ -59,6 +59,26 @@ namespace osu.Game.Localisation.SkinComponents
/// </summary> /// </summary>
public static LocalisableString ShowLabelDescription => new TranslatableString(getKey(@"show_label_description"), @"Whether the component's label should be shown."); public static LocalisableString ShowLabelDescription => new TranslatableString(getKey(@"show_label_description"), @"Whether the component's label should be shown.");
/// <summary>
/// "Colour"
/// </summary>
public static LocalisableString Colour => new TranslatableString(getKey(@"colour"), @"Colour");
/// <summary>
/// "The colour of the component."
/// </summary>
public static LocalisableString ColourDescription => new TranslatableString(getKey(@"colour_description"), @"The colour of the component.");
/// <summary>
/// "Font colour"
/// </summary>
public static LocalisableString FontColour => new TranslatableString(getKey(@"font_colour"), @"Font colour");
/// <summary>
/// "The colour of the font."
/// </summary>
public static LocalisableString FontColourDescription => new TranslatableString(getKey(@"font_colour_description"), @"The colour of the font.");
private static string getKey(string key) => $@"{prefix}:{key}"; private static string getKey(string key) => $@"{prefix}:{key}";
} }
} }

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Localisation.HUD; using osu.Game.Localisation.HUD;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
namespace osu.Game.Screens.Play.HUD namespace osu.Game.Screens.Play.HUD
@ -28,6 +29,8 @@ namespace osu.Game.Screens.Play.HUD
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))] [SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))]
public Bindable<bool> ShowTime { get; } = new BindableBool(true); public Bindable<bool> ShowTime { get; } = new BindableBool(true);
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public new BindableColour4 Colour { get; } = new BindableColour4(Colour4.White);
[Resolved] [Resolved]
private Player? player { get; set; } private Player? player { get; set; }
@ -114,6 +117,7 @@ namespace osu.Game.Screens.Play.HUD
base.Update(); base.Update();
content.Height = bar.Height + bar_height + info.Height; content.Height = bar.Height + bar_height + info.Height;
graphContainer.Height = bar.Height; graphContainer.Height = bar.Height;
base.Colour = Colour.Value;
} }
protected override void UpdateProgress(double progress, bool isIntro) protected override void UpdateProgress(double progress, bool isIntro)

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
@ -21,6 +22,9 @@ namespace osu.Game.Screens.Play.HUD
[SettingSource("Inverted shear")] [SettingSource("Inverted shear")]
public BindableBool InvertShear { get; } = new BindableBool(); public BindableBool InvertShear { get; } = new BindableBool();
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public new BindableColour4 Colour { get; } = new BindableColour4(Color4Extensions.FromHex("#66CCFF"));
public ArgonWedgePiece() public ArgonWedgePiece()
{ {
CornerRadius = 10f; CornerRadius = 10f;
@ -37,7 +41,7 @@ namespace osu.Game.Screens.Play.HUD
InternalChild = new Box InternalChild = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientVertical(Color4Extensions.FromHex("#66CCFF").Opacity(0.0f), Color4Extensions.FromHex("#66CCFF").Opacity(0.25f)), Colour = ColourInfo.GradientVertical(Colour.Value.Opacity(0.0f), Colour.Value.Opacity(0.25f)),
}; };
} }
@ -46,6 +50,7 @@ namespace osu.Game.Screens.Play.HUD
base.LoadComplete(); base.LoadComplete();
InvertShear.BindValueChanged(v => Shear = new Vector2(0.8f, 0f) * (v.NewValue ? -1 : 1), true); InvertShear.BindValueChanged(v => Shear = new Vector2(0.8f, 0f) * (v.NewValue ? -1 : 1), true);
Colour.BindValueChanged(c => InternalChild.Colour = ColourInfo.GradientVertical(Colour.Value.Opacity(0.0f), Colour.Value.Opacity(0.25f)));
} }
} }
} }

View File

@ -10,6 +10,7 @@ using osu.Framework.Utils;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Localisation.HUD; using osu.Game.Localisation.HUD;
using osu.Game.Localisation.SkinComponents;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osuTK; using osuTK;
@ -35,6 +36,8 @@ namespace osu.Game.Screens.Play.HUD
[SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))] [SettingSource(typeof(SongProgressStrings), nameof(SongProgressStrings.ShowTime), nameof(SongProgressStrings.ShowTimeDescription))]
public Bindable<bool> ShowTime { get; } = new BindableBool(true); public Bindable<bool> ShowTime { get; } = new BindableBool(true);
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public new BindableColour4 Colour { get; } = new BindableColour4(Colour4.White);
[Resolved] [Resolved]
private Player? player { get; set; } private Player? player { get; set; }
@ -114,6 +117,8 @@ namespace osu.Game.Screens.Play.HUD
if (!Precision.AlmostEquals(Height, newHeight, 5f)) if (!Precision.AlmostEquals(Height, newHeight, 5f))
content.Height = newHeight; content.Height = newHeight;
base.Colour = Colour.Value;
} }
private void updateBarVisibility() private void updateBarVisibility()

View File

@ -123,6 +123,8 @@ namespace osu.Game.Skinning.Components
} }
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40); protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
protected override void SetFontColour(Colour4 fontColour) => text.Colour = fontColour;
} }
// WARNING: DO NOT ADD ANY VALUES TO THIS ENUM ANYWHERE ELSE THAN AT THE END. // WARNING: DO NOT ADD ANY VALUES TO THIS ENUM ANYWHERE ELSE THAN AT THE END.

View File

@ -27,6 +27,9 @@ namespace osu.Game.Skinning.Components
Precision = 0.01f Precision = 0.01f
}; };
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Colour), nameof(SkinnableComponentStrings.ColourDescription))]
public new BindableColour4 Colour { get; } = new BindableColour4(Colour4.White);
public BoxElement() public BoxElement()
{ {
Size = new Vector2(400, 80); Size = new Vector2(400, 80);
@ -48,6 +51,7 @@ namespace osu.Game.Skinning.Components
base.Update(); base.Update();
base.CornerRadius = CornerRadius.Value * Math.Min(DrawWidth, DrawHeight); base.CornerRadius = CornerRadius.Value * Math.Min(DrawWidth, DrawHeight);
base.Colour = Colour.Value;
} }
} }
} }

View File

@ -53,5 +53,7 @@ namespace osu.Game.Skinning.Components
} }
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40); protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
protected override void SetFontColour(Colour4 fontColour) => text.Colour = fontColour;
} }
} }

View File

@ -36,5 +36,7 @@ namespace osu.Game.Skinning.Components
} }
protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40); protected override void SetFont(FontUsage font) => text.Font = font.With(size: 40);
protected override void SetFontColour(Colour4 fontColour) => text.Colour = fontColour;
} }
} }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -20,11 +21,16 @@ namespace osu.Game.Skinning
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))] [SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus); public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.FontColour), nameof(SkinnableComponentStrings.FontColourDescription))]
public BindableColour4 FontColour { get; } = new BindableColour4(Colour4.White);
/// <summary> /// <summary>
/// Implement to apply the user font selection to one or more components. /// Implement to apply the user font selection to one or more components.
/// </summary> /// </summary>
protected abstract void SetFont(FontUsage font); protected abstract void SetFont(FontUsage font);
protected abstract void SetFontColour(Colour4 fontColour);
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -37,6 +43,8 @@ namespace osu.Game.Skinning
FontUsage f = OsuFont.GetFont(e.NewValue, weight: fontWeight); FontUsage f = OsuFont.GetFont(e.NewValue, weight: fontWeight);
SetFont(f); SetFont(f);
}, true); }, true);
FontColour.BindValueChanged(e => SetFontColour(e.NewValue), true);
} }
} }
} }