Skip to content

[New Feature] Minimize button for UI windows #8

@ghost

Description

@ghost

What will the fix solve? Please describe.

Some UI windows (e.g. the Part Manager) take up a lot of space and can require frequent interaction, and it can be annoying to keep opening and closing them

Describe the solution you'd like
A minimize button

Additional context

Maybe this would be suitable for this mod, to add minimize buttons to a few of the windows. At least for the Part Manager an initial solution has been implemented

image

  • Minimize reduces the window size (y) to 100, could maybe go further by removing the slider but it seems alright
  • Maximize restores size (y) to 900 max, or just above the bottom of the screen
  • An alternative icon could be used, it's set to null as I don't know how to access the other icons in the assets
[HarmonyPatch(typeof(PartsManagerCore), nameof(PartsManagerCore.Initialize))]
[HarmonyPostfix]
        public static void AddMinBtn(PartsManagerCore __instance) {

            // clone close button
            
            GameObject xBtn = __instance.transform.FindChildRecursive("BTN-Close")?.gameObject;
            if (xBtn == null) return;
            GameObject minBtn = UnityEngine.Object.Instantiate(xBtn, xBtn.transform.parent);
            minBtn.transform.SetSiblingIndex(minBtn.transform.parent.childCount - 2);

            // replace icon

            Image imageComp = minBtn.GetChild("Icon")?.GetComponent<Image>();
            if (imageComp != null) {
                imageComp.sprite = null; // replace with an icon instead ???
            }

            // add resize action

            UIAction_Void_Button actionComp = minBtn.GetComponent<UIAction_Void_Button>();
            if (actionComp != null) {
                actionComp.enabled = false;
                ButtonExtended btnComp = minBtn.GetComponent<ButtonExtended>();
                if (btnComp != null) {
                    btnComp.onClick.AddListener(delegate {
                        RectTransform tformComp = __instance.GetComponent<RectTransform>();
                        if (tformComp == null) return;
                        float botEdgePad = 18;
                        float minSizeY = 100;
                        float maxSizeY = Math.Min((Screen.height / 2) + minSizeY - botEdgePad + tformComp.localPosition.y, 900);
                        tformComp.localPosition = new Vector2(tformComp.localPosition.x,
                            tformComp.localPosition.y + (tformComp.sizeDelta.y == minSizeY ? -(maxSizeY - minSizeY) : tformComp.sizeDelta.y - minSizeY));
                        tformComp.sizeDelta = new Vector2 (tformComp.sizeDelta.x,
                            tformComp.sizeDelta.y == minSizeY ? maxSizeY : minSizeY);
                    });
                }
            }

        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions