1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:52:57 +08:00

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
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -1,6 +1,8 @@
// 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.
#nullable enable
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
@ -17,18 +19,13 @@ using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTextBox : BasicTextBox
{
private readonly Sample[] textAddedSamples = new Sample[4];
private Sample capsTextAddedSample;
private Sample textRemovedSample;
private Sample textCommittedSample;
private Sample caretMovedSample;
/// <summary>
/// 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.
@ -42,10 +39,15 @@ namespace osu.Game.Graphics.UserInterface
protected override SpriteText CreatePlaceholder() => new OsuSpriteText
{
Font = OsuFont.GetFont(italics: true),
Colour = new Color4(180, 180, 180, 255),
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()
{
Height = 40;
@ -56,12 +58,14 @@ namespace osu.Game.Graphics.UserInterface
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
}
[BackgroundDependencyLoader]
private void load(OsuColour colour, AudioManager audio)
[BackgroundDependencyLoader(true)]
private void load(OverlayColourProvider? colourProvider, OsuColour colour, AudioManager audio)
{
BackgroundUnfocused = Color4.Black.Opacity(0.5f);
BackgroundFocused = OsuColour.Gray(0.3f).Opacity(0.8f);
BackgroundCommit = BorderColour = colour.Yellow;
BackgroundUnfocused = colourProvider?.Background5 ?? Color4.Black.Opacity(0.5f);
BackgroundFocused = colourProvider?.Background3 ?? OsuColour.Gray(0.3f).Opacity(0.8f);
BackgroundCommit = BorderColour = colourProvider?.Highlight1 ?? colour.Yellow;
Placeholder.Colour = colourProvider?.Foreground1 ?? new Color4(180, 180, 180, 255);
for (int i = 0; i < textAddedSamples.Length; i++)
textAddedSamples[i] = audio.Samples.Get($@"Keyboard/key-press-{1 + i}");