1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:17:27 +08:00

Rework Content storage in ColumnFlow

This commit is contained in:
Andrei Zavatski 2024-01-30 03:07:37 +03:00
parent 58bcef934b
commit 7dba870518
4 changed files with 21 additions and 20 deletions

View File

@ -91,7 +91,7 @@ namespace osu.Game.Rulesets.Mania.Tests
{
foreach (var stage in stages)
{
for (int i = 0; i < stage.Columns.Count; i++)
for (int i = 0; i < stage.Columns.Length; i++)
{
var obj = new Note { Column = i, StartTime = Time.Current + 2000 };
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
@ -105,7 +105,7 @@ namespace osu.Game.Rulesets.Mania.Tests
{
foreach (var stage in stages)
{
for (int i = 0; i < stage.Columns.Count; i++)
for (int i = 0; i < stage.Columns.Length; i++)
{
var obj = new HoldNote { Column = i, StartTime = Time.Current + 2000, Duration = 500 };
obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());

View File

@ -4,8 +4,6 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -28,20 +26,21 @@ namespace osu.Game.Rulesets.Mania.UI
/// <summary>
/// All contents added to this <see cref="ColumnFlow{TContent}"/>.
/// </summary>
public IReadOnlyList<TContent> Content => columns.Children.Select(c => c.Count == 0 ? null : (TContent)c.Child).ToList();
public TContent[] Content { get; }
private readonly FillFlowContainer<Container> columns;
private readonly FillFlowContainer<Container<TContent>> columns;
private readonly StageDefinition stageDefinition;
public ColumnFlow(StageDefinition stageDefinition)
{
this.stageDefinition = stageDefinition;
Content = new TContent[stageDefinition.Columns];
AutoSizeAxes = Axes.X;
Masking = true;
InternalChild = columns = new FillFlowContainer<Container>
InternalChild = columns = new FillFlowContainer<Container<TContent>>
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
@ -49,7 +48,7 @@ namespace osu.Game.Rulesets.Mania.UI
};
for (int i = 0; i < stageDefinition.Columns; i++)
columns.Add(new Container { RelativeSizeAxes = Axes.Y });
columns.Add(new Container<TContent> { RelativeSizeAxes = Axes.Y });
}
private ISkinSource currentSkin;
@ -102,7 +101,10 @@ namespace osu.Game.Rulesets.Mania.UI
/// </summary>
/// <param name="column">The index of the column to set the content of.</param>
/// <param name="content">The content.</param>
public void SetContentForColumn(int column, TContent content) => columns[column].Child = content;
public void SetContentForColumn(int column, TContent content)
{
Content[column] = columns[column].Child = content;
}
private void updateMobileSizing()
{

View File

@ -71,7 +71,7 @@ namespace osu.Game.Rulesets.Mania.UI
stages.Add(newStage);
AddNested(newStage);
firstColumnIndex += newStage.Columns.Count;
firstColumnIndex += newStage.Columns.Length;
}
}
@ -125,9 +125,9 @@ namespace osu.Game.Rulesets.Mania.UI
foreach (var stage in stages)
{
if (index >= stage.Columns.Count)
if (index >= stage.Columns.Length)
{
index -= stage.Columns.Count;
index -= stage.Columns.Length;
continue;
}
@ -140,7 +140,7 @@ namespace osu.Game.Rulesets.Mania.UI
/// <summary>
/// Retrieves the total amount of columns across all stages in this playfield.
/// </summary>
public int TotalColumns => stages.Sum(s => s.Columns.Count);
public int TotalColumns => stages.Sum(s => s.Columns.Length);
private Stage getStageByColumn(int column)
{
@ -148,7 +148,7 @@ namespace osu.Game.Rulesets.Mania.UI
foreach (var stage in stages)
{
sum += stage.Columns.Count;
sum += stage.Columns.Length;
if (sum > column)
return stage;
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
@ -37,7 +36,7 @@ namespace osu.Game.Rulesets.Mania.UI
public const float HIT_TARGET_POSITION = 110;
public IReadOnlyList<Column> Columns => columnFlow.Content;
public Column[] Columns => columnFlow.Content;
private readonly ColumnFlow<Column> columnFlow;
private readonly JudgementContainer<DrawableManiaJudgement> judgements;
@ -184,13 +183,13 @@ namespace osu.Game.Rulesets.Mania.UI
NewResult += OnNewResult;
}
public override void Add(HitObject hitObject) => Columns.ElementAt(((ManiaHitObject)hitObject).Column - firstColumnIndex).Add(hitObject);
public override void Add(HitObject hitObject) => Columns[((ManiaHitObject)hitObject).Column - firstColumnIndex].Add(hitObject);
public override bool Remove(HitObject hitObject) => Columns.ElementAt(((ManiaHitObject)hitObject).Column - firstColumnIndex).Remove(hitObject);
public override bool Remove(HitObject hitObject) => Columns[((ManiaHitObject)hitObject).Column - firstColumnIndex].Remove(hitObject);
public override void Add(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Add(h);
public override void Add(DrawableHitObject h) => Columns[((ManiaHitObject)h.HitObject).Column - firstColumnIndex].Add(h);
public override bool Remove(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Remove(h);
public override bool Remove(DrawableHitObject h) => Columns[((ManiaHitObject)h.HitObject).Column - firstColumnIndex].Remove(h);
public void Add(BarLine barLine) => base.Add(barLine);