From ef40197713009fd58c04ddc4f516a6cefd001ed8 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 4 Apr 2024 17:11:15 +0900 Subject: [PATCH] Add mania touch overlay Adjust default anchor/origin --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 20 ++- .../UI/ManiaTouchInputOverlay.cs | 144 ++++++++++++++++++ 2 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/UI/ManiaTouchInputOverlay.cs diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index b3420c49f3b8..7610e485824c 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers; using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics.Primitives; using osu.Game.Rulesets.Mania.Beatmaps; @@ -60,10 +61,23 @@ public ManiaPlayfield(List stageDefinitions) throw new ArgumentException("Can't have zero or fewer stages."); GridContainer playfieldGrid; - AddInternal(playfieldGrid = new GridContainer + + RelativeSizeAxes = Axes.Y; + AutoSizeAxes = Axes.X; + + AddRangeInternal(new Drawable[] { - RelativeSizeAxes = Axes.Both, - Content = new[] { new Drawable[stageDefinitions.Count] } + playfieldGrid = new GridContainer + { + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Content = new[] { new Drawable[stageDefinitions.Count] }, + ColumnDimensions = Enumerable.Range(0, stageDefinitions.Count).Select(_ => new Dimension(GridSizeMode.AutoSize)).ToArray() + }, + new ManiaTouchInputOverlay + { + RelativeSizeAxes = Axes.Both, + } }); var normalColumnAction = ManiaAction.Key1; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaTouchInputOverlay.cs b/osu.Game.Rulesets.Mania/UI/ManiaTouchInputOverlay.cs new file mode 100644 index 000000000000..476461959d7f --- /dev/null +++ b/osu.Game.Rulesets.Mania/UI/ManiaTouchInputOverlay.cs @@ -0,0 +1,144 @@ +// Copyright (c) ppy Pty Ltd . 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 osu.Game.Skinning; +using osuTK; + +namespace osu.Game.Rulesets.Mania.UI +{ + public partial class ManiaTouchInputOverlay : CompositeDrawable, ISerialisableDrawable + { + [SettingSource("Spacing", "The spacing between input receptors.")] + public BindableFloat Spacing { get; } = new BindableFloat(10) + { + Precision = 1, + MinValue = 0, + MaxValue = 100, + }; + + [Resolved] + private ManiaPlayfield playfield { get; set; } = null!; + + public ManiaTouchInputOverlay() + { + Anchor = Anchor.BottomCentre; + Origin = Anchor.BottomCentre; + RelativeSizeAxes = Axes.Both; + Height = 0.5f; + } + + [BackgroundDependencyLoader] + private void load() + { + List receptorGridContent = new List(); + List receptorGridDimensions = new List(); + + bool first = true; + + foreach (var stage in playfield.Stages) + { + foreach (var column in stage.Columns) + { + if (!first) + { + receptorGridContent.Add(new Gutter { Spacing = { BindTarget = Spacing } }); + receptorGridDimensions.Add(new Dimension(GridSizeMode.AutoSize)); + } + + receptorGridContent.Add(new InputReceptor()); + receptorGridDimensions.Add(new Dimension()); + + first = false; + } + } + + InternalChild = new GridContainer + { + RelativeSizeAxes = Axes.Both, + Content = new[] { receptorGridContent.ToArray() }, + ColumnDimensions = receptorGridDimensions.ToArray() + }; + } + + public bool UsesFixedAnchor { get; set; } + + public partial class InputReceptor : CompositeDrawable + { + private readonly Box highlightOverlay; + + public InputReceptor() + { + 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) + { + updateHighlight(true); + return true; + } + + protected override void OnTouchUp(TouchUpEvent e) + { + updateHighlight(false); + } + + protected override bool OnMouseDown(MouseDownEvent e) + { + updateHighlight(true); + return true; + } + + protected override void OnMouseUp(MouseUpEvent e) + { + updateHighlight(false); + } + + private void updateHighlight(bool enabled) + { + highlightOverlay.FadeTo(enabled ? 0.1f : 0, enabled ? 80 : 400, Easing.OutQuint); + } + } + + private partial class Gutter : Drawable + { + public readonly IBindable Spacing = new Bindable(); + + public Gutter() + { + Spacing.BindValueChanged(s => Size = new Vector2(s.NewValue)); + } + } + } +}