2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// 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;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
2016-09-02 19:30:27 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-04-18 15:05:58 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Judgements;
|
2017-05-03 11:37:47 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using System.Linq;
|
2017-05-03 18:38:15 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-05-10 13:56:39 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-05-11 11:33:19 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-05-16 18:14:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
|
using osu.Framework.MathUtils;
|
2017-05-29 13:44:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
2017-06-02 19:17:44 +08:00
|
|
|
|
using osu.Game.Rulesets.Timing;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
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-05-03 11:44:19 +08:00
|
|
|
|
public class ManiaPlayfield : Playfield<ManiaHitObject, ManiaJudgement>
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-05-11 11:33:19 +08:00
|
|
|
|
public const float HIT_TARGET_POSITION = 50;
|
|
|
|
|
|
2017-06-07 17:42:30 +08:00
|
|
|
|
private const double time_span_default = 1500;
|
|
|
|
|
public const double TIME_SPAN_MIN = 50;
|
|
|
|
|
public const double TIME_SPAN_MAX = 10000;
|
|
|
|
|
private const double time_span_step = 50;
|
2017-05-11 11:33:19 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
/// <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>
|
2017-05-03 19:11:24 +08:00
|
|
|
|
private static readonly Key[] default_keys = { Key.A, Key.S, Key.D, Key.F, Key.J, Key.K, Key.L, Key.Semicolon };
|
2017-05-03 18:38:15 +08:00
|
|
|
|
|
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-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-06-09 15:11:31 +08:00
|
|
|
|
private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default)
|
|
|
|
|
{
|
|
|
|
|
MinValue = TIME_SPAN_MIN,
|
|
|
|
|
MaxValue = TIME_SPAN_MAX
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly SpeedAdjustmentCollection barLineContainer;
|
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;
|
|
|
|
|
|
|
|
|
|
private readonly int columnCount;
|
|
|
|
|
|
2017-06-01 13:26:21 +08:00
|
|
|
|
public ManiaPlayfield(int columnCount)
|
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-05-03 11:37:47 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
2016-09-02 19:30:27 +08:00
|
|
|
|
{
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-05-29 13:44:42 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-11 19:04:28 +08:00
|
|
|
|
Masking = true,
|
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-05-29 13:44:42 +08:00
|
|
|
|
Name = "Masked elements",
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
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
|
|
|
|
|
{
|
|
|
|
|
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-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-05-29 13:44:42 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-05-11 11:33:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-16 16:34:41 +08:00
|
|
|
|
Padding = new MarginPadding { Top = HIT_TARGET_POSITION },
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-06-16 12:00:08 +08:00
|
|
|
|
barLineContainer = new SpeedAdjustmentCollection(Axes.Y)
|
2017-05-16 16:34:41 +08:00
|
|
|
|
{
|
|
|
|
|
Name = "Bar lines",
|
2017-05-29 13:44:42 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-06-09 21:03:28 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
VisibleTimeRange = visibleTimeRange
|
2017-05-29 13:44:42 +08:00
|
|
|
|
// Width is set in the Update method
|
2017-05-16 16:34:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
for (int i = 0; i < columnCount; i++)
|
2017-06-09 15:11:31 +08:00
|
|
|
|
columns.Add(new Column { VisibleTimeRange = visibleTimeRange });
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
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
|
|
|
|
|
for (int i = 0; i < columnCount; i++)
|
|
|
|
|
{
|
2017-05-22 14:27:38 +08:00
|
|
|
|
Column column = Columns.ElementAt(i);
|
2017-05-03 18:38:15 +08:00
|
|
|
|
column.IsSpecial = isSpecialColumn(i);
|
|
|
|
|
|
|
|
|
|
if (!column.IsSpecial)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-05-22 14:27:38 +08:00
|
|
|
|
column.Key.Value = Key.Space;
|
2017-05-03 18:38:15 +08:00
|
|
|
|
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
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
// We'll set the keys for non-special columns in another separate loop because it's not mirrored like the above colours
|
|
|
|
|
// Todo: This needs to go when we get to bindings and use Button1, ..., ButtonN instead
|
|
|
|
|
for (int i = 0; i < nonSpecialColumns.Count; i++)
|
2017-05-03 11:37:47 +08:00
|
|
|
|
{
|
2017-05-03 18:38:15 +08:00
|
|
|
|
Column column = nonSpecialColumns[i];
|
2017-05-03 11:37:47 +08:00
|
|
|
|
|
2017-05-03 18:38:15 +08:00
|
|
|
|
int keyOffset = default_keys.Length / 2 - nonSpecialColumns.Count / 2 + i;
|
|
|
|
|
if (keyOffset >= 0 && keyOffset < default_keys.Length)
|
2017-05-22 14:27:38 +08:00
|
|
|
|
column.Key.Value = default_keys[keyOffset];
|
2017-05-03 18:42:20 +08:00
|
|
|
|
else
|
|
|
|
|
// There is no default key defined for this column. Let's set this to Unknown for now
|
|
|
|
|
// however note that this will be gone after bindings are in place
|
2017-05-22 14:27:38 +08:00
|
|
|
|
column.Key.Value = Key.Unknown;
|
2017-05-03 11:37:47 +08:00
|
|
|
|
}
|
2017-05-03 18:38:15 +08:00
|
|
|
|
}
|
2017-05-03 11:37:47 +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
|
|
|
|
|
2017-05-22 14:27:38 +08:00
|
|
|
|
public override void Add(DrawableHitObject<ManiaHitObject, ManiaJudgement> h) => Columns.ElementAt(h.HitObject.Column).Add(h);
|
2017-05-29 14:18:06 +08:00
|
|
|
|
public void Add(DrawableBarLine barline) => barLineContainer.Add(barline);
|
2017-06-16 08:54:28 +08:00
|
|
|
|
public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.Add(speedAdjustment);
|
2017-05-11 11:33:19 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (state.Keyboard.ControlPressed)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Minus:
|
2017-06-09 15:11:31 +08:00
|
|
|
|
transformVisibleTimeRangeTo(visibleTimeRange + time_span_step, 200, EasingTypes.OutQuint);
|
2017-05-11 11:33:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case Key.Plus:
|
2017-06-09 15:11:31 +08:00
|
|
|
|
transformVisibleTimeRangeTo(visibleTimeRange - time_span_step, 200, EasingTypes.OutQuint);
|
2017-05-11 11:33:19 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 15:11:31 +08:00
|
|
|
|
private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, EasingTypes easing = EasingTypes.None)
|
2017-05-16 18:14:27 +08:00
|
|
|
|
{
|
2017-06-09 15:11:31 +08:00
|
|
|
|
TransformTo(() => visibleTimeRange.Value, newTimeRange, duration, easing, new TransformTimeSpan());
|
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-05-29 14:18:06 +08:00
|
|
|
|
barLineContainer.Width = columns.Width;
|
2017-05-29 13:44:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 18:14:27 +08:00
|
|
|
|
private class TransformTimeSpan : Transform<double>
|
|
|
|
|
{
|
|
|
|
|
public override double CurrentValue
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
double time = Time?.Current ?? 0;
|
|
|
|
|
if (time < StartTime) return StartValue;
|
|
|
|
|
if (time >= EndTime) return EndValue;
|
|
|
|
|
|
|
|
|
|
return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Apply(Drawable d)
|
|
|
|
|
{
|
|
|
|
|
base.Apply(d);
|
|
|
|
|
|
|
|
|
|
var p = (ManiaPlayfield)d;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
p.visibleTimeRange.Value = (float)CurrentValue;
|
2017-05-16 18:14:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-02 19:30:27 +08:00
|
|
|
|
}
|
2017-05-03 12:03:46 +08:00
|
|
|
|
}
|