2020-08-25 00:21:27 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-08-25 00:21:27 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Mania.Skinning;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A <see cref="Drawable"/> which flows its contents according to the <see cref="Column"/>s in a <see cref="Stage"/>.
|
2020-08-25 17:44:32 +08:00
|
|
|
/// Content can be added to individual columns via <see cref="SetContentForColumn"/>.
|
2020-08-25 00:21:27 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TContent">The type of content in each column.</typeparam>
|
|
|
|
public partial class ColumnFlow<TContent> : CompositeDrawable
|
|
|
|
where TContent : Drawable
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// All contents added to this <see cref="ColumnFlow{TContent}"/>.
|
|
|
|
/// </summary>
|
2024-01-30 08:07:37 +08:00
|
|
|
public TContent[] Content { get; }
|
2020-08-25 00:21:27 +08:00
|
|
|
|
2024-01-30 08:07:37 +08:00
|
|
|
private readonly FillFlowContainer<Container<TContent>> columns;
|
2020-08-25 00:21:27 +08:00
|
|
|
private readonly StageDefinition stageDefinition;
|
|
|
|
|
2024-11-12 17:07:27 +08:00
|
|
|
public new bool Masking
|
|
|
|
{
|
|
|
|
get => base.Masking;
|
|
|
|
set => base.Masking = value;
|
|
|
|
}
|
|
|
|
|
2020-08-25 00:21:27 +08:00
|
|
|
public ColumnFlow(StageDefinition stageDefinition)
|
|
|
|
{
|
|
|
|
this.stageDefinition = stageDefinition;
|
2024-01-30 08:07:37 +08:00
|
|
|
Content = new TContent[stageDefinition.Columns];
|
2020-08-25 00:21:27 +08:00
|
|
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
2022-10-06 17:03:48 +08:00
|
|
|
Masking = true;
|
|
|
|
|
2024-01-30 08:07:37 +08:00
|
|
|
InternalChild = columns = new FillFlowContainer<Container<TContent>>
|
2020-08-25 00:21:27 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < stageDefinition.Columns; i++)
|
2024-01-30 08:07:37 +08:00
|
|
|
columns.Add(new Container<TContent> { RelativeSizeAxes = Axes.Y });
|
2020-08-25 00:21:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private ISkinSource currentSkin;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin)
|
|
|
|
{
|
|
|
|
currentSkin = skin;
|
|
|
|
|
|
|
|
skin.SourceChanged += onSkinChanged;
|
|
|
|
onSkinChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onSkinChanged()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < stageDefinition.Columns; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
float spacing = currentSkin.GetConfig<ManiaSkinConfigurationLookup, float>(
|
2022-10-06 13:10:39 +08:00
|
|
|
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.ColumnSpacing, i - 1))
|
2020-08-25 00:21:27 +08:00
|
|
|
?.Value ?? Stage.COLUMN_SPACING;
|
|
|
|
|
|
|
|
columns[i].Margin = new MarginPadding { Left = spacing };
|
|
|
|
}
|
|
|
|
|
|
|
|
float? width = currentSkin.GetConfig<ManiaSkinConfigurationLookup, float>(
|
2022-10-06 13:10:39 +08:00
|
|
|
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.ColumnWidth, i))
|
2020-08-25 00:21:27 +08:00
|
|
|
?.Value;
|
|
|
|
|
2023-12-15 17:02:27 +08:00
|
|
|
bool isSpecialColumn = stageDefinition.IsSpecialColumn(i);
|
|
|
|
|
|
|
|
// only used by default skin (legacy skins get defaults set in LegacyManiaSkinConfiguration)
|
|
|
|
width ??= isSpecialColumn ? Column.SPECIAL_COLUMN_WIDTH : Column.COLUMN_WIDTH;
|
|
|
|
|
|
|
|
columns[i].Width = width.Value;
|
2020-08-25 00:21:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Sets the content of one of the columns of this <see cref="ColumnFlow{TContent}"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="column">The index of the column to set the content of.</param>
|
|
|
|
/// <param name="content">The content.</param>
|
2024-01-30 08:07:37 +08:00
|
|
|
public void SetContentForColumn(int column, TContent content)
|
|
|
|
{
|
|
|
|
Content[column] = columns[column].Child = content;
|
|
|
|
}
|
2020-08-25 00:21:27 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (currentSkin != null)
|
|
|
|
currentSkin.SourceChanged -= onSkinChanged;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|