mirror of
https://github.com/ppy/osu
synced 2025-04-01 22:48:33 +00:00
Refactor SkinEditor
to support switching target screens without full reload
This commit is contained in:
parent
32c7a023f8
commit
9a1ade4f79
osu.Game
@ -1142,8 +1142,6 @@ namespace osu.Game
|
|||||||
|
|
||||||
private void screenChanged(IScreen current, IScreen newScreen)
|
private void screenChanged(IScreen current, IScreen newScreen)
|
||||||
{
|
{
|
||||||
skinEditor.Reset();
|
|
||||||
|
|
||||||
switch (newScreen)
|
switch (newScreen)
|
||||||
{
|
{
|
||||||
case IntroScreen intro:
|
case IntroScreen intro:
|
||||||
@ -1185,6 +1183,8 @@ namespace osu.Game
|
|||||||
else
|
else
|
||||||
BackButton.Hide();
|
BackButton.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skinEditor.SetTarget((Screen)newScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen);
|
private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen);
|
||||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Skinning.Editor
|
|||||||
|
|
||||||
protected override bool StartHidden => true;
|
protected override bool StartHidden => true;
|
||||||
|
|
||||||
private readonly Drawable targetScreen;
|
private Drawable targetScreen;
|
||||||
|
|
||||||
private OsuTextFlowContainer headerText;
|
private OsuTextFlowContainer headerText;
|
||||||
|
|
||||||
@ -42,11 +42,13 @@ namespace osu.Game.Skinning.Editor
|
|||||||
|
|
||||||
private bool hasBegunMutating;
|
private bool hasBegunMutating;
|
||||||
|
|
||||||
|
private Container blueprintContainerContainer;
|
||||||
|
|
||||||
public SkinEditor(Drawable targetScreen)
|
public SkinEditor(Drawable targetScreen)
|
||||||
{
|
{
|
||||||
this.targetScreen = targetScreen;
|
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
UpdateTargetScreen(targetScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -113,13 +115,9 @@ namespace osu.Game.Skinning.Editor
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
RequestPlacement = placeComponent
|
RequestPlacement = placeComponent
|
||||||
},
|
},
|
||||||
new Container
|
blueprintContainerContainer = new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new SkinBlueprintContainer(targetScreen),
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,6 +145,21 @@ namespace osu.Game.Skinning.Editor
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateTargetScreen(Drawable targetScreen)
|
||||||
|
{
|
||||||
|
this.targetScreen = targetScreen;
|
||||||
|
|
||||||
|
Scheduler.AddOnce(loadBlueprintContainer);
|
||||||
|
|
||||||
|
void loadBlueprintContainer()
|
||||||
|
{
|
||||||
|
blueprintContainerContainer.Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SkinBlueprintContainer(targetScreen),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void skinChanged()
|
private void skinChanged()
|
||||||
{
|
{
|
||||||
headerText.Clear();
|
headerText.Clear();
|
||||||
|
@ -1,6 +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.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -8,6 +9,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
|
|
||||||
@ -114,15 +116,36 @@ namespace osu.Game.Skinning.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exit any existing skin editor due to the game state changing.
|
/// Set a new target screen which will be used to find skinnable components.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Reset()
|
public void SetTarget(Screen screen)
|
||||||
{
|
{
|
||||||
skinEditor?.Save();
|
if (skinEditor == null) return;
|
||||||
skinEditor?.Hide();
|
|
||||||
skinEditor?.Expire();
|
|
||||||
|
|
||||||
skinEditor = null;
|
skinEditor.Save();
|
||||||
|
|
||||||
|
// AddOnce with paramter will ensure the newest target is loaded if there is any overlap.
|
||||||
|
Scheduler.AddOnce(setTarget, screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTarget(Screen target)
|
||||||
|
{
|
||||||
|
Debug.Assert(skinEditor != null);
|
||||||
|
|
||||||
|
if (!target.IsLoaded)
|
||||||
|
{
|
||||||
|
Scheduler.AddOnce(setTarget, target);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skinEditor.State.Value == Visibility.Visible)
|
||||||
|
skinEditor.UpdateTargetScreen(target);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skinEditor.Hide();
|
||||||
|
skinEditor.Expire();
|
||||||
|
skinEditor = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user