2024-04-04 16:11:15 +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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
|
|
{
|
2024-05-14 19:28:14 +08:00
|
|
|
/// <summary>
|
|
|
|
/// An overlay that captures and displays osu!mania mouse and touch input.
|
|
|
|
/// </summary>
|
|
|
|
public partial class ManiaTouchInputArea : VisibilityContainer
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
2024-05-14 19:28:14 +08:00
|
|
|
// visibility state affects our child. we always want to handle input.
|
|
|
|
public override bool PropagatePositionalInputSubTree => true;
|
|
|
|
public override bool PropagateNonPositionalInputSubTree => true;
|
|
|
|
|
2024-04-04 17:20:30 +08:00
|
|
|
[SettingSource("Spacing", "The spacing between receptors.")]
|
2024-04-04 16:11:15 +08:00
|
|
|
public BindableFloat Spacing { get; } = new BindableFloat(10)
|
|
|
|
{
|
|
|
|
Precision = 1,
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 100,
|
|
|
|
};
|
|
|
|
|
2024-04-04 17:20:30 +08:00
|
|
|
[SettingSource("Opacity", "The receptor opacity.")]
|
|
|
|
public BindableFloat Opacity { get; } = new BindableFloat(1)
|
|
|
|
{
|
|
|
|
Precision = 0.1f,
|
|
|
|
MinValue = 0,
|
|
|
|
MaxValue = 1
|
|
|
|
};
|
|
|
|
|
2024-04-04 16:11:15 +08:00
|
|
|
[Resolved]
|
2024-05-06 15:24:32 +08:00
|
|
|
private DrawableManiaRuleset drawableRuleset { get; set; } = null!;
|
2024-04-04 16:11:15 +08:00
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
private GridContainer gridContainer = null!;
|
|
|
|
|
2024-05-14 19:16:07 +08:00
|
|
|
public ManiaTouchInputArea()
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
Origin = Anchor.BottomCentre;
|
2024-05-06 15:24:32 +08:00
|
|
|
|
2024-04-04 16:11:15 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Height = 0.5f;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
List<Drawable> receptorGridContent = new List<Drawable>();
|
|
|
|
List<Dimension> receptorGridDimensions = new List<Dimension>();
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
|
2024-05-06 15:24:32 +08:00
|
|
|
foreach (var stage in drawableRuleset.Playfield.Stages)
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
|
|
|
foreach (var column in stage.Columns)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
receptorGridContent.Add(new Gutter { Spacing = { BindTarget = Spacing } });
|
|
|
|
receptorGridDimensions.Add(new Dimension(GridSizeMode.AutoSize));
|
|
|
|
}
|
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
receptorGridContent.Add(new ColumnInputReceptor { Action = { BindTarget = column.Action } });
|
2024-04-04 16:11:15 +08:00
|
|
|
receptorGridDimensions.Add(new Dimension());
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
InternalChild = gridContainer = new GridContainer
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-05-14 19:28:14 +08:00
|
|
|
AlwaysPresent = true,
|
2024-04-04 16:11:15 +08:00
|
|
|
Content = new[] { receptorGridContent.ToArray() },
|
|
|
|
ColumnDimensions = receptorGridDimensions.ToArray()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-04 17:20:30 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Opacity.BindValueChanged(o => Alpha = o.NewValue, true);
|
|
|
|
}
|
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
|
|
|
// Hide whenever the keyboard is used.
|
|
|
|
Hide();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
Show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
|
|
{
|
|
|
|
Show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
gridContainer.FadeIn(500, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
gridContainer.FadeOut(300);
|
|
|
|
}
|
2024-04-04 16:11:15 +08:00
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
public partial class ColumnInputReceptor : CompositeDrawable
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
public readonly IBindable<ManiaAction> Action = new Bindable<ManiaAction>();
|
|
|
|
|
2024-04-04 16:11:15 +08:00
|
|
|
private readonly Box highlightOverlay;
|
|
|
|
|
2024-04-04 16:25:05 +08:00
|
|
|
[Resolved]
|
|
|
|
private ManiaInputManager? inputManager { get; set; }
|
|
|
|
|
|
|
|
private bool isPressed;
|
|
|
|
|
2024-05-14 19:28:14 +08:00
|
|
|
public ColumnInputReceptor()
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 10,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0.15f,
|
|
|
|
},
|
|
|
|
highlightOverlay = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
updateButton(true);
|
2024-05-14 19:28:14 +08:00
|
|
|
return false; // handled by parent container to show overlay.
|
2024-04-04 16:11:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnTouchUp(TouchUpEvent e)
|
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
updateButton(false);
|
2024-04-04 16:11:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
updateButton(true);
|
2024-05-14 19:28:14 +08:00
|
|
|
return false; // handled by parent container to show overlay.
|
2024-04-04 16:11:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
updateButton(false);
|
2024-04-04 16:11:15 +08:00
|
|
|
}
|
|
|
|
|
2024-04-04 16:25:05 +08:00
|
|
|
private void updateButton(bool press)
|
2024-04-04 16:11:15 +08:00
|
|
|
{
|
2024-04-04 16:25:05 +08:00
|
|
|
if (press == isPressed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
isPressed = press;
|
|
|
|
|
|
|
|
if (press)
|
|
|
|
{
|
|
|
|
inputManager?.KeyBindingContainer?.TriggerPressed(Action.Value);
|
|
|
|
highlightOverlay.FadeTo(0.1f, 80, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
inputManager?.KeyBindingContainer?.TriggerReleased(Action.Value);
|
|
|
|
highlightOverlay.FadeTo(0, 400, Easing.OutQuint);
|
|
|
|
}
|
2024-04-04 16:11:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class Gutter : Drawable
|
|
|
|
{
|
|
|
|
public readonly IBindable<float> Spacing = new Bindable<float>();
|
|
|
|
|
|
|
|
public Gutter()
|
|
|
|
{
|
|
|
|
Spacing.BindValueChanged(s => Size = new Vector2(s.NewValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|