mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 13:35:37 +08:00
Merge pull request #13626 from Henry-YSLin/IHasSeed-interface
Extract `SeedSettingsControl` to `IHasSeed` interface
This commit is contained in:
commit
a1da9c5ee3
12
osu.Game/Rulesets/Mods/IHasSeed.cs
Normal file
12
osu.Game/Rulesets/Mods/IHasSeed.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Mods
|
||||||
|
{
|
||||||
|
public interface IHasSeed
|
||||||
|
{
|
||||||
|
Bindable<int?> Seed { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -2,17 +2,13 @@
|
|||||||
// 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.Bindables;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
|
||||||
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
|
||||||
{
|
{
|
||||||
public abstract class ModRandom : Mod
|
public abstract class ModRandom : Mod, IHasSeed
|
||||||
{
|
{
|
||||||
public override string Name => "Random";
|
public override string Name => "Random";
|
||||||
public override string Acronym => "RD";
|
public override string Acronym => "RD";
|
||||||
@ -20,88 +16,11 @@ 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(ModRandomSettingsControl))]
|
[SettingSource("Seed", "Use a custom seed instead of a random one", SettingControlType = typeof(SeedSettingsControl))]
|
||||||
public Bindable<int?> Seed { get; } = new Bindable<int?>
|
public Bindable<int?> Seed { get; } = new Bindable<int?>
|
||||||
{
|
{
|
||||||
Default = null,
|
Default = null,
|
||||||
Value = null
|
Value = null
|
||||||
};
|
};
|
||||||
|
|
||||||
private class ModRandomSettingsControl : 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 SettingsNumberBox.NumberBox seedNumberBox;
|
|
||||||
|
|
||||||
public SeedControl()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Y;
|
|
||||||
|
|
||||||
InternalChildren = new[]
|
|
||||||
{
|
|
||||||
new GridContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
seedNumberBox.Current.BindValueChanged(e =>
|
|
||||||
{
|
|
||||||
int? value = null;
|
|
||||||
|
|
||||||
if (int.TryParse(e.NewValue, out var intVal))
|
|
||||||
value = intVal;
|
|
||||||
|
|
||||||
current.Value = value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
if (current.Value == null)
|
|
||||||
seedNumberBox.Text = current.Current.Value.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
92
osu.Game/Rulesets/Mods/SeedSettingsControl.cs
Normal file
92
osu.Game/Rulesets/Mods/SeedSettingsControl.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// 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.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 OsuNumberBox seedNumberBox;
|
||||||
|
|
||||||
|
public SeedControl()
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
InternalChildren = new[]
|
||||||
|
{
|
||||||
|
new GridContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
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 OsuNumberBox
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
if (current.Value == null)
|
||||||
|
seedNumberBox.Text = current.Current.Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user