Esempio n. 1
0
 public static void Postfix(MechLabPanel __instance)
 {
     try
     {
         MechLabLayoutUtils.FixMechLabLayouts(__instance);
         CustomWidgetsFixMechLab.Setup(__instance);
         MechLabMoveUIElements.MoveMechUIElements(__instance);
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
 }
    internal static void MoveMechRoleInfo(MechLabPanel panel)
    {
        var armWidget = panel.rightArmWidget;

        var finder         = new MechLabLayoutFinder(panel);
        var layout_details = finder.LayoutDetails ?? armWidget.transform.Find("layout_details");

        if (layout_details == null)
        {
            return;
        }

        var go = layout_details.gameObject;

        go.SetActive(!panel.IsSimGame);

        if (layout_details.parent == armWidget.transform)
        {
            return;
        }

        var arm = armWidget.transform.parent;

        MechLabLayoutUtils.EnableLayout(arm.gameObject);
        {
            var component = go.GetComponent <RectTransform>();
            component.pivot            = new(0, 1);
            component.anchorMin        = new(0, 0);
            component.anchorMax        = new(0, 0);
            component.anchoredPosition = new(0, -40);
        }
        {
            var component = go.GetComponent <LayoutElement>() ?? go.AddComponent <LayoutElement>();
            component.ignoreLayout = true;
            component.enabled      = true;
        }
        layout_details.transform.SetParent(arm.transform, false);
    }
    private static void SetupCapacitiesLayout(MechDef mechDef, LocalizableText remainingTonnage)
    {
        var layoutTonnage    = remainingTonnage.transform.parent;
        var objStatus        = layoutTonnage.parent;
        var customCapacities = objStatus.Find("custom_capacities");

        if (customCapacities == null)
        {
            {
                var layoutHardpoints = objStatus.Find("layout_hardpoints");
                MechLabLayoutUtils.NormalizeRectTransform(layoutHardpoints.gameObject);
            }

            var go = new GameObject("custom_capacities");

            go.AddComponent <Image>();
            var tracker = go.AddComponent <UIColorRefTracker>();
            tracker.SetUIColor(UIColor.DarkGray);

            var group = go.AddComponent <VerticalLayoutGroup>();
            group.childForceExpandHeight = group.childForceExpandWidth = false;
            group.childControlHeight     = group.childControlWidth = true;
            group.childAlignment         = TextAnchor.UpperRight;
            group.spacing = 5;
            group.padding = new(0, 0, 5, 5);

            var fitter = go.AddComponent <ContentSizeFitter>();
            fitter.horizontalFit = fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;

            MechLabLayoutUtils.NormalizeRectTransform(go);

            customCapacities = go.transform;
            customCapacities.SetParent(objStatus, false);
            customCapacities.SetSiblingIndex(1);
        }

        void SetCapacity(CustomCapacitiesSettings.CustomCapacity customCapacity, ref int shownCounter)
        {
            var id      = customCapacity.Description.Id;
            var element = customCapacities.Find(id)?.GetComponent <CustomCapacityUIElement>();

            if (element == null)
            {
                var go = new GameObject(id);
                element = go.AddComponent <CustomCapacityUIElement>();
                go.transform.SetParent(customCapacities, false);
            }

            {
                CustomCapacitiesFeature.Shared.CalculateCustomCapacityResults(
                    mechDef,
                    customCapacity,
                    out var description,
                    out var text,
                    out var color,
                    out var show
                    );

                element.SetData(description, text, color);

                if (show)
                {
                    shownCounter++;
                }
                element.gameObject.SetActive(show);
            }
        }

        var shownCounter = 0;

        SetCapacity(CustomCapacitiesFeature.Shared.Settings.CarryWeight, ref shownCounter);
        foreach (var customCapacity in CustomCapacitiesFeature.Shared.Settings.Capacities)
        {
            SetCapacity(customCapacity, ref shownCounter);
        }
        customCapacities.gameObject.SetActive(shownCounter > 0);
    }