Apply NRT to all skin editor classes

This commit is contained in:
Dean Herbert
2023-01-26 17:46:19 +09:00
parent 9677a8e3b3
commit 2017ac1135
6 changed files with 59 additions and 57 deletions

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)
@ -130,7 +132,7 @@ namespace osu.Game.Skinning.Editor
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
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)
{ {