1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 18:32:56 +08:00

Apply nullability to SkinComponentToolbox and split out reflection method to get all skinnable components

This commit is contained in:
Dean Herbert 2022-08-01 14:03:57 +09:00
parent f9f9b65c86
commit 5b98a73edc
2 changed files with 23 additions and 21 deletions

View File

@ -98,5 +98,14 @@ namespace osu.Game.Screens.Play.HUD
return Drawable.Empty(); return Drawable.Empty();
} }
} }
public static Type[] GetAllAvailableDrawables()
{
return typeof(OsuGame).Assembly.GetTypes()
.Where(t => !t.IsInterface && !t.IsAbstract)
.Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t))
.OrderBy(t => t.Name)
.ToArray();
}
} }
} }

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; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
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;
@ -16,24 +13,25 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Screens.Edit.Components; using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Play.HUD;
using osuTK; using osuTK;
namespace osu.Game.Skinning.Editor namespace osu.Game.Skinning.Editor
{ {
public class SkinComponentToolbox : EditorSidebarSection public class SkinComponentToolbox : EditorSidebarSection
{ {
public Action<Type> RequestPlacement; public Action<Type>? RequestPlacement;
private readonly CompositeDrawable target; private readonly CompositeDrawable? target;
public SkinComponentToolbox(CompositeDrawable target = null) private FillFlowContainer fill = null!;
public SkinComponentToolbox(CompositeDrawable? target = null)
: base("Components") : base("Components")
{ {
this.target = target; this.target = target;
} }
private FillFlowContainer fill;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -52,12 +50,7 @@ namespace osu.Game.Skinning.Editor
{ {
fill.Clear(); fill.Clear();
var skinnableTypes = typeof(OsuGame).Assembly.GetTypes() var skinnableTypes = SkinnableInfo.GetAllAvailableDrawables();
.Where(t => !t.IsInterface && !t.IsAbstract)
.Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t))
.OrderBy(t => t.Name)
.ToArray();
foreach (var type in skinnableTypes) foreach (var type in skinnableTypes)
attemptAddComponent(type); attemptAddComponent(type);
} }
@ -90,21 +83,21 @@ namespace osu.Game.Skinning.Editor
public class ToolboxComponentButton : OsuButton public class ToolboxComponentButton : OsuButton
{ {
public Action<Type>? RequestPlacement;
protected override bool ShouldBeConsideredForInput(Drawable child) => false; protected override bool ShouldBeConsideredForInput(Drawable child) => false;
public override bool PropagateNonPositionalInputSubTree => false; public override bool PropagateNonPositionalInputSubTree => false;
private readonly Drawable component; private readonly Drawable component;
private readonly CompositeDrawable dependencySource; private readonly CompositeDrawable? dependencySource;
public Action<Type> RequestPlacement; private Container innerContainer = null!;
private Container innerContainer;
private const float contracted_size = 60; private const float contracted_size = 60;
private const float expanded_size = 120; private const float expanded_size = 120;
public ToolboxComponentButton(Drawable component, CompositeDrawable dependencySource) public ToolboxComponentButton(Drawable component, CompositeDrawable? dependencySource)
{ {
this.component = component; this.component = component;
this.dependencySource = dependencySource; this.dependencySource = dependencySource;
@ -184,9 +177,9 @@ namespace osu.Game.Skinning.Editor
public class DependencyBorrowingContainer : Container public class DependencyBorrowingContainer : Container
{ {
private readonly CompositeDrawable donor; private readonly CompositeDrawable? donor;
public DependencyBorrowingContainer(CompositeDrawable donor) public DependencyBorrowingContainer(CompositeDrawable? donor)
{ {
this.donor = donor; this.donor = donor;
} }