mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
Merge pull request #6432 from LeNitrous/customized-mods
Add per-mod settings
This commit is contained in:
commit
166e957104
107
osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs
Normal file
107
osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs
Normal file
@ -0,0 +1,107 @@
|
||||
// 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 System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneModSettings : OsuTestScene
|
||||
{
|
||||
private TestModSelectOverlay modSelect;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Add(modSelect = new TestModSelectOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
});
|
||||
|
||||
var testMod = new TestModCustomisable1();
|
||||
|
||||
AddStep("open", modSelect.Show);
|
||||
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
|
||||
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
|
||||
AddStep("select mod", () => modSelect.SelectMod(testMod));
|
||||
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
|
||||
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
|
||||
AddStep("deselect mod", () => modSelect.SelectMod(testMod));
|
||||
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
|
||||
}
|
||||
|
||||
private class TestModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
public new Container ModSettingsContainer => base.ModSettingsContainer;
|
||||
public new TriangleButton CustomiseButton => base.CustomiseButton;
|
||||
|
||||
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
|
||||
|
||||
public void SelectMod(Mod mod) =>
|
||||
ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
|
||||
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
foreach (var section in ModSectionsContainer)
|
||||
{
|
||||
if (section.ModType == ModType.Conversion)
|
||||
{
|
||||
section.Mods = new Mod[]
|
||||
{
|
||||
new TestModCustomisable1(),
|
||||
new TestModCustomisable2()
|
||||
};
|
||||
}
|
||||
else
|
||||
section.Mods = Array.Empty<Mod>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TestModCustomisable1 : TestModCustomisable
|
||||
{
|
||||
public override string Name => "Customisable Mod 1";
|
||||
|
||||
public override string Acronym => "CM1";
|
||||
}
|
||||
|
||||
private class TestModCustomisable2 : TestModCustomisable
|
||||
{
|
||||
public override string Name => "Customisable Mod 2";
|
||||
|
||||
public override string Acronym => "CM2";
|
||||
}
|
||||
|
||||
private abstract class TestModCustomisable : Mod, IApplicableMod
|
||||
{
|
||||
public override double ScoreMultiplier => 1.0;
|
||||
|
||||
public override ModType Type => ModType.Conversion;
|
||||
|
||||
[SettingSource("Sample float", "Change something for a mod")]
|
||||
public BindableFloat SliderBindable { get; } = new BindableFloat
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 10,
|
||||
Default = 5,
|
||||
Value = 7
|
||||
};
|
||||
|
||||
[SettingSource("Sample bool", "Clicking this changes a setting")]
|
||||
public BindableBool TickBindable { get; } = new BindableBool();
|
||||
}
|
||||
}
|
||||
}
|
56
osu.Game/Overlays/Mods/ModControlSection.cs
Normal file
56
osu.Game/Overlays/Mods/ModControlSection.cs
Normal file
@ -0,0 +1,56 @@
|
||||
// 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.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public class ModControlSection : Container
|
||||
{
|
||||
protected FillFlowContainer FlowContent;
|
||||
protected override Container<Drawable> Content => FlowContent;
|
||||
|
||||
public readonly Mod Mod;
|
||||
|
||||
public ModControlSection(Mod mod)
|
||||
{
|
||||
Mod = mod;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
FlowContent = new FillFlowContainer
|
||||
{
|
||||
Margin = new MarginPadding { Top = 30 },
|
||||
Spacing = new Vector2(0, 5),
|
||||
Direction = FillDirection.Vertical,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
|
||||
AddRange(Mod.CreateSettingsControls());
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = Mod.Name,
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
||||
Colour = colours.Yellow,
|
||||
},
|
||||
FlowContent
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -57,6 +57,15 @@ namespace osu.Game.Overlays.Mods
|
||||
}).ToArray();
|
||||
|
||||
modsLoadCts?.Cancel();
|
||||
|
||||
if (modContainers.Length == 0)
|
||||
{
|
||||
ModIconsLoaded = true;
|
||||
headerLabel.Hide();
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
ModIconsLoaded = false;
|
||||
|
||||
LoadComponentsAsync(modContainers, c =>
|
||||
@ -67,18 +76,9 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
buttons = modContainers.OfType<ModButton>().ToArray();
|
||||
|
||||
if (value.Any())
|
||||
{
|
||||
headerLabel.FadeIn(200);
|
||||
this.FadeIn(200);
|
||||
}
|
||||
else
|
||||
{
|
||||
// transition here looks weird as mods instantly disappear.
|
||||
headerLabel.Hide();
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ModButton[] buttons = { };
|
||||
|
@ -13,6 +13,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -31,6 +32,7 @@ namespace osu.Game.Overlays.Mods
|
||||
public class ModSelectOverlay : WaveOverlayContainer
|
||||
{
|
||||
protected readonly TriangleButton DeselectAllButton;
|
||||
protected readonly TriangleButton CustomiseButton;
|
||||
protected readonly TriangleButton CloseButton;
|
||||
|
||||
protected readonly OsuSpriteText MultiplierLabel;
|
||||
@ -42,6 +44,10 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
|
||||
|
||||
protected readonly FillFlowContainer<ModControlSection> ModSettingsContent;
|
||||
|
||||
protected readonly Container ModSettingsContainer;
|
||||
|
||||
protected readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
protected readonly IBindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
||||
@ -226,6 +232,17 @@ namespace osu.Game.Overlays.Mods
|
||||
Right = 20
|
||||
}
|
||||
},
|
||||
CustomiseButton = new TriangleButton
|
||||
{
|
||||
Width = 180,
|
||||
Text = "Customisation",
|
||||
Action = () => ModSettingsContainer.Alpha = ModSettingsContainer.Alpha == 1 ? 0 : 1,
|
||||
Enabled = { Value = false },
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Right = 20
|
||||
}
|
||||
},
|
||||
CloseButton = new TriangleButton
|
||||
{
|
||||
Width = 180,
|
||||
@ -271,6 +288,36 @@ namespace osu.Game.Overlays.Mods
|
||||
},
|
||||
},
|
||||
},
|
||||
ModSettingsContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
Width = 0.25f,
|
||||
Alpha = 0,
|
||||
X = -100,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(0, 0, 0, 192)
|
||||
},
|
||||
new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = ModSettingsContent = new FillFlowContainer<ModControlSection>
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Spacing = new Vector2(0f, 10f),
|
||||
Padding = new MarginPadding(20),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -381,12 +428,14 @@ namespace osu.Game.Overlays.Mods
|
||||
refreshSelectedMods();
|
||||
}
|
||||
|
||||
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> e)
|
||||
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||
{
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
section.SelectTypes(e.NewValue.Select(m => m.GetType()).ToList());
|
||||
section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList());
|
||||
|
||||
updateMods();
|
||||
|
||||
updateModSettings(mods);
|
||||
}
|
||||
|
||||
private void updateMods()
|
||||
@ -411,6 +460,25 @@ namespace osu.Game.Overlays.Mods
|
||||
UnrankedLabel.FadeTo(ranked ? 0 : 1, 200);
|
||||
}
|
||||
|
||||
private void updateModSettings(ValueChangedEvent<IReadOnlyList<Mod>> selectedMods)
|
||||
{
|
||||
foreach (var added in selectedMods.NewValue.Except(selectedMods.OldValue))
|
||||
{
|
||||
var controls = added.CreateSettingsControls().ToList();
|
||||
if (controls.Count > 0)
|
||||
ModSettingsContent.Add(new ModControlSection(added) { Children = controls });
|
||||
}
|
||||
|
||||
foreach (var removed in selectedMods.OldValue.Except(selectedMods.NewValue))
|
||||
ModSettingsContent.RemoveAll(section => section.Mod == removed);
|
||||
|
||||
bool hasSettings = ModSettingsContent.Children.Count > 0;
|
||||
CustomiseButton.Enabled.Value = hasSettings;
|
||||
|
||||
if (!hasSettings)
|
||||
ModSettingsContainer.Hide();
|
||||
}
|
||||
|
||||
private void modButtonPressed(Mod selectedMod)
|
||||
{
|
||||
if (selectedMod != null)
|
||||
|
@ -69,7 +69,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
/// <summary>
|
||||
/// Creates a copy of this <see cref="Mod"/> initialised to a default state.
|
||||
/// </summary>
|
||||
public virtual Mod CreateCopy() => (Mod)Activator.CreateInstance(GetType());
|
||||
public virtual Mod CreateCopy() => (Mod)MemberwiseClone();
|
||||
|
||||
public bool Equals(IMod other) => GetType() == other?.GetType();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user