Skip to content

Commit 5b5d8f8

Browse files
Merge branch 'master' of github.com:Scialytic/B9PartSwitch into Scialytic-master
2 parents e441b3a + 2582f45 commit 5b5d8f8

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

B9PartSwitch/B9PartSwitch.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,4 @@ if $(ConfigurationName) == Release (
215215
<Target Name="AfterBuild">
216216
</Target>
217217
-->
218-
</Project>
218+
</Project>

B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using TMPro;
55
using B9PartSwitch.UI;
6+
using UnityEngine;
7+
using UnityEngine.UI;
68

79
namespace B9PartSwitch
810
{
@@ -76,6 +78,8 @@ private static DialogGUIBase[] CreateOptions(ModuleB9PartSwitch module, IList<Ca
7678

7779
SwitcherSubtypeDescriptionGenerator subtypeDescriptionGenerator = new SwitcherSubtypeDescriptionGenerator(module);
7880

81+
options.Add(new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize));
82+
7983
foreach (PartSubtype subtype in module.subtypes)
8084
{
8185
if (!subtype.IsUnlocked()) continue;
@@ -104,7 +108,26 @@ private static DialogGUIBase[] CreateOptions(ModuleB9PartSwitch module, IList<Ca
104108

105109
options.Add(new DialogGUIButton(Localization.PartSwitchFlightDialog_CancelString, delegate { } ));
106110

107-
return options.ToArray();
111+
const float buttonHeight = 35;
112+
if (buttonHeight * options.Count < 0.75f * Screen.height) return options.ToArray();
113+
114+
DialogGUIBase[] scrollList = {
115+
new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize),
116+
new DialogGUIScrollList(
117+
new Vector2(1, 0.75f * Screen.height),
118+
false,
119+
true,
120+
new DialogGUIVerticalLayout(
121+
true,
122+
true,
123+
4,
124+
new RectOffset(6, 24, 10, 10),
125+
TextAnchor.MiddleCenter,
126+
options.ToArray()
127+
)
128+
)
129+
};
130+
return scrollList;
108131
}
109132
}
110133
}

B9PartSwitch/UI/UIPartActionSubtypeSelector.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ public override void Setup(UIPartActionWindow window, Part part, PartModule part
111111
subtypeTitleText.text = switcherModule.CurrentSubtype.title;
112112

113113
subtypeButtons[currentButtonIndex].Activate();
114+
115+
// up to 7 subtypeButtons fit in the PAW without scrolling
116+
if (subtypeButtons.Count > 7)
117+
{
118+
scrollMain.scrollSensitivity = subtypeButtons.Count;
119+
// scrollMain.horizontalNormalizedPosition is the left edge of the viewport relative to the content.
120+
// scrollMain.viewport.rect.width will be 200+(2/3) units after layout stuff is finished. Sadly, it is 0 when this code runs so we can't make use of it here.
121+
// Each button is effectively 28 units wide, meaning the viewport is 7+(1/6) buttons wide.
122+
// If we scroll past the last button, the buttons will bounce back so that the last button is touching the viewport's right edge.
123+
// That bounce could make a player lose their place in the button list (plus it just looks bad). Therefore, we don't use 1.0 to set the viewport full right.
124+
const float viewportWidthInButtons = 7+1/6f;
125+
if (currentButtonIndex < 4) scrollMain.horizontalNormalizedPosition = 0f;
126+
else if (subtypeButtons.Count - currentButtonIndex < 5) scrollMain.horizontalNormalizedPosition = (subtypeButtons.Count - viewportWidthInButtons) / subtypeButtons.Count;
127+
else scrollMain.horizontalNormalizedPosition = (currentButtonIndex + 4 - viewportWidthInButtons) / subtypeButtons.Count;
128+
}
114129
}
115130

116131
private void PreviousSubtype()

0 commit comments

Comments
 (0)