internal static void Setup(MechLabPanel mechLabPanel) { if (PropertiesWidget != null) { PropertiesWidget.gameObject.transform.SetParent(mechLabPanel.rightArmWidget.transform, false); PropertiesWidget.Init(mechLabPanel); return; } { var template = mechLabPanel.centerTorsoWidget; var container = mechLabPanel.rightArmWidget.transform.parent.gameObject; var clg = container.GetComponent <VerticalLayoutGroup>(); //clg.spacing = 20; clg.padding = new RectOffset(0, 0, MechLabSlotsFeature.settings.MechLabArmTopPadding, 0); var go = UnityEngine.Object.Instantiate(template.gameObject, null); //go.transform.SetAsFirstSibling(); { //go.EnableLayout(); go.transform.SetParent(mechLabPanel.rightArmWidget.transform, false); go.GetComponent <LayoutElement>().ignoreLayout = true; go.transform.GetChild("layout_armor").gameObject.SetActive(false); go.transform.GetChild("layout_hardpoints").gameObject.SetActive(false); go.transform.GetChild("layout_locationText").GetChild("txt_structure").gameObject.SetActive(false); var rect = go.GetComponent <RectTransform>(); rect.pivot = new Vector2(0, 0); rect.localPosition = new Vector3(0, 20); } go.name = "MechPropertiesWidget"; go.transform.GetChild("layout_locationText").GetChild("txt_location").GetComponent <TextMeshProUGUI>().text = MechLabSlotsFeature.settings.MechLabGeneralWidgetLabel; go.SetActive(MechLabSlotsFeature.settings.MechLabGeneralWidgetEnabled); PropertiesWidget = go.GetComponent <MechLabLocationWidget>(); PropertiesWidget.Init(mechLabPanel); var layout = new WidgetLayout(PropertiesWidget); // doesnt work with highlight frame //layout.layout_slots_glg.padding.top = 8; //layout.layout_slottedComponents_vlg.padding.top = 8; // doesnt work at all //var emptySpace = new GameObject("Cool GameObject made from Code"); //var emptySpaceRect = emptySpace.AddComponent<RectTransform>(); //emptySpaceRect.sizeDelta = new Vector2(1, 8); //emptySpace.AddComponent<LayoutElement>(); //emptySpace.transform.SetParent(layout.layout_slots, false); //emptySpace.transform.SetAsFirstSibling(); //emptySpace.SetActive(true); MechLabSlotsFixer.ModifyLayoutSlotCount(layout, MechLabSlotsFeature.settings.MechLabGeneralSlots); } { var mechRectTransform = mechLabPanel.leftArmWidget.transform.parent.parent.GetComponent <RectTransform>(); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); } }
internal static void Setup(MechLabPanel mechLabPanel) { if (PropertiesWidget != null) { PropertiesWidget.gameObject.transform.SetParent(mechLabPanel.rightArmWidget.transform, false); PropertiesWidget.Init(mechLabPanel); return; } { var template = mechLabPanel.centerTorsoWidget; var container = mechLabPanel.rightArmWidget.transform.parent.gameObject; var clg = container.GetComponent <VerticalLayoutGroup>(); clg.padding = new RectOffset(0, 0, MechLabSlotsFeature.settings.MechLabArmTopPadding, 0); var go = UnityEngine.Object.Instantiate(template.gameObject, null); { go.transform.SetParent(mechLabPanel.rightArmWidget.transform, false); go.GetComponent <LayoutElement>().ignoreLayout = true; go.transform.GetChild("layout_armor").gameObject.SetActive(false); go.transform.GetChild("layout_hardpoints").gameObject.SetActive(false); go.transform.GetChild("layout_locationText").GetChild("txt_structure").gameObject.SetActive(false); var rect = go.GetComponent <RectTransform>(); rect.pivot = new Vector2(0, 0); rect.localPosition = new Vector3(0, 20); var vlg = go.GetComponent <VerticalLayoutGroup>(); vlg.padding = new RectOffset(0, 0, 0, 3); vlg.spacing = 4; } go.name = "MechPropertiesWidget"; go.transform.GetChild("layout_locationText").GetChild("txt_location").GetComponent <TextMeshProUGUI>().text = MechLabSlotsFeature.settings.MechLabGeneralWidgetLabel; go.SetActive(MechLabSlotsFeature.settings.MechLabGeneralWidgetEnabled); PropertiesWidget = go.GetComponent <MechLabLocationWidget>(); PropertiesWidget.Init(mechLabPanel); var layout = new WidgetLayout(PropertiesWidget); MechLabSlotsFixer.ModifyLayoutSlotCount(layout, MechLabSlotsFeature.settings.MechLabGeneralSlots); } { var mechRectTransform = mechLabPanel.leftArmWidget.transform.parent.parent.GetComponent <RectTransform>(); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); } }
public static void Postfix(MechLabPanel __instance) { if (MechPropertiesWidget != null) { return; } try { var mechLabPanel = __instance; var Representation = mechLabPanel.transform.GetChild("Representation"); var OBJ_mech = Representation.GetChild("OBJ_mech"); foreach (Transform container in OBJ_mech) { { var go = container.gameObject; go.EnableLayout(); var component = go.GetComponent <ContentSizeFitter>() ?? go.AddComponent <ContentSizeFitter>(); component.verticalFit = ContentSizeFitter.FitMode.PreferredSize; component.enabled = true; } foreach (Transform widget in container) { if (widget.GetComponent <MechLabLocationWidget>() == null) { continue; } widget.gameObject.EnableLayout(); widget.GetChild("layout_slots").gameObject.EnableLayout(); } } { var go = OBJ_mech.gameObject; go.EnableLayout(); var component = go.GetComponent <ContentSizeFitter>() ?? go.AddComponent <ContentSizeFitter>(); component.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; component.verticalFit = ContentSizeFitter.FitMode.PreferredSize; component.enabled = true; } } catch (Exception e) { Control.mod.Logger.LogError(e); } try { { var template = __instance.centerTorsoWidget; var container = __instance.rightArmWidget.transform.parent.gameObject; var clg = container.GetComponent <VerticalLayoutGroup>(); //clg.spacing = 20; clg.padding = new RectOffset(0, 0, Control.settings.MechLabArmTopPadding, 0); var go = UnityEngine.Object.Instantiate(template.gameObject, null); //go.transform.SetAsFirstSibling(); { //go.EnableLayout(); go.transform.SetParent(__instance.rightArmWidget.transform, false); go.GetComponent <LayoutElement>().ignoreLayout = true; go.transform.GetChild("layout_armor").gameObject.SetActive(false); go.transform.GetChild("layout_hardpoints").gameObject.SetActive(false); go.transform.GetChild("layout_locationText").GetChild("txt_structure").gameObject.SetActive(false); var rect = go.GetComponent <RectTransform>(); rect.pivot = new Vector2(0, 0); rect.localPosition = new Vector3(0, 20); } go.name = "MechPropertiesWidget"; go.transform.GetChild("layout_locationText").GetChild("txt_location").GetComponent <TextMeshProUGUI>().text = "General"; go.SetActive(Control.settings.MechLabGeneralWidgetEnabled); MechPropertiesWidget = go.GetComponent <MechLabLocationWidget>(); MechPropertiesWidget.Init(__instance); var layout = new MechLabLocationWidget_SetData_Patch.WidgetLayout(MechPropertiesWidget); // doesnt work with highlight frame //layout.layout_slots_glg.padding.top = 8; //layout.layout_slottedComponents_vlg.padding.top = 8; // doesnt work at all //var emptySpace = new GameObject("Cool GameObject made from Code"); //var emptySpaceRect = emptySpace.AddComponent<RectTransform>(); //emptySpaceRect.sizeDelta = new Vector2(1, 8); //emptySpace.AddComponent<LayoutElement>(); //emptySpace.transform.SetParent(layout.layout_slots, false); //emptySpace.transform.SetAsFirstSibling(); //emptySpace.SetActive(true); MechLabLocationWidget_SetData_Patch.ModifySlotCount(layout, 3); } { var mechRectTransform = __instance.leftArmWidget.transform.parent.parent.GetComponent <RectTransform>(); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); } } catch (Exception e) { Control.mod.Logger.LogError(e); } try { var mechLabPanel = __instance; var Representation = mechLabPanel.transform.GetChild("Representation"); var OBJ_mech = Representation.GetChild("OBJ_mech"); var layout_details = OBJ_mech .GetChild("Centerline") .GetChild("layout_details"); if (layout_details != null) { var go = layout_details.gameObject; go.EnableLayout(); go.GetComponent <LayoutElement>().ignoreLayout = true; var leftArm = OBJ_mech.GetChild("LeftArm"); var vlg = leftArm.GetComponent <VerticalLayoutGroup>(); vlg.padding = new RectOffset(0, 0, Control.settings.MechLabArmTopPadding, 0); //layout_details.parent = leftArm; //layout_details.SetAsFirstSibling(); var leftArmWidget = leftArm.GetChild(0); layout_details.SetParent(leftArmWidget, false); var rect = go.GetComponent <RectTransform>(); rect.pivot = new Vector2(0, 0); rect.localPosition = new Vector3(0, 0); } } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal static void SetupWidget( string id, ref MechLabLocationWidget topWidget, MechLabPanel mechLabPanel, MechLabLocationWidget armWidget, MechLabSlotsSettings.WidgetSettings settings ) { GameObject go; if (topWidget == null) { var template = mechLabPanel.centerTorsoWidget; go = Object.Instantiate(template.gameObject, null); go.name = id; go.SetActive(settings.Enabled); { var vlg = go.GetComponent <VerticalLayoutGroup>(); vlg.padding = new RectOffset(0, 0, 0, 3); vlg.spacing = 4; } go.transform.GetChild("layout_armor").gameObject.SetActive(false); go.transform.GetChild("layout_hardpoints").gameObject.SetActive(false); go.transform.GetChild("layout_locationText").GetChild("txt_structure").gameObject.SetActive(false); go.transform.GetChild("layout_locationText").GetChild("txt_location").GetComponent <TextMeshProUGUI>().text = settings.Label; topWidget = go.GetComponent <MechLabLocationWidget>(); } else { go = topWidget.gameObject; } var parent = armWidget.transform.parent; go.transform.SetParent(parent, false); go.transform.SetAsFirstSibling(); go.GetComponent <LayoutElement>().ignoreLayout = true; { var rect = go.GetComponent <RectTransform>(); rect.localPosition = new Vector3(0, 0); rect.pivot = new Vector2(0, 0); rect.anchoredPosition = new Vector2(0, -MechLabSlotsFeature.settings.MechLabArmTopPadding + 20); } { var clg = parent.GetComponent <VerticalLayoutGroup>(); clg.padding = new RectOffset(0, 0, MechLabSlotsFeature.settings.MechLabArmTopPadding, 0); } topWidget.Init(mechLabPanel); var layout = new WidgetLayout(topWidget); MechLabSlotsFixer.ModifyLayoutSlotCount(layout, settings.Slots); { var mechRectTransform = parent.parent.GetComponent <RectTransform>(); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); } }