Add extension point for ruleset-specific beatmap setup sections

This commit is contained in:
Bartłomiej Dach 2021-08-22 16:40:17 +02:00
parent cdd0262ca1
commit ce1912781e
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
4 changed files with 48 additions and 13 deletions

View File

@ -28,6 +28,7 @@ using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Testing;
using osu.Game.Extensions;
using osu.Game.Rulesets.Filter;
using osu.Game.Screens.Edit.Setup;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Rulesets
@ -315,5 +316,11 @@ namespace osu.Game.Rulesets
/// </summary>
[CanBeNull]
public virtual IRulesetFilterCriteria CreateRulesetFilterCriteria() => null;
/// <summary>
/// Can be overridden to add a ruleset-specific section to the editor beatmap setup screen.
/// </summary>
[CanBeNull]
public virtual RulesetSetupSection CreateEditorSetupSectionForRuleset() => null;
}
}

View File

@ -0,0 +1,20 @@
// 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.Localisation;
using osu.Game.Rulesets;
namespace osu.Game.Screens.Edit.Setup
{
public abstract class RulesetSetupSection : SetupSection
{
public sealed override LocalisableString Title => $"{rulesetInfo.Name}-specific";
private readonly RulesetInfo rulesetInfo;
protected RulesetSetupSection(RulesetInfo rulesetInfo)
{
this.rulesetInfo = rulesetInfo;
}
}
}

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics.Containers;
@ -21,22 +22,28 @@ namespace osu.Game.Screens.Edit.Setup
}
[BackgroundDependencyLoader]
private void load()
private void load(EditorBeatmap beatmap)
{
var sectionsEnumerable = new List<SetupSection>
{
new ResourcesSection(),
new MetadataSection(),
new DifficultySection(),
new ColoursSection(),
new DesignSection(),
};
var rulesetSpecificSection = beatmap.BeatmapInfo.Ruleset?.CreateInstance()?.CreateEditorSetupSectionForRuleset();
if (rulesetSpecificSection != null)
sectionsEnumerable.Add(rulesetSpecificSection);
AddRange(new Drawable[]
{
sections = new SetupScreenSectionsContainer
{
FixedHeader = header,
RelativeSizeAxes = Axes.Both,
Children = new SetupSection[]
{
new ResourcesSection(),
new MetadataSection(),
new DifficultySection(),
new ColoursSection(),
new DesignSection(),
}
ChildrenEnumerable = sectionsEnumerable,
FixedHeader = header
},
});
}

View File

@ -12,9 +12,9 @@ using osuTK;
namespace osu.Game.Screens.Edit.Setup
{
internal abstract class SetupSection : Container
public abstract class SetupSection : Container
{
private readonly FillFlowContainer flow;
private FillFlowContainer flow;
/// <summary>
/// Used to align some of the child <see cref="LabelledDrawable{T}"/>s together to achieve a grid-like look.
@ -31,7 +31,8 @@ namespace osu.Game.Screens.Edit.Setup
public abstract LocalisableString Title { get; }
protected SetupSection()
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;