internal static void ModifyLayoutSlotCount(WidgetLayout layout, int maxSlots) { var slots = layout.slots; var changedSlotCount = maxSlots - slots.Count; if (changedSlotCount < 0) { // remove abundant while (slots.Count > maxSlots) { var slot = slots.Last(); slots.RemoveAt(slots.Count - 1); UnityEngine.Object.Destroy(slot.gameObject); } } else if (changedSlotCount > 0) { var templateSlot = slots[0]; // add missing var index = slots[0].GetSiblingIndex(); for (var i = slots.Count; i < maxSlots; i++) { var newSlot = UnityEngine.Object.Instantiate(templateSlot, layout.layout_slots); //newSlot.localPosition = new Vector3(0, -(1 + i * SlotHeight), 0); newSlot.SetSiblingIndex(index + i); newSlot.name = "slot (" + i + ")"; slots.Add(newSlot); } } }
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 FixSlots(WidgetLayout widgetLayout, int ___maxSlots) { // MechPropertiesWidget feature if (widgetLayout.widget == (widgetLayout.widget.parentDropTarget as MechLabPanel).centerTorsoWidget) { ___maxSlots = Mathf.Max(0, ___maxSlots - MechLabSlotsFeature.settings.MechLabGeneralSlots); } ModifyLayoutSlotCount(widgetLayout, ___maxSlots); }
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); } }
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); } }