mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:42:56 +08:00
Refactor mod sections and make them overridable
This commit is contained in:
parent
328bd191d4
commit
3741f05ab3
@ -11,26 +11,23 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Humanizer;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
{
|
{
|
||||||
public abstract class ModSection : Container
|
public class ModSection : CompositeDrawable
|
||||||
{
|
{
|
||||||
private readonly OsuSpriteText headerLabel;
|
private readonly Drawable header;
|
||||||
|
|
||||||
public FillFlowContainer<ModButtonEmpty> ButtonsContainer { get; }
|
public FillFlowContainer<ModButtonEmpty> ButtonsContainer { get; }
|
||||||
|
|
||||||
public Action<Mod> Action;
|
public Action<Mod> Action;
|
||||||
protected abstract Key[] ToggleKeys { get; }
|
|
||||||
public abstract ModType ModType { get; }
|
|
||||||
|
|
||||||
public string Header
|
public Key[] ToggleKeys;
|
||||||
{
|
|
||||||
get => headerLabel.Text;
|
public readonly ModType ModType;
|
||||||
set => headerLabel.Text = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null);
|
public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null);
|
||||||
|
|
||||||
@ -61,7 +58,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
if (modContainers.Length == 0)
|
if (modContainers.Length == 0)
|
||||||
{
|
{
|
||||||
ModIconsLoaded = true;
|
ModIconsLoaded = true;
|
||||||
headerLabel.Hide();
|
header.Hide();
|
||||||
Hide();
|
Hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -76,7 +73,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
buttons = modContainers.OfType<ModButton>().ToArray();
|
buttons = modContainers.OfType<ModButton>().ToArray();
|
||||||
|
|
||||||
headerLabel.FadeIn(200);
|
header.FadeIn(200);
|
||||||
this.FadeIn(200);
|
this.FadeIn(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,23 +150,19 @@ namespace osu.Game.Overlays.Mods
|
|||||||
button.Deselect();
|
button.Deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ModSection()
|
public ModSection(ModType type)
|
||||||
{
|
{
|
||||||
|
ModType = type;
|
||||||
|
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
|
||||||
Origin = Anchor.TopCentre;
|
Origin = Anchor.TopCentre;
|
||||||
Anchor = Anchor.TopCentre;
|
Anchor = Anchor.TopCentre;
|
||||||
|
|
||||||
Children = new Drawable[]
|
InternalChildren = new[]
|
||||||
{
|
{
|
||||||
headerLabel = new OsuSpriteText
|
header = CreateHeader(type.Humanize(LetterCasing.Title)),
|
||||||
{
|
|
||||||
Origin = Anchor.TopLeft,
|
|
||||||
Anchor = Anchor.TopLeft,
|
|
||||||
Position = new Vector2(0f, 0f),
|
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
|
||||||
},
|
|
||||||
ButtonsContainer = new FillFlowContainer<ModButtonEmpty>
|
ButtonsContainer = new FillFlowContainer<ModButtonEmpty>
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -185,5 +178,11 @@ namespace osu.Game.Overlays.Mods
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual Drawable CreateHeader(string text) => new OsuSpriteText
|
||||||
|
{
|
||||||
|
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
||||||
|
Text = text
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ using osu.Game.Graphics.Containers;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Overlays.Mods.Sections;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -190,13 +189,31 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Width = content_width,
|
Width = content_width,
|
||||||
LayoutDuration = 200,
|
LayoutDuration = 200,
|
||||||
LayoutEasing = Easing.OutQuint,
|
LayoutEasing = Easing.OutQuint,
|
||||||
Children = new ModSection[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new DifficultyReductionSection { Action = modButtonPressed },
|
CreateModSection(ModType.DifficultyReduction).With(s =>
|
||||||
new DifficultyIncreaseSection { Action = modButtonPressed },
|
{
|
||||||
new AutomationSection { Action = modButtonPressed },
|
s.ToggleKeys = new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P };
|
||||||
new ConversionSection { Action = modButtonPressed },
|
s.Action = modButtonPressed;
|
||||||
new FunSection { Action = modButtonPressed },
|
}),
|
||||||
|
CreateModSection(ModType.DifficultyIncrease).With(s =>
|
||||||
|
{
|
||||||
|
s.ToggleKeys = new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L };
|
||||||
|
s.Action = modButtonPressed;
|
||||||
|
}),
|
||||||
|
CreateModSection(ModType.Automation).With(s =>
|
||||||
|
{
|
||||||
|
s.ToggleKeys = new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M };
|
||||||
|
s.Action = modButtonPressed;
|
||||||
|
}),
|
||||||
|
CreateModSection(ModType.Conversion).With(s =>
|
||||||
|
{
|
||||||
|
s.Action = modButtonPressed;
|
||||||
|
}),
|
||||||
|
CreateModSection(ModType.Fun).With(s =>
|
||||||
|
{
|
||||||
|
s.Action = modButtonPressed;
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -454,6 +471,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
|
private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a <see cref="ModSection"/> that groups <see cref="Mod"/>s with the same <see cref="ModType"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">The <see cref="ModType"/> of <see cref="Mod"/>s in the section.</param>
|
||||||
|
/// <returns>The <see cref="ModSection"/>.</returns>
|
||||||
|
protected virtual ModSection CreateModSection(ModType type) => new ModSection(type);
|
||||||
|
|
||||||
#region Disposal
|
#region Disposal
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -1,19 +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.Game.Rulesets.Mods;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods.Sections
|
|
||||||
{
|
|
||||||
public class AutomationSection : ModSection
|
|
||||||
{
|
|
||||||
protected override Key[] ToggleKeys => new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M };
|
|
||||||
public override ModType ModType => ModType.Automation;
|
|
||||||
|
|
||||||
public AutomationSection()
|
|
||||||
{
|
|
||||||
Header = @"Automation";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +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.Game.Rulesets.Mods;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods.Sections
|
|
||||||
{
|
|
||||||
public class ConversionSection : ModSection
|
|
||||||
{
|
|
||||||
protected override Key[] ToggleKeys => null;
|
|
||||||
public override ModType ModType => ModType.Conversion;
|
|
||||||
|
|
||||||
public ConversionSection()
|
|
||||||
{
|
|
||||||
Header = @"Conversion";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +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.Game.Rulesets.Mods;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods.Sections
|
|
||||||
{
|
|
||||||
public class DifficultyIncreaseSection : ModSection
|
|
||||||
{
|
|
||||||
protected override Key[] ToggleKeys => new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L };
|
|
||||||
public override ModType ModType => ModType.DifficultyIncrease;
|
|
||||||
|
|
||||||
public DifficultyIncreaseSection()
|
|
||||||
{
|
|
||||||
Header = @"Difficulty Increase";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +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.Game.Rulesets.Mods;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods.Sections
|
|
||||||
{
|
|
||||||
public class DifficultyReductionSection : ModSection
|
|
||||||
{
|
|
||||||
protected override Key[] ToggleKeys => new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P };
|
|
||||||
public override ModType ModType => ModType.DifficultyReduction;
|
|
||||||
|
|
||||||
public DifficultyReductionSection()
|
|
||||||
{
|
|
||||||
Header = @"Difficulty Reduction";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +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.Game.Rulesets.Mods;
|
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods.Sections
|
|
||||||
{
|
|
||||||
public class FunSection : ModSection
|
|
||||||
{
|
|
||||||
protected override Key[] ToggleKeys => null;
|
|
||||||
public override ModType ModType => ModType.Fun;
|
|
||||||
|
|
||||||
public FunSection()
|
|
||||||
{
|
|
||||||
Header = @"Fun";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user