private static IEnumerable <MechLabItemSlotElement> Elements(MechLabPanel panel) { return(MechDefBuilder.Locations .Select(location => panel.GetLocationWidget((ArmorLocation)location)) .Select(widget => new MechLabLocationWidgetAdapter(widget)) .SelectMany(adapter => adapter.LocalInventory)); }
internal void RefreshData(MechLabPanel mechLab) { var builder = new MechDefBuilder(mechLab.activeMechDef); var fslList = new List <DynamicSlotBuilder>(); foreach (var location in MechDefBuilder.Locations) { // armorlocation = chassislocation for main locations var widget = mechLab.GetLocationWidget((ArmorLocation)location); ClearFillers(widget); var adapter = new MechLabLocationWidgetAdapter(widget); fslList.Add(new DynamicSlotBuilder(builder, location, adapter)); } //for (var reservedSlots = builder.Reserved; reservedSlots > 0; reservedSlots--) foreach (var reservedSlot in builder.GetReservedSlots()) { var fsl = fslList.Max(); if (fsl.currentFreeSlots <= 0) { // no more free slots to use up! break; } ShowFiller(fsl.adapter.instance, reservedSlot, fsl.currentFreeSlotIndex, fsl.currentFreeSlotFixed); fsl.currentFreeSlots--; } }
public static IEnumerable <MechLabItemSlotElement> Elements(this MechLabPanel mechLab) { return(MechDefSlots.Locations .Select(location => mechLab.GetLocationWidget((ArmorLocation)location)) .Select(widget => new MechLabLocationWidgetAdapter(widget)) .SelectMany(adapter => adapter.LocalInventory)); }
internal static void OnStripArmor(MechLabPanel mechLabPanel) { if (!MechArmorState.Strip(mechLabPanel.activeMechDef, InputUtils.ControlModifierPressed, out var updates)) { return; } foreach (var update in updates) { var widget = mechLabPanel.GetLocationWidget(update.Location); widget.SetArmor(update.Location.IsRear(), update.Assigned); Control.Logger.Trace?.Log($"OnStripArmor.SetArmor update={update}"); } mechLabPanel.FlagAsModified(); mechLabPanel.ValidateLoadout(false); }
internal static void OnMaxArmor(MechLabPanel mechLabPanel, MechLabMechInfoWidget infoWidget) { if (!MechArmorState.Maximize(mechLabPanel.activeMechDef, InputUtils.ControlModifierPressed, ArmorStructureRatioFeature.ArmorPerStep, out var updates)) { return; } foreach (var update in updates) { var widget = mechLabPanel.GetLocationWidget(update.Location); widget.SetArmor(update.Location.IsRear(), update.Assigned); Control.Logger.Trace?.Log($"OnMaxArmor.SetArmor update={update}"); } infoWidget.RefreshInfo(); mechLabPanel.FlagAsModified(); mechLabPanel.ValidateLoadout(false); }
private static readonly ChassisLocations[] Locations = MechDefSlots.Locations; // order of locations to fill up first #endregion internal void RefreshData(MechLabPanel mechLab) { var fillerImageCache = MechLabLocationWidgetSetDataPatch.FillerImageCache; if (fillerImageCache.Count < Locations.Length) { return; } var slots = new MechDefSlots(mechLab.activeMechDef); using (var reservedSlots = slots.GetReservedSlots().GetEnumerator()) { foreach (var location in Locations) { var fillerImages = fillerImageCache[location]; var widget = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations var adapter = new MechLabLocationWidgetAdapter(widget); var used = adapter.usedSlots; for (var i = 0; i < adapter.maxSlots; i++) { var fillerImage = fillerImages[i]; if (i >= used && reservedSlots.MoveNext()) { var reservedSlot = reservedSlots.Current; if (reservedSlot == null) { throw new NullReferenceException(); } fillerImage.gameObject.SetActive(true); var uicolor = reservedSlot.ReservedSlotColor; var color = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.GetUIColor(uicolor); fillerImage.color = slots.IsOverloaded ? DynamicSlotsSpaceMissingColor : color; } else { fillerImage.gameObject.SetActive(false); } } } } }
internal void RefreshData(MechLabPanel mechLab) { if (MechLabLocationWidget_SetData_Patch.Fillers.Count < MechDefBuilder.Locations.Length) { return; } var slots = new MechDefBuilder(mechLab.activeMechDef); using (var reservedSlots = slots.GetReservedSlots().GetEnumerator()) { foreach (var location in MechDefBuilder.Locations) { var fillers = MechLabLocationWidget_SetData_Patch.Fillers[location]; var widget = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations var adapter = new MechLabLocationWidgetAdapter(widget); var used = adapter.usedSlots; var start = location == ChassisLocations.CenterTorso ? Control.settings.MechLabGeneralSlots : 0; for (var i = start; i < adapter.maxSlots; i++) { var fillerIndex = location == ChassisLocations.CenterTorso ? i - Control.settings.MechLabGeneralSlots : i; var filler = fillers[fillerIndex]; if (i >= used && reservedSlots.MoveNext()) { var reservedSlot = reservedSlots.Current; if (reservedSlot == null) { throw new NullReferenceException(); } filler.Show(reservedSlot); } else { filler.Hide(); } } } } }
private static readonly ChassisLocations[] Locations = MechDefSlots.Locations; // order of locations to fill up first #endregion internal void RefreshData(MechLabPanel mechLab) { if (MechLabLocationWidget_SetData_Patch.Fillers.Count < Locations.Length) { return; } var slots = new MechDefSlots(mechLab.activeMechDef); using (var reservedSlots = slots.GetReservedSlots().GetEnumerator()) { foreach (var location in Locations) { var fillers = MechLabLocationWidget_SetData_Patch.Fillers[location]; var widget = mechLab.GetLocationWidget((ArmorLocation)location); // by chance armorlocation = chassislocation for main locations var adapter = new MechLabLocationWidgetAdapter(widget); var used = adapter.usedSlots; for (var i = 0; i < adapter.maxSlots; i++) { var filler = fillers[i]; if (i >= used && reservedSlots.MoveNext()) { var reservedSlot = reservedSlots.Current; if (reservedSlot == null) { throw new NullReferenceException(); } filler.Show(reservedSlot); } else { filler.Hide(); } } } } }
public static bool Prefix(MechLabPanel __instance, MechLabMechInfoWidget ___mechInfoWidget, MechLabItemSlotElement ___dragItem) { try { if (__instance.Initialized && ___dragItem == null && !LocationExtensions.ChassisLocationList.Any(location => __instance.GetLocationWidget(location).IsDestroyed)) { ArmorMaximizerHandler.OnMaxArmor(__instance, ___mechInfoWidget); return(false); } } catch (Exception e) { Control.Logger.Error.Log(e); } return(true); }
internal void RefreshData(MechLabPanel mechLab) { var builder = new MechDefBuilder(mechLab.activeMechDef); var fslList = new List <DynamicSlotBuilder>(); var fslDict = new Dictionary <ChassisLocations, DynamicSlotBuilder>(); foreach (var location in MechDefBuilder.Locations) { // armorlocation = chassislocation for main locations var widget = mechLab.GetLocationWidget((ArmorLocation)location); ClearFillers(widget); var adapter = new MechLabLocationWidgetAdapter(widget); var dsbuilder = new DynamicSlotBuilder(builder, location, adapter); fslList.Add(dsbuilder); fslDict.Add(location, dsbuilder); } // first pass for items with location restrictions foreach (var componentRef in builder.Inventory) { var slot = componentRef.Def.GetComponent <DynamicSlots>(); if (slot == null || !slot.InnerAdjacentOnly) { continue; } var reservedSlots = slot.ReservedSlots; var location = componentRef.MountedLocation; { var fsl = fslDict[location]; while (fsl.currentFreeSlots > 0 && reservedSlots > 0) { ShowFiller(fsl.adapter.instance, slot, fsl.currentFreeSlotIndex, fsl.currentFreeSlotFixed); fsl.currentFreeSlots--; reservedSlots--; } } if (reservedSlots <= 0) { continue; } location = MechDefBuilder.GetInnerAdjacentLocation(location); if (location == ChassisLocations.None) { continue; } { var fsl = fslDict[location]; while (fsl.currentFreeSlots > 0 && reservedSlots > 0) { ShowFiller(fsl.adapter.instance, slot, fsl.currentFreeSlotIndex, true); fsl.currentFreeSlots--; reservedSlots--; } } } // second pass dynamic slots without location restrictions foreach (var slot in builder.Inventory.Select(c => c.GetComponent <DynamicSlots>()).Where(c => c != null && !c.InnerAdjacentOnly)) { var reservedSlots = slot.ReservedSlots; while (reservedSlots > 0) { var fsl = fslList.Max(); if (fsl.currentFreeSlots <= 0) { return; // no free slots left to use if thats the max } ShowFiller(fsl.adapter.instance, slot, fsl.currentFreeSlotIndex, fsl.currentFreeSlotFixed); fsl.currentFreeSlots--; reservedSlots--; } } }