internal static bool OnRemoveItemRepair(this MechLabLocationWidget widget, IMechLabDraggableItem item, bool validate) { var component = item.ComponentRef.Def; repair_state = true; repair_widget = widget; if (component.Is <Flags>(out var f) && f.AutoRepair) { Control.LogDebug(DType.DefaultHandle, $"AutoRepair: {component.Description.Id} "); item.ComponentRef.DamageLevel = ComponentDamageLevel.Penalized; var t = Traverse.Create(item).Method("RefreshDamageOverlays").GetValue(); item.RepairComponent(true); repair_state = false; return(true); } repair_state = true; var mechlab = widget.parentDropTarget as MechLabPanel; foreach (var validator in component.GetComponents <IOnItemGrab>()) { repair_state = validator.OnItemGrab(item, mechlab, out _); if (!repair_state) { return(true); } } return(widget.OnRemoveItem(item, validate)); }
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); }
internal static void RefreshDropHighlights(MechLabLocationWidget widget, IMechLabDraggableItem item) { if (item == null) { PropertiesWidget.ShowHighlightFrame(false); } }
public static void OnItemGrab_Pre(MechLabInventoryWidget __instance, ref IMechLabDraggableItem item) { if (state != null && state.inventoryWidget == __instance) { try { LogDebug(string.Format("OnItemGrab")); var nlv = item as InventoryItemElement_NotListView; var nlvtmp = state.instance.dataManager.PooledInstantiate(ListElementController_BASE_NotListView.INVENTORY_ELEMENT_PREFAB_NotListView , BattleTechResourceType.UIModulePrefabs, null, null, null) .GetComponent <InventoryItemElement_NotListView>(); var lec = nlv.controller; var iw = nlvtmp; var cref = state.GetRef(lec); iw.ClearEverything(); iw.ComponentRef = cref; lec.ItemWidget = iw; iw.SetData(lec, state.inventoryWidget, lec.quantity, false, null); lec.SetupLook(iw); iw.gameObject.SetActive(true); item = iw; } catch (Exception e) { LogException(e); } } }
public static bool Prefix(IMechLabDraggableItem item, ref bool __result, MechLabPanel ___mechLab, ref MechComponentRef __state) { try { Control.LogDebug(DType.ComponentInstall, $"OnItemGrab.Prefix {item.ComponentRef.ComponentDefID}"); foreach (var grab_handler in item.ComponentRef.Def.GetComponents <IOnItemGrab>()) { if (item.ComponentRef.Flags <CCFlags>().NoRemove) { __result = false; return(false); } if (!grab_handler.OnItemGrab(item, ___mechLab, out var error)) { if (!string.IsNullOrEmpty(error)) { ___mechLab.ShowDropErrorMessage(new Text(error)); } __result = false; return(false); } } } catch (Exception e) { Control.LogError(e); } return(true); }
internal static bool OnRemoveItemStrip(this MechLabLocationWidget widget, IMechLabDraggableItem item, bool validate) { var component = item.ComponentRef.Def; strip_widget = widget; Control.LogDebug(DType.DefaultHandle, $"Removing {component.Description.Id} "); var mechlab = widget.parentDropTarget as MechLabPanel; strip_state = true; foreach (var validator in component.GetComponents <IOnItemGrab>()) { Control.LogDebug(DType.DefaultHandle, $"- {validator.GetType()}"); strip_state = validator.OnItemGrab(item, mechlab, out _); if (!strip_state) { Control.LogDebug(DType.DefaultHandle, $"-- Canceled"); return(true); } } return(widget.OnRemoveItem(item, validate)); }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget w) { if (Links != null && Links.Length > 0) { RemoveLinked(item, mechLab); } }
public static void Prefix(MechLabDismountWidget __instance, IMechLabDraggableItem item) { try { var panel = __instance.ParentDropTarget as MechLabPanel; if (panel == null) { return; } if (panel.baseWorkOrder == null) { return; } if (!panel.IsSimGame) { return; } if (item == null) { return; } EnginePersistence.DismountWidgetOnAddItem(__instance, panel, item); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
public static void Postfix(IMechLabDraggableItem item, List <MechLabItemSlotElement> ___localInventory) { if (item.ComponentRef?.Def == null || !item.ComponentRef.Def.Is <ISorter>()) { return; } MechLabLocationWidget_SetData_Patch.Sorter.SortWidgetInventory(___localInventory); }
public void RemoveLinked(IMechLabDraggableItem item, MechLabPanel mechLab) { var helper = new MechLabHelper(mechLab); foreach (var r_link in Links) { Control.LogDebug(DType.ComponentInstall, $"{r_link.ComponentDefId} from {r_link.Location}"); DefaultHelper.RemoveMechLab(r_link.ComponentDefId, r_link.ComponentDefType ?? Def.ComponentType, helper, r_link.Location); } }
public static void Prefix(MechLabLocationWidget __instance, IMechLabDraggableItem item) { try { MechPropertiesWidget.RefreshDropHighlights(__instance, item); } catch (Exception e) { Control.Logger.Error.Log(e); } }
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); } }
public static void Postfix(IMechLabDraggableItem item, ref bool __result, MechComponentRef __state, MechLabPanel ___mechLab, MechLabLocationWidget __instance) { if (!__result) { return; } foreach (var grab_handler in item.ComponentRef.Def.GetComponents <IOnItemGrabbed>()) { grab_handler.OnItemGrabbed(item, ___mechLab, __instance); } ___mechLab.ValidateLoadout(false); }
public static bool OnAddItem_Pre(MechLabInventoryWidget __instance, IMechLabDraggableItem item) { if (state != null && state.inventoryWidget == __instance) { try { var nlv = item as InventoryItemElement_NotListView; var quantity = nlv == null ? 1 : nlv.controller.quantity; var existing = state.FetchItem(item.ComponentRef); if (existing == null) { LogDebug(string.Format("OnAddItem new {0}", quantity)); var controller = nlv == null ? null : nlv.controller; if (controller == null) { if (item.ComponentRef.ComponentDefType == ComponentType.Weapon) { var ncontroller = new ListElementController_InventoryWeapon_NotListView(); ncontroller.InitAndCreate(item.ComponentRef, state.instance.dataManager, state.inventoryWidget, quantity, false); controller = ncontroller; } else { var ncontroller = new ListElementController_InventoryGear_NotListView(); ncontroller.InitAndCreate(item.ComponentRef, state.instance.dataManager, state.inventoryWidget, quantity, false); controller = ncontroller; } } state.rawInventory.Add(controller); state.rawInventory = state.Sort(state.rawInventory); state.FilterChanged(false); } else { LogDebug(string.Format("OnAddItem existing {0}", quantity)); if (existing.quantity != Int32.MinValue) { existing.ModifyQuantity(quantity); } state.Refresh(false); } } catch (Exception e) { LogException(e); } return(false); } else { return(true); } }
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); }
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); }
// 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 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); } }
public static bool OnRemoveItem_Pre(MechLabInventoryWidget __instance, IMechLabDraggableItem item) { if (state != null && state.inventoryWidget == __instance) { try { var nlv = item as InventoryItemElement_NotListView; var existing = state.FetchItem(item.ComponentRef); if (existing == null) { LogError(string.Format("OnRemoveItem new (should be impossible?) {0}", nlv.controller.quantity)); } else { LogDebug(string.Format("OnRemoveItem existing {0}", nlv.controller.quantity)); if (existing.quantity != Int32.MinValue) { existing.ModifyQuantity(-1); if (existing.quantity < 1) { state.rawInventory.Remove(existing); } } state.FilterChanged(false); state.Refresh(false); } } catch (Exception e) { LogException(e); } return(false); } else { return(true); } }
public void OnItemGrabbed(IMechLabDraggableItem item, MechLabPanel mechLab, MechLabLocationWidget widget) { if (widget.loadout.Location != ChassisLocations.LeftArm && widget.loadout.Location != ChassisLocations.RightArm) { return; } var loc_helper = new LocationHelper(widget); var total_slot = ArmActuatorSlot.None; var mount_loc = widget.loadout.Location; var ml_helper = new MechLabHelper(mechLab); CustomComponents.Control.LogDebug(DType.ComponentInstall, $"- ArmActuator: {Def.Description.Id} {Type}"); void add_default(ArmActuatorSlot slot) { bool add_item(string id) { if (string.IsNullOrEmpty(id)) { return(false); } var r = DefaultHelper.CreateRef(id, ComponentType.Upgrade, mechLab.dataManager, mechLab.Sim); if (r.Is <ArmActuator>(out var actuator) && (actuator.Type & total_slot) == 0) { DefaultHelper.AddMechLab(id, ComponentType.Upgrade, ml_helper, mount_loc); total_slot = total_slot | actuator.Type; return(true); } return(false); } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"--- adding {slot} to {total_slot}"); if (total_slot.HasFlag(slot)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"---- already present"); return; } if (add_item(ArmActuatorCC.GetDefaultActuator(mechLab.activeMechDef, mount_loc, slot))) { return; } add_item(ArmActuatorCC.GetDefaultActuator(null, mount_loc, slot)); } for (int i = loc_helper.LocalInventory.Count - 1; i >= 0; i--) { var slotitem = loc_helper.LocalInventory[i]; if (!slotitem.ComponentRef.Is <ArmActuator>()) { continue; } var actuator = slotitem.ComponentRef.GetComponent <ArmActuator>(); if (slotitem.ComponentRef.IsDefault() && !slotitem.ComponentRef.IsModuleFixed(ml_helper.MechLab.activeMechDef)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- removing {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); DefaultHelper.RemoveMechLab(slotitem.ComponentRef.ComponentDefID, slotitem.ComponentRef.ComponentDefType, ml_helper, mount_loc); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- checking {slotitem.ComponentRef.ComponentDefID} {actuator.Type}"); total_slot = total_slot | actuator.Type; } } CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- actuators {total_slot}"); add_default(ArmActuatorSlot.PartShoulder); add_default(ArmActuatorSlot.PartUpper); if (ArmActuatorCC.IsIgnoreFullActuators(mechLab.activeMechDef)) { if (total_slot.HasFlag(ArmActuatorSlot.PartHand) && !total_slot.HasFlag(ArmActuatorSlot.PartLower)) { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- Removing hand from {total_slot}"); var hand = loc_helper.LocalInventory.FirstOrDefault(i => i.ComponentRef.Is <ArmActuator>(out var actuator) && actuator.Type.HasFlag(ArmActuatorSlot.PartHand)); if (hand == null || hand.ComponentRef.IsFixed) { return; } var dragitem = mechLab.DragItem; widget.OnRemoveItem(hand, false); mechLab.ForceItemDrop(hand); ml_helper.SetDragItem(dragitem as MechLabItemSlotElement); } else { CustomComponents.Control.LogDebug(DType.ComponentInstall, $"-- hand already removed from {total_slot}"); } } else { var limit = mechLab.activeMechDef.Chassis.Is <ArmActuatorSupport>(out var s) ? s.GetLimit(mount_loc) : ArmActuatorSlot.Hand; if (limit.HasFlag(ArmActuatorSlot.PartLower)) { add_default(ArmActuatorSlot.PartLower); } if (limit.HasFlag(ArmActuatorSlot.PartHand)) { add_default(ArmActuatorSlot.PartHand); } } }
// auto strip engine when dismount internal static void DismountWidgetOnAddItem(MechLabDismountWidget widget, MechLabPanel panel, IMechLabDraggableItem item) { StripEngine(panel, item); }
// 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(); }
// auto strip engine when put back to inventory internal static void InventoryWidgetOnAddItem(MechLabInventoryWidget widget, MechLabPanel panel, IMechLabDraggableItem item) { if (StripEngine(panel, item)) { widget.RefreshFilterToggles(); } }