mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 15:43:18 +08:00
Refactor SeedSettingsControl
and related controls
This commit is contained in:
parent
31c786e1c3
commit
3b822cd5cf
10
osu.Game/Overlays/Settings/OutlinedNumberBox.cs
Normal file
10
osu.Game/Overlays/Settings/OutlinedNumberBox.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings
|
||||||
|
{
|
||||||
|
public class OutlinedNumberBox : OutlinedTextBox
|
||||||
|
{
|
||||||
|
protected override bool CanAddCharacter(char character) => char.IsNumber(character);
|
||||||
|
}
|
||||||
|
}
|
49
osu.Game/Overlays/Settings/OutlinedTextBox.cs
Normal file
49
osu.Game/Overlays/Settings/OutlinedTextBox.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings
|
||||||
|
{
|
||||||
|
public class OutlinedTextBox : OsuTextBox
|
||||||
|
{
|
||||||
|
private const float border_thickness = 3;
|
||||||
|
|
||||||
|
private Color4 borderColourFocused;
|
||||||
|
private Color4 borderColourUnfocused;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colour)
|
||||||
|
{
|
||||||
|
borderColourUnfocused = colour.Gray4.Opacity(0.5f);
|
||||||
|
borderColourFocused = BorderColour;
|
||||||
|
|
||||||
|
updateBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFocus(FocusEvent e)
|
||||||
|
{
|
||||||
|
base.OnFocus(e);
|
||||||
|
|
||||||
|
updateBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFocusLost(FocusLostEvent e)
|
||||||
|
{
|
||||||
|
base.OnFocusLost(e);
|
||||||
|
|
||||||
|
updateBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBorder()
|
||||||
|
{
|
||||||
|
BorderThickness = border_thickness;
|
||||||
|
BorderColour = HasFocus ? borderColourFocused : borderColourUnfocused;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,15 +7,11 @@ namespace osu.Game.Overlays.Settings
|
|||||||
{
|
{
|
||||||
public class SettingsNumberBox : SettingsItem<string>
|
public class SettingsNumberBox : SettingsItem<string>
|
||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new NumberBox
|
protected override Drawable CreateControl() => new OutlinedNumberBox
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
CommitOnFocusLost = true
|
||||||
};
|
};
|
||||||
|
|
||||||
public class NumberBox : SettingsTextBox.TextBox
|
|
||||||
{
|
|
||||||
protected override bool CanAddCharacter(char character) => char.IsNumber(character);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,60 +1,17 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
public class SettingsTextBox : SettingsItem<string>
|
public class SettingsTextBox : SettingsItem<string>
|
||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new TextBox
|
protected override Drawable CreateControl() => new OutlinedTextBox
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
CommitOnFocusLost = true,
|
CommitOnFocusLost = true
|
||||||
};
|
};
|
||||||
|
|
||||||
public class TextBox : OsuTextBox
|
|
||||||
{
|
|
||||||
private const float border_thickness = 3;
|
|
||||||
|
|
||||||
private Color4 borderColourFocused;
|
|
||||||
private Color4 borderColourUnfocused;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colour)
|
|
||||||
{
|
|
||||||
borderColourUnfocused = colour.Gray4.Opacity(0.5f);
|
|
||||||
borderColourFocused = BorderColour;
|
|
||||||
|
|
||||||
updateBorder();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnFocus(FocusEvent e)
|
|
||||||
{
|
|
||||||
base.OnFocus(e);
|
|
||||||
|
|
||||||
updateBorder();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnFocusLost(FocusLostEvent e)
|
|
||||||
{
|
|
||||||
base.OnFocusLost(e);
|
|
||||||
|
|
||||||
updateBorder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBorder()
|
|
||||||
{
|
|
||||||
BorderThickness = border_thickness;
|
|
||||||
BorderColour = HasFocus ? borderColourFocused : borderColourUnfocused;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly SettingsNumberBox.NumberBox seedNumberBox;
|
private readonly OutlinedNumberBox seedNumberBox;
|
||||||
|
|
||||||
public SeedControl()
|
public SeedControl()
|
||||||
{
|
{
|
||||||
@ -42,31 +42,11 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
InternalChildren = new[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
new GridContainer
|
seedNumberBox = new OutlinedNumberBox
|
||||||
{
|
{
|
||||||
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
CommitOnFocusLost = true
|
||||||
ColumnDimensions = new[]
|
|
||||||
{
|
|
||||||
new Dimension(),
|
|
||||||
new Dimension(GridSizeMode.Absolute, 2),
|
|
||||||
new Dimension(GridSizeMode.Relative, 0.25f)
|
|
||||||
},
|
|
||||||
RowDimensions = new[]
|
|
||||||
{
|
|
||||||
new Dimension(GridSizeMode.AutoSize)
|
|
||||||
},
|
|
||||||
Content = new[]
|
|
||||||
{
|
|
||||||
new Drawable[]
|
|
||||||
{
|
|
||||||
seedNumberBox = new SettingsNumberBox.NumberBox
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
CommitOnFocusLost = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,8 +63,9 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (current.Value == null)
|
base.Update();
|
||||||
seedNumberBox.Text = current.Current.Value.ToString();
|
if (Current.Value == null)
|
||||||
|
seedNumberBox.Current.Value = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user