Пример #1
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);
        }
            // 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);
                }));
            }
        public static bool Prefix(MechLabLocationWidget __instance, PointerEventData eventData, MechLabDropTargetType addToType)
        {
            try
            {
                if (!Control.settings.HardpointFix.EnforceHardpointLimits)
                {
                    return(true);
                }

                var vhl = new MechLabLocationWidgetPatchHelper(__instance);
                return(vhl.MechLabLocationWidgetOnMechLabDrop(eventData));
            }
            catch (Exception e)
            {
                Control.mod.Logger.LogError(e);
                return(true);
            }
        }
Пример #4
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);
        }