public static void Postfix(MechLabLocationWidget __instance, int ___maxSlots)
 {
     try
     {
         var widgetLayout = new WidgetLayout(__instance);
         MechLabSlotsFixer.FixSlots(widgetLayout, ___maxSlots);
         DynamicSlotsFeature.PrepareWidget(widgetLayout);
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
    public static bool Prefix(MechLabLocationWidget __instance, bool isOriginalLocation, ref MechComponentRef?cRef)
    {
        try
        {
            return(CustomWidgetsFixMechLab.ShowHighlightFrame(__instance, isOriginalLocation, ref cRef));
        }
        catch (Exception e)
        {
            Control.Logger.Error.Log(e);
        }

        return(false);
    }
Esempio n. 3
0
        // only allow one engine part per specific location
        public static bool Prefix(
            MechLabLocationWidget __instance,
            PointerEventData eventData,
            MechLabDropTargetType addToType,
            MechLabPanel ___mechLab,
            List <MechLabItemSlotElement> ___localInventory,
            int ___usedSlots,
            int ___maxSlots,
            ref Text ____dropErrorMessage)
        {
            try
            {
                if (___mechLab == null)
                {
                    return(false);
                }

                var dragItem = ___mechLab.DragItem as MechLabItemSlotElement;
                if (dragItem == null)
                {
                    return(false);
                }

                var result = EngineHeat.Shared.ValidateDrop(dragItem, __instance);

                if (result is MechLabDropRemoveDragItemResult)
                {
                    // remove item and delete it
                    dragItem.thisCanvasGroup.blocksRaycasts = true;
                    dragItem.MountedLocation = ChassisLocations.None;
                    ___mechLab.dataManager.PoolGameObject(MechLabPanel.MECHCOMPONENT_ITEM_PREFAB, dragItem.gameObject);
                    ___mechLab.ClearDragItem(true);
                    return(false);
                }

                if (result is MechLabDropErrorResult error)
                {
                    ____dropErrorMessage = new Text(error.errorMessage);
                    ___mechLab.ShowDropErrorMessage(____dropErrorMessage);
                    ___mechLab.OnDrop(eventData);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }

            return(true);
        }
        static bool Prefix(MechLabLocationWidget __instance)
        {
            int   mod   = Mathf.FloorToInt(__instance.currentRearArmor) % 5;
            float delta = Math.Min(__instance.currentRearArmor, mod == 0 ? UnityGameInstance.BattleTechGame.MechStatisticsConstants.ARMOR_PER_STEP : mod);

            if (delta > 0)
            {
                LocationDef locationDef = ReflectionUtils.GetChassisLocationDef(__instance);
                __instance.currentRearArmor -= delta;
                __instance.maxArmor          = ArmorRules.MaxFrontArmor(locationDef, __instance.loadout, __instance.currentRearArmor);
                __instance.ModifyArmor(true, 0, true);
            }
            return(false);
        }
Esempio n. 5
0
 public static void Prefix(MechLabLocationWidget __instance, IMechLabDraggableItem item)
 {
     try
     {
         if (item == null)
         {
             MechLabPanel_InitWidgets_Patch.MechPropertiesWidget.ShowHighlightFrame(false);
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
Esempio n. 6
0
 internal WidgetLayout(MechLabLocationWidget widget, ChassisLocations location)
 {
     this.location = location;
     this.widget   = widget;
     layout_slots  = widget.transform.GetChild("layout_slots");
     if (layout_slots == null)
     {
         return;
     }
     slots = layout_slots.GetChildren()
             .Where(x => x.name.StartsWith("slot"))
             .OrderByDescending(x => x.localPosition.y)
             .ToList();
 }
Esempio n. 7
0
        internal DynamicSlotBuilder(
            MechDefBuilder builder,
            ChassisLocations location,
            MechLabLocationWidget widget)
        {
            this.location = location;
            this.widget   = widget;

            var locationInfo = builder.GetLocationInfo(location);

            currentFreeSlots = locationInfo.InventoryFree;
            fixedSlots       = locationInfo.CalcMinimumFixedSlotsLocalAndGlobal;

            maxSlots = widget.maxSlots;
        }
Esempio n. 8
0
 public static bool Prefix(MechLabLocationWidget __instance, PointerEventData eventData)
 {
     try
     {
         if (MechPropertiesWidget.OnDrop(__instance, eventData))
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         Control.Logger.Error.Log(e);
     }
     return(true);
 }
        public LocationHelper(MechLabLocationWidget widget)
        {
            this.widget = widget;
            main        = Traverse.Create(widget);
            var hplist = new List <HardpointInfo>();
            var mech   = MechLabHelper.CurrentMechLab.ActiveMech;

            HardpointWidgets = main
                               .Field <MechLabHardpointElement[]>("hardpoints")
                               .Value
                               .Select(i => new LocationHardpointHelper(i))
                               .ToArray();

            UpdateHardpointUsage();
            RefreshHardpoints();
        }
Esempio n. 10
0
        public static bool RefreshHardpoints(MechLabLocationWidget __instance)
        {
            if (MechLabHelper.CurrentMechLab == null || !MechLabHelper.CurrentMechLab.InMechLab)
            {
                return(false);
            }

            var lhelper = MechLabHelper.CurrentMechLab.GetLocationHelper(__instance.loadout.Location);

            if (lhelper != null)
            {
                lhelper.RefreshHardpoints();
            }

            return(false);
        }
Esempio n. 11
0
        public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget)
        {
            Control.LogDebug(DType.ComponentInstall, $"- AutoReplace");
            Control.LogDebug(DType.ComponentInstall, $"-- search replace for {item.ComponentRef.ComponentDefID}");
            if (string.IsNullOrEmpty(ComponentDefId))
            {
                Control.LogDebug(DType.ComponentInstall, $"-- no replacement, skipping");
                return;
            }
            Control.LogDebug(DType.ComponentInstall, $"-- {widget}");
            var location = Location == ChassisLocations.None ? widget.loadout.Location : Location;

            DefaultHelper.AddMechLab(ComponentDefId, Def.ComponentType, new MechLabHelper(mechLab), location);
            Control.LogDebug(DType.ComponentInstall, $"-- added {ComponentDefId} to {location}");
            mechLab.ValidateLoadout(false);
        }
Esempio n. 12
0
        public static void Postfix(MechLabLocationWidget __instance, int ___maxSlots, ref LocationLoadoutDef loadout)
        {
            try
            {
                var widget = __instance;

                var widgetLayout = new WidgetLayout(widget);
                MechLabSlotsFixer.FixSlots(widgetLayout, ___maxSlots);
                DynamicSlotsFeature.PrepareWidget(widgetLayout);
                AdjustMechLabLocationNaming(widget, loadout.Location);
            }
            catch (Exception e)
            {
                Control.Logger.Error.Log(e);
            }
        }
 public static bool Prefix(MechLabLocationWidget __instance, PointerEventData eventData, MechLabDropTargetType addToType)
 {
     try
     {
         if (!Control.settings.enforceHardpointLimits)
         {
             return(true);
         }
         var vhl = new MechLabLocationWidgetPatchHelper(__instance);
         return(vhl.MechLabLocationWidgetOnMechLabDrop(eventData));
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
         return(true);
     }
 }
 public static bool Prefix(MechLabLocationWidget __instance, PointerEventData eventData)
 {
     try
     {
         if (__instance == MechLabPanel_InitWidgets_Patch.MechPropertiesWidget)
         {
             var mechLab = (MechLabPanel)__instance.parentDropTarget;
             mechLab.centerTorsoWidget.OnDrop(eventData);
             return(false);
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
     return(true);
 }
Esempio n. 15
0
        public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget)
        {
            Control.LogDebug(DType.ComponentInstall, $"- Category {CategoryID}");
            Control.LogDebug(DType.ComponentInstall, $"-- search replace for {item.ComponentRef.ComponentDefID}");

            var replace = DefaultFixer.Shared.GetReplaceFor(mechLab.activeMechDef, CategoryID, widget.loadout.Location, mechLab.sim);

            if (replace == null)
            {
                Control.LogDebug(DType.ComponentInstall, $"-- no replacement, skipping");
                return;
            }

            DefaultHelper.AddMechLab(replace, new MechLabHelper(mechLab));
            Control.LogDebug(DType.ComponentInstall, $"-- added {replace.ComponentDefID} to {replace.MountedLocation}");
            mechLab.ValidateLoadout(false);
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        public static bool Prefix(MechLabLocationWidget __instance, PointerEventData eventData, MechLabDropTargetType addToType, MechLabPanel ___mechLab, Text ____dropErrorMessage)
        {
            var sim = UnityGameInstance.BattleTechGame.Simulation;

            if (sim == null)
            {
                return(true);
            }

            if (!ModState.IsComponentValidForRefit)
            {
                ___mechLab.ShowDropErrorMessage(____dropErrorMessage);
                ___mechLab.OnDrop(eventData);
                return(false);
            }

            return(true);
        }
Esempio n. 18
0
        public static bool RepairAll(bool forceRepairStructure, bool validate, MechLabLocationWidget __instance)
        {
            var mechLab = MechLabHelper.CurrentMechLab;

            if (!mechLab.InMechLab || !mechLab.InSimGame)
            {
                return(false);
            }

            if (forceRepairStructure || __instance.loadout.CurrentInternalStructure > 0f)
            {
                __instance.RepairStructure(validate);
            }

            var changes  = new Queue <IChange>();
            var lheleper = mechLab.GetLocationHelper(__instance.loadout.Location);

            foreach (var item in lheleper.LocalInventory.Where(i =>
                                                               i.ComponentRef.DamageLevel == ComponentDamageLevel.Functional ||
                                                               i.ComponentRef.DamageLevel != ComponentDamageLevel.Installing))
            {
                if (item.ComponentRef.IsFixed || item.ComponentRef.Flags <CCFlags>().AutoRepair)
                {
                    item.ComponentRef.DamageLevel = ComponentDamageLevel.Penalized;
                    item.RepairComponent(false);
                }
                else if (item.ComponentRef.DamageLevel != ComponentDamageLevel.Destroyed)
                {
                    item.RepairComponent(true);
                }
                else
                {
                    item.RepairComponent(true);
                    changes.Add(new Change_Remove(item.ComponentRef.ComponentDefID, __instance.loadout.Location));
                }
            }

            var state = new InventoryOperationState(changes, mechLab.ActiveMech);

            state.DoChanges();
            state.ApplyMechlab();

            return(false);
        }
Esempio n. 19
0
        internal static void AdvancedStripping(this MechLabLocationWidget widget, MechLabPanel panel)
        {
            if (!panel.Initialized)
            {
                return;
            }

            var loclInv = Traverse.Create(widget).Field("localInventory").GetValue <List <MechLabItemSlotElement> >();

            for (int i = loclInv.Count - 1; i >= 0; i--)
            {
                MechLabItemSlotElement mechLabItemSlotElement = loclInv[i];
                if (!mechLabItemSlotElement.ComponentRef.IsFixed && (mechLabItemSlotElement.ComponentRef.Def is WeaponDef || mechLabItemSlotElement.ComponentRef.Def is AmmunitionBoxDef))
                {
                    widget.OnRemoveItem(mechLabItemSlotElement, true);
                    panel.ForceItemDrop(mechLabItemSlotElement);
                }
            }
        }
            // Copied from OnMechLabDrop() but with inplace replacing of parts removed
            public static bool Prefix(
                MechLabLocationWidget __instance,
                MechLabPanel ___mechLab,
                Localize.Text ____dropErrorMessage,
                PointerEventData eventData,
                MechLabDropTargetType addToType)
            {
                return(_harmonyManager.PrefixLogExceptions(() =>
                {
                    if (!___mechLab.Initialized)
                    {
                        return;
                    }

                    if (___mechLab.DragItem == null)
                    {
                        return;
                    }

                    IMechLabDraggableItem dragItem = ___mechLab.DragItem;
                    bool flag = __instance.ValidateAdd(dragItem.ComponentRef);
                    if (!flag)
                    {
                        ___mechLab.ShowDropErrorMessage(____dropErrorMessage);
                        ___mechLab.OnDrop(eventData);
                        return;
                    }

                    bool clearOriginalItem = __instance.OnAddItem(dragItem, true);
                    if (__instance.Sim != null)
                    {
                        WorkOrderEntry_InstallComponent subEntry =
                            __instance.Sim.CreateComponentInstallWorkOrder(___mechLab.baseWorkOrder.MechID,
                                                                           dragItem.ComponentRef, __instance.loadout.Location, dragItem.MountedLocation);
                        ___mechLab.baseWorkOrder.AddSubEntry(subEntry);
                    }

                    dragItem.MountedLocation = __instance.loadout.Location;
                    ___mechLab.ClearDragItem(clearOriginalItem);
                    __instance.RefreshHardpointData();
                    ___mechLab.ValidateLoadout(false);
                }));
            }
Esempio n. 21
0
        // allow gyro upgrades to be 1 slot and still only be added once
        public static void Postfix(
            MechLabLocationWidget __instance,
            MechComponentDef newComponentDef,
            List <MechLabItemSlotElement> ___localInventory,
            ref string ___dropErrorMessage,
            ref bool __result)
        {
            try
            {
                if (!__result)
                {
                    return;
                }

                Gyro.ValidateAdd(newComponentDef, ___localInventory, ref ___dropErrorMessage, ref __result);
                if (!__result)
                {
                    return;
                }

                EngineMisc.EngineSlotsValidateAdd(newComponentDef, ___localInventory, ref ___dropErrorMessage, ref __result);
                if (!__result)
                {
                    return;
                }

                EngineMisc.EngineCoreValidateAdd(newComponentDef, ___localInventory, ref ___dropErrorMessage, ref __result);
                if (!__result)
                {
                    return;
                }

                Cockpit.ValidateAdd(newComponentDef, ___localInventory, ref ___dropErrorMessage, ref __result);
                if (!__result)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }
Esempio n. 22
0
        public static bool ShowHighlightFrame(MechLabLocationWidget __instance, MechComponentRef cRef, bool isOriginalLocation, bool canBeAdded)
        {
            if (cRef == null)
            {
                __instance.ShowHighlightFrame(false);
                return(false);
            }

            var show = !cRef.Flags <CCFlags>().NoRemove;

            if (show)
            {
                show = !cRef.IsFixed;
            }

            var location = __instance.loadout.Location;

            if (show)
            {
                var mech    = MechLabHelper.CurrentMechLab.ActiveMech;
                var allowed = cRef.Is <IAllowedLocations>(out var al) ? al.GetLocationsFor(mech) : cRef.Def.AllowedLocations;
                show = (allowed & location) > ChassisLocations.None;
            }

            if (show)
            {
                var use_hp  = cRef.Def.GetComponent <UseHardpointCustom>();
                var replace = cRef.GetComponent <ReplaceHardpoint>();


                if (use_hp != null && !use_hp.WeaponCategory.Is_NotSet || replace != null && replace.Valid)
                {
                    var lhelper = MechLabHelper.CurrentMechLab.GetLocationHelper(location);
                    var wc      = use_hp == null ? replace.UseWeaponCategory : use_hp.WeaponCategory;

                    show = lhelper.HardpointsUsage?.Any(i => i.hpInfo.CompatibleID.Contains(wc.ID)) ?? false;
                }
            }

            __instance.ShowHighlightFrame(show, isOriginalLocation ? UIColor.Blue : UIColor.Gold);

            return(false);
        }
        internal static void ShowHighlightFrame(MechLabLocationWidget widget, ref MechComponentRef cRef)
        {
            if (cRef == null)
            {
                return;
            }

            if (widget == PropertiesWidget)
            {
                return;
            }

            if (!IsMechConfiguration(cRef?.Def))
            {
                return;
            }

            cRef = null;
            PropertiesWidget.ShowHighlightFrame(true);
        }
Esempio n. 24
0
        internal static void Postfix(
            MechLabLocationWidget __instance,
            ref LocationDef ___chassisLocationDef,

            ref int ___currentBallisticCount,
            ref int ___currentEnergyCount,
            ref int ___currentMissileCount,
            ref int ___currentSmallCount,

            ref int ___totalBallisticHardpoints,
            ref int ___totalEnergyHardpoints,
            ref int ___totalMissileHardpoints,
            ref int ___totalSmallHardpoints,

            ref MechLabHardpointElement[] ___hardpoints,
            ref List <MechLabItemSlotElement> ___localInventory)
        {
            try
            {
                var inventory  = ___localInventory.Select(x => x.ComponentRef.Def);
                var hardpoints = ___chassisLocationDef.Hardpoints;
                if (hardpoints == null)
                {
                    // how can this happen? is this from the properties widget?
                    Control.Logger.Debug?.Log($"hardpoints is null in location={__instance.loadout?.Location}");
                    return;
                }

                var calc = new HardpointOmniUsageCalculator(inventory, hardpoints);

                Control.Logger.Debug?.Log(calc);

                ___currentBallisticCount = calc.Ballistic.VanillaUsage;
                ___currentEnergyCount    = calc.Energy.VanillaUsage;
                ___currentMissileCount   = calc.Missile.VanillaUsage;
                ___currentSmallCount     = calc.Small.VanillaUsage;

                ___totalBallisticHardpoints = calc.Ballistic.DynamicMax;
                ___totalEnergyHardpoints    = calc.Energy.DynamicMax;
                ___totalMissileHardpoints   = calc.Missile.DynamicMax;
                ___totalSmallHardpoints     = calc.Small.DynamicMax;
 public static void Prefix(MechLabLocationWidget __instance, ref MechComponentRef cRef)
 {
     try
     {
         if (cRef != null)
         {
             if (__instance != MechLabPanel_InitWidgets_Patch.MechPropertiesWidget)
             {
                 if (MechConfiguration.IsMechConfiguration(cRef?.Def))
                 {
                     cRef = null;
                     MechLabPanel_InitWidgets_Patch.MechPropertiesWidget.ShowHighlightFrame(true);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Control.mod.Logger.LogError(e);
     }
 }
    internal static void OnArmorAddOrSubtract(MechLabLocationWidget widget, bool isRearArmor, float direction)
    {
        var stepPrecision = ArmorMaximizerFeature.Shared.Settings.StepPrecision.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;
        var stepSize      = ArmorMaximizerFeature.Shared.Settings.StepSize.Get() ?? ArmorStructureRatioFeature.ArmorPerStep;

        var stepDirection = direction < 0 ? -1 : 1;
        var current       = isRearArmor ? widget.currentRearArmor : widget.currentArmor;

        var updated = stepDirection > 0
            ? PrecisionUtils.RoundUp(current + stepSize, stepPrecision)
            : PrecisionUtils.RoundDown(current - stepSize, stepPrecision);

        Control.Logger.Trace?.Log($"HandleArmorUpdate stepDirection={stepDirection} current={current} precision={stepPrecision} isRearArmor={isRearArmor}");
        if (stepDirection > 0)
        {
            var max = isRearArmor ? widget.maxRearArmor : widget.maxArmor;
            updated = Mathf.Min(updated, max);

            var maxTotal     = ArmorStructureRatioFeature.GetMaximumArmorPoints(widget.chassisLocationDef);
            var maxOther     = maxTotal - updated;
            var currentOther = isRearArmor ? widget.currentArmor : widget.currentRearArmor;
            var updatedOther = Mathf.Min(currentOther, maxOther);

            var otherNotChanged = PrecisionUtils.Equals(currentOther, updatedOther);
            if (otherNotChanged || !ArmorLocationLocker.IsLocked(widget.loadout.Location, !isRearArmor))
            {
                widget.SetArmor(isRearArmor, updated);
                widget.SetArmor(!isRearArmor, updatedOther);
            }

            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated} maxTotal={maxTotal} maxOther={maxOther} currentOther={currentOther} updatedOther={updatedOther} isRearArmor={updatedOther}");
        }
        else
        {
            updated = Mathf.Max(updated, 0);
            widget.SetArmor(isRearArmor, updated);
            Control.Logger.Trace?.Log($"HandleArmorUpdate updated={updated}");
        }
    }
    internal static void OnRefreshArmor(MechLabLocationWidget widget)
    {
        void RefreshArmorBar(LanceStat lanceStat, bool isRearArmor)
        {
            lanceStat.SetTextColor(UIColor.White, UIColor.White);
            RefreshBarColor(widget, isRearArmor);

            void SetButtonColor(string buttonId, UIColor uiColor)
            {
                var button = lanceStat.transform.Find(buttonId);
                // the plus icon is actually made of two minus icons
                var icons = button.Find("startButtonFill").GetChildren();

                foreach (var icon in icons)
                {
                    var colorRefTracker = icon.GetComponent <UIColorRefTracker>();
                    colorRefTracker.SetUIColor(uiColor);
                }
            }

            const UIColor limitReachedColor = UIColor.MedGray;
            {
                var max        = isRearArmor ? widget.maxRearArmor : widget.maxArmor;
                var current    = isRearArmor ? widget.currentRearArmor : widget.currentArmor;
                var maxReached = PrecisionUtils.SmallerOrEqualsTo(max, current);
                SetButtonColor("bttn_plus", maxReached ? limitReachedColor : UIColor.White);
            }
            {
                var minReached = PrecisionUtils.SmallerOrEqualsTo(isRearArmor ? widget.currentRearArmor : widget.currentArmor, 0);
                SetButtonColor("bttn_minus", minReached ? limitReachedColor : UIColor.White);
            }
        }

        RefreshArmorBar(widget.armorBar, false);
        if (widget.useRearArmor)
        {
            RefreshArmorBar(widget.rearArmorBar, true);
        }
    }
Esempio n. 28
0
        public static void SetArmor(this MechLabPanel mechLabPanel, MechLabLocationWidget locationWidget, LocationLoadoutDef loadout)
        {
            locationWidget.currentArmor = loadout.AssignedArmor;
            bool locationHasRearArmor = (bool)AccessTools.Field(typeof(MechLabLocationWidget), "useRearArmor").GetValue(locationWidget);

            if (locationHasRearArmor)
            {
                locationWidget.currentRearArmor = loadout.AssignedRearArmor;
            }

            // Create work-order, otherwise Mech is invalid after it is actually changed
            // Check if the values actually changed beforehand (Vanilla does actually NOT check this)
            int armorDiff = (int)Mathf.Abs(locationWidget.currentArmor - locationWidget.originalArmor) + (int)Mathf.Abs(locationWidget.currentRearArmor - locationWidget.originalRearArmor);

            if (armorDiff != 0)
            {
                WorkOrderEntry_ModifyMechArmor subEntry = locationWidget.Sim.CreateMechArmorModifyWorkOrder(mechLabPanel.activeMechDef.GUID, locationWidget.loadout.Location, armorDiff, (int)locationWidget.currentArmor, (int)locationWidget.currentRearArmor);
                mechLabPanel.baseWorkOrder.AddSubEntry(subEntry);
            }
            //mechLabPanel.ValidateLoadout(false);

            ReflectionHelper.InvokePrivateMethode(locationWidget, "RefreshArmor", null);
        }
Esempio n. 29
0
        public static void Postfix(IMechLabDraggableItem item, ref bool __result, MechComponentRef __state,
                                   MechLabPanel ___mechLab, MechLabLocationWidget __instance)
        {
            try
            {
                if (!__result)
                {
                    return;
                }


                var changes = new Queue <IChange>();
                changes.Enqueue(new Change_Remove(item.ComponentRef, __instance.loadout.Location, true));
                var state = new InventoryOperationState(changes, MechLabHelper.CurrentMechLab.ActiveMech);
                state.DoChanges();
                state.ApplyMechlab();

                ___mechLab.ValidateLoadout(false);
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
Esempio n. 30
0
        public static void Postfix(MechLabLocationWidget __instance, int ___maxSlots, LocationLoadoutDef ___loadout)
        {
            try
            {
                // we can't reduce to zero
                if (___maxSlots < 1)
                {
                    return;
                }

                var widgetLayout = new WidgetLayout(__instance, ___loadout.Location);
                if (widgetLayout.layout_slots == null)
                {
                    return;
                }

                ModifySlotCount(widgetLayout, ___maxSlots);
                AddFillersToSlots(widgetLayout);
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
            }
        }