1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 16:02:58 +08:00

Merge pull request #22430 from peppy/skin-editor-nrt

Apply NRT to all skin editor classes
This commit is contained in:
Dean Herbert 2023-02-02 13:57:57 +09:00 committed by GitHub
commit 10df64467a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 73 additions and 88 deletions

View File

@ -376,7 +376,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
protected override void OnFree() protected override void OnFree()
{ {
slidingSample.Samples = null; slidingSample.ClearSamples();
base.OnFree(); base.OnFree();
} }
} }

View File

@ -126,7 +126,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
PathVersion.UnbindFrom(HitObject.Path.Version); PathVersion.UnbindFrom(HitObject.Path.Version);
slidingSample.Samples = null; slidingSample?.ClearSamples();
} }
protected override void LoadSamples() protected override void LoadSamples()

View File

@ -119,7 +119,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
base.OnFree(); base.OnFree();
spinningSample.Samples = null; spinningSample.ClearSamples();
} }
protected override void LoadSamples() protected override void LoadSamples()

View File

@ -303,8 +303,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
samplesBindable.CollectionChanged -= onSamplesChanged; samplesBindable.CollectionChanged -= onSamplesChanged;
// Release the samples for other hitobjects to use. // Release the samples for other hitobjects to use.
if (Samples != null) Samples?.ClearSamples();
Samples.Samples = null;
foreach (var obj in nestedHitObjects) foreach (var obj in nestedHitObjects)
{ {

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -20,18 +18,18 @@ namespace osu.Game.Skinning.Editor
{ {
public partial class SkinBlueprint : SelectionBlueprint<ISkinnableDrawable> public partial class SkinBlueprint : SelectionBlueprint<ISkinnableDrawable>
{ {
private Container box; private Container box = null!;
private Container outlineBox; private Container outlineBox = null!;
private AnchorOriginVisualiser anchorOriginVisualiser; private AnchorOriginVisualiser anchorOriginVisualiser = null!;
private Drawable drawable => (Drawable)Item; private Drawable drawable => (Drawable)Item;
protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent; protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; } = null!;
public SkinBlueprint(ISkinnableDrawable component) public SkinBlueprint(ISkinnableDrawable component)
: base(component) : base(component)

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
@ -28,7 +26,7 @@ namespace osu.Game.Skinning.Editor
private readonly List<BindableList<ISkinnableDrawable>> targetComponents = new List<BindableList<ISkinnableDrawable>>(); private readonly List<BindableList<ISkinnableDrawable>> targetComponents = new List<BindableList<ISkinnableDrawable>>();
[Resolved] [Resolved]
private SkinEditor editor { get; set; } private SkinEditor editor { get; set; } = null!;
public SkinBlueprintContainer(Drawable target) public SkinBlueprintContainer(Drawable target)
{ {
@ -61,7 +59,7 @@ namespace osu.Game.Skinning.Editor
} }
} }
private void componentsChanged(object sender, NotifyCollectionChangedEventArgs e) => Schedule(() => private void componentsChanged(object? sender, NotifyCollectionChangedEventArgs e) => Schedule(() =>
{ {
switch (e.Action) switch (e.Action)
{ {

View File

@ -1,10 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -42,39 +41,39 @@ namespace osu.Game.Skinning.Editor
protected override bool StartHidden => true; protected override bool StartHidden => true;
private Drawable targetScreen; private Drawable targetScreen = null!;
private OsuTextFlowContainer headerText; private OsuTextFlowContainer headerText = null!;
private Bindable<Skin> currentSkin; private Bindable<Skin> currentSkin = null!;
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
[Resolved] [Resolved]
private SkinManager skins { get; set; } private OsuGame? game { get; set; }
[Resolved] [Resolved]
private OsuColour colours { get; set; } private SkinManager skins { get; set; } = null!;
[Resolved] [Resolved]
private RealmAccess realm { get; set; } private OsuColour colours { get; set; } = null!;
[Resolved(canBeNull: true)] [Resolved]
private SkinEditorOverlay skinEditorOverlay { get; set; } private RealmAccess realm { get; set; } = null!;
[Resolved]
private SkinEditorOverlay? skinEditorOverlay { get; set; }
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private bool hasBegunMutating; private bool hasBegunMutating;
private Container content; private Container? content;
private EditorSidebar componentsSidebar; private EditorSidebar componentsSidebar = null!;
private EditorSidebar settingsSidebar; private EditorSidebar settingsSidebar = null!;
[Resolved(canBeNull: true)] [Resolved]
private OnScreenDisplay onScreenDisplay { get; set; } private OnScreenDisplay? onScreenDisplay { get; set; }
public SkinEditor() public SkinEditor()
{ {
@ -234,11 +233,14 @@ namespace osu.Game.Skinning.Editor
// Immediately clear the previous blueprint container to ensure it doesn't try to interact with the old target. // Immediately clear the previous blueprint container to ensure it doesn't try to interact with the old target.
content?.Clear(); content?.Clear();
Scheduler.AddOnce(loadBlueprintContainer); Scheduler.AddOnce(loadBlueprintContainer);
Scheduler.AddOnce(populateSettings); Scheduler.AddOnce(populateSettings);
void loadBlueprintContainer() void loadBlueprintContainer()
{ {
Debug.Assert(content != null);
content.Child = new SkinBlueprintContainer(targetScreen); content.Child = new SkinBlueprintContainer(targetScreen);
componentsSidebar.Child = new SkinComponentToolbox(getFirstTarget() as CompositeDrawable) componentsSidebar.Child = new SkinComponentToolbox(getFirstTarget() as CompositeDrawable)
@ -311,9 +313,9 @@ namespace osu.Game.Skinning.Editor
private IEnumerable<ISkinnableTarget> availableTargets => targetScreen.ChildrenOfType<ISkinnableTarget>(); private IEnumerable<ISkinnableTarget> availableTargets => targetScreen.ChildrenOfType<ISkinnableTarget>();
private ISkinnableTarget getFirstTarget() => availableTargets.FirstOrDefault(); private ISkinnableTarget? getFirstTarget() => availableTargets.FirstOrDefault();
private ISkinnableTarget getTarget(GlobalSkinComponentLookup.LookupType target) private ISkinnableTarget? getTarget(GlobalSkinComponentLookup.LookupType target)
{ {
return availableTargets.FirstOrDefault(c => c.Target == target); return availableTargets.FirstOrDefault(c => c.Target == target);
} }
@ -327,7 +329,7 @@ namespace osu.Game.Skinning.Editor
currentSkin.Value.ResetDrawableTarget(t); currentSkin.Value.ResetDrawableTarget(t);
// add back default components // add back default components
getTarget(t.Target).Reload(); getTarget(t.Target)?.Reload();
} }
} }
@ -342,7 +344,7 @@ namespace osu.Game.Skinning.Editor
currentSkin.Value.UpdateDrawableTarget(t); currentSkin.Value.UpdateDrawableTarget(t);
skins.Save(skins.CurrentSkin.Value); skins.Save(skins.CurrentSkin.Value);
onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, currentSkin.Value.SkinInfo.ToString())); onScreenDisplay?.Display(new SkinEditorToast(ToastStrings.SkinSaved, currentSkin.Value.SkinInfo.ToString() ?? "Unknown"));
} }
protected override bool OnHover(HoverEvent e) => true; protected override bool OnHover(HoverEvent e) => true;
@ -394,12 +396,18 @@ namespace osu.Game.Skinning.Editor
// This is the best we can do for now. // This is the best we can do for now.
realm.Run(r => r.Refresh()); realm.Run(r => r.Refresh());
var skinnableTarget = getFirstTarget();
// Import still should happen for now, even if not placeable (as it allows a user to import skin resources that would apply to legacy gameplay skins).
if (skinnableTarget == null)
return;
// place component // place component
var sprite = new SkinnableSprite var sprite = new SkinnableSprite
{ {
SpriteName = { Value = file.Name }, SpriteName = { Value = file.Name },
Origin = Anchor.Centre, Origin = Anchor.Centre,
Position = getFirstTarget().ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position), Position = skinnableTarget.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position),
}; };
placeComponent(sprite, false); placeComponent(sprite, false);

View File

@ -1,10 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -29,13 +26,12 @@ namespace osu.Game.Skinning.Editor
protected override bool BlockNonPositionalInput => true; protected override bool BlockNonPositionalInput => true;
[CanBeNull] private SkinEditor? skinEditor;
private SkinEditor skinEditor;
[Resolved(canBeNull: true)] [Resolved]
private OsuGame game { get; set; } private OsuGame game { get; set; } = null!;
private OsuScreen lastTargetScreen; private OsuScreen? lastTargetScreen;
private Vector2 lastDrawSize; private Vector2 lastDrawSize;
@ -81,6 +77,8 @@ namespace osu.Game.Skinning.Editor
AddInternal(editor); AddInternal(editor);
Debug.Assert(lastTargetScreen != null);
SetTarget(lastTargetScreen); SetTarget(lastTargetScreen);
}); });
} }
@ -124,15 +122,15 @@ namespace osu.Game.Skinning.Editor
{ {
Scheduler.AddOnce(updateScreenSizing); Scheduler.AddOnce(updateScreenSizing);
game?.Toolbar.Hide(); game.Toolbar.Hide();
game?.CloseAllOverlays(); game.CloseAllOverlays();
} }
else else
{ {
scalingContainer.SetCustomRect(null); scalingContainer.SetCustomRect(null);
if (lastTargetScreen?.HideOverlaysOnEnter != true) if (lastTargetScreen?.HideOverlaysOnEnter != true)
game?.Toolbar.Show(); game.Toolbar.Show();
} }
} }
@ -158,7 +156,7 @@ namespace osu.Game.Skinning.Editor
Scheduler.AddOnce(setTarget, screen); Scheduler.AddOnce(setTarget, screen);
} }
private void setTarget(OsuScreen target) private void setTarget(OsuScreen? target)
{ {
if (target == null) if (target == null)
return; return;

View File

@ -1,11 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -36,14 +33,14 @@ namespace osu.Game.Skinning.Editor
private const float padding = 10; private const float padding = 10;
[Resolved(canBeNull: true)] [Resolved]
private IPerformFromScreenRunner performer { get; set; } private IPerformFromScreenRunner? performer { get; set; }
[Resolved] [Resolved]
private IBindable<RulesetInfo> ruleset { get; set; } private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved] [Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; } private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
public SkinEditorSceneLibrary() public SkinEditorSceneLibrary()
{ {
@ -107,7 +104,12 @@ namespace osu.Game.Skinning.Editor
var replayGeneratingMod = ruleset.Value.CreateInstance().GetAutoplayMod(); var replayGeneratingMod = ruleset.Value.CreateInstance().GetAutoplayMod();
if (!ModUtils.CheckCompatibleSet(mods.Value.Append(replayGeneratingMod), out var invalid)) IReadOnlyList<Mod> usableMods = mods.Value;
if (replayGeneratingMod != null)
usableMods = usableMods.Append(replayGeneratingMod).ToArray();
if (!ModUtils.CheckCompatibleSet(usableMods, out var invalid))
mods.Value = mods.Value.Except(invalid).ToArray(); mods.Value = mods.Value.Except(invalid).ToArray();
if (replayGeneratingMod != null) if (replayGeneratingMod != null)
@ -129,8 +131,8 @@ namespace osu.Game.Skinning.Editor
Height = BUTTON_HEIGHT; Height = BUTTON_HEIGHT;
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader]
private void load([CanBeNull] OverlayColourProvider overlayColourProvider, OsuColour colours) private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
{ {
BackgroundColour = overlayColourProvider?.Background3 ?? colours.Blue3; BackgroundColour = overlayColourProvider?.Background3 ?? colours.Blue3;
Content.CornerRadius = 5; Content.CornerRadius = 5;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,7 +21,7 @@ namespace osu.Game.Skinning.Editor
public partial class SkinSelectionHandler : SelectionHandler<ISkinnableDrawable> public partial class SkinSelectionHandler : SelectionHandler<ISkinnableDrawable>
{ {
[Resolved] [Resolved]
private SkinEditor skinEditor { get; set; } private SkinEditor skinEditor { get; set; } = null!;
public override bool HandleRotation(float angle) public override bool HandleRotation(float angle)
{ {

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Globalization; using System.Globalization;
using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Formats;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -16,7 +14,7 @@ namespace osu.Game.Skinning
{ {
private readonly LegacyFont font; private readonly LegacyFont font;
private LegacyGlyphStore glyphStore; private LegacyGlyphStore glyphStore = null!;
protected override char FixedWidthReferenceCharacter => '5'; protected override char FixedWidthReferenceCharacter => '5';
@ -49,7 +47,7 @@ namespace osu.Game.Skinning
this.skin = skin; this.skin = skin;
} }
public ITexturedCharacterGlyph Get(string fontName, char character) public ITexturedCharacterGlyph? Get(string fontName, char character)
{ {
string lookup = getLookupName(character); string lookup = getLookupName(character);
@ -79,7 +77,7 @@ namespace osu.Game.Skinning
} }
} }
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character)); public Task<ITexturedCharacterGlyph?> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
} }
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
namespace osu.Game.Skinning namespace osu.Game.Skinning
{ {
public class SkinCustomColourLookup public class SkinCustomColourLookup

View File

@ -1,12 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -39,13 +36,12 @@ namespace osu.Game.Skinning
/// <summary> /// <summary>
/// All raw <see cref="DrawableSamples"/>s contained in this <see cref="SkinnableSound"/>. /// All raw <see cref="DrawableSamples"/>s contained in this <see cref="SkinnableSound"/>.
/// </summary> /// </summary>
[NotNull, ItemNotNull]
protected IEnumerable<DrawableSample> DrawableSamples => samplesContainer.Select(c => c.Sample).Where(s => s != null); protected IEnumerable<DrawableSample> DrawableSamples => samplesContainer.Select(c => c.Sample).Where(s => s != null);
private readonly AudioContainer<PoolableSkinnableSample> samplesContainer; private readonly AudioContainer<PoolableSkinnableSample> samplesContainer;
[Resolved(CanBeNull = true)] [Resolved]
private IPooledSampleProvider samplePool { get; set; } private IPooledSampleProvider? samplePool { get; set; }
/// <summary> /// <summary>
/// Creates a new <see cref="SkinnableSound"/>. /// Creates a new <see cref="SkinnableSound"/>.
@ -59,7 +55,7 @@ namespace osu.Game.Skinning
/// Creates a new <see cref="SkinnableSound"/> with some initial samples. /// Creates a new <see cref="SkinnableSound"/> with some initial samples.
/// </summary> /// </summary>
/// <param name="samples">The initial samples.</param> /// <param name="samples">The initial samples.</param>
public SkinnableSound([NotNull] IEnumerable<ISampleInfo> samples) public SkinnableSound(IEnumerable<ISampleInfo> samples)
: this() : this()
{ {
this.samples = samples.ToArray(); this.samples = samples.ToArray();
@ -69,7 +65,7 @@ namespace osu.Game.Skinning
/// Creates a new <see cref="SkinnableSound"/> with an initial sample. /// Creates a new <see cref="SkinnableSound"/> with an initial sample.
/// </summary> /// </summary>
/// <param name="sample">The initial sample.</param> /// <param name="sample">The initial sample.</param>
public SkinnableSound([NotNull] ISampleInfo sample) public SkinnableSound(ISampleInfo sample)
: this(new[] { sample }) : this(new[] { sample })
{ {
} }
@ -84,8 +80,6 @@ namespace osu.Game.Skinning
get => samples; get => samples;
set set
{ {
value ??= Array.Empty<ISampleInfo>();
if (samples == value) if (samples == value)
return; return;
@ -96,6 +90,8 @@ namespace osu.Game.Skinning
} }
} }
public void ClearSamples() => Samples = Array.Empty<ISampleInfo>();
private bool looping; private bool looping;
/// <summary> /// <summary>