2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-05-20 18:22:42 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-04-13 12:42:21 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-07-28 14:47:57 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
2018-05-20 18:22:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2021-05-12 15:56:07 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-05-20 18:22:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-11-06 14:46:36 +08:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
|
|
|
{
|
2020-04-13 12:42:21 +08:00
|
|
|
|
[Cached]
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ManiaPlayfield : ScrollingPlayfield
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-05-14 18:17:24 +08:00
|
|
|
|
public IReadOnlyList<Stage> Stages => stages;
|
|
|
|
|
|
2020-04-08 13:08:34 +08:00
|
|
|
|
private readonly List<Stage> stages = new List<Stage>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-07-28 14:47:57 +08:00
|
|
|
|
public override Quad SkinnableComponentScreenSpaceDrawQuad
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-08-13 03:55:20 +08:00
|
|
|
|
RectangleF totalArea = RectangleF.Empty;
|
2023-07-28 14:47:57 +08:00
|
|
|
|
|
2023-08-13 03:55:20 +08:00
|
|
|
|
for (int i = 0; i < Stages.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
var stageArea = Stages[i].ScreenSpaceDrawQuad.AABBFloat;
|
|
|
|
|
totalArea = i == 0 ? stageArea : RectangleF.Union(totalArea, stageArea);
|
|
|
|
|
}
|
2023-07-28 14:47:57 +08:00
|
|
|
|
|
2023-08-13 03:55:20 +08:00
|
|
|
|
return totalArea;
|
2023-07-28 14:47:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 08:19:27 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
|
|
|
|
{
|
|
|
|
|
foreach (var s in stages)
|
|
|
|
|
{
|
|
|
|
|
if (s.ReceivePositionalInputAt(screenSpacePos))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-11-29 12:20:37 +08:00
|
|
|
|
|
2018-07-17 14:14:03 +08:00
|
|
|
|
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2022-12-23 04:27:59 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(stageDefinitions);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (stageDefinitions.Count <= 0)
|
|
|
|
|
throw new ArgumentException("Can't have zero or fewer stages.");
|
|
|
|
|
|
|
|
|
|
GridContainer playfieldGrid;
|
2018-08-30 12:30:23 +08:00
|
|
|
|
AddInternal(playfieldGrid = new GridContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[] { new Drawable[stageDefinitions.Count] }
|
2018-08-30 12:30:23 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-08-08 05:36:04 +08:00
|
|
|
|
var columnAction = ManiaAction.Key1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
int firstColumnIndex = 0;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
for (int i = 0; i < stageDefinitions.Count; i++)
|
|
|
|
|
{
|
2024-08-08 05:36:04 +08:00
|
|
|
|
var newStage = new Stage(firstColumnIndex, stageDefinitions[i], ref columnAction);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
playfieldGrid.Content[0][i] = newStage;
|
|
|
|
|
|
|
|
|
|
stages.Add(newStage);
|
|
|
|
|
AddNested(newStage);
|
|
|
|
|
|
2024-01-30 08:07:37 +08:00
|
|
|
|
firstColumnIndex += newStage.Columns.Length;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 15:56:07 +08:00
|
|
|
|
public override void Add(HitObject hitObject) => getStageByColumn(((ManiaHitObject)hitObject).Column).Add(hitObject);
|
|
|
|
|
|
|
|
|
|
public override bool Remove(HitObject hitObject) => getStageByColumn(((ManiaHitObject)hitObject).Column).Remove(hitObject);
|
|
|
|
|
|
2018-07-19 16:04:51 +08:00
|
|
|
|
public override void Add(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Add(h);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-30 10:57:53 +08:00
|
|
|
|
public override bool Remove(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Remove(h);
|
2018-11-20 16:26:00 +08:00
|
|
|
|
|
2021-12-10 13:15:00 +08:00
|
|
|
|
public void Add(BarLine barLine) => stages.ForEach(s => s.Add(barLine));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-12 17:24:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves a column from a screen-space position.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="screenSpacePosition">The screen-space position.</param>
|
|
|
|
|
/// <returns>The column which the <paramref name="screenSpacePosition"/> lies in.</returns>
|
|
|
|
|
public Column GetColumnByPosition(Vector2 screenSpacePosition)
|
|
|
|
|
{
|
|
|
|
|
Column found = null;
|
|
|
|
|
|
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
{
|
|
|
|
|
foreach (var column in stage.Columns)
|
|
|
|
|
{
|
2020-04-28 17:34:55 +08:00
|
|
|
|
if (column.ReceivePositionalInputAt(new Vector2(screenSpacePosition.X, column.ScreenSpaceDrawQuad.Centre.Y)))
|
2018-11-12 17:24:18 +08:00
|
|
|
|
{
|
|
|
|
|
found = column;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 17:55:58 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves a <see cref="Column"/> by index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">The index of the column.</param>
|
|
|
|
|
/// <returns>The <see cref="Column"/> corresponding to the given index.</returns>
|
|
|
|
|
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="index"/> is less than 0 or greater than <see cref="TotalColumns"/>.</exception>
|
2020-04-27 19:35:24 +08:00
|
|
|
|
public Column GetColumn(int index)
|
|
|
|
|
{
|
2020-04-28 17:55:58 +08:00
|
|
|
|
if (index < 0 || index > TotalColumns - 1)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
|
2020-04-27 19:35:24 +08:00
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
{
|
2024-01-30 08:07:37 +08:00
|
|
|
|
if (index >= stage.Columns.Length)
|
2020-04-27 19:35:24 +08:00
|
|
|
|
{
|
2024-01-30 08:07:37 +08:00
|
|
|
|
index -= stage.Columns.Length;
|
2020-04-27 19:35:24 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stage.Columns[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 20:37:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the total amount of columns across all stages in this playfield.
|
|
|
|
|
/// </summary>
|
2024-02-21 00:10:03 +08:00
|
|
|
|
public int TotalColumns
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int sum = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
sum += stage.Columns.Length;
|
|
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-15 20:37:22 +08:00
|
|
|
|
|
2020-04-08 13:08:34 +08:00
|
|
|
|
private Stage getStageByColumn(int column)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
int sum = 0;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
{
|
2024-01-30 08:07:37 +08:00
|
|
|
|
sum += stage.Columns.Length;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (sum > column)
|
|
|
|
|
return stage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|