mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 03:02:54 +08:00
Merge pull request #8832 from smoogipoo/editor-platform-bindings
Use platform bindings for editor actions
This commit is contained in:
commit
baeeafa941
@ -10,24 +10,22 @@ using osu.Game.Rulesets.Osu;
|
|||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Screens.Edit;
|
using osu.Game.Screens.Edit;
|
||||||
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Editor
|
namespace osu.Game.Tests.Visual.Editor
|
||||||
{
|
{
|
||||||
public class TestSceneEditorChangeStates : ScreenTestScene
|
public class TestSceneEditorChangeStates : ScreenTestScene
|
||||||
{
|
{
|
||||||
private EditorBeatmap editorBeatmap;
|
private EditorBeatmap editorBeatmap;
|
||||||
|
private TestEditor editor;
|
||||||
|
|
||||||
public override void SetUpSteps()
|
public override void SetUpSteps()
|
||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
Screens.Edit.Editor editor = null;
|
|
||||||
|
|
||||||
AddStep("load editor", () =>
|
AddStep("load editor", () =>
|
||||||
{
|
{
|
||||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||||
LoadScreen(editor = new Screens.Edit.Editor());
|
LoadScreen(editor = new TestEditor());
|
||||||
});
|
});
|
||||||
|
|
||||||
AddUntilStep("wait for editor to load", () => editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
AddUntilStep("wait for editor to load", () => editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
||||||
@ -160,36 +158,15 @@ namespace osu.Game.Tests.Visual.Editor
|
|||||||
AddAssert("no hitobject added", () => addedObject == null);
|
AddAssert("no hitobject added", () => addedObject == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addUndoSteps()
|
private void addUndoSteps() => AddStep("undo", () => editor.Undo());
|
||||||
|
|
||||||
|
private void addRedoSteps() => AddStep("redo", () => editor.Redo());
|
||||||
|
|
||||||
|
private class TestEditor : Screens.Edit.Editor
|
||||||
{
|
{
|
||||||
AddStep("press undo", () =>
|
public new void Undo() => base.Undo();
|
||||||
{
|
|
||||||
InputManager.PressKey(Key.LControl);
|
|
||||||
InputManager.PressKey(Key.Z);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("release keys", () =>
|
public new void Redo() => base.Redo();
|
||||||
{
|
|
||||||
InputManager.ReleaseKey(Key.LControl);
|
|
||||||
InputManager.ReleaseKey(Key.Z);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addRedoSteps()
|
|
||||||
{
|
|
||||||
AddStep("press redo", () =>
|
|
||||||
{
|
|
||||||
InputManager.PressKey(Key.LControl);
|
|
||||||
InputManager.PressKey(Key.LShift);
|
|
||||||
InputManager.PressKey(Key.Z);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("release keys", () =>
|
|
||||||
{
|
|
||||||
InputManager.ReleaseKey(Key.LControl);
|
|
||||||
InputManager.ReleaseKey(Key.LShift);
|
|
||||||
InputManager.ReleaseKey(Key.Z);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ using osu.Game.Screens.Edit.Design;
|
|||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -37,7 +38,7 @@ using osu.Game.Users;
|
|||||||
namespace osu.Game.Screens.Edit
|
namespace osu.Game.Screens.Edit
|
||||||
{
|
{
|
||||||
[Cached(typeof(IBeatSnapProvider))]
|
[Cached(typeof(IBeatSnapProvider))]
|
||||||
public class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>, IBeatSnapProvider
|
public class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>, IKeyBindingHandler<PlatformAction>, IBeatSnapProvider
|
||||||
{
|
{
|
||||||
public override float BackgroundParallaxAmount => 0.1f;
|
public override float BackgroundParallaxAmount => 0.1f;
|
||||||
|
|
||||||
@ -157,8 +158,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
{
|
{
|
||||||
Items = new[]
|
Items = new[]
|
||||||
{
|
{
|
||||||
undoMenuItem = new EditorMenuItem("Undo", MenuItemType.Standard, undo),
|
undoMenuItem = new EditorMenuItem("Undo", MenuItemType.Standard, Undo),
|
||||||
redoMenuItem = new EditorMenuItem("Redo", MenuItemType.Standard, redo)
|
redoMenuItem = new EditorMenuItem("Redo", MenuItemType.Standard, Redo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,6 +231,30 @@ namespace osu.Game.Screens.Edit
|
|||||||
clock.ProcessFrame();
|
clock.ProcessFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool OnPressed(PlatformAction action)
|
||||||
|
{
|
||||||
|
switch (action.ActionType)
|
||||||
|
{
|
||||||
|
case PlatformActionType.Undo:
|
||||||
|
Undo();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case PlatformActionType.Redo:
|
||||||
|
Redo();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case PlatformActionType.Save:
|
||||||
|
saveBeatmap();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnReleased(PlatformAction action)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
{
|
{
|
||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
@ -241,28 +266,6 @@ namespace osu.Game.Screens.Edit
|
|||||||
case Key.Right:
|
case Key.Right:
|
||||||
seek(e, 1);
|
seek(e, 1);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Key.S:
|
|
||||||
if (e.ControlPressed)
|
|
||||||
{
|
|
||||||
saveBeatmap();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.Z:
|
|
||||||
if (e.ControlPressed)
|
|
||||||
{
|
|
||||||
if (e.ShiftPressed)
|
|
||||||
redo();
|
|
||||||
else
|
|
||||||
undo();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnKeyDown(e);
|
return base.OnKeyDown(e);
|
||||||
@ -326,9 +329,9 @@ namespace osu.Game.Screens.Edit
|
|||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void undo() => changeHandler.RestoreState(-1);
|
protected void Undo() => changeHandler.RestoreState(-1);
|
||||||
|
|
||||||
private void redo() => changeHandler.RestoreState(1);
|
protected void Redo() => changeHandler.RestoreState(1);
|
||||||
|
|
||||||
private void resetTrack(bool seekToStart = false)
|
private void resetTrack(bool seekToStart = false)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user