1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 22:07:28 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs
2018-01-15 18:20:43 +09:00

97 lines
3.4 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Objects;
using OpenTK;
using osu.Framework.Graphics.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.UI
{
public class ManiaPlayfield : ScrollingPlayfield
{
/// <summary>
/// <see cref="ManiaStage"/>s contained by this <see cref="ManiaPlayfield"/>.
/// </summary>
private readonly FillFlowContainer<ManiaStage> stages;
/// <summary>
/// Whether this playfield should be inverted. This flips everything inside the playfield.
/// </summary>
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
/// <summary>
/// The style to use for the special column.
/// </summary>
public Bindable<SpecialColumnPosition> SpecialColumnPosition = new Bindable<SpecialColumnPosition>();
public List<Column> Columns => stages.SelectMany(x => x.Columns).ToList();
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
: base(ScrollingDirection.Up)
{
if (stageDefinitions == null)
throw new ArgumentNullException(nameof(stageDefinitions));
if (stageDefinitions.Count <= 0)
throw new ArgumentException("Can't have zero or fewer stages.");
Inverted.Value = true;
var stageSpacing = 300 / stageDefinitions.Count;
InternalChildren = new Drawable[]
{
stages = new FillFlowContainer<ManiaStage>
{
Name = "Stages",
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(stageSpacing),
}
};
int firstColumnIndex = 0;
for (int i = 0; i < stageDefinitions.Count; i++)
{
var newStage = new ManiaStage(i, firstColumnIndex, stageDefinitions[i]);
newStage.SpecialColumn.BindTo(SpecialColumnPosition);
newStage.VisibleTimeRange.BindTo(VisibleTimeRange);
newStage.Inverted.BindTo(Inverted);
stages.Add(newStage);
AddNested(newStage);
firstColumnIndex += newStage.Columns.Count;
}
}
public override void Add(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Add(h);
public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline));
private ManiaStage getStageByColumn(int column)
{
int sum = 0;
foreach (var stage in stages)
{
sum = sum + stage.Columns.Count;
if (sum > column)
return stage;
}
return null;
}
}
}