2022-03-10 16:42:58 +08:00
|
|
|
// 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.
|
|
|
|
|
2023-01-11 03:31:31 +08:00
|
|
|
using System;
|
2022-03-10 16:42:58 +08:00
|
|
|
using System.Collections.Generic;
|
2022-07-22 15:08:57 +08:00
|
|
|
using System.Diagnostics;
|
2022-03-10 16:42:58 +08:00
|
|
|
using osu.Framework.Allocation;
|
2023-01-10 18:59:57 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-07-22 17:16:01 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-03-10 16:42:58 +08:00
|
|
|
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;
|
2023-01-10 16:27:21 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Configuration;
|
2022-03-10 16:42:58 +08:00
|
|
|
using osuTK;
|
2022-07-22 15:18:22 +08:00
|
|
|
using osuTK.Graphics;
|
2022-03-10 16:42:58 +08:00
|
|
|
|
|
|
|
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.
|
2022-03-10 16:42:58 +08:00
|
|
|
/// </summary>
|
2022-07-22 16:48:07 +08:00
|
|
|
public partial class DrumTouchInputArea : VisibilityContainer
|
2022-03-10 16:42:58 +08:00
|
|
|
{
|
2023-01-11 20:04:52 +08:00
|
|
|
public TaikoTouchControlScheme? ForceControlScheme { get; set; }
|
2022-07-22 16:48:07 +08:00
|
|
|
// visibility state affects our child. we always want to handle input.
|
|
|
|
public override bool PropagatePositionalInputSubTree => true;
|
|
|
|
public override bool PropagateNonPositionalInputSubTree => true;
|
|
|
|
|
2022-07-22 15:08:57 +08:00
|
|
|
private KeyBindingContainer<TaikoAction> keyBindingContainer = null!;
|
2022-03-10 16:42:58 +08:00
|
|
|
|
2022-07-22 16:02:58 +08:00
|
|
|
private readonly Dictionary<object, TaikoAction> trackedActions = new Dictionary<object, TaikoAction>();
|
2022-03-10 16:42:58 +08:00
|
|
|
|
2022-07-22 16:17:38 +08:00
|
|
|
private Container mainContent = null!;
|
2022-03-10 16:42:58 +08:00
|
|
|
|
2022-07-22 16:48:07 +08:00
|
|
|
private QuarterCircle leftCentre = null!;
|
|
|
|
private QuarterCircle rightCentre = null!;
|
2022-07-22 17:07:10 +08:00
|
|
|
private QuarterCircle leftRim = null!;
|
|
|
|
private QuarterCircle rightRim = null!;
|
2022-03-11 20:43:57 +08:00
|
|
|
|
2023-01-13 01:20:07 +08:00
|
|
|
private readonly Bindable<TaikoTouchControlScheme> configTouchControlScheme = new Bindable<TaikoTouchControlScheme>();
|
2023-01-10 18:59:57 +08:00
|
|
|
|
2023-01-10 23:08:18 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
2022-07-22 16:17:38 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-01-10 21:07:07 +08:00
|
|
|
private void load(TaikoInputManager taikoInputManager, TaikoRulesetConfigManager config)
|
2022-03-12 21:01:40 +08:00
|
|
|
{
|
2022-07-22 16:17:38 +08:00
|
|
|
Debug.Assert(taikoInputManager.KeyBindingContainer != null);
|
|
|
|
keyBindingContainer = taikoInputManager.KeyBindingContainer;
|
2022-07-22 15:18:22 +08:00
|
|
|
|
2022-07-22 16:17:38 +08:00
|
|
|
// Container should handle input everywhere.
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2022-07-22 15:18:22 +08:00
|
|
|
|
2022-07-22 16:48:07 +08:00
|
|
|
const float centre_region = 0.80f;
|
|
|
|
|
2023-01-11 20:04:52 +08:00
|
|
|
if (ForceControlScheme == null)
|
2023-01-13 01:55:05 +08:00
|
|
|
{
|
2023-01-11 20:04:52 +08:00
|
|
|
config.BindWith(TaikoRulesetSetting.TouchControlScheme, configTouchControlScheme);
|
2023-01-13 01:55:05 +08:00
|
|
|
configTouchControlScheme.ValueChanged += reloadTouchDrums;
|
|
|
|
}
|
2023-01-11 20:04:52 +08:00
|
|
|
else
|
2023-01-12 04:39:45 +08:00
|
|
|
configTouchControlScheme.Value = ForceControlScheme.Value;
|
2023-01-10 19:38:32 +08:00
|
|
|
|
2022-03-10 16:42:58 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-07-22 16:17:38 +08:00
|
|
|
new Container
|
2022-06-02 13:36:07 +08:00
|
|
|
{
|
2022-07-22 16:17:38 +08:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-07-22 16:48:07 +08:00
|
|
|
Height = 350,
|
2022-07-22 16:17:38 +08:00
|
|
|
Y = 20,
|
|
|
|
Masking = true,
|
|
|
|
FillMode = FillMode.Fit,
|
2022-03-10 16:42:58 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-07-22 16:17:38 +08:00
|
|
|
mainContent = new Container
|
2022-06-02 13:36:07 +08:00
|
|
|
{
|
2022-03-10 21:09:07 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-07-22 16:17:38 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-01-13 01:20:07 +08:00
|
|
|
leftRim = new QuarterCircle(getTaikoActionFromDrumSegment(0), getColourFromTaikoAction(getTaikoActionFromDrumSegment(0)))
|
2022-07-22 16:17:38 +08:00
|
|
|
{
|
2022-07-22 16:48:07 +08:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
X = -2,
|
2022-07-22 16:17:38 +08:00
|
|
|
},
|
2023-01-13 01:20:07 +08:00
|
|
|
leftCentre = new QuarterCircle(getTaikoActionFromDrumSegment(1), getColourFromTaikoAction(getTaikoActionFromDrumSegment(1)))
|
2022-07-22 16:17:38 +08:00
|
|
|
{
|
2022-07-22 16:48:07 +08:00
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomRight,
|
2023-01-11 04:04:57 +08:00
|
|
|
X = -2,
|
|
|
|
Scale = new Vector2(centre_region),
|
2022-07-22 16:17:38 +08:00
|
|
|
},
|
2023-01-13 01:20:07 +08:00
|
|
|
rightRim = new QuarterCircle(getTaikoActionFromDrumSegment(3), getColourFromTaikoAction(getTaikoActionFromDrumSegment(3)))
|
2022-07-22 16:17:38 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2022-07-22 16:48:07 +08:00
|
|
|
Origin = Anchor.BottomRight,
|
2023-01-11 04:04:57 +08:00
|
|
|
X = 2,
|
|
|
|
Rotation = 90,
|
2022-07-22 16:17:38 +08:00
|
|
|
},
|
2023-01-13 01:20:07 +08:00
|
|
|
rightCentre = new QuarterCircle(getTaikoActionFromDrumSegment(2), getColourFromTaikoAction(getTaikoActionFromDrumSegment(2)))
|
2022-07-22 16:48:07 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
X = 2,
|
2023-01-11 07:13:22 +08:00
|
|
|
Scale = new Vector2(centre_region),
|
2022-07-22 16:48:07 +08:00
|
|
|
Rotation = 90,
|
2023-01-11 04:05:41 +08:00
|
|
|
}
|
2022-07-22 16:17:38 +08:00
|
|
|
}
|
2022-03-10 16:42:58 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-03-10 21:09:07 +08:00
|
|
|
|
2023-01-13 01:20:07 +08:00
|
|
|
private readonly TaikoAction[,] mappedTaikoAction =
|
2023-01-12 04:06:43 +08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
// KDDK
|
2023-01-11 04:04:57 +08:00
|
|
|
TaikoAction.LeftRim,
|
|
|
|
TaikoAction.LeftCentre,
|
|
|
|
TaikoAction.RightCentre,
|
|
|
|
TaikoAction.RightRim
|
|
|
|
},
|
2023-01-12 04:06:43 +08:00
|
|
|
{
|
|
|
|
// DDKK
|
2023-01-11 04:04:57 +08:00
|
|
|
TaikoAction.LeftCentre,
|
|
|
|
TaikoAction.RightCentre,
|
|
|
|
TaikoAction.LeftRim,
|
|
|
|
TaikoAction.RightRim
|
|
|
|
},
|
2023-01-12 04:06:43 +08:00
|
|
|
{
|
|
|
|
// KKDD
|
2023-01-11 04:04:57 +08:00
|
|
|
TaikoAction.LeftRim,
|
|
|
|
TaikoAction.RightRim,
|
|
|
|
TaikoAction.LeftCentre,
|
|
|
|
TaikoAction.RightCentre
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-13 01:20:07 +08:00
|
|
|
private TaikoAction getTaikoActionFromDrumSegment(int drumSegment)
|
2023-01-11 04:04:57 +08:00
|
|
|
{
|
|
|
|
return mappedTaikoAction[(int)configTouchControlScheme.Value, drumSegment];
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:02:58 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2022-03-10 16:42:58 +08:00
|
|
|
{
|
2022-07-22 16:02:58 +08:00
|
|
|
// Hide whenever the keyboard is used.
|
2022-07-22 16:48:07 +08:00
|
|
|
Hide();
|
2022-07-22 16:02:58 +08:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-22 15:18:22 +08:00
|
|
|
|
2022-03-10 16:42:58 +08:00
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
|
|
{
|
2022-07-22 16:02:58 +08:00
|
|
|
handleDown(e.Touch.Source, e.ScreenSpaceTouchDownPosition);
|
2022-03-10 21:09:07 +08:00
|
|
|
return true;
|
2022-03-10 16:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnTouchUp(TouchUpEvent e)
|
|
|
|
{
|
2022-07-22 16:02:58 +08:00
|
|
|
handleUp(e.Touch.Source);
|
2022-03-10 16:42:58 +08:00
|
|
|
base.OnTouchUp(e);
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:02:58 +08:00
|
|
|
private void handleDown(object source, Vector2 position)
|
2022-03-11 20:43:57 +08:00
|
|
|
{
|
2022-07-22 16:48:07 +08:00
|
|
|
Show();
|
2022-07-22 16:02:58 +08:00
|
|
|
|
2023-01-11 03:21:04 +08:00
|
|
|
TaikoAction TaikoAction = getTaikoActionFromPosition(position);
|
2022-07-22 16:02:58 +08:00
|
|
|
|
2022-07-22 19:19:13 +08:00
|
|
|
// Not too sure how this can happen, but let's avoid throwing.
|
|
|
|
if (trackedActions.ContainsKey(source))
|
|
|
|
return;
|
|
|
|
|
2023-01-11 03:21:04 +08:00
|
|
|
trackedActions.Add(source, TaikoAction);
|
|
|
|
keyBindingContainer.TriggerPressed(TaikoAction);
|
2022-07-22 16:02:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUp(object source)
|
|
|
|
{
|
|
|
|
keyBindingContainer.TriggerReleased(trackedActions[source]);
|
|
|
|
trackedActions.Remove(source);
|
2022-03-11 20:43:57 +08:00
|
|
|
}
|
|
|
|
|
2022-07-22 17:07:10 +08:00
|
|
|
private bool validMouse(MouseButtonEvent e) =>
|
2022-07-22 17:19:33 +08:00
|
|
|
leftRim.Contains(e.ScreenSpaceMouseDownPosition) || rightRim.Contains(e.ScreenSpaceMouseDownPosition);
|
2022-07-22 17:07:10 +08:00
|
|
|
|
2023-01-10 19:43:28 +08:00
|
|
|
private TaikoAction getTaikoActionFromPosition(Vector2 inputPosition)
|
2022-03-12 21:01:40 +08:00
|
|
|
{
|
2022-07-22 16:48:07 +08:00
|
|
|
bool centreHit = leftCentre.Contains(inputPosition) || rightCentre.Contains(inputPosition);
|
2022-07-22 15:18:22 +08:00
|
|
|
bool leftSide = ToLocalSpace(inputPosition).X < DrawWidth / 2;
|
2023-01-11 04:04:57 +08:00
|
|
|
int drumSegment;
|
2022-03-10 16:42:58 +08:00
|
|
|
|
2022-07-22 15:18:22 +08:00
|
|
|
if (leftSide)
|
2023-01-11 04:04:57 +08:00
|
|
|
drumSegment = centreHit ? 1 : 0;
|
2023-01-10 16:27:21 +08:00
|
|
|
else
|
2023-01-11 04:04:57 +08:00
|
|
|
drumSegment = centreHit ? 2 : 3;
|
2022-03-10 16:42:58 +08:00
|
|
|
|
2023-01-11 04:04:57 +08:00
|
|
|
return getTaikoActionFromDrumSegment(drumSegment);
|
2022-03-10 16:42:58 +08:00
|
|
|
}
|
2022-07-22 16:48:07 +08:00
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
mainContent.FadeIn(500, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
mainContent.FadeOut(300);
|
|
|
|
}
|
|
|
|
|
2023-01-13 01:20:07 +08:00
|
|
|
private Color4 getColourFromTaikoAction(TaikoAction handledAction)
|
|
|
|
{
|
|
|
|
switch (handledAction)
|
|
|
|
{
|
|
|
|
case TaikoAction.LeftRim:
|
|
|
|
case TaikoAction.RightRim:
|
|
|
|
return colours.Blue;
|
|
|
|
case TaikoAction.LeftCentre:
|
|
|
|
case TaikoAction.RightCentre:
|
|
|
|
return colours.Red;
|
|
|
|
}
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
}
|
2022-07-22 16:48:07 +08:00
|
|
|
private partial class QuarterCircle : CompositeDrawable, IKeyBindingHandler<TaikoAction>
|
|
|
|
{
|
2023-01-13 01:55:05 +08:00
|
|
|
private TaikoAction handledAction;
|
2022-07-22 16:48:07 +08:00
|
|
|
|
2023-01-13 01:55:05 +08:00
|
|
|
private Circle overlay;
|
2022-07-22 16:48:07 +08:00
|
|
|
|
2023-01-13 01:55:05 +08:00
|
|
|
private Circle circle;
|
2022-07-22 16:48:07 +08:00
|
|
|
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => circle.Contains(screenSpacePos);
|
|
|
|
|
2023-01-13 01:20:07 +08:00
|
|
|
public QuarterCircle(TaikoAction handledAction, Color4 colour)
|
2022-07-22 16:48:07 +08:00
|
|
|
{
|
2023-01-13 01:20:07 +08:00
|
|
|
this.handledAction = handledAction;
|
2022-07-22 16:48:07 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
circle = new Circle
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-07-22 17:16:01 +08:00
|
|
|
Colour = colour.Multiply(1.4f).Darken(2.8f),
|
2022-07-22 16:48:07 +08:00
|
|
|
Alpha = 0.8f,
|
|
|
|
Scale = new Vector2(2),
|
|
|
|
},
|
|
|
|
overlay = new Circle
|
|
|
|
{
|
|
|
|
Alpha = 0,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Colour = colour,
|
|
|
|
Scale = new Vector2(2),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
|
|
|
|
{
|
2023-01-13 01:20:07 +08:00
|
|
|
if (e.Action == handledAction)
|
2022-07-22 17:16:01 +08:00
|
|
|
overlay.FadeTo(1f, 80, Easing.OutQuint);
|
2022-07-22 16:48:07 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<TaikoAction> e)
|
|
|
|
{
|
2023-01-13 01:20:07 +08:00
|
|
|
if (e.Action == handledAction)
|
2022-07-22 16:48:07 +08:00
|
|
|
overlay.FadeOut(1000, Easing.OutQuint);
|
|
|
|
}
|
2023-01-13 01:55:05 +08:00
|
|
|
|
|
|
|
public void ReloadDrumSegmentProperties(TaikoAction handledAction, Color4 colour)
|
|
|
|
{
|
|
|
|
this.handledAction = handledAction;
|
|
|
|
|
|
|
|
circle.Colour = colour.Multiply(1.4f).Darken(2.8f);
|
|
|
|
overlay.Colour = colour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reloadTouchDrums(object _)
|
|
|
|
{
|
|
|
|
leftRim.ReloadDrumSegmentProperties(getTaikoActionFromDrumSegment(0), getColourFromTaikoAction(getTaikoActionFromDrumSegment(0)));
|
|
|
|
leftCentre.ReloadDrumSegmentProperties(getTaikoActionFromDrumSegment(1), getColourFromTaikoAction(getTaikoActionFromDrumSegment(1)));
|
|
|
|
rightRim.ReloadDrumSegmentProperties(getTaikoActionFromDrumSegment(3), getColourFromTaikoAction(getTaikoActionFromDrumSegment(3)));
|
|
|
|
rightCentre.ReloadDrumSegmentProperties(getTaikoActionFromDrumSegment(2), getColourFromTaikoAction(getTaikoActionFromDrumSegment(2)));
|
2022-07-22 16:48:07 +08:00
|
|
|
}
|
2022-03-10 16:42:58 +08:00
|
|
|
}
|
|
|
|
}
|