2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-05-20 10:22:42 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-11-15 12:37:22 +00:00
|
|
|
|
using System.Linq;
|
2020-04-13 04:42:21 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
2018-05-20 10:22:42 +00:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2018-11-06 06:46:36 +00:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
|
|
|
{
|
2020-04-13 04:42:21 +00:00
|
|
|
|
[Cached]
|
2018-11-06 06:46:36 +00:00
|
|
|
|
public class ManiaPlayfield : ScrollingPlayfield
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-05-14 10:17:24 +00:00
|
|
|
|
public IReadOnlyList<Stage> Stages => stages;
|
|
|
|
|
|
2020-04-08 05:08:34 +00:00
|
|
|
|
private readonly List<Stage> stages = new List<Stage>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-29 04:20:37 +00:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => stages.Any(s => s.ReceivePositionalInputAt(screenSpacePos));
|
|
|
|
|
|
2018-07-17 06:14:03 +00:00
|
|
|
|
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (stageDefinitions == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(stageDefinitions));
|
|
|
|
|
|
|
|
|
|
if (stageDefinitions.Count <= 0)
|
|
|
|
|
throw new ArgumentException("Can't have zero or fewer stages.");
|
|
|
|
|
|
|
|
|
|
GridContainer playfieldGrid;
|
2018-08-30 04:30:23 +00:00
|
|
|
|
AddInternal(playfieldGrid = new GridContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[] { new Drawable[stageDefinitions.Count] }
|
2018-08-30 04:30:23 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
var normalColumnAction = ManiaAction.Key1;
|
|
|
|
|
var specialColumnAction = ManiaAction.Special1;
|
|
|
|
|
int firstColumnIndex = 0;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
for (int i = 0; i < stageDefinitions.Count; i++)
|
|
|
|
|
{
|
2020-04-08 05:08:34 +00:00
|
|
|
|
var newStage = new Stage(firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
playfieldGrid.Content[0][i] = newStage;
|
|
|
|
|
|
|
|
|
|
stages.Add(newStage);
|
|
|
|
|
AddNested(newStage);
|
|
|
|
|
|
|
|
|
|
firstColumnIndex += newStage.Columns.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-19 08:04:51 +00:00
|
|
|
|
public override void Add(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Add(h);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-30 02:57:53 +00:00
|
|
|
|
public override bool Remove(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Remove(h);
|
2018-11-20 08:26:00 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline));
|
|
|
|
|
|
2018-11-12 09:24:18 +00: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 09:34:55 +00:00
|
|
|
|
if (column.ReceivePositionalInputAt(new Vector2(screenSpacePosition.X, column.ScreenSpaceDrawQuad.Centre.Y)))
|
2018-11-12 09:24:18 +00:00
|
|
|
|
{
|
|
|
|
|
found = column;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 09:55:58 +00: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 11:35:24 +00:00
|
|
|
|
public Column GetColumn(int index)
|
|
|
|
|
{
|
2020-04-28 09:55:58 +00:00
|
|
|
|
if (index < 0 || index > TotalColumns - 1)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
|
2020-04-27 11:35:24 +00:00
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
{
|
|
|
|
|
if (index >= stage.Columns.Count)
|
|
|
|
|
{
|
|
|
|
|
index -= stage.Columns.Count;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stage.Columns[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 12:37:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieves the total amount of columns across all stages in this playfield.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int TotalColumns => stages.Sum(s => s.Columns.Count);
|
|
|
|
|
|
2020-04-08 05:08:34 +00:00
|
|
|
|
private Stage getStageByColumn(int column)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
int sum = 0;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
foreach (var stage in stages)
|
|
|
|
|
{
|
2019-11-12 09:56:38 +00:00
|
|
|
|
sum += stage.Columns.Count;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
if (sum > column)
|
|
|
|
|
return stage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|