mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Add basic mod preset column implementation
This commit is contained in:
parent
b2f8934117
commit
6a67d76d7c
@ -0,0 +1,77 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneModPresetColumn : OsuTestScene
|
||||
{
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
||||
|
||||
[Test]
|
||||
public void TestBasicAppearance()
|
||||
{
|
||||
ModPresetColumn modPresetColumn = null!;
|
||||
|
||||
AddStep("create content", () => Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(30),
|
||||
Child = modPresetColumn = new ModPresetColumn
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Presets = createTestPresets().ToArray()
|
||||
}
|
||||
});
|
||||
AddStep("change presets", () => modPresetColumn.Presets = createTestPresets().Skip(1).ToArray());
|
||||
}
|
||||
|
||||
private static IEnumerable<ModPreset> createTestPresets() => new[]
|
||||
{
|
||||
new ModPreset
|
||||
{
|
||||
Name = "First preset",
|
||||
Description = "Please ignore",
|
||||
Mods = new Mod[]
|
||||
{
|
||||
new OsuModHardRock(),
|
||||
new OsuModDoubleTime()
|
||||
}
|
||||
},
|
||||
new ModPreset
|
||||
{
|
||||
Name = "AR0",
|
||||
Description = "For good readers",
|
||||
Mods = new Mod[]
|
||||
{
|
||||
new OsuModDifficultyAdjust
|
||||
{
|
||||
ApproachRate = { Value = 0 }
|
||||
}
|
||||
}
|
||||
},
|
||||
new ModPreset
|
||||
{
|
||||
Name = "This preset is going to have an extraordinarily long name",
|
||||
Description = "This is done so that the capability to truncate overlong texts may be demonstrated",
|
||||
Mods = new Mod[]
|
||||
{
|
||||
new OsuModFlashlight(),
|
||||
new OsuModSpinIn()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
19
osu.Game/Localisation/ModPresetColumnStrings.cs
Normal file
19
osu.Game/Localisation/ModPresetColumnStrings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Localisation
|
||||
{
|
||||
public static class ModPresetColumnStrings
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.ModPresetColumn";
|
||||
|
||||
/// <summary>
|
||||
/// "Personal Presets"
|
||||
/// </summary>
|
||||
public static LocalisableString PersonalPresets => new TranslatableString(getKey(@"personal_presets"), @"Personal Presets");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
77
osu.Game/Overlays/Mods/ModPresetColumn.cs
Normal file
77
osu.Game/Overlays/Mods/ModPresetColumn.cs
Normal file
@ -0,0 +1,77 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public class ModPresetColumn : ModSelectColumn
|
||||
{
|
||||
private IReadOnlyList<ModPreset> presets = Array.Empty<ModPreset>();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the collection of available mod presets.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ModPreset> Presets
|
||||
{
|
||||
get => presets;
|
||||
set
|
||||
{
|
||||
presets = value;
|
||||
|
||||
if (IsLoaded)
|
||||
asyncLoadPanels();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
AccentColour = colours.Orange1;
|
||||
HeaderText = ModPresetColumnStrings.PersonalPresets;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
asyncLoadPanels();
|
||||
}
|
||||
|
||||
private CancellationTokenSource? cancellationTokenSource;
|
||||
|
||||
private Task? latestLoadTask;
|
||||
internal bool ItemsLoaded => latestLoadTask == null;
|
||||
|
||||
private void asyncLoadPanels()
|
||||
{
|
||||
cancellationTokenSource?.Cancel();
|
||||
|
||||
var panels = presets.Select(preset => new ModPresetPanel(preset)
|
||||
{
|
||||
Shear = Vector2.Zero
|
||||
});
|
||||
|
||||
Task? loadTask;
|
||||
|
||||
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
|
||||
{
|
||||
ItemsFlow.ChildrenEnumerable = loaded;
|
||||
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
|
||||
loadTask.ContinueWith(_ =>
|
||||
{
|
||||
if (loadTask == latestLoadTask)
|
||||
latestLoadTask = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user