1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/UI/DrumTouchInputArea.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
4.6 KiB
C#
Raw Normal View History

// 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 System.Collections.Generic;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osuTK;
2022-07-22 15:18:22 +08:00
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.UI
{
/// <summary>
2022-07-22 15:18:22 +08:00
/// An overlay that captures and displays osu!taiko mouse and touch input.
/// </summary>
public class DrumTouchInputArea : Container
{
2022-07-22 15:18:22 +08:00
private readonly Circle outerCircle;
private KeyBindingContainer<TaikoAction> keyBindingContainer = null!;
private readonly Dictionary<object, TaikoAction> trackedActions = new Dictionary<object, TaikoAction>();
2022-07-22 15:18:22 +08:00
private readonly Container mainContent;
2022-07-22 15:18:22 +08:00
private readonly Circle centreCircle;
2022-03-12 21:01:40 +08:00
public DrumTouchInputArea()
{
2022-07-22 15:18:22 +08:00
RelativeSizeAxes = Axes.X;
Height = 300;
Masking = true;
Children = new Drawable[]
{
2022-07-22 15:18:22 +08:00
mainContent = new Container
2022-06-02 13:36:07 +08:00
{
RelativeSizeAxes = Axes.Both,
2022-07-22 15:18:22 +08:00
Height = 2,
Children = new Drawable[]
{
2022-07-22 15:18:22 +08:00
outerCircle = new Circle
2022-06-02 13:36:07 +08:00
{
2022-07-22 15:18:22 +08:00
FillMode = FillMode.Fit,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2022-07-22 15:18:22 +08:00
},
centreCircle = new Circle
{
FillMode = FillMode.Fit,
2022-07-22 15:18:22 +08:00
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.5f),
},
2022-07-22 15:18:22 +08:00
new Box
2022-06-02 13:36:07 +08:00
{
2022-07-22 15:18:22 +08:00
FillMode = FillMode.Fit,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2022-07-22 15:18:22 +08:00
Colour = Color4.Black,
Width = 3,
},
}
},
};
}
[BackgroundDependencyLoader]
private void load(TaikoInputManager taikoInputManager, OsuColour colours)
{
2022-07-22 15:18:22 +08:00
Debug.Assert(taikoInputManager.KeyBindingContainer != null);
keyBindingContainer = taikoInputManager.KeyBindingContainer;
2022-07-22 15:18:22 +08:00
outerCircle.Colour = colours.Gray0;
}
protected override bool OnKeyDown(KeyDownEvent e)
{
// Hide whenever the keyboard is used.
mainContent.Hide();
return false;
}
2022-07-22 15:18:22 +08:00
protected override bool OnMouseDown(MouseDownEvent e)
{
handleDown(e.Button, e.ScreenSpaceMousePosition);
return true;
}
protected override void OnMouseUp(MouseUpEvent e)
{
handleUp(e.Button);
base.OnMouseUp(e);
}
protected override bool OnTouchDown(TouchDownEvent e)
{
handleDown(e.Touch.Source, e.ScreenSpaceTouchDownPosition);
return true;
}
protected override void OnTouchUp(TouchUpEvent e)
{
handleUp(e.Touch.Source);
base.OnTouchUp(e);
}
private void handleDown(object source, Vector2 position)
{
mainContent.Show();
TaikoAction taikoAction = getTaikoActionFromInput(position);
trackedActions.Add(source, taikoAction);
keyBindingContainer.TriggerPressed(taikoAction);
}
private void handleUp(object source)
{
keyBindingContainer.TriggerReleased(trackedActions[source]);
trackedActions.Remove(source);
}
2022-03-12 21:01:40 +08:00
private TaikoAction getTaikoActionFromInput(Vector2 inputPosition)
{
2022-07-22 15:18:22 +08:00
bool centreHit = centreCircle.ScreenSpaceDrawQuad.Contains(inputPosition);
bool leftSide = ToLocalSpace(inputPosition).X < DrawWidth / 2;
2022-07-22 15:18:22 +08:00
if (leftSide)
return centreHit ? TaikoAction.LeftCentre : TaikoAction.LeftRim;
2022-07-22 15:18:22 +08:00
return centreHit ? TaikoAction.RightCentre : TaikoAction.RightRim;
}
}
}