2021-04-29 08:20:22 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning.Editor
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-05-03 05:58:23 +00:00
|
|
|
/// A container which handles loading a skin editor on user request for a specified target.
|
|
|
|
/// This also handles the scaling / positioning adjustment of the target.
|
2021-04-29 08:20:22 +00:00
|
|
|
/// </summary>
|
2021-05-03 05:58:23 +00:00
|
|
|
public class SkinEditorOverlay : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
2021-04-29 08:20:22 +00:00
|
|
|
{
|
|
|
|
private readonly ScalingContainer target;
|
|
|
|
private SkinEditor skinEditor;
|
|
|
|
|
2021-04-30 03:35:58 +00:00
|
|
|
public const float VISIBLE_TARGET_SCALE = 0.8f;
|
2021-04-29 08:20:22 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2021-05-03 05:58:23 +00:00
|
|
|
public SkinEditorOverlay(ScalingContainer target)
|
2021-04-29 08:20:22 +00:00
|
|
|
{
|
|
|
|
this.target = target;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OnPressed(GlobalAction action)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
2021-04-29 08:40:58 +00:00
|
|
|
case GlobalAction.Back:
|
|
|
|
if (skinEditor?.State.Value == Visibility.Visible)
|
|
|
|
{
|
|
|
|
skinEditor.ToggleVisibility();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-04-29 08:20:22 +00:00
|
|
|
case GlobalAction.ToggleSkinEditor:
|
|
|
|
if (skinEditor == null)
|
|
|
|
{
|
|
|
|
LoadComponentAsync(skinEditor = new SkinEditor(target), AddInternal);
|
|
|
|
skinEditor.State.BindValueChanged(editorVisibilityChanged);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
skinEditor.ToggleVisibility();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void editorVisibilityChanged(ValueChangedEvent<Visibility> visibility)
|
|
|
|
{
|
|
|
|
if (visibility.NewValue == Visibility.Visible)
|
|
|
|
{
|
|
|
|
target.Masking = true;
|
|
|
|
target.BorderThickness = 5;
|
|
|
|
target.BorderColour = colours.Yellow;
|
|
|
|
target.AllowScaling = false;
|
2021-04-30 03:35:58 +00:00
|
|
|
target.RelativePositionAxes = Axes.Both;
|
|
|
|
|
|
|
|
target.ScaleTo(VISIBLE_TARGET_SCALE, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
|
2021-05-11 09:17:05 +00:00
|
|
|
target.MoveToX(0.095f, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
|
2021-04-29 08:20:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target.BorderThickness = 0;
|
|
|
|
target.AllowScaling = true;
|
|
|
|
|
|
|
|
target.ScaleTo(1, SkinEditor.TRANSITION_DURATION, Easing.OutQuint).OnComplete(_ => target.Masking = false);
|
2021-04-30 03:35:58 +00:00
|
|
|
target.MoveToX(0f, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
|
2021-04-29 08:20:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(GlobalAction action)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Exit any existing skin editor due to the game state changing.
|
|
|
|
/// </summary>
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
skinEditor?.Hide();
|
|
|
|
skinEditor?.Expire();
|
|
|
|
skinEditor = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|