Merge pull request #17272 from peppy/skin-editor-hide-toolbar

Hide the game toolbar (and overlays) when entering the skin editor
This commit is contained in:
Dan Balasescu
2022-03-16 20:42:20 +09:00
committed by GitHub
3 changed files with 43 additions and 19 deletions

View File

@ -1184,7 +1184,7 @@ namespace osu.Game
BackButton.Hide(); BackButton.Hide();
} }
skinEditor.SetTarget((Screen)newScreen); skinEditor.SetTarget((OsuScreen)newScreen);
} }
private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen); private void screenPushed(IScreen lastScreen, IScreen newScreen) => screenChanged(lastScreen, newScreen);

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -49,16 +48,20 @@ namespace osu.Game.Skinning.Editor
private EditorToolboxGroup settingsToolbox; private EditorToolboxGroup settingsToolbox;
public SkinEditor()
{
}
public SkinEditor(Drawable targetScreen) public SkinEditor(Drawable targetScreen)
{ {
RelativeSizeAxes = Axes.Both;
UpdateTargetScreen(targetScreen); UpdateTargetScreen(targetScreen);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
RelativeSizeAxes = Axes.Both;
InternalChild = new OsuContextMenuContainer InternalChild = new OsuContextMenuContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -155,7 +158,7 @@ namespace osu.Game.Skinning.Editor
Scheduler.AddOnce(skinChanged); Scheduler.AddOnce(skinChanged);
}, true); }, true);
SelectedComponents.BindCollectionChanged(selectionChanged); SelectedComponents.BindCollectionChanged((_, __) => Scheduler.AddOnce(populateSettings), true);
} }
public void UpdateTargetScreen(Drawable targetScreen) public void UpdateTargetScreen(Drawable targetScreen)
@ -163,6 +166,7 @@ namespace osu.Game.Skinning.Editor
this.targetScreen = targetScreen; this.targetScreen = targetScreen;
SelectedComponents.Clear(); SelectedComponents.Clear();
Scheduler.AddOnce(loadBlueprintContainer); Scheduler.AddOnce(loadBlueprintContainer);
void loadBlueprintContainer() void loadBlueprintContainer()
@ -224,7 +228,7 @@ namespace osu.Game.Skinning.Editor
SelectedComponents.Add(component); SelectedComponents.Add(component);
} }
private void selectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void populateSettings()
{ {
settingsToolbox.Clear(); settingsToolbox.Clear();

View File

@ -3,15 +3,15 @@
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Bindables; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; 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;
using osu.Game.Screens;
namespace osu.Game.Skinning.Editor namespace osu.Game.Skinning.Editor
{ {
@ -21,16 +21,21 @@ namespace osu.Game.Skinning.Editor
/// </summary> /// </summary>
public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction> public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
{ {
private readonly ScalingContainer target; private readonly ScalingContainer scalingContainer;
[CanBeNull] [CanBeNull]
private SkinEditor skinEditor; private SkinEditor skinEditor;
public const float VISIBLE_TARGET_SCALE = 0.8f; public const float VISIBLE_TARGET_SCALE = 0.8f;
public SkinEditorOverlay(ScalingContainer target) [Resolved(canBeNull: true)]
private OsuGame game { get; set; }
private OsuScreen lastTargetScreen;
public SkinEditorOverlay(ScalingContainer scalingContainer)
{ {
this.target = target; this.scalingContainer = scalingContainer;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
} }
@ -77,8 +82,8 @@ namespace osu.Game.Skinning.Editor
return; return;
} }
var editor = new SkinEditor(target); var editor = new SkinEditor();
editor.State.BindValueChanged(editorVisibilityChanged); editor.State.BindValueChanged(visibility => updateComponentVisibility());
skinEditor = editor; skinEditor = editor;
@ -95,21 +100,31 @@ namespace osu.Game.Skinning.Editor
return; return;
AddInternal(editor); AddInternal(editor);
SetTarget(lastTargetScreen);
}); });
}); });
} }
private void editorVisibilityChanged(ValueChangedEvent<Visibility> visibility) private void updateComponentVisibility()
{ {
Debug.Assert(skinEditor != null);
const float toolbar_padding_requirement = 0.18f; const float toolbar_padding_requirement = 0.18f;
if (visibility.NewValue == Visibility.Visible) if (skinEditor.State.Value == Visibility.Visible)
{ {
target.SetCustomRect(new RectangleF(toolbar_padding_requirement, 0.1f, 0.8f - toolbar_padding_requirement, 0.7f), true); scalingContainer.SetCustomRect(new RectangleF(toolbar_padding_requirement, 0.1f, 0.8f - toolbar_padding_requirement, 0.7f), true);
game?.Toolbar.Hide();
game?.CloseAllOverlays();
} }
else else
{ {
target.SetCustomRect(null); scalingContainer.SetCustomRect(null);
if (lastTargetScreen?.HideOverlaysOnEnter != true)
game?.Toolbar.Show();
} }
} }
@ -120,17 +135,22 @@ namespace osu.Game.Skinning.Editor
/// <summary> /// <summary>
/// Set a new target screen which will be used to find skinnable components. /// Set a new target screen which will be used to find skinnable components.
/// </summary> /// </summary>
public void SetTarget(Screen screen) public void SetTarget(OsuScreen screen)
{ {
lastTargetScreen = screen;
if (skinEditor == null) return; if (skinEditor == null) return;
skinEditor.Save(); skinEditor.Save();
// ensure the toolbar is re-hidden even if a new screen decides to try and show it.
updateComponentVisibility();
// AddOnce with parameter will ensure the newest target is loaded if there is any overlap. // AddOnce with parameter will ensure the newest target is loaded if there is any overlap.
Scheduler.AddOnce(setTarget, screen); Scheduler.AddOnce(setTarget, screen);
} }
private void setTarget(Screen target) private void setTarget(OsuScreen target)
{ {
Debug.Assert(skinEditor != null); Debug.Assert(skinEditor != null);