1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 08:52:55 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs

152 lines
4.8 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
2017-05-03 11:37:47 +08:00
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;
2018-01-03 21:58:08 +08:00
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;
2017-04-18 15:05:58 +08:00
namespace osu.Game.Rulesets.Mania.UI
{
public class ManiaPlayfield : ScrollingPlayfield
{
/// <summary>
2018-01-03 22:04:51 +08:00
/// list mania column stages
/// </summary>
2018-01-03 21:58:08 +08:00
private readonly FillFlowContainer<ManiaColumnStage> listColumnStages;
/// <summary>
/// Whether this playfield should be inverted. This flips everything inside the playfield.
/// </summary>
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
2017-12-28 22:40:02 +08:00
/// <summary>
/// The style to use for the special column.
/// </summary>
public SpecialColumnPosition SpecialColumnPosition
{
2018-01-03 21:58:08 +08:00
get => listColumnStages.FirstOrDefault()?.SpecialColumnPosition ?? SpecialColumnPosition.Normal;
2017-12-28 22:40:02 +08:00
set
{
2018-01-03 22:04:51 +08:00
foreach (var singleStage in listColumnStages)
2017-12-28 22:40:02 +08:00
{
2018-01-03 22:04:51 +08:00
singleStage.SpecialColumnPosition = value;
2017-12-28 22:40:02 +08:00
}
}
}
public List<Column> Columns
{
get
{
var list = new List<Column>();
2018-01-03 21:58:08 +08:00
foreach (var stage in listColumnStages)
{
2018-01-03 21:58:08 +08:00
list.AddRange(stage.Columns);
}
return list;
}
}
2018-01-03 21:58:08 +08:00
public ManiaPlayfield(List<StageDefinition> stages)
: base(Axes.Y)
{
2018-01-03 21:58:08 +08:00
if (stages.Count <= 0)
2017-05-03 11:58:46 +08:00
throw new ArgumentException("Can't have zero or fewer columns.");
Inverted.Value = true;
InternalChildren = new Drawable[]
2017-05-03 11:37:47 +08:00
{
2018-01-03 21:58:08 +08:00
listColumnStages = new FillFlowContainer<ManiaColumnStage>
{
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Spacing = new Vector2(400),
2017-05-03 11:37:47 +08:00
}
};
2018-01-03 21:58:08 +08:00
var currentAction = ManiaAction.Key1;
2018-01-03 21:58:08 +08:00
foreach (var stage in stages)
{
2018-01-03 22:04:51 +08:00
var drawableStage = new ManiaColumnStage(stage.Columns);
drawableStage.VisibleTimeRange.BindTo(VisibleTimeRange);
2018-01-03 22:04:51 +08:00
listColumnStages.Add(drawableStage);
AddNested(drawableStage);
2018-01-03 21:58:08 +08:00
for (int i = 0; i < stage.Columns; i++)
2017-12-28 22:40:02 +08:00
{
2018-01-03 21:58:08 +08:00
var c = new Column
{
//c.Action = c.IsSpecial ? ManiaAction.Special : currentAction++;
Action = currentAction++
};
2018-01-03 22:04:51 +08:00
drawableStage.AddColumn(c);
2018-01-03 21:58:08 +08:00
AddNested(c);
}
}
Inverted.ValueChanged += invertedChanged;
Inverted.TriggerChange();
}
private void invertedChanged(bool newValue)
{
Scale = new Vector2(1, newValue ? -1 : 1);
2017-05-03 11:37:47 +08:00
2018-01-03 21:58:08 +08:00
foreach (var single in listColumnStages)
2017-05-03 11:37:47 +08:00
{
single.Judgements.Scale = Scale;
}
}
2017-05-03 11:37:47 +08:00
public override void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
{
var maniaObject = (ManiaHitObject)judgedObject.HitObject;
int column = maniaObject.Column;
2018-01-03 21:58:08 +08:00
Columns[column].OnJudgement(judgedObject, judgement);
getFallDownControlContainerByActualColumn(column).AddJudgement(judgement);
}
2017-09-11 11:57:10 +08:00
public override void Add(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column).Add(h);
public void Add(BarLine barline)
{
2018-01-03 21:58:08 +08:00
foreach (var single in listColumnStages)
2017-05-03 11:37:47 +08:00
{
single.HitObjects.Add(new DrawableBarLine(barline));
2017-05-03 11:37:47 +08:00
}
}
2018-01-03 21:58:08 +08:00
private ManiaColumnStage getFallDownControlContainerByActualColumn(int actualColumn)
2017-05-29 13:44:42 +08:00
{
int sum = 0;
2018-01-03 21:58:08 +08:00
foreach (var single in listColumnStages)
{
sum = sum + single.ColumnCount;
if (sum > actualColumn)
{
return single;
}
}
return null;
2017-05-29 13:44:42 +08:00
}
}
2017-05-03 12:03:46 +08:00
}