示例#1
0
 public static bool ChangeColor(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget)
 {
     try
     {
         theWidget.iconBGColors.SetColor(__instance.componentRef);
     }
     catch (Exception ex)
     {
         Control.LogError(ex);
     }
     return(false);
 }
 public static bool ChangeColor(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget)
 {
     try
     {
         ColorExtentions.ChangeBackColor(__instance.componentRef.Def, theWidget);
         TColorExtentions.ChangeTextIconColor(__instance.componentRef.Def, theWidget);
     }
     catch
     {
         return(true);
     }
     return(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);
     }
 }
示例#4
0
 public static void Postfix(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget)
 {
     try
     {
         if (HasOverrideColor(__instance.componentRef.Def, out Color overrideColor))
         {
             UIColorRefTracker[] array = theWidget.iconBGColors;
             for (int i = 0; i < array.Length; i++)
             {
                 array[i].OverrideWithColor(overrideColor);
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
 }
示例#5
0
            static bool Prefix(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget)
            {
                try
                {
                    if (__instance.quantity == -2147483648)
                    {
                        theWidget.qtyElement.SetActive(false);
                        return(false);
                    }

                    theWidget.qtyElement.SetActive(true);
                    theWidget.quantityValue.SetText("{0}", __instance.quantity);
                    theWidget.quantityValueColor.SetUIColor((__instance.quantity > 0 || __instance.quantity == int.MinValue) ? UIColor.White : UIColor.Red);
                    return(false);
                }
                catch (Exception e)
                {
                    Log("*****Exception thrown with ListElementController_InventoryWeapon_NotListView");
                    Log($"theWidget null: {theWidget == null}");
                    Log($"theWidget.qtyElement null: {theWidget.qtyElement == null}");
                    Log($"theWidget.quantityValue null: {theWidget.quantityValue == null}");
                    Log($"theWidget.quantityValueColor null: {theWidget.quantityValueColor == null}");
                    if (theWidget.itemName != null)
                    {
                        Log("theWidget.itemName");
                        Log(theWidget.itemName.ToString());
                    }

                    if (__instance.GetName() != null)
                    {
                        Log("__instance.GetName");
                        Log(__instance.GetName());
                    }

                    Error(e);
                    return(false);
                }
            }
        public PatchMechlabLimitItems(MechLabPanel instance)
        {
            try {
                var sw = new Stopwatch();
                sw.Start();
                this.instance        = instance;
                this.inventoryWidget = new Traverse(instance).Field("inventoryWidget")
                                       .GetValue <MechLabInventoryWidget>()
                                       .LogIfNull("inventoryWidget is null");

                LogDebug($"StorageInventory contains {instance.storageInventory.Count}");

                if (instance.IsSimGame)
                {
                    new Traverse(instance).Field("originalStorageInventory").SetValue(instance.storageInventory.LogIfNull("storageInventory is null"));
                }

                LogDebug($"Mechbay Patch initialized :simGame? {instance.IsSimGame}");

                List <ListElementController_BASE_NotListView> BuildRawInventory()
                => instance.storageInventory.Select <MechComponentRef, ListElementController_BASE_NotListView>(componentRef => {
                    componentRef.LogIfNull("componentRef is null");
                    componentRef.DataManager = instance.dataManager.LogIfNull("(MechLabPanel instance).dataManager is null");
                    componentRef.RefreshComponentDef();
                    componentRef.Def.LogIfNull("componentRef.Def is null");
                    var count = (!instance.IsSimGame
                                          ? int.MinValue
                                          : instance.sim.GetItemCount(componentRef.Def.Description, componentRef.Def.GetType(), instance.sim.GetItemCountDamageType(componentRef)));

                    if (componentRef.ComponentDefType == ComponentType.Weapon)
                    {
                        ListElementController_InventoryWeapon_NotListView controller = new ListElementController_InventoryWeapon_NotListView();
                        controller.InitAndFillInSpecificWidget(componentRef, null, instance.dataManager, null, count, false);
                        return(controller);
                    }
                    else
                    {
                        ListElementController_InventoryGear_NotListView controller = new ListElementController_InventoryGear_NotListView();
                        controller.InitAndFillInSpecificWidget(componentRef, null, instance.dataManager, null, count, false);
                        return(controller);
                    }
                }).ToList();

                /* Build a list of data only for all components. */
                rawInventory = Sort(BuildRawInventory());

                InventoryItemElement_NotListView mkiie(bool nonexistant)
                {
                    var nlv = instance.dataManager.PooledInstantiate(ListElementController_BASE_NotListView.INVENTORY_ELEMENT_PREFAB_NotListView
                                                                     , BattleTechResourceType.UIModulePrefabs, null, null, null)
                              .LogIfNull("Unable to instantiate INVENTORY_ELEMENT_PREFAB_NotListView")
                              .GetComponent <InventoryItemElement_NotListView>()
                              .LogIfNull("Inventory_Element_prefab does not contain a NLV");

                    nlv.gameObject.IsDestroyedError("NLV gameObject has been destroyed");
                    nlv.gameObject.LogIfNull("NLV gameObject has been destroyed");
                    if (!nonexistant)
                    {
                        nlv.SetRadioParent(new Traverse(inventoryWidget).Field("inventoryRadioSet").GetValue <HBSRadioSet>().LogIfNull("inventoryRadioSet is null"));
                        nlv.gameObject.transform.SetParent(new Traverse(inventoryWidget).Field("listParent").GetValue <UnityEngine.Transform>().LogIfNull("listParent is null"), false);
                        nlv.gameObject.transform.localScale = UnityEngine.Vector3.one;
                    }
                    return(nlv);
                };

                iieTmp = mkiie(true);

                /* Allocate very few visual elements, as this is extremely slow for both allocation and deallocation.
                 * It's the difference between a couple of milliseconds and several seconds for many unique items in inventory
                 * This is the core of the fix, the rest is just to make it work within HBS's existing code.
                 */
                List <InventoryItemElement_NotListView> make_ielCache()
                => Enumerable.Repeat <Func <InventoryItemElement_NotListView> >(() => mkiie(false), itemLimit)
                .Select(thunk => thunk())
                .ToList();

                ielCache = make_ielCache();

                var li = new Traverse(inventoryWidget).Field("localInventory").GetValue <List <InventoryItemElement_NotListView> >();
                ielCache.ForEach(iw => li.Add(iw));
                // End

                var lp = new Traverse(inventoryWidget).Field("listParent").GetValue <UnityEngine.Transform>();

                // DummyStart&End are blank rects stored at the beginning and end of the list so that unity knows how big the scrollrect should be
                // "placeholders"
                if (DummyStart == null)
                {
                    DummyStart = new UnityEngine.GameObject().AddComponent <UnityEngine.RectTransform>();
                }
                if (DummyEnd == null)
                {
                    DummyEnd = new UnityEngine.GameObject().AddComponent <UnityEngine.RectTransform>();
                }

                DummyStart.SetParent(lp, false);
                DummyEnd.SetParent(lp, false);
                LogDebug(string.Format("[LimitItems] inventory cached in {0} ms", sw.Elapsed.TotalMilliseconds));

                FilterChanged();
            } catch (Exception e) {
                LogException(e);
            }
        }