mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge branch 'master' into fix-ruleset-changing
This commit is contained in:
@ -1,246 +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.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shaders;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK;
|
||||
using System;
|
||||
using osu.Framework.Graphics.OpenGL.Buffers;
|
||||
using OpenTK.Graphics.ES30;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Timing;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Graphics.OpenGL.Vertices;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
internal class CursorTrail : Drawable
|
||||
{
|
||||
public override bool HandleInput => true;
|
||||
|
||||
private int currentIndex;
|
||||
|
||||
private Shader shader;
|
||||
private Texture texture;
|
||||
|
||||
private Vector2 size => texture.Size * Scale;
|
||||
|
||||
private double timeOffset;
|
||||
|
||||
private float time;
|
||||
|
||||
private readonly TrailDrawNodeSharedData trailDrawNodeSharedData = new TrailDrawNodeSharedData();
|
||||
private const int max_sprites = 2048;
|
||||
|
||||
private readonly TrailPart[] parts = new TrailPart[max_sprites];
|
||||
|
||||
private Vector2? lastPosition;
|
||||
|
||||
private readonly InputResampler resampler = new InputResampler();
|
||||
|
||||
protected override DrawNode CreateDrawNode() => new TrailDrawNode();
|
||||
|
||||
protected override void ApplyDrawNode(DrawNode node)
|
||||
{
|
||||
base.ApplyDrawNode(node);
|
||||
|
||||
TrailDrawNode tNode = (TrailDrawNode)node;
|
||||
tNode.Shader = shader;
|
||||
tNode.Texture = texture;
|
||||
tNode.Size = size;
|
||||
tNode.Time = time;
|
||||
tNode.Shared = trailDrawNodeSharedData;
|
||||
|
||||
for (int i = 0; i < parts.Length; ++i)
|
||||
if (parts[i].InvalidationID > tNode.Parts[i].InvalidationID)
|
||||
tNode.Parts[i] = parts[i];
|
||||
}
|
||||
|
||||
public CursorTrail()
|
||||
{
|
||||
// as we are currently very dependent on having a running clock, let's make our own clock for the time being.
|
||||
Clock = new FramedClock();
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
for (int i = 0; i < max_sprites; i++)
|
||||
{
|
||||
parts[i].InvalidationID = 0;
|
||||
parts[i].WasUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ShaderManager shaders, TextureStore textures)
|
||||
{
|
||||
shader = shaders?.Load(@"CursorTrail", FragmentShaderDescriptor.TEXTURE);
|
||||
texture = textures.Get(@"Cursor/cursortrail");
|
||||
Scale = new Vector2(1 / texture.ScaleAdjust);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
resetTime();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Invalidate(Invalidation.DrawNode, shallPropagate: false);
|
||||
|
||||
const int fade_clock_reset_threshold = 1000000;
|
||||
|
||||
time = (float)(Time.Current - timeOffset) / 500f;
|
||||
if (time > fade_clock_reset_threshold)
|
||||
resetTime();
|
||||
}
|
||||
|
||||
private void resetTime()
|
||||
{
|
||||
for (int i = 0; i < parts.Length; ++i)
|
||||
{
|
||||
parts[i].Time -= time;
|
||||
++parts[i].InvalidationID;
|
||||
}
|
||||
|
||||
time = 0;
|
||||
timeOffset = Time.Current;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(InputState state)
|
||||
{
|
||||
if (lastPosition == null)
|
||||
{
|
||||
lastPosition = state.Mouse.NativeState.Position;
|
||||
resampler.AddPosition(lastPosition.Value);
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
foreach (Vector2 pos2 in resampler.AddPosition(state.Mouse.NativeState.Position))
|
||||
{
|
||||
Trace.Assert(lastPosition.HasValue);
|
||||
|
||||
Vector2 pos1 = lastPosition.Value;
|
||||
Vector2 diff = pos2 - pos1;
|
||||
float distance = diff.Length;
|
||||
Vector2 direction = diff / distance;
|
||||
|
||||
float interval = size.X / 2 * 0.9f;
|
||||
|
||||
for (float d = interval; d < distance; d += interval)
|
||||
{
|
||||
lastPosition = pos1 + direction * d;
|
||||
addPosition(lastPosition.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
private void addPosition(Vector2 pos)
|
||||
{
|
||||
parts[currentIndex].Position = pos;
|
||||
parts[currentIndex].Time = time;
|
||||
++parts[currentIndex].InvalidationID;
|
||||
|
||||
currentIndex = (currentIndex + 1) % max_sprites;
|
||||
}
|
||||
|
||||
private struct TrailPart
|
||||
{
|
||||
public Vector2 Position;
|
||||
public float Time;
|
||||
public long InvalidationID;
|
||||
public bool WasUpdated;
|
||||
}
|
||||
|
||||
private class TrailDrawNodeSharedData
|
||||
{
|
||||
public VertexBuffer<TexturedVertex2D> VertexBuffer;
|
||||
}
|
||||
|
||||
private class TrailDrawNode : DrawNode
|
||||
{
|
||||
public Shader Shader;
|
||||
public Texture Texture;
|
||||
|
||||
public float Time;
|
||||
public TrailDrawNodeSharedData Shared;
|
||||
|
||||
public readonly TrailPart[] Parts = new TrailPart[max_sprites];
|
||||
public Vector2 Size;
|
||||
|
||||
public TrailDrawNode()
|
||||
{
|
||||
for (int i = 0; i < max_sprites; i++)
|
||||
{
|
||||
Parts[i].InvalidationID = 0;
|
||||
Parts[i].WasUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
if (Shared.VertexBuffer == null)
|
||||
Shared.VertexBuffer = new QuadVertexBuffer<TexturedVertex2D>(max_sprites, BufferUsageHint.DynamicDraw);
|
||||
|
||||
Shader.GetUniform<float>("g_FadeClock").Value = Time;
|
||||
|
||||
int updateStart = -1, updateEnd = 0;
|
||||
for (int i = 0; i < Parts.Length; ++i)
|
||||
{
|
||||
if (Parts[i].WasUpdated)
|
||||
{
|
||||
if (updateStart == -1)
|
||||
updateStart = i;
|
||||
updateEnd = i + 1;
|
||||
|
||||
int start = i * 4;
|
||||
int end = start;
|
||||
|
||||
Vector2 pos = Parts[i].Position;
|
||||
ColourInfo colour = DrawInfo.Colour;
|
||||
colour.TopLeft.Linear.A = Parts[i].Time + colour.TopLeft.Linear.A;
|
||||
colour.TopRight.Linear.A = Parts[i].Time + colour.TopRight.Linear.A;
|
||||
colour.BottomLeft.Linear.A = Parts[i].Time + colour.BottomLeft.Linear.A;
|
||||
colour.BottomRight.Linear.A = Parts[i].Time + colour.BottomRight.Linear.A;
|
||||
|
||||
Texture.DrawQuad(
|
||||
new Quad(pos.X - Size.X / 2, pos.Y - Size.Y / 2, Size.X, Size.Y),
|
||||
colour,
|
||||
null,
|
||||
v => Shared.VertexBuffer.Vertices[end++] = v);
|
||||
|
||||
Parts[i].WasUpdated = false;
|
||||
}
|
||||
else if (updateStart != -1)
|
||||
{
|
||||
Shared.VertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
||||
updateStart = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Update all remaining vertices that have been changed.
|
||||
if (updateStart != -1)
|
||||
Shared.VertexBuffer.UpdateRange(updateStart * 4, updateEnd * 4);
|
||||
|
||||
base.Draw(vertexAction);
|
||||
|
||||
Shader.Bind();
|
||||
|
||||
Texture.TextureGL.Bind();
|
||||
Shared.VertexBuffer.Draw();
|
||||
|
||||
Shader.Unbind();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,147 +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 OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public class GameplayCursor : CursorContainer
|
||||
{
|
||||
protected override Drawable CreateCursor() => new OsuCursor();
|
||||
|
||||
public GameplayCursor()
|
||||
{
|
||||
Add(new CursorTrail { Depth = 1 });
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||
{
|
||||
ActiveCursor.Scale = new Vector2(1);
|
||||
ActiveCursor.ScaleTo(1.2f, 100, Easing.OutQuad);
|
||||
return base.OnMouseDown(state, args);
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
if (!state.Mouse.HasMainButtonPressed)
|
||||
ActiveCursor.ScaleTo(1, 200, Easing.OutQuad);
|
||||
return base.OnMouseUp(state, args);
|
||||
}
|
||||
|
||||
public class OsuCursor : Container
|
||||
{
|
||||
private Container cursorContainer;
|
||||
|
||||
private Bindable<double> cursorScale;
|
||||
private Bindable<bool> autoCursorScale;
|
||||
private Bindable<WorkingBeatmap> beatmap;
|
||||
|
||||
public OsuCursor()
|
||||
{
|
||||
Origin = Anchor.Centre;
|
||||
Size = new Vector2(42);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config, OsuGameBase game)
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
cursorContainer = new CircularContainer
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
BorderThickness = Size.X / 6,
|
||||
BorderColour = Color4.White,
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Pink.Opacity(0.5f),
|
||||
Radius = 5,
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
AlwaysPresent = true,
|
||||
},
|
||||
new CircularContainer
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
BorderThickness = Size.X / 3,
|
||||
BorderColour = Color4.White.Opacity(0.5f),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0,
|
||||
AlwaysPresent = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
new CircularContainer
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Scale = new Vector2(0.1f),
|
||||
Masking = true,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.White,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
beatmap = game.Beatmap.GetBoundCopy();
|
||||
beatmap.ValueChanged += v => calculateScale();
|
||||
|
||||
cursorScale = config.GetBindable<double>(OsuSetting.GameplayCursorSize);
|
||||
cursorScale.ValueChanged += v => calculateScale();
|
||||
|
||||
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
|
||||
autoCursorScale.ValueChanged += v => calculateScale();
|
||||
|
||||
calculateScale();
|
||||
}
|
||||
|
||||
private void calculateScale()
|
||||
{
|
||||
float scale = (float)cursorScale.Value;
|
||||
|
||||
if (autoCursorScale && beatmap.Value != null)
|
||||
{
|
||||
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
|
||||
scale *= (float)(1 - 0.7 * (1 + beatmap.Value.BeatmapInfo.Difficulty.CircleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY);
|
||||
}
|
||||
|
||||
cursorContainer.Scale = new Vector2(scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +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;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Rulesets;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps custom action data of type <see cref="T"/> and stores to <see cref="InputState.Data"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the custom action.</typeparam>
|
||||
public class ActionMappingInputManager<T> : PassThroughInputManager
|
||||
where T : struct
|
||||
{
|
||||
private readonly RulesetInfo ruleset;
|
||||
|
||||
private readonly int? variant;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance.
|
||||
/// </summary>
|
||||
/// <param name="ruleset">A reference to identify the current <see cref="Ruleset"/>. Used to lookup mappings. Null for global mappings.</param>
|
||||
/// <param name="variant">An optional variant for the specified <see cref="Ruleset"/>. Used when a ruleset has more than one possible keyboard layouts.</param>
|
||||
protected ActionMappingInputManager(RulesetInfo ruleset = null, int? variant = null)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
this.variant = variant;
|
||||
}
|
||||
|
||||
protected IDictionary<Key, T> Mappings { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BindingStore bindings)
|
||||
{
|
||||
var rulesetId = ruleset?.ID;
|
||||
foreach (var b in bindings.Query<Binding>(b => b.RulesetID == rulesetId && b.Variant == variant))
|
||||
Mappings[b.Key] = (T)(object)b.Action;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private T parseStringRepresentation(string str)
|
||||
{
|
||||
T res;
|
||||
|
||||
if (Enum.TryParse(str, out res))
|
||||
return res;
|
||||
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +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.Game.Rulesets;
|
||||
using OpenTK.Input;
|
||||
using SQLite.Net.Attributes;
|
||||
using SQLiteNetExtensions.Attributes;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public class Binding
|
||||
{
|
||||
[ForeignKey(typeof(RulesetInfo))]
|
||||
public int? RulesetID { get; set; }
|
||||
|
||||
[Indexed]
|
||||
public int? Variant { get; set; }
|
||||
|
||||
public Key Key { get; set; }
|
||||
|
||||
public int Action { get; set; }
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input.Bindings;
|
||||
using SQLite.Net;
|
||||
|
||||
namespace osu.Game.Input
|
||||
@ -15,14 +16,32 @@ namespace osu.Game.Input
|
||||
{
|
||||
}
|
||||
|
||||
protected override int StoreVersion => 2;
|
||||
|
||||
protected override void PerformMigration(int currentVersion, int targetVersion)
|
||||
{
|
||||
base.PerformMigration(currentVersion, targetVersion);
|
||||
|
||||
while (currentVersion++ < targetVersion)
|
||||
{
|
||||
switch (currentVersion)
|
||||
{
|
||||
case 1:
|
||||
// cannot migrate; breaking underlying changes.
|
||||
Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Prepare(bool reset = false)
|
||||
{
|
||||
Connection.CreateTable<Binding>();
|
||||
Connection.CreateTable<DatabasedKeyBinding>();
|
||||
}
|
||||
|
||||
protected override Type[] ValidTypes => new[]
|
||||
{
|
||||
typeof(Binding)
|
||||
typeof(DatabasedKeyBinding)
|
||||
};
|
||||
|
||||
}
|
||||
|
34
osu.Game/Input/Bindings/DatabasedKeyBinding.cs
Normal file
34
osu.Game/Input/Bindings/DatabasedKeyBinding.cs
Normal 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 osu.Framework.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
using SQLite.Net.Attributes;
|
||||
using SQLiteNetExtensions.Attributes;
|
||||
|
||||
namespace osu.Game.Input.Bindings
|
||||
{
|
||||
[Table("KeyBinding")]
|
||||
public class DatabasedKeyBinding : KeyBinding
|
||||
{
|
||||
[ForeignKey(typeof(RulesetInfo))]
|
||||
public int? RulesetID { get; set; }
|
||||
|
||||
[Indexed]
|
||||
public int? Variant { get; set; }
|
||||
|
||||
[Column("Keys")]
|
||||
public string KeysString
|
||||
{
|
||||
get { return KeyCombination.ToString(); }
|
||||
private set { KeyCombination = value; }
|
||||
}
|
||||
|
||||
[Column("Action")]
|
||||
public new int Action
|
||||
{
|
||||
get { return base.Action; }
|
||||
private set { base.Action = value; }
|
||||
}
|
||||
}
|
||||
}
|
57
osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs
Normal file
57
osu.Game/Input/Bindings/DatabasedKeyBindingInputManager.cs
Normal file
@ -0,0 +1,57 @@
|
||||
// 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.Allocation;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Input.Bindings
|
||||
{
|
||||
/// <summary>
|
||||
/// A KeyBindingInputManager with a database backing for custom overrides.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the custom action.</typeparam>
|
||||
public abstract class DatabasedKeyBindingInputManager<T> : KeyBindingInputManager<T>
|
||||
where T : struct
|
||||
{
|
||||
private readonly RulesetInfo ruleset;
|
||||
|
||||
private readonly int? variant;
|
||||
|
||||
private BindingStore store;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new instance.
|
||||
/// </summary>
|
||||
/// <param name="ruleset">A reference to identify the current <see cref="Ruleset"/>. Used to lookup mappings. Null for global mappings.</param>
|
||||
/// <param name="variant">An optional variant for the specified <see cref="Ruleset"/>. Used when a ruleset has more than one possible keyboard layouts.</param>
|
||||
/// <param name="simultaneousMode">Specify how to deal with multiple matches of <see cref="KeyCombination"/>s and <see cref="T"/>s.</param>
|
||||
protected DatabasedKeyBindingInputManager(RulesetInfo ruleset = null, int? variant = null, SimultaneousBindingMode simultaneousMode = SimultaneousBindingMode.None)
|
||||
: base(simultaneousMode)
|
||||
{
|
||||
this.ruleset = ruleset;
|
||||
this.variant = variant;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(BindingStore bindings)
|
||||
{
|
||||
store = bindings;
|
||||
}
|
||||
|
||||
protected override void ReloadMappings()
|
||||
{
|
||||
// load defaults
|
||||
base.ReloadMappings();
|
||||
|
||||
var rulesetId = ruleset?.ID;
|
||||
|
||||
// load from database if present.
|
||||
if (store != null)
|
||||
{
|
||||
foreach (var b in store.Query<DatabasedKeyBinding>(b => b.RulesetID == rulesetId && b.Variant == variant))
|
||||
KeyBindings.Add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
osu.Game/Input/Bindings/GlobalBindingInputManager.cs
Normal file
68
osu.Game/Input/Bindings/GlobalBindingInputManager.cs
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Input;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Input.Bindings
|
||||
{
|
||||
public class GlobalBindingInputManager : DatabasedKeyBindingInputManager<GlobalAction>
|
||||
{
|
||||
private readonly Drawable handler;
|
||||
|
||||
public GlobalBindingInputManager(OsuGameBase game)
|
||||
{
|
||||
if (game is IKeyBindingHandler<GlobalAction>)
|
||||
handler = game;
|
||||
}
|
||||
|
||||
protected override IEnumerable<KeyBinding> CreateDefaultMappings() => new[]
|
||||
{
|
||||
new KeyBinding(Key.F8, GlobalAction.ToggleChat),
|
||||
new KeyBinding(Key.F9, GlobalAction.ToggleSocial),
|
||||
new KeyBinding(new[] { Key.LControl, Key.LAlt, Key.R }, GlobalAction.ResetInputSettings),
|
||||
new KeyBinding(new[] { Key.LControl, Key.T }, GlobalAction.ToggleToolbar),
|
||||
new KeyBinding(new[] { Key.LControl, Key.O }, GlobalAction.ToggleSettings),
|
||||
new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect),
|
||||
};
|
||||
|
||||
protected override bool PropagateKeyDown(IEnumerable<Drawable> drawables, InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (handler != null)
|
||||
drawables = new[] { handler }.Concat(drawables);
|
||||
|
||||
// always handle ourselves before all children.
|
||||
return base.PropagateKeyDown(drawables, state, args);
|
||||
}
|
||||
|
||||
protected override bool PropagateKeyUp(IEnumerable<Drawable> drawables, InputState state, KeyUpEventArgs args)
|
||||
{
|
||||
if (handler != null)
|
||||
drawables = new[] { handler }.Concat(drawables);
|
||||
|
||||
// always handle ourselves before all children.
|
||||
return base.PropagateKeyUp(drawables, state, args);
|
||||
}
|
||||
}
|
||||
|
||||
public enum GlobalAction
|
||||
{
|
||||
[Description("Toggle chat overlay")]
|
||||
ToggleChat,
|
||||
[Description("Toggle social overlay")]
|
||||
ToggleSocial,
|
||||
[Description("Reset input settings")]
|
||||
ResetInputSettings,
|
||||
[Description("Toggle toolbar")]
|
||||
ToggleToolbar,
|
||||
[Description("Toggle settings")]
|
||||
ToggleSettings,
|
||||
[Description("Toggle osu!direct")]
|
||||
ToggleDirect,
|
||||
}
|
||||
}
|
@ -9,17 +9,16 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Graphics.UserInterface.Volume;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Overlays.Toolbar;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
using OpenTK;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
@ -27,10 +26,11 @@ using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
public class OsuGame : OsuGameBase
|
||||
public class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
public Toolbar Toolbar;
|
||||
|
||||
@ -169,10 +169,6 @@ namespace osu.Game
|
||||
volume = new VolumeControl(),
|
||||
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
|
||||
new OnScreenDisplay(),
|
||||
new GlobalHotkeys //exists because UserInputManager is at a level below us.
|
||||
{
|
||||
Handler = globalHotkeyPressed
|
||||
}
|
||||
});
|
||||
|
||||
LoadComponentAsync(screenStack = new Loader(), d =>
|
||||
@ -252,63 +248,43 @@ namespace osu.Game
|
||||
Cursor.State = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private bool globalHotkeyPressed(InputState state, KeyDownEventArgs args)
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (args.Repeat || intro == null) return false;
|
||||
if (intro == null) return false;
|
||||
|
||||
switch (args.Key)
|
||||
switch (action)
|
||||
{
|
||||
case Key.F8:
|
||||
case GlobalAction.ToggleChat:
|
||||
chat.ToggleVisibility();
|
||||
return true;
|
||||
case Key.F9:
|
||||
case GlobalAction.ToggleSocial:
|
||||
social.ToggleVisibility();
|
||||
return true;
|
||||
case Key.PageUp:
|
||||
case Key.PageDown:
|
||||
var swClock = (Clock as ThrottledFrameClock)?.Source as StopwatchClock;
|
||||
if (swClock == null) return false;
|
||||
case GlobalAction.ResetInputSettings:
|
||||
var sensitivity = frameworkConfig.GetBindable<double>(FrameworkSetting.CursorSensitivity);
|
||||
|
||||
swClock.Rate *= args.Key == Key.PageUp ? 1.1f : 0.9f;
|
||||
Logger.Log($@"Adjusting game clock to {swClock.Rate}", LoggingTarget.Debug);
|
||||
sensitivity.Disabled = false;
|
||||
sensitivity.Value = 1;
|
||||
sensitivity.Disabled = true;
|
||||
|
||||
frameworkConfig.Set(FrameworkSetting.ActiveInputHandlers, string.Empty);
|
||||
return true;
|
||||
case GlobalAction.ToggleToolbar:
|
||||
Toolbar.ToggleVisibility();
|
||||
return true;
|
||||
case GlobalAction.ToggleSettings:
|
||||
settings.ToggleVisibility();
|
||||
return true;
|
||||
case GlobalAction.ToggleDirect:
|
||||
direct.ToggleVisibility();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state.Keyboard.ControlPressed)
|
||||
{
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.R:
|
||||
if (state.Keyboard.AltPressed)
|
||||
{
|
||||
var sensitivity = frameworkConfig.GetBindable<double>(FrameworkSetting.CursorSensitivity);
|
||||
|
||||
sensitivity.Disabled = false;
|
||||
sensitivity.Value = 1;
|
||||
sensitivity.Disabled = true;
|
||||
|
||||
frameworkConfig.Set(FrameworkSetting.ActiveInputHandlers, string.Empty);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Key.T:
|
||||
Toolbar.ToggleVisibility();
|
||||
return true;
|
||||
case Key.O:
|
||||
settings.ToggleVisibility();
|
||||
return true;
|
||||
case Key.D:
|
||||
if (state.Keyboard.ShiftPressed || state.Keyboard.AltPressed)
|
||||
return false;
|
||||
|
||||
direct.ToggleVisibility();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action) => false;
|
||||
|
||||
public event Action<Screen> ScreenChanged;
|
||||
|
||||
private Container mainContent;
|
||||
|
@ -20,6 +20,7 @@ using SQLite.Net;
|
||||
using osu.Framework.Graphics.Performance;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
@ -187,13 +188,14 @@ namespace osu.Game
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Cursor = new MenuCursor(),
|
||||
new OsuTooltipContainer(Cursor)
|
||||
new GlobalBindingInputManager(this)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = content = new OsuContextMenuContainer
|
||||
Child = new OsuTooltipContainer(Cursor)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
Child = content = new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both },
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -245,7 +245,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = "Register new account",
|
||||
//Action = registerLink
|
||||
//Binding = registerLink
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Screens.Select
|
||||
/// <param name="text">Text on the button.</param>
|
||||
/// <param name="colour">Colour of the button.</param>
|
||||
/// <param name="hotkey">Hotkey of the button.</param>
|
||||
/// <param name="action">Action the button does.</param>
|
||||
/// <param name="action">Binding the button does.</param>
|
||||
/// <param name="depth">
|
||||
/// <para>Higher depth to be put on the left, and lower to be put on the right.</para>
|
||||
/// <para>Notice this is different to <see cref="Options.BeatmapOptionsOverlay"/>!</para>
|
||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Screens.Select.Options
|
||||
/// <param name="colour">Colour of the button.</param>
|
||||
/// <param name="icon">Icon of the button.</param>
|
||||
/// <param name="hotkey">Hotkey of the button.</param>
|
||||
/// <param name="action">Action the button does.</param>
|
||||
/// <param name="action">Binding the button does.</param>
|
||||
/// <param name="depth">
|
||||
/// <para>Lower depth to be put on the left, and higher to be put on the right.</para>
|
||||
/// <para>Notice this is different to <see cref="Footer"/>!</para>
|
||||
|
@ -92,8 +92,10 @@
|
||||
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
|
||||
<Compile Include="Graphics\UserInterface\OsuContextMenuItem.cs" />
|
||||
<Compile Include="Input\Binding.cs" />
|
||||
<Compile Include="Input\Bindings\DatabasedKeyBinding.cs" />
|
||||
<Compile Include="Input\Bindings\DatabasedKeyBindingInputManager.cs" />
|
||||
<Compile Include="Input\BindingStore.cs" />
|
||||
<Compile Include="Input\Bindings\GlobalBindingInputManager.cs" />
|
||||
<Compile Include="IO\FileStore.cs" />
|
||||
<Compile Include="IO\FileInfo.cs" />
|
||||
<Compile Include="Online\API\Requests\GetUsersRequest.cs" />
|
||||
@ -120,7 +122,6 @@
|
||||
<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" />
|
||||
@ -142,8 +143,6 @@
|
||||
<Compile Include="Rulesets\RulesetInfo.cs" />
|
||||
<Compile Include="Rulesets\Scoring\ScoreStore.cs" />
|
||||
<Compile Include="Graphics\Backgrounds\Triangles.cs" />
|
||||
<Compile Include="Graphics\Cursor\CursorTrail.cs" />
|
||||
<Compile Include="Graphics\Cursor\GameplayCursor.cs" />
|
||||
<Compile Include="Graphics\IHasAccentColour.cs" />
|
||||
<Compile Include="Graphics\Sprites\OsuSpriteText.cs" />
|
||||
<Compile Include="Graphics\UserInterface\BackButton.cs" />
|
||||
|
Reference in New Issue
Block a user