From 424e576bb97ee43d6585da431249a971b3549fc7 Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+cptmoore@users.noreply.github.com> Date: Sat, 2 Dec 2023 06:28:23 +0100 Subject: [PATCH] Chassis custom widget settings: Fall back to defaults, though its based on slot count for now. --- .../MechLabSlots/CustomWidgetsFixMechLab.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs b/source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs index 404e4222..f262e83c 100644 --- a/source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs +++ b/source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs @@ -89,8 +89,10 @@ internal static void SetupWidget(string id, topWidget.Init(mechLabPanel); + // allow modify layout to go to 0 and var layout = new WidgetLayout(topWidget); MechLabSlotsFixer.ModifyLayoutSlotCount(layout, settings.Slots); + { var mechRectTransform = parent.parent.GetComponent(); LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform); @@ -195,26 +197,27 @@ ref MechComponentRef? cRef internal static void ShowOrHideCustomWidgets(MechLabLocationWidget widget) { - if (widget.loadout.Location != ChassisLocations.CenterTorso) + if (TopLeftWidget == null || TopRightWidget == null) { + Log.Main.Warning?.Log("Top widgets not initialized even though they should be"); return; } - var custom = widget.mechLab.activeMechDef.Chassis.GetComponent(); - if (custom == null) + if (widget.loadout.Location != ChassisLocations.CenterTorso) { return; } - static void ShowOrHideCustomWidget(MechLabLocationWidget? customWidget, bool? enabled) + var custom = widget.mechLab.activeMechDef.Chassis.GetComponent(); + static void ShowOrHideCustomWidget( + MechLabLocationWidget customWidget, + bool? enabled, + MechLabSlotsSettings.WidgetSettings settings + ) { - if (customWidget == null || !enabled.HasValue) - { - return; - } - customWidget.gameObject.SetActive(enabled.Value); + customWidget.gameObject.SetActive(enabled ?? settings.Enabled); } - ShowOrHideCustomWidget(TopLeftWidget, custom.TopLeftWidgetEnabled); - ShowOrHideCustomWidget(TopRightWidget, custom.TopRightWidgetEnabled); + ShowOrHideCustomWidget(TopLeftWidget, custom?.TopLeftWidgetEnabled, MechLabSlotsFeature.settings.TopLeftWidget); + ShowOrHideCustomWidget(TopRightWidget, custom?.TopRightWidgetEnabled, MechLabSlotsFeature.settings.TopRightWidget); } }