mirror of
https://github.com/ppy/osu
synced 2025-03-11 05:49:12 +00:00
Show components available for current screen only (using actual live dependencies)
This commit is contained in:
parent
b07ca87965
commit
cc356bcfe4
@ -2,24 +2,16 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Edit.Components;
|
||||
using osuTK;
|
||||
|
||||
@ -29,26 +21,19 @@ namespace osu.Game.Skinning.Editor
|
||||
{
|
||||
public Action<Type> RequestPlacement;
|
||||
|
||||
[Cached]
|
||||
private ScoreProcessor scoreProcessor = new ScoreProcessor(new DummyRuleset())
|
||||
{
|
||||
Combo = { Value = RNG.Next(1, 1000) },
|
||||
TotalScore = { Value = RNG.Next(1000, 10000000) }
|
||||
};
|
||||
private readonly CompositeDrawable target;
|
||||
|
||||
[Cached(typeof(HealthProcessor))]
|
||||
private HealthProcessor healthProcessor = new DrainingHealthProcessor(0);
|
||||
|
||||
public SkinComponentToolbox()
|
||||
public SkinComponentToolbox(CompositeDrawable target = null)
|
||||
: base("Components")
|
||||
{
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
private FillFlowContainer fill;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
FillFlowContainer fill;
|
||||
|
||||
Child = fill = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
@ -57,6 +42,13 @@ namespace osu.Game.Skinning.Editor
|
||||
Spacing = new Vector2(2)
|
||||
};
|
||||
|
||||
reloadComponents();
|
||||
}
|
||||
|
||||
private void reloadComponents()
|
||||
{
|
||||
fill.Clear();
|
||||
|
||||
var skinnableTypes = typeof(OsuGame).Assembly.GetTypes()
|
||||
.Where(t => !t.IsInterface)
|
||||
.Where(t => typeof(ISkinnableDrawable).IsAssignableFrom(t))
|
||||
@ -64,18 +56,10 @@ namespace osu.Game.Skinning.Editor
|
||||
.ToArray();
|
||||
|
||||
foreach (var type in skinnableTypes)
|
||||
{
|
||||
var component = attemptAddComponent(type);
|
||||
|
||||
if (component != null)
|
||||
{
|
||||
component.RequestPlacement = t => RequestPlacement?.Invoke(t);
|
||||
fill.Add(component);
|
||||
}
|
||||
}
|
||||
attemptAddComponent(type);
|
||||
}
|
||||
|
||||
private static ToolboxComponentButton attemptAddComponent(Type type)
|
||||
private void attemptAddComponent(Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -83,14 +67,15 @@ namespace osu.Game.Skinning.Editor
|
||||
|
||||
Debug.Assert(instance != null);
|
||||
|
||||
if (!((ISkinnableDrawable)instance).IsEditable)
|
||||
return null;
|
||||
if (!((ISkinnableDrawable)instance).IsEditable) return;
|
||||
|
||||
return new ToolboxComponentButton(instance);
|
||||
fill.Add(new ToolboxComponentButton(instance, target)
|
||||
{
|
||||
RequestPlacement = t => RequestPlacement?.Invoke(t)
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,6 +86,7 @@ namespace osu.Game.Skinning.Editor
|
||||
public override bool PropagateNonPositionalInputSubTree => false;
|
||||
|
||||
private readonly Drawable component;
|
||||
private readonly CompositeDrawable dependencySource;
|
||||
|
||||
public Action<Type> RequestPlacement;
|
||||
|
||||
@ -109,9 +95,10 @@ namespace osu.Game.Skinning.Editor
|
||||
private const float contracted_size = 60;
|
||||
private const float expanded_size = 120;
|
||||
|
||||
public ToolboxComponentButton(Drawable component)
|
||||
public ToolboxComponentButton(Drawable component, CompositeDrawable dependencySource)
|
||||
{
|
||||
this.component = component;
|
||||
this.dependencySource = dependencySource;
|
||||
|
||||
Enabled.Value = true;
|
||||
|
||||
@ -143,7 +130,7 @@ namespace osu.Game.Skinning.Editor
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(10) { Bottom = 20 },
|
||||
Masking = true,
|
||||
Child = innerContainer = new Container
|
||||
Child = innerContainer = new DependencyBorrowingContainer(dependencySource)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
@ -186,14 +173,17 @@ namespace osu.Game.Skinning.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private class DummyRuleset : Ruleset
|
||||
public class DependencyBorrowingContainer : Container
|
||||
{
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type) => throw new NotImplementedException();
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException();
|
||||
public override string Description => string.Empty;
|
||||
public override string ShortName => string.Empty;
|
||||
private readonly CompositeDrawable donor;
|
||||
|
||||
public DependencyBorrowingContainer(CompositeDrawable donor)
|
||||
{
|
||||
this.donor = donor;
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
||||
new DependencyContainer(donor?.Dependencies ?? base.CreateChildDependencies(parent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ namespace osu.Game.Skinning.Editor
|
||||
private Container content;
|
||||
|
||||
private EditorSidebarSection settingsToolbox;
|
||||
private EditorSidebar componentsSidebar;
|
||||
|
||||
public SkinEditor()
|
||||
{
|
||||
@ -146,16 +147,7 @@ namespace osu.Game.Skinning.Editor
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new EditorSidebar
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
new SkinComponentToolbox
|
||||
{
|
||||
RequestPlacement = placeComponent
|
||||
},
|
||||
}
|
||||
},
|
||||
componentsSidebar = new EditorSidebar(),
|
||||
content = new Container
|
||||
{
|
||||
Depth = float.MaxValue,
|
||||
@ -211,7 +203,15 @@ namespace osu.Game.Skinning.Editor
|
||||
Scheduler.AddOnce(loadBlueprintContainer);
|
||||
Scheduler.AddOnce(populateSettings);
|
||||
|
||||
void loadBlueprintContainer() => content.Child = new SkinBlueprintContainer(targetScreen);
|
||||
void loadBlueprintContainer()
|
||||
{
|
||||
content.Child = new SkinBlueprintContainer(targetScreen);
|
||||
|
||||
componentsSidebar.Child = new SkinComponentToolbox(getFirstTarget() as CompositeDrawable)
|
||||
{
|
||||
RequestPlacement = placeComponent
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void skinChanged()
|
||||
@ -238,12 +238,7 @@ namespace osu.Game.Skinning.Editor
|
||||
|
||||
private void placeComponent(Type type)
|
||||
{
|
||||
var target = availableTargets.FirstOrDefault()?.Target;
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
var targetContainer = getTarget(target.Value);
|
||||
var targetContainer = getFirstTarget();
|
||||
|
||||
if (targetContainer == null)
|
||||
return;
|
||||
@ -278,6 +273,8 @@ namespace osu.Game.Skinning.Editor
|
||||
|
||||
private IEnumerable<ISkinnableTarget> availableTargets => targetScreen.ChildrenOfType<ISkinnableTarget>();
|
||||
|
||||
private ISkinnableTarget getFirstTarget() => availableTargets.FirstOrDefault();
|
||||
|
||||
private ISkinnableTarget getTarget(SkinnableTarget target)
|
||||
{
|
||||
return availableTargets.FirstOrDefault(c => c.Target == target);
|
||||
|
Loading…
Reference in New Issue
Block a user