-
Notifications
You must be signed in to change notification settings - Fork 32
QoL improvements for parts with a large number of subtypes #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9702aa2
76824bf
a913cdd
ba5749a
c87dafe
c4174fb
a67e74f
2582f45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could put the width in a constant somewhere and derive the rest of the numbers from it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the 28 unit button width already accessible somewhere? I couldn't find it, but maybe I'm just not looking in the right place. Everything I tried is still 0 or 1 when this code runs. Without that, it's two constants (viewportWidth and buttonWidth) that would be needed. I could certainly do it that way. Let me know what you think/prefer.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of it being accessible anywhere. I could go either way on this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unavoidably awkward either way, but overall I think a single viewportWidthInButtons constant is preferable to splitting it into two (e.g., viewportWidth and buttonWidth). We only ever need the ratio (viewportWidth / buttonWidth); there's currently no use for either part individually. I think there's more risk of confusion for future contributors with viewportWidth and buttonWidth, whereas viewportWidthInButtons sounds like a special-purpose value that shouldn't be used for anything else. |
||
| 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() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.