コード例 #1
0
        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--;
            }
        }
コード例 #2
0
        internal static void AdjustLocationNaming(MechLabLocationWidget widget, ChassisLocations location)
        {
            // just hide armor = 0 stuff
            widget.gameObject.SetActive(!widget.ShouldHide());

            var mechLab = (MechLabPanel)widget.parentDropTarget;
            var text    = GetLocationName(mechLab.activeMechDef.Chassis, location);

            var adapter = new MechLabLocationWidgetAdapter(widget);

            adapter.locationName.SetText(text);
        }
コード例 #3
0
            internal DynamicSlotBuilder(
                MechDefBuilder builder,
                ChassisLocations location,
                MechLabLocationWidgetAdapter adapter)
            {
                this.builder  = builder;
                this.location = location;
                this.adapter  = adapter;

                currentFreeSlots = builder.GetFreeSlots(location);

                finalTotalFree = this.builder.TotalFree;
                maxSlots       = adapter.maxSlots;
            }
コード例 #4
0
            internal DynamicSlotBuilder(
                MechDefBuilder builder,
                ChassisLocations location,
                MechLabLocationWidgetAdapter adapter)
            {
                this.builder  = builder;
                this.location = location;
                this.adapter  = adapter;

                var locationInfo = builder.GetLocationInfo(location);

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

                maxSlots = adapter.maxSlots;
            }
コード例 #5
0
        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();
                        }
                    }
                }
            }
        }
コード例 #6
0
 internal MechLabLocationWidgetPatchHelper(MechLabLocationWidget widget)
 {
     _adapter = new MechLabLocationWidgetAdapter(widget);
 }
コード例 #7
0
        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--;
                }
            }
        }