From fe39a47797d9d754c59c86414d90bd237a02e9cb Mon Sep 17 00:00:00 2001 From: Pasi4K5 Date: Sat, 12 Jun 2021 00:34:53 +0200 Subject: [PATCH] Add `OsuModSettingsTextBox` and `OsuModSettingsNumberBox` --- .../UserInterface/OsuModSettingsNumberBox.cs | 10 +++++ .../UserInterface/OsuModSettingsTextBox.cs | 44 +++++++++++++++++++ osu.Game/Overlays/Settings/SettingsTextBox.cs | 2 +- osu.Game/Rulesets/Mods/ModRandom.cs | 4 +- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Graphics/UserInterface/OsuModSettingsNumberBox.cs create mode 100644 osu.Game/Graphics/UserInterface/OsuModSettingsTextBox.cs diff --git a/osu.Game/Graphics/UserInterface/OsuModSettingsNumberBox.cs b/osu.Game/Graphics/UserInterface/OsuModSettingsNumberBox.cs new file mode 100644 index 0000000000..4ec4165c0e --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuModSettingsNumberBox.cs @@ -0,0 +1,10 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuModSettingsNumberBox : OsuModSettingsTextBox + { + protected override bool CanAddCharacter(char character) => char.IsNumber(character); + } +} diff --git a/osu.Game/Graphics/UserInterface/OsuModSettingsTextBox.cs b/osu.Game/Graphics/UserInterface/OsuModSettingsTextBox.cs new file mode 100644 index 0000000000..6720727b7a --- /dev/null +++ b/osu.Game/Graphics/UserInterface/OsuModSettingsTextBox.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.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics.Colour; +using osu.Framework.Input.Events; + +namespace osu.Game.Graphics.UserInterface +{ + public class OsuModSettingsTextBox : OsuTextBox + { + private const float border_thickness = 3; + + private SRGBColour borderColourFocused; + private SRGBColour borderColourUnfocused; + + [BackgroundDependencyLoader] + private void load(OsuColour colour) + { + borderColourUnfocused = colour.Gray4.Opacity(0.5f); + borderColourFocused = BorderColour; + + BorderThickness = border_thickness; + BorderColour = borderColourUnfocused; + } + + protected override void OnFocus(FocusEvent e) + { + base.OnFocus(e); + + BorderThickness = border_thickness; + BorderColour = borderColourFocused; + } + + protected override void OnFocusLost(FocusLostEvent e) + { + base.OnFocusLost(e); + + BorderThickness = border_thickness; + BorderColour = borderColourUnfocused; + } + } +} diff --git a/osu.Game/Overlays/Settings/SettingsTextBox.cs b/osu.Game/Overlays/Settings/SettingsTextBox.cs index 5e700a1d6b..43bc8e87f8 100644 --- a/osu.Game/Overlays/Settings/SettingsTextBox.cs +++ b/osu.Game/Overlays/Settings/SettingsTextBox.cs @@ -8,7 +8,7 @@ namespace osu.Game.Overlays.Settings { public class SettingsTextBox : SettingsItem { - protected override Drawable CreateControl() => new OsuTextBox + protected override Drawable CreateControl() => new OsuModSettingsTextBox { Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, diff --git a/osu.Game/Rulesets/Mods/ModRandom.cs b/osu.Game/Rulesets/Mods/ModRandom.cs index 3f14263420..450b2a0680 100644 --- a/osu.Game/Rulesets/Mods/ModRandom.cs +++ b/osu.Game/Rulesets/Mods/ModRandom.cs @@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Mods } } - private readonly OsuNumberBox seedNumberBox; + private readonly OsuModSettingsNumberBox seedNumberBox; public SeedControl() { @@ -76,7 +76,7 @@ namespace osu.Game.Rulesets.Mods { new Drawable[] { - seedNumberBox = new OsuNumberBox + seedNumberBox = new OsuModSettingsNumberBox { RelativeSizeAxes = Axes.X, CommitOnFocusLost = true