1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 14:02:54 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs

108 lines
3.6 KiB
C#
Raw Normal View History

// 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
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;
2018-11-15 20:37:22 +08:00
using System.Linq;
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;
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
{
2018-11-06 14:46:36 +08:00
public class ManiaPlayfield : ScrollingPlayfield
2018-04-13 17:19:50 +08:00
{
private readonly List<ManiaStage> stages = new List<ManiaStage>();
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => stages.Any(s => s.ReceivePositionalInputAt(screenSpacePos));
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
2018-04-13 17:19:50 +08: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;
AddInternal(playfieldGrid = new GridContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
Content = new[] { new Drawable[stageDefinitions.Count] }
});
2018-04-13 17:19:50 +08:00
var normalColumnAction = ManiaAction.Key1;
var specialColumnAction = ManiaAction.Special1;
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++)
{
2018-07-19 16:04:51 +08:00
var newStage = new ManiaStage(firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
2018-04-13 17:19:50 +08:00
playfieldGrid.Content[0][i] = newStage;
stages.Add(newStage);
AddNested(newStage);
firstColumnIndex += newStage.Columns.Count;
}
}
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
public override bool Remove(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Remove(h);
2018-11-20 16:26:00 +08:00
2018-04-13 17:19:50 +08:00
public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline));
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)
{
if (column.ReceivePositionalInputAt(screenSpacePosition))
{
found = column;
break;
}
}
if (found != null)
break;
}
return found;
}
2018-11-15 20:37:22 +08:00
/// <summary>
/// Retrieves the total amount of columns across all stages in this playfield.
/// </summary>
public int TotalColumns => stages.Sum(s => s.Columns.Count);
2018-04-13 17:19:50 +08:00
private ManiaStage getStageByColumn(int column)
{
int sum = 0;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
foreach (var stage in stages)
{
2019-11-12 17:56:38 +08:00
sum += stage.Columns.Count;
2018-04-13 17:19:50 +08:00
if (sum > column)
return stage;
}
return null;
}
}
}