mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Add the skin editor to the game
This commit is contained in:
parent
141d3af302
commit
b936043956
@ -48,6 +48,7 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings),
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.D }, GlobalAction.ToggleBeatmapListing),
|
||||
new KeyBinding(new[] { InputKey.Control, InputKey.N }, GlobalAction.ToggleNotifications),
|
||||
new KeyBinding(new[] { InputKey.Shift, InputKey.F2 }, GlobalAction.ToggleSkinEditor),
|
||||
|
||||
new KeyBinding(InputKey.Escape, GlobalAction.Back),
|
||||
new KeyBinding(InputKey.ExtraMouseButton1, GlobalAction.Back),
|
||||
@ -258,6 +259,9 @@ namespace osu.Game.Input.Bindings
|
||||
EditorNudgeLeft,
|
||||
|
||||
[Description("Nudge selection right")]
|
||||
EditorNudgeRight
|
||||
EditorNudgeRight,
|
||||
|
||||
[Description("Toggle skin editor")]
|
||||
ToggleSkinEditor,
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ using osu.Game.Utils;
|
||||
using LogLevel = osu.Framework.Logging.LogLevel;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Skinning.Editor;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
@ -597,6 +598,8 @@ namespace osu.Game
|
||||
screenContainer = new ScalingContainer(ScalingMode.ExcludeOverlays)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
receptor = new BackButton.Receptor(),
|
||||
@ -616,6 +619,7 @@ namespace osu.Game
|
||||
logoContainer = new Container { RelativeSizeAxes = Axes.Both },
|
||||
}
|
||||
},
|
||||
skinEditor = new SkinEditorContainer(screenContainer),
|
||||
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
@ -942,6 +946,8 @@ namespace osu.Game
|
||||
|
||||
private ScalingContainer screenContainer;
|
||||
|
||||
private SkinEditorContainer skinEditor;
|
||||
|
||||
protected override bool OnExiting()
|
||||
{
|
||||
if (ScreenStack.CurrentScreen is Loader)
|
||||
@ -968,6 +974,8 @@ namespace osu.Game
|
||||
|
||||
protected virtual void ScreenChanged(IScreen current, IScreen newScreen)
|
||||
{
|
||||
skinEditor.Reset();
|
||||
|
||||
switch (newScreen)
|
||||
{
|
||||
case IntroScreen intro:
|
||||
|
@ -4,16 +4,16 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
|
||||
namespace osu.Game.Skinning.Editor
|
||||
{
|
||||
public class SkinEditor : VisibilityContainer
|
||||
public class SkinEditor : FocusedOverlayContainer
|
||||
{
|
||||
public const double TRANSITION_DURATION = 500;
|
||||
|
||||
private readonly Drawable target;
|
||||
private Container border;
|
||||
|
||||
protected override bool StartHidden => true;
|
||||
|
||||
@ -25,32 +25,13 @@ namespace osu.Game.Skinning.Editor
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load()
|
||||
{
|
||||
InternalChild = new OsuContextMenuContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
border = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
BorderColour = colours.Yellow,
|
||||
BorderThickness = 5,
|
||||
CornerRadius = 5,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
AlwaysPresent = true,
|
||||
Alpha = 0,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
}
|
||||
},
|
||||
new SkinBlueprintContainer(target),
|
||||
}
|
||||
};
|
||||
@ -62,29 +43,18 @@ namespace osu.Game.Skinning.Editor
|
||||
Show();
|
||||
}
|
||||
|
||||
private const double transition_duration = 500;
|
||||
private const float visible_target_scale = 0.8f;
|
||||
protected override bool OnHover(HoverEvent e) => true;
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
if (IsLoaded)
|
||||
{
|
||||
target.ScaleTo(visible_target_scale, transition_duration, Easing.OutQuint);
|
||||
border.ScaleTo(visible_target_scale, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
this.FadeIn(transition_duration);
|
||||
this.FadeIn(TRANSITION_DURATION, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
if (IsLoaded)
|
||||
{
|
||||
target.ScaleTo(1, transition_duration, Easing.OutQuint);
|
||||
border.ScaleTo(1, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
this.FadeOut(transition_duration, Easing.OutQuint);
|
||||
this.FadeOut(TRANSITION_DURATION, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
87
osu.Game/Skinning/Editor/SkinEditorContainer.cs
Normal file
87
osu.Game/Skinning/Editor/SkinEditorContainer.cs
Normal file
@ -0,0 +1,87 @@
|
||||
// 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>
|
||||
/// A container which handles loading a skin editor on user request.
|
||||
/// </summary>
|
||||
public class SkinEditorContainer : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private readonly ScalingContainer target;
|
||||
private SkinEditor skinEditor;
|
||||
|
||||
private const float visible_target_scale = 0.8f;
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
public SkinEditorContainer(ScalingContainer target)
|
||||
{
|
||||
this.target = target;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
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.ScaleTo(visible_target_scale, SkinEditor.TRANSITION_DURATION, Easing.OutQuint);
|
||||
|
||||
target.Masking = true;
|
||||
target.BorderThickness = 5;
|
||||
target.BorderColour = colours.Yellow;
|
||||
target.AllowScaling = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
target.BorderThickness = 0;
|
||||
target.AllowScaling = true;
|
||||
|
||||
target.ScaleTo(1, SkinEditor.TRANSITION_DURATION, Easing.OutQuint).OnComplete(_ => target.Masking = false);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user