mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 16:22:57 +08:00
217 lines
8.5 KiB
C#
217 lines
8.5 KiB
C#
// Copyright (c) 2007-2017 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 osu.Game.Rulesets.UI;
|
|
using OpenTK;
|
|
using OpenTK.Graphics;
|
|
using osu.Game.Rulesets.Mania.Judgements;
|
|
using osu.Framework.Graphics.Containers;
|
|
using System;
|
|
using osu.Game.Graphics;
|
|
using osu.Framework.Allocation;
|
|
using OpenTK.Input;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using osu.Framework.Configuration;
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
{
|
|
public class ManiaPlayfield : ScrollingPlayfield<ManiaHitObject, ManiaJudgement>
|
|
{
|
|
public const float HIT_TARGET_POSITION = 50;
|
|
|
|
/// <summary>
|
|
/// Default column keys, expanding outwards from the middle as more column are added.
|
|
/// E.g. 2 columns use FJ, 4 columns use DFJK, 6 use SDFJKL, etc...
|
|
/// </summary>
|
|
private static readonly Key[] default_keys = { Key.A, Key.S, Key.D, Key.F, Key.J, Key.K, Key.L, Key.Semicolon };
|
|
|
|
private SpecialColumnPosition specialColumnPosition;
|
|
/// <summary>
|
|
/// The style to use for the special column.
|
|
/// </summary>
|
|
public SpecialColumnPosition SpecialColumnPosition
|
|
{
|
|
get { return specialColumnPosition; }
|
|
set
|
|
{
|
|
if (IsLoaded)
|
|
throw new InvalidOperationException($"Setting {nameof(SpecialColumnPosition)} after the playfield is loaded requires re-creating the playfield.");
|
|
specialColumnPosition = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether this playfield should be inverted. This flips everything inside the playfield.
|
|
/// </summary>
|
|
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
|
|
|
|
private readonly FlowContainer<Column> columns;
|
|
public IEnumerable<Column> Columns => columns.Children;
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
private readonly Container<Drawable> content;
|
|
|
|
private List<Color4> normalColumnColours = new List<Color4>();
|
|
private Color4 specialColumnColour;
|
|
|
|
private readonly int columnCount;
|
|
|
|
public ManiaPlayfield(int columnCount)
|
|
: base(Axes.Y)
|
|
{
|
|
this.columnCount = columnCount;
|
|
|
|
if (columnCount <= 0)
|
|
throw new ArgumentException("Can't have zero or fewer columns.");
|
|
|
|
Inverted.Value = true;
|
|
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
new Container
|
|
{
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
RelativeSizeAxes = Axes.Both,
|
|
Masking = true,
|
|
Children = new Drawable[]
|
|
{
|
|
new Container
|
|
{
|
|
Name = "Masked elements",
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
RelativeSizeAxes = Axes.Y,
|
|
AutoSizeAxes = Axes.X,
|
|
Masking = true,
|
|
Children = new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = Color4.Black
|
|
},
|
|
columns = new FillFlowContainer<Column>
|
|
{
|
|
Name = "Columns",
|
|
RelativeSizeAxes = Axes.Y,
|
|
AutoSizeAxes = Axes.X,
|
|
Direction = FillDirection.Horizontal,
|
|
Padding = new MarginPadding { Left = 1, Right = 1 },
|
|
Spacing = new Vector2(1, 0)
|
|
}
|
|
}
|
|
},
|
|
new Container
|
|
{
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
RelativeSizeAxes = Axes.Both,
|
|
Padding = new MarginPadding { Top = HIT_TARGET_POSITION },
|
|
Children = new[]
|
|
{
|
|
content = new Container
|
|
{
|
|
Name = "Bar lines",
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
RelativeSizeAxes = Axes.Y,
|
|
// Width is set in the Update method
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
var currentAction = ManiaAction.Key1;
|
|
for (int i = 0; i < columnCount; i++)
|
|
{
|
|
var c = new Column();
|
|
c.VisibleTimeRange.BindTo(VisibleTimeRange);
|
|
|
|
c.IsSpecial = isSpecialColumn(i);
|
|
c.Action = c.IsSpecial ? ManiaAction.Special : currentAction++;
|
|
|
|
columns.Add(c);
|
|
AddNested(c);
|
|
}
|
|
|
|
Inverted.ValueChanged += invertedChanged;
|
|
Inverted.TriggerChange();
|
|
}
|
|
|
|
private void invertedChanged(bool newValue)
|
|
{
|
|
Scale = new Vector2(1, newValue ? -1 : 1);
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuColour colours)
|
|
{
|
|
normalColumnColours = new List<Color4>
|
|
{
|
|
colours.RedDark,
|
|
colours.GreenDark
|
|
};
|
|
|
|
specialColumnColour = colours.BlueDark;
|
|
|
|
// Set the special column + colour + key
|
|
foreach (var column in Columns)
|
|
{
|
|
if (!column.IsSpecial)
|
|
continue;
|
|
|
|
column.AccentColour = specialColumnColour;
|
|
}
|
|
|
|
var nonSpecialColumns = Columns.Where(c => !c.IsSpecial).ToList();
|
|
|
|
// We'll set the colours of the non-special columns in a separate loop, because the non-special
|
|
// column colours are mirrored across their centre and special styles mess with this
|
|
for (int i = 0; i < Math.Ceiling(nonSpecialColumns.Count / 2f); i++)
|
|
{
|
|
Color4 colour = normalColumnColours[i % normalColumnColours.Count];
|
|
nonSpecialColumns[i].AccentColour = colour;
|
|
nonSpecialColumns[nonSpecialColumns.Count - 1 - i].AccentColour = colour;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether the column index is a special column for this playfield.
|
|
/// </summary>
|
|
/// <param name="column">The 0-based column index.</param>
|
|
/// <returns>Whether the column is a special column.</returns>
|
|
private bool isSpecialColumn(int column)
|
|
{
|
|
switch (SpecialColumnPosition)
|
|
{
|
|
default:
|
|
case SpecialColumnPosition.Normal:
|
|
return columnCount % 2 == 1 && column == columnCount / 2;
|
|
case SpecialColumnPosition.Left:
|
|
return column == 0;
|
|
case SpecialColumnPosition.Right:
|
|
return column == columnCount - 1;
|
|
}
|
|
}
|
|
|
|
public override void Add(DrawableHitObject<ManiaHitObject, ManiaJudgement> h) => Columns.ElementAt(h.HitObject.Column).Add(h);
|
|
public void Add(DrawableBarLine barline) => HitObjects.Add(barline);
|
|
|
|
protected override void Update()
|
|
{
|
|
// Due to masking differences, it is not possible to get the width of the columns container automatically
|
|
// While masking on effectively only the Y-axis, so we need to set the width of the bar line container manually
|
|
content.Width = columns.Width;
|
|
}
|
|
}
|
|
}
|