1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-07 20:12:54 +08:00

Support custom input overlay color

This commit is contained in:
normalid 2024-07-23 23:35:25 +08:00
parent c7b110a471
commit c52a993607
5 changed files with 49 additions and 23 deletions

View File

@ -9,6 +9,7 @@ using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Rulesets.Objects.Legacy; using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Skinning;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Beatmaps.Formats namespace osu.Game.Beatmaps.Formats
@ -93,14 +94,8 @@ namespace osu.Game.Beatmaps.Formats
return line; return line;
} }
protected void HandleColours<TModel>(TModel output, string line, bool allowAlpha) private Color4 convertSettingStringToColor4(string[] split, bool allowAlpha, KeyValuePair<string, string> pair)
{ {
var pair = SplitKeyVal(line);
bool isCombo = pair.Key.StartsWith(@"Combo", StringComparison.Ordinal);
string[] split = pair.Value.Split(',');
if (split.Length != 3 && split.Length != 4) if (split.Length != 3 && split.Length != 4)
throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B or R,G,B,A): {pair.Value}"); throw new InvalidOperationException($@"Color specified in incorrect format (should be R,G,B or R,G,B,A): {pair.Value}");
@ -115,6 +110,17 @@ namespace osu.Game.Beatmaps.Formats
{ {
throw new InvalidOperationException(@"Color must be specified with 8-bit integer components"); throw new InvalidOperationException(@"Color must be specified with 8-bit integer components");
} }
return colour;
}
protected void HandleColours<TModel>(TModel output, string line, bool allowAlpha)
{
var pair = SplitKeyVal(line);
string[] split = pair.Value.Split(',');
Color4 colour = convertSettingStringToColor4(split, allowAlpha, pair);
bool isCombo = pair.Key.StartsWith(@"Combo", StringComparison.Ordinal);
if (isCombo) if (isCombo)
{ {
@ -128,6 +134,13 @@ namespace osu.Game.Beatmaps.Formats
tHasCustomColours.CustomColours[pair.Key] = colour; tHasCustomColours.CustomColours[pair.Key] = colour;
} }
bool isInputOverlayText = pair.Key.StartsWith(@"InputOverlayText");
if (isInputOverlayText)
{
if (!(output is SkinConfiguration tSkinConfiguration)) return;
tSkinConfiguration.InputOverlayText = colour;
}
} }
protected KeyValuePair<string, string> SplitKeyVal(string line, char separator = ':', bool shouldTrim = true) protected KeyValuePair<string, string> SplitKeyVal(string line, char separator = ':', bool shouldTrim = true)

View File

@ -16,13 +16,19 @@ namespace osu.Game.Skinning
{ {
public bool UsesFixedAnchor { get; set; } public bool UsesFixedAnchor { get; set; }
public float TransitionDuration { get; set; } = 150f; public float TransitionDuration { get; set; } = 50f;
public Colour4 KeyTextColour { get; set; } = Colour4.White; public Colour4 KeyTextColour
{
get => keyTextColour;
set
{
keyTextColour = value;
overlayKeyText.Colour = value;
}
}
public Colour4 KeyDownBackgroundColour { get; set; } = Colour4.Yellow; private Colour4 keyTextColour = Colour4.White;
public Colour4 KeyUpBackgroundColour { get; set; } = Colour4.White;
private float keyTextRotation = 0f; private float keyTextRotation = 0f;
@ -66,7 +72,7 @@ namespace osu.Game.Skinning
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Text = trigger.Name, Text = trigger.Name,
Colour = KeyTextColour, Colour = keyTextColour,
Font = OsuFont.GetFont(size: 20), Font = OsuFont.GetFont(size: 20),
Rotation = KeyTextRotation Rotation = KeyTextRotation
}, },
@ -89,8 +95,7 @@ namespace osu.Game.Skinning
protected override void Activate(bool forwardPlayback = true) protected override void Activate(bool forwardPlayback = true)
{ {
base.Activate(forwardPlayback); base.Activate(forwardPlayback);
keyContainer.ScaleTo(0.75f, TransitionDuration); keyContainer.ScaleTo(0.8f, TransitionDuration);
keyContainer.FadeColour(KeyDownBackgroundColour, TransitionDuration);
overlayKeyText.Text = CountPresses.Value.ToString(); overlayKeyText.Text = CountPresses.Value.ToString();
} }
@ -98,7 +103,6 @@ namespace osu.Game.Skinning
{ {
base.Deactivate(forwardPlayback); base.Deactivate(forwardPlayback);
keyContainer.ScaleTo(1f, TransitionDuration); keyContainer.ScaleTo(1f, TransitionDuration);
keyContainer.FadeColour(KeyUpBackgroundColour, TransitionDuration);
} }
} }
} }

View File

@ -5,7 +5,6 @@ using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -45,10 +44,13 @@ namespace osu.Game.Skinning
}); });
} }
[BackgroundDependencyLoader] [Resolved]
private void load(ISkinSource source) private ISkinSource source { get; set; } = null!;
protected override void LoadComplete()
{ {
source.GetConfig<string, Colour4>("InputOverlayText")?.BindValueChanged(v => base.LoadComplete();
source.GetConfig<SkinConfiguration.LegacySetting, Colour4>(SkinConfiguration.LegacySetting.InputOverlayText)?.BindValueChanged(v =>
{ {
KeyTextColor = v.NewValue; KeyTextColor = v.NewValue;
}, true); }, true);
@ -69,14 +71,15 @@ namespace osu.Game.Skinning
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
// keep the text are always horizontal // keep the text are always horizontal
foreach (var child in KeyFlow.Cast<LegacyKeyCounter>()) foreach (var child in KeyFlow.Cast<LegacyKeyCounter>())
child.KeyTextRotation = -Rotation; child.KeyTextRotation = -Rotation;
} }
private Color4 keyTextColor = Color4.White; private Colour4 keyTextColor = Colour4.White;
public Color4 KeyTextColor public Colour4 KeyTextColor
{ {
get => keyTextColor; get => keyTextColor;
set set

View File

@ -15,6 +15,7 @@ using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Framework.Logging;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osu.Game.Extensions; using osu.Game.Extensions;
@ -309,7 +310,8 @@ namespace osu.Game.Skinning
{ {
case SkinConfiguration.LegacySetting.Version: case SkinConfiguration.LegacySetting.Version:
return SkinUtils.As<TValue>(new Bindable<decimal>(Configuration.LegacyVersion ?? SkinConfiguration.LATEST_VERSION)); return SkinUtils.As<TValue>(new Bindable<decimal>(Configuration.LegacyVersion ?? SkinConfiguration.LATEST_VERSION));
case SkinConfiguration.LegacySetting.InputOverlayText:
return SkinUtils.As<TValue>(new Bindable<Colour4>(Configuration.InputOverlayText ?? Colour4.White));
default: default:
return genericLookup<SkinConfiguration.LegacySetting, TValue>(legacySetting); return genericLookup<SkinConfiguration.LegacySetting, TValue>(legacySetting);
} }

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 System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;
using osuTK.Graphics; using osuTK.Graphics;
@ -38,8 +39,11 @@ namespace osu.Game.Skinning
AnimationFramerate, AnimationFramerate,
LayeredHitSounds, LayeredHitSounds,
AllowSliderBallTint, AllowSliderBallTint,
InputOverlayText,
} }
public Colour4? InputOverlayText { get; internal set; }
public static List<Color4> DefaultComboColours { get; } = new List<Color4> public static List<Color4> DefaultComboColours { get; } = new List<Color4>
{ {
new Color4(255, 192, 0, 255), new Color4(255, 192, 0, 255),