Skip to content

Commit 76c2429

Browse files
committed
fix: preserve grouping controls on narrow mod rows
1 parent 4ae4def commit 76c2429

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

BetterModMenu.Tests/LogicTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,22 @@ public void GetTopBarPresentation_UsesIconOnlyActions()
509509
Assert.AreEqual(ModdingScreenConstants.TopBarButtonCompactWidth, wide.ButtonWidth);
510510
}
511511

512+
[TestMethod]
513+
public void ShouldShowRowMoveButtons_PreservesGroupPickerOnNarrowRows()
514+
{
515+
const float compactControlsWidth = 184f;
516+
const float exactThreshold =
517+
compactControlsWidth +
518+
ModdingScreenConstants.RowControlsRightPadding +
519+
ModdingScreenConstants.RowNativeTickboxReserveWidth +
520+
ModdingScreenConstants.RowMinimumCompactLeftContentWidth;
521+
522+
Assert.IsFalse(ModdingScreenLayoutRules.ShouldShowRowMoveButtons(rowWidth: 270f, compactControlsWidth));
523+
Assert.IsFalse(ModdingScreenLayoutRules.ShouldShowRowMoveButtons(rowWidth: exactThreshold - 1f, compactControlsWidth));
524+
Assert.IsTrue(ModdingScreenLayoutRules.ShouldShowRowMoveButtons(rowWidth: exactThreshold, compactControlsWidth));
525+
Assert.IsTrue(ModdingScreenLayoutRules.ShouldShowRowMoveButtons(rowWidth: 0f, compactControlsWidth));
526+
}
527+
512528
[TestMethod]
513529
public void Localization_UsesSts2LanguageCodesPlusVietnamese()
514530
{

BetterModMenu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Better Mod Menu",
44
"author": "Crunch",
55
"description": "Adds profile and grouping functionality to the Slay the Spire 2 mod manager.",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"min_game_version": "0.107.1",
88
"has_pck": false,
99
"has_dll": true,

Patches/ModdingScreenConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ internal static class ModdingScreenConstants
3434
public const float RowButtonSize = 32f;
3535
public const float RowDropdownWidth = 140f;
3636
public const float RowDropdownCompactWidth = 112f;
37+
public const float RowDropdownNarrowWidth = 80f;
3738
public const float RowControlsRightPadding = 12f;
3839
public const float RowNativeTickboxReserveWidth = 84f;
3940
public const float RowMinimumLeftContentWidth = 480f;
41+
public const float RowMinimumCompactLeftContentWidth = 160f;
4042
public const float RowGameplayIndicatorSlotWidth = 22f;
4143
public const float RowGameplayIndicatorSize = 14f;
4244
public const float GroupHeaderIconButtonSize = 34f;

Patches/ModdingScreenLayoutRules.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ internal readonly record struct TopBarPresentation(
1212

1313
internal static class ModdingScreenLayoutRules
1414
{
15+
public static bool ShouldShowRowMoveButtons(float rowWidth, float controlsWidth)
16+
{
17+
float trailingInset = ModdingScreenConstants.RowControlsRightPadding + ModdingScreenConstants.RowNativeTickboxReserveWidth;
18+
return rowWidth <= 0 ||
19+
rowWidth - trailingInset - controlsWidth >= ModdingScreenConstants.RowMinimumCompactLeftContentWidth;
20+
}
21+
1522
public static TopBarPresentation GetTopBarPresentation(bool isCompact)
1623
{
1724
return new TopBarPresentation(

Patches/NModMenuRowPatch.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public static void Postfix_Ready(NModMenuRow __instance)
104104

105105
container.AddChild(groupDropdown);
106106

107-
__instance.Resized += () => UpdateCustomControlsLayout(__instance, container, groupDropdown);
108-
Callable.From(() => UpdateCustomControlsLayout(__instance, container, groupDropdown)).CallDeferred();
107+
__instance.Resized += () => UpdateCustomControlsLayout(__instance, container, upBtn, downBtn, groupDropdown);
108+
Callable.From(() => UpdateCustomControlsLayout(__instance, container, upBtn, downBtn, groupDropdown)).CallDeferred();
109109
}
110110

111111
internal static void RefreshVisibleModNames(NModdingScreen screen)
@@ -347,7 +347,12 @@ private static void RemoveColoredNameLabel(Node root)
347347
return null;
348348
}
349349

350-
private static void UpdateCustomControlsLayout(NModMenuRow row, HBoxContainer container, OptionButton groupDropdown)
350+
private static void UpdateCustomControlsLayout(
351+
NModMenuRow row,
352+
HBoxContainer container,
353+
Button upButton,
354+
Button downButton,
355+
OptionButton groupDropdown)
351356
{
352357
if (!GodotObject.IsInstanceValid(row) || !GodotObject.IsInstanceValid(container))
353358
return;
@@ -361,6 +366,15 @@ private static void UpdateCustomControlsLayout(NModMenuRow row, HBoxContainer co
361366
groupDropdown.CustomMinimumSize = new Vector2(ModdingScreenConstants.RowDropdownCompactWidth, ModdingScreenConstants.ToolbarControlHeight);
362367
}
363368

369+
upButton.Visible = true;
370+
downButton.Visible = true;
371+
float compactControlsWidth = container.GetCombinedMinimumSize().X;
372+
bool showMoveButtons = ModdingScreenLayoutRules.ShouldShowRowMoveButtons(row.Size.X, compactControlsWidth);
373+
upButton.Visible = showMoveButtons;
374+
downButton.Visible = showMoveButtons;
375+
if (!showMoveButtons)
376+
groupDropdown.CustomMinimumSize = new Vector2(ModdingScreenConstants.RowDropdownNarrowWidth, ModdingScreenConstants.ToolbarControlHeight);
377+
364378
float width = container.GetCombinedMinimumSize().X;
365379
float height = container.GetCombinedMinimumSize().Y;
366380
container.SetAnchorsPreset(Control.LayoutPreset.CenterRight);

0 commit comments

Comments
 (0)