Recolour text box using OverlayColourProvider

This commit is contained in:
Bartłomiej Dach
2021-10-17 12:51:51 +02:00
parent a7f3beabe3
commit addcef4f5d

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -17,18 +19,13 @@ using osu.Framework.Input.Events;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osuTK; using osuTK;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public class OsuTextBox : BasicTextBox public class OsuTextBox : BasicTextBox
{ {
private readonly Sample[] textAddedSamples = new Sample[4];
private Sample capsTextAddedSample;
private Sample textRemovedSample;
private Sample textCommittedSample;
private Sample caretMovedSample;
/// <summary> /// <summary>
/// Whether to allow playing a different samples based on the type of character. /// Whether to allow playing a different samples based on the type of character.
/// If set to false, the same sample will be used for all characters. /// If set to false, the same sample will be used for all characters.
@ -42,10 +39,15 @@ namespace osu.Game.Graphics.UserInterface
protected override SpriteText CreatePlaceholder() => new OsuSpriteText protected override SpriteText CreatePlaceholder() => new OsuSpriteText
{ {
Font = OsuFont.GetFont(italics: true), Font = OsuFont.GetFont(italics: true),
Colour = new Color4(180, 180, 180, 255),
Margin = new MarginPadding { Left = 2 }, Margin = new MarginPadding { Left = 2 },
}; };
private readonly Sample?[] textAddedSamples = new Sample[4];
private Sample? capsTextAddedSample;
private Sample? textRemovedSample;
private Sample? textCommittedSample;
private Sample? caretMovedSample;
public OsuTextBox() public OsuTextBox()
{ {
Height = 40; Height = 40;
@ -56,12 +58,14 @@ namespace osu.Game.Graphics.UserInterface
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; }; Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(OsuColour colour, AudioManager audio) private void load(OverlayColourProvider? colourProvider, OsuColour colour, AudioManager audio)
{ {
BackgroundUnfocused = Color4.Black.Opacity(0.5f); BackgroundUnfocused = colourProvider?.Background5 ?? Color4.Black.Opacity(0.5f);
BackgroundFocused = OsuColour.Gray(0.3f).Opacity(0.8f); BackgroundFocused = colourProvider?.Background3 ?? OsuColour.Gray(0.3f).Opacity(0.8f);
BackgroundCommit = BorderColour = colour.Yellow; BackgroundCommit = BorderColour = colourProvider?.Highlight1 ?? colour.Yellow;
Placeholder.Colour = colourProvider?.Foreground1 ?? new Color4(180, 180, 180, 255);
for (int i = 0; i < textAddedSamples.Length; i++) for (int i = 0; i < textAddedSamples.Length; i++)
textAddedSamples[i] = audio.Samples.Get($@"Keyboard/key-press-{1 + i}"); textAddedSamples[i] = audio.Samples.Get($@"Keyboard/key-press-{1 + i}");