1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 00:27:25 +08:00

Merge remote-tracking branch 'origin/customized-mods' into customized-mods

This commit is contained in:
unknown 2019-11-04 23:21:45 +08:00
commit 1216d66a4c
4 changed files with 131 additions and 1 deletions

View 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.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,
};
if (Mod is IModHasSettings modHasSettings)
AddRange(modHasSettings.CreateControls());
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddRangeInternal(new Drawable[]
{
new OsuSpriteText
{
Text = Mod.Name,
Font = OsuFont.GetFont(weight: FontWeight.Bold),
Colour = colours.Yellow,
},
FlowContent
});
}
}
}

View File

@ -31,6 +31,7 @@ namespace osu.Game.Overlays.Mods
public class ModSelectOverlay : WaveOverlayContainer
{
protected readonly TriangleButton DeselectAllButton;
protected readonly TriangleButton CustomizeButton;
protected readonly TriangleButton CloseButton;
protected readonly OsuSpriteText MultiplierLabel;
@ -42,6 +43,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 +231,16 @@ namespace osu.Game.Overlays.Mods
Right = 20
}
},
CustomizeButton = new TriangleButton
{
Width = 180,
Text = "Customization",
Action = () => ModSettingsContainer.Alpha = ModSettingsContainer.Alpha == 1 ? 0 : 1,
Margin = new MarginPadding
{
Right = 20
}
},
CloseButton = new TriangleButton
{
Width = 180,
@ -271,6 +286,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),
}
}
}
}
};
}
@ -284,10 +329,24 @@ namespace osu.Game.Overlays.Mods
Ruleset.BindTo(ruleset);
if (mods != null) SelectedMods.BindTo(mods);
SelectedMods.ValueChanged += updateModSettings;
Ruleset.ValueChanged += _ => ModSettingsContent.Clear();
sampleOn = audio.Samples.Get(@"UI/check-on");
sampleOff = audio.Samples.Get(@"UI/check-off");
}
private void updateModSettings(ValueChangedEvent<IReadOnlyList<Mod>> selectedMods)
{
var added = selectedMods.NewValue.Except(selectedMods.OldValue).FirstOrDefault();
var removed = selectedMods.OldValue.Except(selectedMods.NewValue).FirstOrDefault();
if (added is IModHasSettings)
ModSettingsContent.Add(new ModControlSection(added));
else if (removed is IModHasSettings)
ModSettingsContent.Remove(ModSettingsContent.Children.Where(section => section.Mod == removed).FirstOrDefault());
}
public void DeselectAll()
{
foreach (var section in ModSectionsContainer.Children)

View File

@ -0,0 +1,15 @@
// 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.Graphics;
namespace osu.Game.Rulesets.Mods
{
/// <summary>
/// An interface for mods that allows user control over it's properties.
/// </summary>
public interface IModHasSettings
{
Drawable[] CreateControls();
}
}

View File

@ -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();
}