2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-05-03 11:37:47 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using System.Linq;
|
2017-05-03 18:38:15 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-23 19:50:03 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-05-10 13:56:39 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-05-29 13:44:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-09-12 16:37:37 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2018-01-04 18:22:15 +08:00
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-09-12 17:19:28 +08:00
|
|
|
|
public class ManiaPlayfield : ScrollingPlayfield
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-05-11 11:33:19 +08:00
|
|
|
|
public const float HIT_TARGET_POSITION = 50;
|
|
|
|
|
|
2017-05-04 14:18:20 +08:00
|
|
|
|
private SpecialColumnPosition specialColumnPosition;
|
2017-05-03 18:38:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The style to use for the special column.
|
|
|
|
|
/// </summary>
|
2017-05-04 14:18:20 +08:00
|
|
|
|
public SpecialColumnPosition SpecialColumnPosition
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-05-04 14:18:20 +08:00
|
|
|
|
get { return specialColumnPosition; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
throw new InvalidOperationException($"Setting {nameof(SpecialColumnPosition)} after the playfield is loaded requires re-creating the playfield.");
|
|
|
|
|
specialColumnPosition = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-03 18:38:15 +08:00
|
|
|
|
|
2017-08-23 19:50:03 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this playfield should be inverted. This flips everything inside the playfield.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
|
|
|
|
|
|
2017-05-22 14:27:38 +08:00
|
|
|
|
private readonly FlowContainer<Column> columns;
|
|
|
|
|
public IEnumerable<Column> Columns => columns.Children;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-08-07 16:45:45 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
private readonly Container<Drawable> content;
|
2017-05-11 11:33:19 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
private List<Color4> normalColumnColours = new List<Color4>();
|
|
|
|
|
private Color4 specialColumnColour;
|
|
|
|
|
|
2017-09-11 16:53:27 +08:00
|
|
|
|
private readonly Container<DrawableManiaJudgement> judgements;
|
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
private readonly int columnCount;
|
|
|
|
|
|
2017-06-01 13:26:21 +08:00
|
|
|
|
public ManiaPlayfield(int columnCount)
|
2018-01-04 21:05:20 +08:00
|
|
|
|
: base(ScrollingDirection.Up)
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-05-03 18:38:15 +08:00
|
|
|
|
this.columnCount = columnCount;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
if (columnCount <= 0)
|
2017-05-03 11:58:46 +08:00
|
|
|
|
throw new ArgumentException("Can't have zero or fewer columns.");
|
2016-09-02 19:30:27 +08:00
|
|
|
|
|
2017-08-23 19:50:03 +08:00
|
|
|
|
Inverted.Value = true;
|
|
|
|
|
|
2017-09-11 12:44:39 +08:00
|
|
|
|
Container topLevelContainer;
|
2017-08-07 13:56:26 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
|
|
|
|
new Container
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-09-11 09:46:54 +08:00
|
|
|
|
Name = "Playfield elements",
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-09-11 09:46:54 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2017-05-03 11:37:47 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-29 13:44:42 +08:00
|
|
|
|
new Container
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
2017-09-11 09:46:54 +08:00
|
|
|
|
Name = "Columns mask",
|
2017-05-03 11:37:47 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
2017-05-29 13:44:42 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2017-09-11 09:46:54 +08:00
|
|
|
|
Name = "Background",
|
2017-05-29 13:44:42 +08:00
|
|
|
|
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)
|
2017-09-11 09:46:54 +08:00
|
|
|
|
},
|
2017-05-29 13:44:42 +08:00
|
|
|
|
}
|
2017-05-11 11:33:19 +08:00
|
|
|
|
},
|
2017-05-16 16:34:41 +08:00
|
|
|
|
new Container
|
2017-05-11 11:33:19 +08:00
|
|
|
|
{
|
2017-09-11 09:46:54 +08:00
|
|
|
|
Name = "Barlines mask",
|
2017-05-29 13:44:42 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-09-11 09:46:54 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 1366, // Bar lines should only be masked on the vertical axis
|
|
|
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Child = content = new Container
|
2017-05-16 16:34:41 +08:00
|
|
|
|
{
|
2017-09-11 09:46:54 +08:00
|
|
|
|
Name = "Bar lines",
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Top = HIT_TARGET_POSITION }
|
2017-05-16 16:34:41 +08:00
|
|
|
|
}
|
2017-09-11 09:46:54 +08:00
|
|
|
|
},
|
2017-09-11 16:53:27 +08:00
|
|
|
|
judgements = new Container<DrawableManiaJudgement>
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Y = HIT_TARGET_POSITION + 150,
|
|
|
|
|
BypassAutoSizeAxes = Axes.Both
|
|
|
|
|
},
|
2017-09-11 09:46:54 +08:00
|
|
|
|
topLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
var currentAction = ManiaAction.Key1;
|
2017-05-03 18:38:15 +08:00
|
|
|
|
for (int i = 0; i < columnCount; i++)
|
2017-08-07 13:56:26 +08:00
|
|
|
|
{
|
2017-08-08 11:59:50 +08:00
|
|
|
|
var c = new Column();
|
|
|
|
|
c.VisibleTimeRange.BindTo(VisibleTimeRange);
|
|
|
|
|
|
2017-08-23 12:42:11 +08:00
|
|
|
|
c.IsSpecial = isSpecialColumn(i);
|
|
|
|
|
c.Action = c.IsSpecial ? ManiaAction.Special : currentAction++;
|
|
|
|
|
|
2017-09-11 12:44:39 +08:00
|
|
|
|
topLevelContainer.Add(c.TopLevelContainer.CreateProxy());
|
|
|
|
|
|
2017-08-07 13:56:26 +08:00
|
|
|
|
columns.Add(c);
|
|
|
|
|
AddNested(c);
|
|
|
|
|
}
|
2017-08-23 19:50:03 +08:00
|
|
|
|
|
|
|
|
|
Inverted.ValueChanged += invertedChanged;
|
|
|
|
|
Inverted.TriggerChange();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void invertedChanged(bool newValue)
|
|
|
|
|
{
|
|
|
|
|
Scale = new Vector2(1, newValue ? -1 : 1);
|
2017-09-11 16:53:27 +08:00
|
|
|
|
judgements.Scale = Scale;
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-01-11 12:40:46 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
2017-05-03 18:38:15 +08:00
|
|
|
|
normalColumnColours = new List<Color4>
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
|
|
|
|
colours.RedDark,
|
2017-05-03 18:38:15 +08:00
|
|
|
|
colours.GreenDark
|
2017-05-03 11:37:47 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
specialColumnColour = colours.BlueDark;
|
|
|
|
|
|
|
|
|
|
// Set the special column + colour + key
|
2017-08-23 12:42:11 +08:00
|
|
|
|
foreach (var column in Columns)
|
2017-05-03 18:38:15 +08:00
|
|
|
|
{
|
|
|
|
|
if (!column.IsSpecial)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
column.AccentColour = specialColumnColour;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-22 14:27:38 +08:00
|
|
|
|
var nonSpecialColumns = Columns.Where(c => !c.IsSpecial).ToList();
|
2017-05-03 11:37:47 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-03 11:37:47 +08:00
|
|
|
|
|
2018-01-15 19:45:30 +08:00
|
|
|
|
public void OnJudgement(DrawableHitObject judgedObject, Judgement judgement)
|
2017-09-11 16:53:27 +08:00
|
|
|
|
{
|
|
|
|
|
judgements.Clear();
|
2017-09-12 16:37:37 +08:00
|
|
|
|
judgements.Add(new DrawableManiaJudgement(judgement)
|
2017-09-11 16:53:27 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-09-11 11:57:10 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2017-05-04 13:46:10 +08:00
|
|
|
|
switch (SpecialColumnPosition)
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
2017-05-03 18:38:15 +08:00
|
|
|
|
default:
|
2017-05-04 13:46:10 +08:00
|
|
|
|
case SpecialColumnPosition.Normal:
|
2017-05-03 18:38:15 +08:00
|
|
|
|
return columnCount % 2 == 1 && column == columnCount / 2;
|
2017-05-04 13:46:10 +08:00
|
|
|
|
case SpecialColumnPosition.Left:
|
2017-05-03 18:38:15 +08:00
|
|
|
|
return column == 0;
|
2017-05-04 13:46:10 +08:00
|
|
|
|
case SpecialColumnPosition.Right:
|
2017-05-03 18:38:15 +08:00
|
|
|
|
return column == columnCount - 1;
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
2016-09-02 19:30:27 +08:00
|
|
|
|
}
|
2017-05-10 13:56:39 +08:00
|
|
|
|
|
2018-01-15 19:45:30 +08:00
|
|
|
|
public override void Add(DrawableHitObject h)
|
|
|
|
|
{
|
|
|
|
|
h.OnJudgement += OnJudgement;
|
|
|
|
|
Columns.ElementAt(((ManiaHitObject)h.HitObject).Column).Add(h);
|
|
|
|
|
}
|
2017-09-12 17:19:28 +08:00
|
|
|
|
|
2017-08-07 16:45:45 +08:00
|
|
|
|
public void Add(DrawableBarLine barline) => HitObjects.Add(barline);
|
2017-05-16 18:14:27 +08:00
|
|
|
|
|
2017-05-29 13:44:42 +08:00
|
|
|
|
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
|
2017-08-07 16:45:45 +08:00
|
|
|
|
content.Width = columns.Width;
|
2017-05-29 13:44:42 +08:00
|
|
|
|
}
|
2016-09-02 19:30:27 +08:00
|
|
|
|
}
|
2017-05-03 12:03:46 +08:00
|
|
|
|
}
|