1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +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()
{
slidingSample.Samples = null;
slidingSample.ClearSamples();
base.OnFree();
}
}

View File

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

View File

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

View File

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

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
@ -20,18 +18,18 @@ namespace osu.Game.Skinning.Editor
{
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;
protected override bool ShouldBeAlive => drawable.IsAlive && Item.IsPresent;
[Resolved]
private OsuColour colours { get; set; }
private OsuColour colours { get; set; } = null!;
public SkinBlueprint(ISkinnableDrawable component)
: base(component)

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
@ -28,7 +26,7 @@ namespace osu.Game.Skinning.Editor
private readonly List<BindableList<ISkinnableDrawable>> targetComponents = new List<BindableList<ISkinnableDrawable>>();
[Resolved]
private SkinEditor editor { get; set; }
private SkinEditor editor { get; set; } = null!;
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)
{

View File

@ -1,10 +1,9 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@ -42,39 +41,39 @@ namespace osu.Game.Skinning.Editor
protected override bool StartHidden => true;
private Drawable targetScreen;
private Drawable targetScreen = null!;
private OsuTextFlowContainer headerText;
private OsuTextFlowContainer headerText = null!;
private Bindable<Skin> currentSkin;
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private Bindable<Skin> currentSkin = null!;
[Resolved]
private SkinManager skins { get; set; }
private OsuGame? game { get; set; }
[Resolved]
private OsuColour colours { get; set; }
private SkinManager skins { get; set; } = null!;
[Resolved]
private RealmAccess realm { get; set; }
private OsuColour colours { get; set; } = null!;
[Resolved(canBeNull: true)]
private SkinEditorOverlay skinEditorOverlay { get; set; }
[Resolved]
private RealmAccess realm { get; set; } = null!;
[Resolved]
private SkinEditorOverlay? skinEditorOverlay { get; set; }
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private bool hasBegunMutating;
private Container content;
private Container? content;
private EditorSidebar componentsSidebar;
private EditorSidebar settingsSidebar;
private EditorSidebar componentsSidebar = null!;
private EditorSidebar settingsSidebar = null!;
[Resolved(canBeNull: true)]
private OnScreenDisplay onScreenDisplay { get; set; }
[Resolved]
private OnScreenDisplay? onScreenDisplay { get; set; }
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.
content?.Clear();
Scheduler.AddOnce(loadBlueprintContainer);
Scheduler.AddOnce(populateSettings);
void loadBlueprintContainer()
{
Debug.Assert(content != null);
content.Child = new SkinBlueprintContainer(targetScreen);
componentsSidebar.Child = new SkinComponentToolbox(getFirstTarget() as CompositeDrawable)
@ -311,9 +313,9 @@ namespace osu.Game.Skinning.Editor
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);
}
@ -327,7 +329,7 @@ namespace osu.Game.Skinning.Editor
currentSkin.Value.ResetDrawableTarget(t);
// 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);
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;
@ -394,12 +396,18 @@ namespace osu.Game.Skinning.Editor
// This is the best we can do for now.
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
var sprite = new SkinnableSprite
{
SpriteName = { Value = file.Name },
Origin = Anchor.Centre,
Position = getFirstTarget().ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position),
Position = skinnableTarget.ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position),
};
placeComponent(sprite, false);

View File

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

View File

@ -1,11 +1,8 @@
// 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.
#nullable disable
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -36,14 +33,14 @@ namespace osu.Game.Skinning.Editor
private const float padding = 10;
[Resolved(canBeNull: true)]
private IPerformFromScreenRunner performer { get; set; }
[Resolved]
private IPerformFromScreenRunner? performer { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
[Resolved]
private Bindable<IReadOnlyList<Mod>> mods { get; set; }
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
public SkinEditorSceneLibrary()
{
@ -107,7 +104,12 @@ namespace osu.Game.Skinning.Editor
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();
if (replayGeneratingMod != null)
@ -129,8 +131,8 @@ namespace osu.Game.Skinning.Editor
Height = BUTTON_HEIGHT;
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] OverlayColourProvider overlayColourProvider, OsuColour colours)
[BackgroundDependencyLoader]
private void load(OverlayColourProvider? overlayColourProvider, OsuColour colours)
{
BackgroundColour = overlayColourProvider?.Background3 ?? colours.Blue3;
Content.CornerRadius = 5;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -23,7 +21,7 @@ namespace osu.Game.Skinning.Editor
public partial class SkinSelectionHandler : SelectionHandler<ISkinnableDrawable>
{
[Resolved]
private SkinEditor skinEditor { get; set; }
private SkinEditor skinEditor { get; set; } = null!;
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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Globalization;
using osu.Game.Beatmaps.Formats;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
@ -16,7 +14,7 @@ namespace osu.Game.Skinning
{
private readonly LegacyFont font;
private LegacyGlyphStore glyphStore;
private LegacyGlyphStore glyphStore = null!;
protected override char FixedWidthReferenceCharacter => '5';
@ -49,7 +47,7 @@ namespace osu.Game.Skinning
this.skin = skin;
}
public ITexturedCharacterGlyph Get(string fontName, char character)
public ITexturedCharacterGlyph? Get(string fontName, char 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.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
namespace osu.Game.Skinning
{
public class SkinCustomColourLookup

View File

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