1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Use new population methods and implement osu! ruleset actions

This commit is contained in:
Dean Herbert 2017-08-10 18:28:43 +09:00
parent b6bb07c0b5
commit e9a11ebc9f
6 changed files with 66 additions and 49 deletions

View File

@ -49,9 +49,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
disc.Texture = textures.Get(@"Play/osu/disc"); disc.Texture = textures.Get(@"Play/osu/disc");
} }
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{ {
return Hit?.Invoke() ?? false; if (state.Data is OsuAction)
{
switch ((OsuAction)state.Data)
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
return IsHovered && (Hit?.Invoke() ?? false);
}
}
return false;
} }
} }
} }

View File

@ -0,0 +1,50 @@
// 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 System.Linq;
using osu.Framework.Input;
using osu.Game.Input;
using OpenTK.Input;
using KeyboardState = osu.Framework.Input.KeyboardState;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Game.Rulesets.Osu
{
public class OsuInputManager : ActionMappingInputManager<OsuAction>
{
public OsuInputManager(RulesetInfo ruleset) : base(ruleset, concurrencyMode: ConcurrentActionMode.UniqueActions)
{
}
protected override void TransformState(InputState state)
{
base.TransformState(state);
var mouse = state.Mouse as MouseState;
var keyboard = state.Keyboard as KeyboardState;
if (mouse != null && keyboard != null)
{
if (mouse.IsPressed(MouseButton.Left))
keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 1 });
if (mouse.IsPressed(MouseButton.Right))
keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 2 });
}
}
protected override IDictionary<KeyCombination, OsuAction> CreateDefaultMappings() => new Dictionary<KeyCombination, OsuAction>
{
{ Key.Z, OsuAction.LeftButton },
{ Key.X, OsuAction.RightButton },
{ Key.LastKey + 1, OsuAction.LeftButton },
{ Key.LastKey + 2, OsuAction.RightButton },
};
}
public enum OsuAction
{
LeftButton,
RightButton
}
}

View File

@ -1,39 +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 System.Linq;
using osu.Framework.Input;
using OpenTK.Input;
using KeyboardState = osu.Framework.Input.KeyboardState;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Game.Rulesets.Osu
{
public class OsuKeyConversionInputManager : PassThroughInputManager
{
private bool leftViaKeyboard;
private bool rightViaKeyboard;
protected override void TransformState(InputState state)
{
base.TransformState(state);
var mouse = state.Mouse as MouseState;
var keyboard = state.Keyboard as KeyboardState;
if (keyboard != null)
{
leftViaKeyboard = keyboard.Keys.Contains(Key.Z);
rightViaKeyboard = keyboard.Keys.Contains(Key.X);
}
if (mouse != null)
{
if (leftViaKeyboard)
mouse.SetPressed(MouseButton.Left, true);
if (rightViaKeyboard)
mouse.SetPressed(MouseButton.Right, true);
}
}
}
}

View File

@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI
protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield(); protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield();
protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuKeyConversionInputManager(); protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo);
protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h) protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h)
{ {

View File

@ -77,7 +77,7 @@
<Compile Include="OsuDifficulty\Skills\Skill.cs" /> <Compile Include="OsuDifficulty\Skills\Skill.cs" />
<Compile Include="OsuDifficulty\Skills\Speed.cs" /> <Compile Include="OsuDifficulty\Skills\Speed.cs" />
<Compile Include="OsuDifficulty\Utils\History.cs" /> <Compile Include="OsuDifficulty\Utils\History.cs" />
<Compile Include="OsuKeyConversionInputManager.cs" /> <Compile Include="OsuInputManager.cs" />
<Compile Include="UI\OsuSettings.cs" /> <Compile Include="UI\OsuSettings.cs" />
<Compile Include="Scoring\OsuScoreProcessor.cs" /> <Compile Include="Scoring\OsuScoreProcessor.cs" />
<Compile Include="UI\OsuRulesetContainer.cs" /> <Compile Include="UI\OsuRulesetContainer.cs" />

View File

@ -94,7 +94,7 @@ namespace osu.Game.Input
private readonly List<Binding> pressedBindings = new List<Binding>(); private readonly List<Binding> pressedBindings = new List<Binding>();
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override void PopulateDataKeyDown(InputState state, KeyDownEventArgs args)
{ {
if (!args.Repeat && (concurrencyMode > ConcurrentActionMode.None || pressedBindings.Count == 0)) if (!args.Repeat && (concurrencyMode > ConcurrentActionMode.None || pressedBindings.Count == 0))
{ {
@ -109,11 +109,9 @@ namespace osu.Game.Input
pressedBindings.Add(validBinding); pressedBindings.Add(validBinding);
} }
} }
return base.OnKeyDown(state, args);
} }
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) protected override void PopulateDataKeyUp(InputState state, KeyUpEventArgs args)
{ {
foreach (var binding in pressedBindings.ToList()) foreach (var binding in pressedBindings.ToList())
{ {
@ -127,8 +125,6 @@ namespace osu.Game.Input
state.Data = binding.GetAction<T>(); state.Data = binding.GetAction<T>();
} }
} }
return base.OnKeyUp(state, args);
} }
} }
} }