@@ -492,11 +492,10 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
492492
493493 if (! showAll && ! shouldFeatureAppear(feature)) continue
494494
495- val featureElement = createFeatureElement(feature, subcategoryComponent)
495+ // Create the feature element, containing the title, description and config type
496+ createFeatureElement(feature, subcategoryComponent)
496497
497- if (featureElement != null ) {
498- drawnFeatures++
499- }
498+ drawnFeatures++
500499 }
501500 // Don't draw subcategory title if no features
502501 if (drawnFeatures != 0 ) {
@@ -506,7 +505,7 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
506505 }
507506 }
508507
509- // Populate the feature-options after all features have been created
508+ // After all features have been loaded, go back through and populate the parent features with their options
510509
511510 // Loop through all categories
512511 for (category in ConfigManager .categories) {
@@ -515,6 +514,7 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
515514 // Loop through all features in subcategory
516515 for (feature in subcategory.features.values) {
517516 if (! showAll && feature.parentName.isEmpty()) continue
517+
518518 // Ensure that the features option has a real parent
519519 if (feature.parentFeature == null ) {
520520 if (feature.parentName.isNotEmpty()) {
@@ -533,8 +533,9 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
533533 if (featureOption != null ) {
534534 // Add feature to parent's reference so it can be hidden / unhidden in future
535535 feature.parentFeature!! .optionElements[feature.name] = featureOption
536- // Hide suboptions by default
537- featureOption.featureComponent.hide(true )
536+
537+ // Hide sub options so original height is not affected
538+ featureOption.featureAndOptionsComponent.hide(true )
538539 }
539540 }
540541 }
@@ -575,55 +576,60 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
575576 return false
576577 }
577578
579+ // Used to create main feature, which contains the title, description and config type
578580 private fun createFeatureElement (
579581 feature : ConfigManager .Feature ,
580582 subcategoryComponent : UIComponent
581- ): ConfigManager .Feature ? {
582-
583- val featureContainer = UIContainer ().constrain {
583+ ): ConfigManager .Feature {
584+ // This is the main ui element, everything else is a child of this, and when options are present, they are cut off by this element when not expanded
585+ val featureAndOptionsContainer = UIContainer ().constrain {
584586 x = CenterConstraint ()
585587 y = SiblingConstraintFixed (6f )
586588 width = 99 .percent
587589 height = ChildBasedSizeConstraint (2f )
588590 } childOf subcategoryComponent effect ScissorEffect ()
589591
590- val featureBackground =
592+ // Create the background for the feature and options container
593+ val featureAndOptionsBackground =
591594 OutlinedRoundedRectangle (featureBorderColorState.get().colorState.constraint, 1f , 6f ).constrain {
592595 x = CenterConstraint ()
593596 y = SiblingConstraintFixed (6f )
594597 width = if (feature.parentName.isEmpty()) 100 .percent else 90 .percent
595598 height = ChildBasedSizeConstraint (2f )
596599 color = featureBackgroundColorState.get().colorState.constraint
597- } childOf featureContainer
600+ } childOf featureAndOptionsContainer
598601
599- val secondContainer = UIContainer ().constrain {
602+ // The feature container, which contains the title, description
603+ val featureContainer = UIContainer ().constrain {
600604 x = PixelConstraint (0f )
601605 y = SiblingConstraintFixed (6f )
602606 width = 100 .percent
603607 height = ChildBasedSizeConstraint (2f )
604- } childOf featureBackground
608+ } childOf featureAndOptionsBackground
605609
606610 val featureTitle = CustomUIText (feature.name, scale = 1.5f ).constrain {
607611 x = 3 .pixels
608612 y = 3 .pixels
609- } childOf secondContainer
613+ } childOf featureContainer
610614
611615 if (feature.description != " " ) {
612616 val featureDescription = CustomUIWrappedText (feature.description).constrain {
613617 x = 3 .pixels
614618 y = SiblingConstraintFixed (2f )
615619 width = 80 .percent - 2 .pixels
616620 color = Color .GRAY .constraint
617- } childOf secondContainer
621+ } childOf featureContainer
618622 }
619623
620- populateFeature(feature, secondContainer)
624+ // Populate the feature with its config type, ie toggle, text input, etc.
625+ populateFeature(feature, featureContainer)
621626
622- feature.featureComponent = featureContainer
627+ feature.featureAndOptionsComponent = featureAndOptionsContainer
623628
624629 return feature
625630 }
626631
632+ // Create a feature option element, which is a child of the parent feature, and contains the title, description and config type
627633 private fun createFeatureOptionElement (
628634 feature : ConfigManager .Feature
629635 ): ConfigManager .Feature ? {
@@ -632,7 +638,7 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
632638 return null
633639 }
634640
635- val parentComponent = feature.parentFeature!! .featureComponent
641+ val parentComponent = feature.parentFeature!! .featureAndOptionsComponent
636642
637643 val parentFeatureBackground = parentComponent.children.getOrNull(0 ) ? : return null
638644
@@ -662,7 +668,7 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
662668
663669 populateFeature(feature, featureContainer)
664670
665- feature.featureComponent = featureContainer
671+ feature.featureAndOptionsComponent = featureContainer
666672
667673 return feature
668674 }
@@ -940,6 +946,7 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
940946 ignoredHeights.add(button)
941947 }
942948
949+ // Give parents a settings gear if they have options, allowing for expanding and collapsing of options
943950 if (feature.isParent) {
944951 val unhovered = Color (200 , 200 , 200 )
945952 val hovered = Color (255 , 255 , 255 )
@@ -962,33 +969,45 @@ class ConfigGui : WindowScreen(ElementaVersion.V2, newGuiScale = 2, drawDefaultB
962969 setColorAnimation(Animations .OUT_EXP , 0.5f , unhovered.constraint)
963970 }
964971 }
965- var orignalHeight = 0 .pixels
972+
973+ // Calculate the height of the feature, waits 500ms because the components must be rendered first
974+ var smallSizeHeight = 0 .pixels
966975
967976 Utils .setTimeout({
968- orignalHeight = feature.featureComponent .getHeight().pixels
977+ smallSizeHeight = feature.featureAndOptionsComponent .getHeight().pixels
969978 }, 500 )
970979
980+ // Hides the color picker if it is open
971981 clearPopup()
972982
983+ // On click, toggle the options hidden state
973984 settingsGear.onMouseClick {
974985 feature.optionsHidden = ! feature.optionsHidden
986+
987+ // Rotate the settings gear
975988 settingsGear.setTargetAngle(if (feature.optionsHidden) 0f else 90f )
976989
990+ // Hides the color picker if it is open
977991 clearPopup()
978992
979- val parentFeatureBackground = feature.featureComponent.children.getOrNull(0 )
993+ val featureBackground = feature.featureAndOptionsComponent.children.getOrNull(0 )
994+
980995 if (! feature.optionsHidden) {
981- parentFeatureBackground?.setHeight(orignalHeight)
982- parentFeatureBackground?.animate {
996+ // If the feature is being expanded, set the height to the small size height, then animate to the full height
997+ featureBackground?.setHeight(smallSizeHeight)
998+ featureBackground?.animate {
983999 setHeightAnimation(Animations .IN_OUT_EXP , 0.35f , ChildBasedSizeConstraint (2f ), 0f )
9841000 }
1001+
1002+ // Unhide all the options in the feature
9851003 feature.optionElements.values.forEach {
986- it.featureComponent .unhide(true )
1004+ it.featureAndOptionsComponent .unhide(true )
9871005 }
9881006 } else {
989- parentFeatureBackground?.setHeight(feature.featureComponent.getHeight().pixels)
990- parentFeatureBackground?.animate {
991- setHeightAnimation(Animations .IN_OUT_EXP , 0.35f , orignalHeight, 0f )
1007+ // If the feature is being collapsed, set the height to the full height, then animate to the small size height
1008+ featureBackground?.setHeight(feature.featureAndOptionsComponent.getHeight().pixels)
1009+ featureBackground?.animate {
1010+ setHeightAnimation(Animations .IN_OUT_EXP , 0.35f , smallSizeHeight, 0f )
9921011 }
9931012 }
9941013 }
0 commit comments