Add custom actions for Catch

Reworks input management for rulesets
This commit is contained in:
Dean Herbert 2017-08-09 11:50:34 +09:00
parent 06e5f7de09
commit b88f37de45
11 changed files with 116 additions and 58 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Catch.UI;
using OpenTK;
@ -15,14 +16,18 @@ namespace osu.Desktop.Tests.Visual
Children = new Drawable[]
{
new CatcherArea
new CatchInputManager
{
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Size = new Vector2(1, 0.2f),
}
Child = new CatcherArea
{
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Size = new Vector2(1, 0.2f),
}
},
};
}
}

View File

@ -0,0 +1,32 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Input;
using OpenTK.Input;
namespace osu.Game.Rulesets.Catch
{
public class CatchInputManager : ActionMappingInputManager<CatchAction>
{
public CatchInputManager()
{
Mappings = new Dictionary<Key, CatchAction>
{
{ Key.Z, CatchAction.MoveLeft },
{ Key.Left, CatchAction.MoveLeft },
{ Key.X, CatchAction.MoveRight },
{ Key.Right, CatchAction.MoveRight },
{ Key.LShift, CatchAction.Dash },
{ Key.RShift, CatchAction.Dash },
};
}
}
public enum CatchAction
{
MoveLeft,
MoveRight,
Dash
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Beatmaps;
using osu.Game.Rulesets.Catch.Beatmaps;
@ -27,6 +28,8 @@ namespace osu.Game.Rulesets.Catch.UI
protected override Playfield<CatchBaseHit, CatchJudgement> CreatePlayfield() => new CatchPlayfield();
protected override PassThroughInputManager CreateKeyConversionInputManager() => new CatchInputManager();
protected override DrawableHitObject<CatchBaseHit, CatchJudgement> GetVisualRepresentation(CatchBaseHit h)
{
if (h is Fruit)

View File

@ -15,7 +15,6 @@ using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawable;
using osu.Game.Rulesets.Objects.Drawables;
using OpenTK;
using OpenTK.Input;
namespace osu.Game.Rulesets.Catch.UI
{
@ -63,9 +62,6 @@ namespace osu.Game.Rulesets.Catch.UI
Child = createCatcherSprite();
}
private bool leftPressed;
private bool rightPressed;
private int currentDirection;
private bool dashing;
@ -114,19 +110,20 @@ namespace osu.Game.Rulesets.Catch.UI
{
if (args.Repeat) return true;
switch (args.Key)
if (state.Data is CatchAction)
{
case Key.Left:
currentDirection = -1;
leftPressed = true;
return true;
case Key.Right:
currentDirection = 1;
rightPressed = true;
return true;
case Key.ShiftLeft:
Dashing = true;
return true;
switch ((CatchAction)state.Data)
{
case CatchAction.MoveLeft:
currentDirection--;
return true;
case CatchAction.MoveRight:
currentDirection++;
return true;
case CatchAction.Dash:
Dashing = true;
return true;
}
}
return base.OnKeyDown(state, args);
@ -134,19 +131,20 @@ namespace osu.Game.Rulesets.Catch.UI
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
{
switch (args.Key)
if (state.Data is CatchAction)
{
case Key.Left:
currentDirection = rightPressed ? 1 : 0;
leftPressed = false;
return true;
case Key.Right:
currentDirection = leftPressed ? -1 : 0;
rightPressed = false;
return true;
case Key.ShiftLeft:
Dashing = false;
return true;
switch ((CatchAction)state.Data)
{
case CatchAction.MoveLeft:
currentDirection++;
return true;
case CatchAction.MoveRight:
currentDirection--;
return true;
case CatchAction.Dash:
Dashing = false;
return true;
}
}
return base.OnKeyUp(state, args);
@ -161,7 +159,7 @@ namespace osu.Game.Rulesets.Catch.UI
float speed = Dashing ? 1.5f : 1;
Scale = new Vector2(Math.Sign(currentDirection), 1);
X = (float)MathHelper.Clamp(X + currentDirection * Clock.ElapsedFrameTime / 1800 * speed, 0, 1);
X = (float)MathHelper.Clamp(X + Math.Sign(currentDirection) * Clock.ElapsedFrameTime / 1800 * speed, 0, 1);
}
public void AddToStack(DrawableHitObject<CatchBaseHit, CatchJudgement> fruit, Vector2 absolutePosition)

View File

@ -38,6 +38,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
@ -50,6 +51,7 @@
<ItemGroup>
<Compile Include="Beatmaps\CatchBeatmapConverter.cs" />
<Compile Include="CatchDifficultyCalculator.cs" />
<Compile Include="RulesetInputManager.cs" />
<Compile Include="Scoring\CatchScoreProcessor.cs" />
<Compile Include="Judgements\CatchJudgement.cs" />
<Compile Include="Objects\CatchBaseHit.cs" />

View File

@ -3,14 +3,13 @@
using System.Linq;
using osu.Framework.Input;
using osu.Game.Screens.Play;
using OpenTK.Input;
using KeyboardState = osu.Framework.Input.KeyboardState;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Game.Rulesets.Osu
{
public class OsuKeyConversionInputManager : KeyConversionInputManager
public class OsuKeyConversionInputManager : PassThroughInputManager
{
private bool leftViaKeyboard;
private bool rightViaKeyboard;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
using OpenTK;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Beatmaps;
@ -12,7 +13,6 @@ using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Osu.UI
{
@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI
protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield();
protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager();
protected override PassThroughInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager();
protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h)
{

View File

@ -0,0 +1,34 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Input;
using OpenTK.Input;
namespace osu.Game.Input
{
public class ActionMappingInputManager<T> : PassThroughInputManager
where T : struct
{
protected IDictionary<Key, T> Mappings { get; set; }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
mapKey(state, args.Key);
return base.OnKeyDown(state, args);
}
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
{
mapKey(state, args.Key);
return base.OnKeyUp(state, args);
}
private void mapKey(InputState state, Key key)
{
T mappedData;
if (Mappings.TryGetValue(key, out mappedData))
state.Data = mappedData;
}
}
}

View File

@ -14,6 +14,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Input;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring;
using OpenTK;
@ -47,7 +48,7 @@ namespace osu.Game.Rulesets.UI
/// <summary>
/// The key conversion input manager for this HitRenderer.
/// </summary>
protected readonly KeyConversionInputManager KeyConversionInputManager;
protected readonly PassThroughInputManager KeyConversionInputManager;
/// <summary>
/// Whether we are currently providing the local user a gameplay cursor.
@ -87,7 +88,7 @@ namespace osu.Game.Rulesets.UI
/// Creates a key conversion input manager.
/// </summary>
/// <returns>The input manager.</returns>
protected virtual KeyConversionInputManager CreateKeyConversionInputManager() => new KeyConversionInputManager();
protected virtual PassThroughInputManager CreateKeyConversionInputManager() => new PassThroughInputManager();
protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay);

View File

@ -1,16 +0,0 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
namespace osu.Game.Screens.Play
{
/// <summary>
/// An InputManager primarily used to map keys to new functions.
/// By default this does nothing; override TransformState to make alterations.
/// </summary>
public class KeyConversionInputManager : PassThroughInputManager
{
}
}

View File

@ -118,6 +118,7 @@
<Compile Include="Overlays\Profile\Sections\RecentSection.cs" />
<Compile Include="Graphics\Containers\ConstrainedIconContainer.cs" />
<Compile Include="Rulesets\Mods\IApplicableToDifficulty.cs" />
<Compile Include="Input\ActionMappingInputManager.cs" />
<Compile Include="Users\UserCoverBackground.cs" />
<Compile Include="Overlays\UserProfileOverlay.cs" />
<Compile Include="Overlays\Profile\ProfileHeader.cs" />
@ -309,7 +310,6 @@
<Compile Include="Screens\Multiplayer\MatchCreate.cs" />
<Compile Include="Screens\Play\FailOverlay.cs" />
<Compile Include="Screens\Play\MenuOverlay.cs" />
<Compile Include="Screens\Play\KeyConversionInputManager.cs" />
<Compile Include="Screens\Play\PlayerInputManager.cs" />
<Compile Include="Screens\Play\PlayerLoader.cs" />
<Compile Include="Screens\Play\ReplayPlayer.cs" />