Skip to content

Commit

Permalink
Merge pull request #25777 from peppy/fix-tablet-mania-column-sizing
Browse files Browse the repository at this point in the history
Fix column sizing exceeding screen width on tablets
  • Loading branch information
bdach committed Dec 15, 2023
2 parents 94f63d6 + df887ab commit 7caca90
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
Expand Down Expand Up @@ -100,16 +99,9 @@ public ManiaArgonSkinTransformer(ISkin skin, IBeatmap beatmap)
return SkinUtils.As<TValue>(new Bindable<float>(30));

case LegacyManiaSkinConfigurationLookups.ColumnWidth:

float width;

bool isSpecialColumn = stage.IsSpecialColumn(columnIndex);

// Best effort until we have better mobile support.
if (RuntimeInfo.IsMobile)
width = 170 * Math.Min(1, 7f / beatmap.TotalColumns) * (isSpecialColumn ? 1.8f : 1);
else
width = 60 * (isSpecialColumn ? 2 : 1);
float width = 60 * (isSpecialColumn ? 2 : 1);

return SkinUtils.As<TValue>(new Bindable<float>(width));

Expand Down
47 changes: 39 additions & 8 deletions osu.Game.Rulesets.Mania/UI/ColumnFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
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;
using osuTK;

namespace osu.Game.Rulesets.Mania.UI
{
Expand Down Expand Up @@ -60,6 +63,12 @@ private void load(ISkinSource skin)
onSkinChanged();
}

protected override void LoadComplete()
{
base.LoadComplete();
updateMobileSizing();
}

private void onSkinChanged()
{
for (int i = 0; i < stageDefinition.Columns; i++)
Expand All @@ -77,12 +86,15 @@ private void onSkinChanged()
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.ColumnWidth, i))
?.Value;

if (width == null)
// only used by default skin (legacy skins get defaults set in LegacyManiaSkinConfiguration)
columns[i].Width = stageDefinition.IsSpecialColumn(i) ? Column.SPECIAL_COLUMN_WIDTH : Column.COLUMN_WIDTH;
else
columns[i].Width = width.Value;
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;
}

updateMobileSizing();
}

/// <summary>
Expand All @@ -92,10 +104,29 @@ private void onSkinChanged()
/// <param name="content">The content.</param>
public void SetContentForColumn(int column, TContent content) => columns[column].Child = content;

public new MarginPadding Padding
private void updateMobileSizing()
{
get => base.Padding;
set => base.Padding = value;
if (!IsLoaded || !RuntimeInfo.IsMobile)
return;

// GridContainer+CellContainer containing this stage (gets split up for dual stages).
Vector2? containingCell = this.FindClosestParent<Stage>()?.Parent?.DrawSize;

// Will be null in tests.
if (containingCell == null)
return;

float aspectRatio = containingCell.Value.X / containingCell.Value.Y;

// 2.83 is a mostly arbitrary scale-up (170 / 60, based on original implementation for argon)
float mobileAdjust = 2.83f * Math.Min(1, 7f / stageDefinition.Columns);
// 1.92 is a "reference" mobile screen aspect ratio for phones.
// We should scale it back for cases like tablets which aren't so extreme.
mobileAdjust *= aspectRatio / 1.92f;

// Best effort until we have better mobile support.
for (int i = 0; i < stageDefinition.Columns; i++)
columns[i].Width *= mobileAdjust;
}

protected override void Dispose(bool isDisposing)
Expand Down

0 comments on commit 7caca90

Please sign in to comment.