From 456916f680c608acbd24ed3953e97e630a656551 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 15 Dec 2023 18:02:27 +0900 Subject: [PATCH 1/4] Fix column sizing exceeding screen width on tablets --- .../Argon/ManiaArgonSkinTransformer.cs | 10 +---- osu.Game.Rulesets.Mania/UI/ColumnFlow.cs | 45 +++++++++++++++---- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs b/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs index ca7f84cb4d..7f6540e7b5 100644 --- a/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs +++ b/osu.Game.Rulesets.Mania/Skinning/Argon/ManiaArgonSkinTransformer.cs @@ -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; @@ -100,16 +99,9 @@ namespace osu.Game.Rulesets.Mania.Skinning.Argon return SkinUtils.As(new Bindable(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(new Bindable(width)); diff --git a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs index 0bc0bf4caf..44c318a2c5 100644 --- a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs +++ b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs @@ -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 { @@ -60,6 +63,12 @@ namespace osu.Game.Rulesets.Mania.UI onSkinChanged(); } + protected override void LoadComplete() + { + base.LoadComplete(); + updateMobileSizing(); + } + private void onSkinChanged() { for (int i = 0; i < stageDefinition.Columns; i++) @@ -77,12 +86,15 @@ namespace osu.Game.Rulesets.Mania.UI 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(); } /// @@ -92,10 +104,27 @@ namespace osu.Game.Rulesets.Mania.UI /// The content. 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) + return; + + for (int i = 0; i < stageDefinition.Columns; i++) + { + // GridContainer+CellContainer containing this stage (gets split up for dual stages). + Vector2 containingCell = this.FindClosestParent().Parent!.DrawSize; + + // Best effort until we have better mobile support. + if (RuntimeInfo.IsMobile) + { + // These numbers are based on mobile phones, aspect ~1.92. + float mobileAdjust = 2.83f * Math.Min(1, 7f / stageDefinition.Columns); + // We should scale it back for cases like tablets which aren't so extreme. + mobileAdjust *= (containingCell.X / containingCell.Y) / 1.92f; + + columns[i].Width *= mobileAdjust; + } + } } protected override void Dispose(bool isDisposing) From eb5a8284f1200e80a8e9b616e68b8a056c8a84e2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 15 Dec 2023 19:15:25 +0900 Subject: [PATCH 2/4] Move mobile check earlier to avoid unnecessary looping --- osu.Game.Rulesets.Mania/UI/ColumnFlow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs index 44c318a2c5..f28619fb64 100644 --- a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs +++ b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs @@ -106,7 +106,7 @@ namespace osu.Game.Rulesets.Mania.UI private void updateMobileSizing() { - if (!IsLoaded) + if (!IsLoaded || !RuntimeInfo.IsMobile) return; for (int i = 0; i < stageDefinition.Columns; i++) From e8f3e52c9e0bccbe6f67f4904e4db0a45bd29f4b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 15 Dec 2023 19:17:48 +0900 Subject: [PATCH 3/4] Fix nullref failure in tests --- osu.Game.Rulesets.Mania/UI/ColumnFlow.cs | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs index f28619fb64..3ecd14ce81 100644 --- a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs +++ b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs @@ -109,22 +109,23 @@ namespace osu.Game.Rulesets.Mania.UI if (!IsLoaded || !RuntimeInfo.IsMobile) return; + // GridContainer+CellContainer containing this stage (gets split up for dual stages). + Vector2? containingCell = this.FindClosestParent()?.Parent?.DrawSize; + + // Will be null in tests. + if (containingCell == null) + return; + + float aspectRatio = containingCell.Value.X / containingCell.Value.Y; + + // These numbers are based on mobile phones, aspect ~1.92. + float mobileAdjust = 2.83f * Math.Min(1, 7f / stageDefinition.Columns); + // 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++) - { - // GridContainer+CellContainer containing this stage (gets split up for dual stages). - Vector2 containingCell = this.FindClosestParent().Parent!.DrawSize; - - // Best effort until we have better mobile support. - if (RuntimeInfo.IsMobile) - { - // These numbers are based on mobile phones, aspect ~1.92. - float mobileAdjust = 2.83f * Math.Min(1, 7f / stageDefinition.Columns); - // We should scale it back for cases like tablets which aren't so extreme. - mobileAdjust *= (containingCell.X / containingCell.Y) / 1.92f; - - columns[i].Width *= mobileAdjust; - } - } + columns[i].Width *= mobileAdjust; } protected override void Dispose(bool isDisposing) From 432ce275c4dad16cc1ad848bfbe4900445d0c8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 15 Dec 2023 20:43:18 +0100 Subject: [PATCH 4/4] Explain magic constants better --- osu.Game.Rulesets.Mania/UI/ColumnFlow.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs index 3ecd14ce81..8734f8ac8a 100644 --- a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs +++ b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs @@ -118,8 +118,9 @@ namespace osu.Game.Rulesets.Mania.UI float aspectRatio = containingCell.Value.X / containingCell.Value.Y; - // These numbers are based on mobile phones, aspect ~1.92. + // 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;