// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.UI; using OpenTK; namespace osu.Game.Rulesets.Mania.UI { public class ManiaPlayfield : ScrollingPlayfield { /// /// list mania column stages /// private readonly FillFlowContainer listColumnStages; /// /// Whether this playfield should be inverted. This flips everything inside the playfield. /// public readonly Bindable Inverted = new Bindable(true); /// /// The style to use for the special column. /// public SpecialColumnPosition SpecialColumnPosition { get => listColumnStages.FirstOrDefault()?.SpecialColumnPosition ?? SpecialColumnPosition.Normal; set { foreach (var singleStage in listColumnStages) { singleStage.SpecialColumnPosition = value; } } } public List Columns => listColumnStages.SelectMany(x => x.Columns).ToList(); public ManiaPlayfield(List stages) : base(Axes.Y) { if (stages.Count <= 0) throw new ArgumentException("Can't have zero or fewer columns."); Inverted.Value = true; InternalChildren = new Drawable[] { listColumnStages = new FillFlowContainer { Direction = FillDirection.Horizontal, RelativeSizeAxes = Axes.Y, Anchor = Anchor.Centre, Origin = Anchor.Centre, Spacing = new Vector2(400), } }; var currentAction = ManiaAction.Key1; foreach (var stage in stages) { var drawableStage = new ManiaColumnStage(stage.Columns); drawableStage.VisibleTimeRange.BindTo(VisibleTimeRange); listColumnStages.Add(drawableStage); AddNested(drawableStage); for (int i = 0; i < stage.Columns; i++) { var c = new Column { //c.Action = c.IsSpecial ? ManiaAction.Special : currentAction++; Action = currentAction++ }; drawableStage.AddColumn(c); AddNested(c); } } Inverted.ValueChanged += invertedChanged; Inverted.TriggerChange(); } private void invertedChanged(bool newValue) { Scale = new Vector2(1, newValue ? -1 : 1); foreach (var single in listColumnStages) { single.Judgements.Scale = Scale; } } public override void OnJudgement(DrawableHitObject judgedObject, Judgement judgement) { var maniaObject = (ManiaHitObject)judgedObject.HitObject; int column = maniaObject.Column; Columns[column].OnJudgement(judgedObject, judgement); getFallDownControlContainerByActualColumn(column).AddJudgement(judgement); } public override void Add(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column).Add(h); public void Add(BarLine barline) { foreach (var single in listColumnStages) { single.HitObjects.Add(new DrawableBarLine(barline)); } } private ManiaColumnStage getFallDownControlContainerByActualColumn(int actualColumn) { int sum = 0; foreach (var single in listColumnStages) { sum = sum + single.ColumnCount; if (sum > actualColumn) { return single; } } return null; } } }