mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 00:52:56 +08:00
Moved the string
to int?
conversion logic into SettingsNumberBox
This commit is contained in:
parent
3b822cd5cf
commit
0cceef8da5
@ -147,7 +147,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
private readonly Bindable<string> beatmapId = new Bindable<string>();
|
private readonly Bindable<int?> beatmapId = new Bindable<int?>();
|
||||||
|
|
||||||
private readonly Bindable<string> mods = new Bindable<string>();
|
private readonly Bindable<string> mods = new Bindable<string>();
|
||||||
|
|
||||||
@ -220,14 +220,12 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RulesetStore rulesets)
|
private void load(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
beatmapId.Value = Model.ID.ToString();
|
beatmapId.Value = Model.ID;
|
||||||
beatmapId.BindValueChanged(idString =>
|
beatmapId.BindValueChanged(idInt =>
|
||||||
{
|
{
|
||||||
int.TryParse(idString.NewValue, out var parsed);
|
Model.ID = idInt.NewValue ?? 0;
|
||||||
|
|
||||||
Model.ID = parsed;
|
if (idInt.NewValue != idInt.OldValue)
|
||||||
|
|
||||||
if (idString.NewValue != idString.OldValue)
|
|
||||||
Model.BeatmapInfo = null;
|
Model.BeatmapInfo = null;
|
||||||
|
|
||||||
if (Model.BeatmapInfo != null)
|
if (Model.BeatmapInfo != null)
|
||||||
|
@ -147,7 +147,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
private readonly Bindable<string> beatmapId = new Bindable<string>();
|
private readonly Bindable<int?> beatmapId = new Bindable<int?>();
|
||||||
|
|
||||||
private readonly Bindable<string> score = new Bindable<string>();
|
private readonly Bindable<string> score = new Bindable<string>();
|
||||||
|
|
||||||
@ -228,16 +228,12 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RulesetStore rulesets)
|
private void load(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
beatmapId.Value = Model.ID.ToString();
|
beatmapId.Value = Model.ID;
|
||||||
beatmapId.BindValueChanged(idString =>
|
beatmapId.BindValueChanged(idInt =>
|
||||||
{
|
{
|
||||||
int parsed;
|
Model.ID = idInt.NewValue ?? 0;
|
||||||
|
|
||||||
int.TryParse(idString.NewValue, out parsed);
|
if (idInt.NewValue != idInt.OldValue)
|
||||||
|
|
||||||
Model.ID = parsed;
|
|
||||||
|
|
||||||
if (idString.NewValue != idString.OldValue)
|
|
||||||
Model.BeatmapInfo = null;
|
Model.BeatmapInfo = null;
|
||||||
|
|
||||||
if (Model.BeatmapInfo != null)
|
if (Model.BeatmapInfo != null)
|
||||||
|
@ -214,7 +214,7 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private TournamentGameBase game { get; set; }
|
private TournamentGameBase game { get; set; }
|
||||||
|
|
||||||
private readonly Bindable<string> userId = new Bindable<string>();
|
private readonly Bindable<int?> userId = new Bindable<int?>();
|
||||||
|
|
||||||
private readonly Container drawableContainer;
|
private readonly Container drawableContainer;
|
||||||
|
|
||||||
@ -278,14 +278,12 @@ namespace osu.Game.Tournament.Screens.Editors
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
userId.Value = user.Id.ToString();
|
userId.Value = user.Id;
|
||||||
userId.BindValueChanged(idString =>
|
userId.BindValueChanged(idInt =>
|
||||||
{
|
{
|
||||||
int.TryParse(idString.NewValue, out var parsed);
|
user.Id = idInt.NewValue ?? 0;
|
||||||
|
|
||||||
user.Id = parsed;
|
if (idInt.NewValue != idInt.OldValue)
|
||||||
|
|
||||||
if (idString.NewValue != idString.OldValue)
|
|
||||||
user.Username = string.Empty;
|
user.Username = string.Empty;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(user.Username))
|
if (!string.IsNullOrEmpty(user.Username))
|
||||||
|
@ -1,17 +1,68 @@
|
|||||||
// 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.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
public class SettingsNumberBox : SettingsItem<string>
|
public class SettingsNumberBox : SettingsItem<int?>
|
||||||
{
|
{
|
||||||
protected override Drawable CreateControl() => new OutlinedNumberBox
|
protected override Drawable CreateControl() => new NumberControl
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Margin = new MarginPadding { Top = 5 }
|
||||||
|
};
|
||||||
|
|
||||||
|
private sealed class NumberControl : CompositeDrawable, IHasCurrentValue<int?>
|
||||||
|
{
|
||||||
|
private readonly BindableWithCurrent<int?> current = new BindableWithCurrent<int?>();
|
||||||
|
|
||||||
|
private readonly OutlinedNumberBox numberBox;
|
||||||
|
|
||||||
|
public Bindable<int?> Current
|
||||||
|
{
|
||||||
|
get => current;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
current.Current = value;
|
||||||
|
numberBox.Text = value.Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberControl()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
InternalChildren = new[]
|
||||||
|
{
|
||||||
|
numberBox = new OutlinedNumberBox
|
||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
CommitOnFocusLost = true
|
CommitOnFocusLost = true
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
numberBox.Current.BindValueChanged(e =>
|
||||||
|
{
|
||||||
|
int? value = null;
|
||||||
|
|
||||||
|
if (int.TryParse(e.NewValue, out var intVal))
|
||||||
|
value = intVal;
|
||||||
|
|
||||||
|
current.Value = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
if (Current.Value == null)
|
||||||
|
numberBox.Current.Value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Overlays.Settings;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Mods
|
namespace osu.Game.Rulesets.Mods
|
||||||
{
|
{
|
||||||
@ -16,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
public override IconUsage? Icon => OsuIcon.Dice;
|
public override IconUsage? Icon => OsuIcon.Dice;
|
||||||
public override double ScoreMultiplier => 1;
|
public override double ScoreMultiplier => 1;
|
||||||
|
|
||||||
[SettingSource("Seed", "Use a custom seed instead of a random one", SettingControlType = typeof(SeedSettingsControl))]
|
[SettingSource("Seed", "Use a custom seed instead of a random one", SettingControlType = typeof(SettingsNumberBox))]
|
||||||
public Bindable<int?> Seed { get; } = new Bindable<int?>
|
public Bindable<int?> Seed { get; } = new Bindable<int?>
|
||||||
{
|
{
|
||||||
Default = null,
|
Default = null,
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
// 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.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
using osu.Game.Overlays.Settings;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Mods
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A settings control for use by <see cref="IHasSeed"/> mods which have a customisable seed value.
|
|
||||||
/// </summary>
|
|
||||||
public class SeedSettingsControl : SettingsItem<int?>
|
|
||||||
{
|
|
||||||
protected override Drawable CreateControl() => new SeedControl
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Margin = new MarginPadding { Top = 5 }
|
|
||||||
};
|
|
||||||
|
|
||||||
private sealed class SeedControl : CompositeDrawable, IHasCurrentValue<int?>
|
|
||||||
{
|
|
||||||
private readonly BindableWithCurrent<int?> current = new BindableWithCurrent<int?>();
|
|
||||||
|
|
||||||
public Bindable<int?> Current
|
|
||||||
{
|
|
||||||
get => current;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
current.Current = value;
|
|
||||||
seedNumberBox.Text = value.Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly OutlinedNumberBox seedNumberBox;
|
|
||||||
|
|
||||||
public SeedControl()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Y;
|
|
||||||
|
|
||||||
InternalChildren = new[]
|
|
||||||
{
|
|
||||||
seedNumberBox = new OutlinedNumberBox
|
|
||||||
{
|
|
||||||
Margin = new MarginPadding { Top = 5 },
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
CommitOnFocusLost = true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
seedNumberBox.Current.BindValueChanged(e =>
|
|
||||||
{
|
|
||||||
int? value = null;
|
|
||||||
|
|
||||||
if (int.TryParse(e.NewValue, out var intVal))
|
|
||||||
value = intVal;
|
|
||||||
|
|
||||||
current.Value = value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
if (Current.Value == null)
|
|
||||||
seedNumberBox.Current.Value = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user