1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00

simplify column type check logic

This commit is contained in:
mcendu 2020-03-31 11:53:17 +08:00
parent e0a876ceaf
commit 323146e4a6
No known key found for this signature in database
GPG Key ID: FBCD5D45163D6364
4 changed files with 46 additions and 43 deletions

View File

@ -0,0 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Rulesets.Mania.Beatmaps
{
public enum ColumnType
{
Even,
Odd,
Special
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Beatmaps namespace osu.Game.Rulesets.Mania.Beatmaps
@ -21,5 +22,19 @@ namespace osu.Game.Rulesets.Mania.Beatmaps
/// <param name="column">The 0-based column index.</param> /// <param name="column">The 0-based column index.</param>
/// <returns>Whether the column is a special column.</returns> /// <returns>Whether the column is a special column.</returns>
public bool IsSpecialColumn(int column) => Columns % 2 == 1 && column == Columns / 2; public bool IsSpecialColumn(int column) => Columns % 2 == 1 && column == Columns / 2;
/// <summary>
/// Get the type of column given a column index.
/// </summary>
/// <param name="column">The 0-based column index.</param>
/// <returns>The type of the column.</returns>
public ColumnType GetTypeOfColumn(int column)
{
if (IsSpecialColumn(column))
return ColumnType.Special;
int distanceToEdge = Math.Min(column, (Columns - 1) - column);
return distanceToEdge % 2 == 1 ? ColumnType.Odd : ColumnType.Even;
}
} }
} }

View File

@ -16,6 +16,7 @@ using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using osu.Game.Rulesets.Mania.UI.Components; using osu.Game.Rulesets.Mania.UI.Components;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osuTK; using osuTK;
using osu.Game.Rulesets.Mania.Beatmaps;
namespace osu.Game.Rulesets.Mania.UI namespace osu.Game.Rulesets.Mania.UI
{ {
@ -101,22 +102,24 @@ namespace osu.Game.Rulesets.Mania.UI
public override Axes RelativeSizeAxes => Axes.Y; public override Axes RelativeSizeAxes => Axes.Y;
private bool isSpecial; private ColumnType columnType;
public bool IsSpecial public ColumnType ColumnType
{ {
get => isSpecial; get => columnType;
set set
{ {
if (isSpecial == value) if (columnType == value)
return; return;
isSpecial = value; columnType = value;
Width = isSpecial ? special_column_width : COLUMN_WIDTH; Width = IsSpecial ? special_column_width : COLUMN_WIDTH;
} }
} }
public bool IsSpecial => columnType == ColumnType.Special;
private Color4 accentColour; private Color4 accentColour;
public Color4 AccentColour public Color4 AccentColour

View File

@ -39,8 +39,12 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly Container topLevelContainer; private readonly Container topLevelContainer;
private List<Color4> normalColumnColours = new List<Color4>(); private readonly Dictionary<ColumnType, Color4> columnColours = new Dictionary<ColumnType, Color4>
private Color4 specialColumnColour; {
{ ColumnType.Even, new Color4(94, 0, 57, 255) },
{ ColumnType.Odd, new Color4(6, 84, 0, 255) },
{ ColumnType.Special, new Color4(0, 48, 63, 255) }
};
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos)); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Columns.Any(c => c.ReceivePositionalInputAt(screenSpacePos));
@ -125,11 +129,12 @@ namespace osu.Game.Rulesets.Mania.UI
for (int i = 0; i < definition.Columns; i++) for (int i = 0; i < definition.Columns; i++)
{ {
var isSpecial = definition.IsSpecialColumn(i); var columnType = definition.GetTypeOfColumn(i);
var column = new Column(firstColumnIndex + i) var column = new Column(firstColumnIndex + i)
{ {
IsSpecial = isSpecial, ColumnType = columnType,
Action = { Value = isSpecial ? specialColumnStartAction++ : normalColumnStartAction++ } AccentColour = columnColours[columnType],
Action = { Value = columnType == ColumnType.Special ? specialColumnStartAction++ : normalColumnStartAction++ }
}; };
AddColumn(column); AddColumn(column);
@ -195,38 +200,6 @@ namespace osu.Game.Rulesets.Mania.UI
}); });
} }
[BackgroundDependencyLoader]
private void load()
{
normalColumnColours = new List<Color4>
{
new Color4(94, 0, 57, 255),
new Color4(6, 84, 0, 255)
};
specialColumnColour = new Color4(0, 48, 63, 255);
// 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;
}
}
protected override void Update() protected override void Update()
{ {
// Due to masking differences, it is not possible to get the width of the columns container automatically // Due to masking differences, it is not possible to get the width of the columns container automatically