Skip to content

Commit

Permalink
Added CustomWidgetChassis (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Dec 1, 2023
1 parent dcea481 commit 0ef1aac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
10 changes: 10 additions & 0 deletions source/Features/MechLabSlots/CustomWidgetChassisCustom.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CustomComponents;

namespace MechEngineer.Features.MechLabSlots;

[CustomComponent("CustomWidgetChassis")]
public class CustomWidgetChassisCustom : SimpleCustomChassis
{
public bool TopLeftWidgetEnabled { get; set; }
public bool TopRightWidgetEnabled { get; set; }
}
21 changes: 15 additions & 6 deletions source/Features/MechLabSlots/CustomWidgetsFixMechLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,33 @@ internal static bool IsCustomWidget(MechLabLocationWidget widget)

internal static void Setup(MechLabPanel mechLabPanel)
{
var cwcc = mechLabPanel.activeMechDef.Chassis.GetComponent<CustomWidgetChassisCustom>();

SetupWidget(
"TopLeftWidget",
ref TopLeftWidget,
mechLabPanel,
mechLabPanel.rightArmWidget,
MechLabSlotsFeature.settings.TopLeftWidget
MechLabSlotsFeature.settings.TopLeftWidget,
cwcc?.TopLeftWidgetEnabled
);

SetupWidget(
"TopRightWidget",
ref TopRightWidget,
mechLabPanel,
mechLabPanel.leftArmWidget,
MechLabSlotsFeature.settings.TopRightWidget
MechLabSlotsFeature.settings.TopRightWidget,
cwcc?.TopRightWidgetEnabled
);
}

internal static void SetupWidget(
string id,
internal static void SetupWidget(string id,
ref MechLabLocationWidget? topWidget,
MechLabPanel mechLabPanel,
MechLabLocationWidget armWidget,
MechLabSlotsSettings.WidgetSettings settings
)
MechLabSlotsSettings.WidgetSettings settings,
bool? chassisEnabled)
{
GameObject go;
if (topWidget == null)
Expand All @@ -71,6 +74,7 @@ MechLabSlotsSettings.WidgetSettings settings
else
{
go = topWidget.gameObject;
go.SetActive(settings.Enabled);
}

var parent = armWidget.transform.parent;
Expand All @@ -96,6 +100,11 @@ MechLabSlotsSettings.WidgetSettings settings
var mechRectTransform = parent.parent.GetComponent<RectTransform>();
LayoutRebuilder.ForceRebuildLayoutImmediate(mechRectTransform);
}

if (chassisEnabled.HasValue)
{
go.SetActive(chassisEnabled.Value);
}
}

internal static void OnAdditem_SetParent(Transform @this, Transform parent, bool worldPositionStays)
Expand Down

0 comments on commit 0ef1aac

Please sign in to comment.