1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 04:43:01 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs

95 lines
3.4 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// 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;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Mania.Objects;
2017-05-03 11:37:47 +08:00
using osu.Framework.Graphics.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Game.Rulesets.Judgements;
2018-01-03 21:58:08 +08:00
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Mania.Configuration;
2018-01-04 18:22:15 +08:00
using osu.Game.Rulesets.UI.Scrolling;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Mania.UI
{
public class ManiaPlayfield : ScrollingPlayfield
{
/// <summary>
/// Whether this playfield should be inverted. This flips everything inside the playfield.
/// </summary>
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
public List<Column> Columns => stages.SelectMany(x => x.Columns).ToList();
private readonly List<ManiaStage> stages = new List<ManiaStage>();
2018-01-15 17:20:43 +08:00
public ManiaPlayfield(List<StageDefinition> stageDefinitions)
: base(ScrollingDirection.Up)
{
2018-01-15 17:20:43 +08:00
if (stageDefinitions == null)
throw new ArgumentNullException(nameof(stageDefinitions));
2018-01-15 17:20:43 +08:00
if (stageDefinitions.Count <= 0)
2018-01-15 17:11:53 +08:00
throw new ArgumentException("Can't have zero or fewer stages.");
Inverted.Value = true;
GridContainer playfieldGrid;
InternalChild = playfieldGrid = new GridContainer
2017-05-03 11:37:47 +08:00
{
RelativeSizeAxes = Axes.Both,
Content = new[] { new Drawable[stageDefinitions.Count] }
2017-05-03 11:37:47 +08:00
};
var normalColumnAction = ManiaAction.Key1;
var specialColumnAction = ManiaAction.Special1;
2018-01-15 17:11:53 +08:00
int firstColumnIndex = 0;
2018-01-15 17:20:43 +08:00
for (int i = 0; i < stageDefinitions.Count; i++)
{
var newStage = new ManiaStage(firstColumnIndex, stageDefinitions[i], ref normalColumnAction, ref specialColumnAction);
2018-01-15 17:11:53 +08:00
newStage.VisibleTimeRange.BindTo(VisibleTimeRange);
newStage.Inverted.BindTo(Inverted);
playfieldGrid.Content[0][i] = newStage;
2017-08-23 12:42:11 +08:00
2018-01-15 17:11:53 +08:00
stages.Add(newStage);
AddNested(newStage);
2017-09-11 12:44:39 +08:00
2018-01-15 17:11:53 +08:00
firstColumnIndex += newStage.Columns.Count;
}
}
2018-01-15 17:20:43 +08:00
public override void Add(DrawableHitObject h) => getStageByColumn(((ManiaHitObject)h.HitObject).Column).Add(h);
2017-09-11 11:57:10 +08:00
2018-01-15 17:20:43 +08:00
public void Add(BarLine barline) => stages.ForEach(s => s.Add(barline));
private ManiaStage getStageByColumn(int column)
{
int sum = 0;
foreach (var stage in stages)
{
2018-01-15 17:11:53 +08:00
sum = sum + stage.Columns.Count;
if (sum > column)
return stage;
}
return null;
2017-05-03 11:37:47 +08:00
}
[BackgroundDependencyLoader]
private void load(ManiaConfigManager maniaConfig)
2017-05-03 11:37:47 +08:00
{
maniaConfig.BindWith(ManiaSetting.ScrollTime, VisibleTimeRange);
}
2017-05-03 11:37:47 +08:00
internal void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
{
getStageByColumn(((ManiaHitObject)judgedObject.HitObject).Column).OnJudgement(judgedObject, judgement);
2017-05-29 13:44:42 +08:00
}
}
2017-05-03 12:03:46 +08:00
}