Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions B9PartSwitch/B9PartSwitch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Reference Include="UnityEngine.CoreModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<Private>False</Private>
</Reference>
Expand Down
25 changes: 24 additions & 1 deletion B9PartSwitch/PartSwitch/PartSwitchFlightDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using TMPro;
using B9PartSwitch.UI;
using UnityEngine;
using UnityEngine.UI;

namespace B9PartSwitch
{
Expand Down Expand Up @@ -76,6 +78,8 @@ private static DialogGUIBase[] CreateOptions(ModuleB9PartSwitch module, IList<Ca

SwitcherSubtypeDescriptionGenerator subtypeDescriptionGenerator = new SwitcherSubtypeDescriptionGenerator(module);

options.Add(new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize));

foreach (PartSubtype subtype in module.subtypes)
{
if (!subtype.IsUnlocked()) continue;
Expand Down Expand Up @@ -104,7 +108,26 @@ private static DialogGUIBase[] CreateOptions(ModuleB9PartSwitch module, IList<Ca

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

return options.ToArray();
const float buttonHeight = 35;
if (buttonHeight * options.Count < 0.75f * Screen.height) return options.ToArray();

DialogGUIBase[] scrollList = {
new DialogGUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize),
new DialogGUIScrollList(
new Vector2(1, 0.75f * Screen.height),
false,
true,
new DialogGUIVerticalLayout(
true,
true,
4,
new RectOffset(6, 24, 10, 10),
TextAnchor.MiddleCenter,
options.ToArray()
)
)
};
return scrollList;
}
}
}
15 changes: 15 additions & 0 deletions B9PartSwitch/UI/UIPartActionSubtypeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ public override void Setup(UIPartActionWindow window, Part part, PartModule part
subtypeTitleText.text = switcherModule.CurrentSubtype.title;

subtypeButtons[currentButtonIndex].Activate();

// up to 7 subtypeButtons fit in the PAW without scrolling
if (subtypeButtons.Count > 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()
Expand Down