Skip to content

Commit

Permalink
Chassis custom widget settings: Fall back to defaults, though its bas…
Browse files Browse the repository at this point in the history
…ed on slot count for now.
  • Loading branch information
CptMoore committed Dec 2, 2023
1 parent d917050 commit 424e576
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RectTransform>();
LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform);
Expand Down Expand Up @@ -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<CustomWidgetChassisCustom>();
if (custom == null)
if (widget.loadout.Location != ChassisLocations.CenterTorso)
{
return;
}

static void ShowOrHideCustomWidget(MechLabLocationWidget? customWidget, bool? enabled)
var custom = widget.mechLab.activeMechDef.Chassis.GetComponent<CustomWidgetChassisCustom>();
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);
}
}

0 comments on commit 424e576

Please sign in to comment.