Exemplo n.º 1
0
        public static bool FixGetMechdef(ref ShopDefItem itemDef, Shop shop, bool isBulkAdd, bool isSelling, IMechLabDropTarget targetWidget,
                                         MechLabInventoryWidget_ListView ___inventoryWidget, bool ___isInBuyingState, SimGameState ___simState,
                                         SG_Shop_Screen __instance)
        {
            if (itemDef.Type == ShopItemType.Mech && !___isInBuyingState)
            {
                var dataManager = ___simState.DataManager;

                string guid8 = itemDef.GUID;
                if (dataManager.ChassisDefs.Exists(guid8))
                {
                    ChassisDef chassisDef = dataManager.ChassisDefs.Get(guid8);
                    string     newGUID    = ___simState.GenerateSimGameUID();
                    var        id         = ChassisHandler.GetMDefFromCDef(guid8);
                    MechDef    stockMech  = dataManager.MechDefs.Get(id);
                    MechDef    mechDef3   = new MechDef(chassisDef, newGUID, stockMech);
                    mechDef3.Refresh();
                    if (mechDef3 != null)
                    {
                        InventoryDataObject_ShopFullMech inventoryDataObject_ShopFullMech2 = new InventoryDataObject_ShopFullMech();
                        inventoryDataObject_ShopFullMech2.Init(mechDef3, itemDef, shop, ___simState, dataManager,
                                                               targetWidget, itemDef.Count, isSelling, new UnityAction <InventoryItemElement>(__instance.OnItemSelected));
                        ___inventoryWidget.AddItemToInventory(inventoryDataObject_ShopFullMech2, isBulkAdd);
                        inventoryDataObject_ShopFullMech2.SetItemDraggable(false);
                    }
                }
                return(false);
            }

            return(true);
        }
        public static bool AddItemToInventory(MechLabInventoryWidget_ListView __instance, InventoryDataObject_BASE ItemData)
        {
            LogDebug("ShopTabLagFix: AddItemToInventory");
            var _this  = __instance;
            var _items = _this.ListView.Items;
            InventoryDataObject_BASE listElementController_BASE = null;

            foreach (InventoryDataObject_BASE listElementController_BASE2 in _this.inventoryData)
            {
                if (listElementController_BASE2.GetItemType() == ItemData.GetItemType() && listElementController_BASE2.IsDuplicateContent(ItemData) && _this.ParentDropTarget != null && _this.StackQuantities)
                {
                    listElementController_BASE = listElementController_BASE2;
                    break;
                }
            }

            if (listElementController_BASE != null)
            {
                listElementController_BASE.ModifyQuantity(1);
            }
            else
            {
                // OnItemAdded logic does not seem to be needed?
                // HBSLoopScroll 219-228
                _items.Add(ItemData);
            }
            return(false);
        }
Exemplo n.º 3
0
        internal static void Prefix(MechLabInventoryWidget_ListView __instance)
        {
            try
            {
                var adapter = new MechLabInventoryWidget_ListViewAdapter(__instance);

                if (adapter.invertSort)
                {
                    return;
                }

                if (adapter.currentListItemSorter is InventorySorterListComparer)
                {
                    return;
                }

                adapter.currentListItemSorter = new InventorySorterListComparer(adapter.currentListItemSorter.Compare);
                adapter.currentSort           = new InventorySorterListComparer(adapter.currentSort).Compare;
                adapter.invertSort            = false;
            }
            catch (Exception e)
            {
                Control.LogError(e);
            }
        }
Exemplo n.º 4
0
        public BuyHelper(SG_Shop_Screen shopScreen, InventoryDataObject_SHOP selectedController, SimGameState simGameState)
        {
            this.shopScreen   = shopScreen;
            this.simGameState = simGameState;
            shopIDO           = selectedController;

            Traverse traverse = Traverse.Create(shopScreen).Field("inventoryWidget");

            inventoryWidget = (MechLabInventoryWidget_ListView)traverse.GetValue();
        }
Exemplo n.º 5
0
        private static bool Prefix(MechLabInventoryWidget_ListView __instance)
        {
            IComparer <ListElementController_BASE> currComp = Traverse.Create(__instance).Field("currentListItemSorter").GetValue <IComparer <ListElementController_BASE> >();
            bool currDir = Traverse.Create(__instance).Field("invertSort").GetValue <bool>();

            try
            {
                Traverse.Create(__instance).Field("currentListItemSorter").SetValue(new Comparer_ListView());
                Traverse.Create(__instance).Field("invertSort").SetValue(true);
                return(true);
            }
            catch (Exception e)
            {
                BetterSorting.Log($"Failed to sort MechLabInventoryWidget, resetting to default.{Environment.NewLine}Details:{e.ToString()}");
                Traverse.Create(__instance).Field("currentSort").SetValue(currComp);
                Traverse.Create(__instance).Field("invertSort").SetValue(currDir);
                return(true);
            }
        }