diff --git a/B9PartSwitch/B9PartSwitch.csproj b/B9PartSwitch/B9PartSwitch.csproj index c8d15c94..3f15cc6e 100644 --- a/B9PartSwitch/B9PartSwitch.csproj +++ b/B9PartSwitch/B9PartSwitch.csproj @@ -46,6 +46,9 @@ False + + False + False diff --git a/B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs b/B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs index 3df83646..0f5bf0fe 100644 --- a/B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs +++ b/B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs @@ -3,6 +3,8 @@ using System.Linq; using TMPro; using B9PartSwitch.UI; +using UnityEngine; +using UnityEngine.UI; namespace B9PartSwitch { @@ -76,6 +78,8 @@ private static DialogGUIBase[] CreateOptions(ModuleB9PartSwitch module, IList 7) + { + scrollMain.scrollSensitivity = subtypeButtons.Count; + // scrollMain.horizontalNormalizedPosition is the left edge of the viewport relative to the content. + // 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. + // Each button is effectively 28 units wide, meaning the viewport is 7+(1/6) buttons wide. + // If we scroll past the last button, the buttons will bounce back so that the last button is touching the viewport's right edge. + // 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. + const float viewportWidthInButtons = 7+1/6f; + if (currentButtonIndex < 4) scrollMain.horizontalNormalizedPosition = 0f; + else if (subtypeButtons.Count - currentButtonIndex < 5) scrollMain.horizontalNormalizedPosition = (subtypeButtons.Count - viewportWidthInButtons) / subtypeButtons.Count; + else scrollMain.horizontalNormalizedPosition = (currentButtonIndex + 4 - viewportWidthInButtons) / subtypeButtons.Count; + } } private void PreviousSubtype()