コード例 #1
0
        // auto strip engine when put back to inventory
        internal static void InventoryWidgetOnAddItem(MechLabInventoryWidget widget, MechLabPanel panel, IMechLabDraggableItem item)
        {
            if (item.ItemType != MechLabDraggableItemType.MechComponentItem)
            {
                return;
            }

            var componentRef = item.ComponentRef;

            var engineRef = componentRef.GetEngineRef();

            if (engineRef == null)
            {
                return;
            }

            //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem " + componentRef.Def.Description.Id + " UID=" + componentRef.SimGameUID);

            foreach (var componentDefID in engineRef.GetInternalComponents())
            {
                //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem extracting componentDefID=" + componentDefID);
                var @ref = CreateMechComponentRef(componentDefID, panel.sim, panel.dataManager);

                var mechLabItemSlotElement = panel.CreateMechComponentItem(@ref, false, ChassisLocations.None, null);
                widget.OnAddItem(mechLabItemSlotElement, false);
            }
            //engineRef.ClearInternalComponents();

            //SaveEngineState(engineRef, panel);

            widget.RefreshFilterToggles();
        }
コード例 #2
0
        internal static bool StripEngine(MechLabPanel panel, IMechLabDraggableItem item)
        {
            if (item.ItemType != MechLabDraggableItemType.MechComponentItem)
            {
                return(false);
            }

            var componentRef = item.ComponentRef;

            var engineRef = componentRef.GetEngineRef();

            if (engineRef == null)
            {
                return(false);
            }

            //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem " + componentRef.Def.Description.Id + " UID=" + componentRef.SimGameUID);

            foreach (var componentDefID in engineRef.GetInternalComponents())
            {
                //Control.mod.Logger.LogDebug("MechLabInventoryWidget.OnAddItem extracting componentDefID=" + componentDefID);
                var @ref = CreateMechComponentRef(componentDefID, panel.sim, panel.dataManager);

                var mechLabItemSlotElement = panel.CreateMechComponentItem(@ref, false, item.MountedLocation, item.DropParent);
                mechLabItemSlotElement.gameObject.transform.localScale = Vector3.one;
                panel.OnAddItem(mechLabItemSlotElement, false);
            }
            engineRef.ClearInternalComponents();

            SaveEngineState(engineRef, panel);

            return(true);
        }
コード例 #3
0
        public static MechLabItemSlotElement CreateSlot(string id, ComponentType type, MechLabPanel mechLab)
        {
            var component_ref = new MechComponentRef(id, string.Empty, type, ChassisLocations.None, isFixed: true);

            if (!component_ref.IsDefault())
            {
                Control.LogError($"CreateDefault: {id} not default or not exist");
            }

            if (mechLab.IsSimGame)
            {
                component_ref.SetSimGameUID(mechLab.Sim.GenerateSimGameUID());
            }

            return(mechLab.CreateMechComponentItem(component_ref, false, ChassisLocations.None, mechLab));
        }
コード例 #4
0
        // @ToDo: Somehow implement that manual Remove/Add of components AFTER this method-call calculates work-orders correctly
        public static void SetEquipment(this MechLabPanel mechLabPanel, List <InventoryItemElement_Simple> equipment, MechLabLocationWidget locationWidget, LocationLoadoutDef loadout)
        {
            locationWidget.loadout = loadout;

            // Nah. This kills fixed equipment!
            //locationWidget.ClearInventory();

            for (int i = 0; i < equipment.Count; i++)
            {
                if (equipment[i].ComponentRef.MountedLocation == loadout.Location)
                {
                    Logger.Debug("[Extensions.SetEquipment] Component: " + equipment[i].ComponentRef.ComponentDefID + " gets installed at: " + loadout.Location.ToString() + " and was fetched from (simulated): " + equipment[i].Origin);

                    // NOTE that creation of items (vs. simulate-grabbing the real ones from inventory) will confuse the work-order-entries
                    // @ToDo: Try setting "copyComponentRef" to true and test somewhen
                    MechLabItemSlotElement mechLabItemSlotElement = mechLabPanel.CreateMechComponentItem(equipment[i].ComponentRef, false, loadout.Location, locationWidget, null);
                    Traverse.Create(mechLabItemSlotElement).Field("originalDropParentType").SetValue(equipment[i].Origin);

                    if (mechLabItemSlotElement != null)
                    {
                        List <MechLabItemSlotElement> ___localInventory = (List <MechLabItemSlotElement>)AccessTools.Field(typeof(MechLabLocationWidget), "localInventory").GetValue(locationWidget);
                        ___localInventory.Add(mechLabItemSlotElement);
                        int ___usedSlots = (int)AccessTools.Field(typeof(MechLabLocationWidget), "usedSlots").GetValue(locationWidget);
                        ___usedSlots += equipment[i].ComponentRef.Def.InventorySize;
                        Transform ___inventoryParent = (Transform)AccessTools.Field(typeof(MechLabLocationWidget), "inventoryParent").GetValue(locationWidget);
                        mechLabItemSlotElement.gameObject.transform.SetParent(___inventoryParent, false);
                        mechLabItemSlotElement.gameObject.transform.localScale = Vector3.one;

                        ReflectionHelper.InvokePrivateMethode(locationWidget, "RefreshMechComponentData", new object[] { mechLabItemSlotElement, false });
                        locationWidget.RefreshHardpointData();

                        // Add WorkOrderEntry
                        WorkOrderEntry_InstallComponent subEntry = locationWidget.Sim.CreateComponentInstallWorkOrder(mechLabPanel.baseWorkOrder.MechID, equipment[i].ComponentRef, loadout.Location, ChassisLocations.None);
                        mechLabPanel.baseWorkOrder.AddSubEntry(subEntry);
                    }
                }
            }
            //mechLabPanel.ValidateLoadout(false);
        }
コード例 #5
0
 public static MechLabItemSlotElement CreateSlot(MechComponentRef item, MechLabPanel mechLab)
 {
     return(mechLab.CreateMechComponentItem(item, false, ChassisLocations.None, mechLab));
 }