public void SetupPocket(BackpackPocket pocket) { if (pocket == BackpackPocket.None) { return; } this.m_ActivePlane = null; this.m_ActivePocket = pocket; this.SetBackpackTransform(pocket); PocketGrid pocketGrid = null; if (pocket != BackpackPocket.Main) { if (pocket == BackpackPocket.Front) { this.m_ActivePlane = this.m_FrontPlane; this.m_MainPlane.gameObject.SetActive(false); this.m_ActivePlane.gameObject.SetActive(true); this.m_FrontPocketGrid.Setup(); pocketGrid = this.m_FrontPocketGrid; } } else { this.m_ActivePlane = this.m_MainPlane; this.m_FrontPlane.gameObject.SetActive(false); this.m_ActivePlane.gameObject.SetActive(true); this.m_MainPocketGrid.Setup(); pocketGrid = this.m_MainPocketGrid; } if (pocket != BackpackPocket.None) { List <GameObject> objectToDisable = this.m_Backpack.GetObjectToDisable(pocket); for (int i = 0; i < this.m_Backpack.transform.childCount; i++) { GameObject gameObject = this.m_Backpack.transform.GetChild(i).gameObject; if (this.m_FakeItemsData.ContainsKey(gameObject) && !this.m_FakeItemsData[gameObject]) { gameObject.SetActive(false); } else { gameObject.SetActive(!objectToDisable.Contains(this.m_Backpack.transform.GetChild(i).gameObject)); } } foreach (Item item in this.m_Items) { item.gameObject.SetActive(item.m_Info.m_BackpackPocket == pocket); if (pocketGrid != null && item.m_Info.m_InventoryCellsGroup != null && item.m_CurrentSlot == null) { item.m_Info.m_InventoryCellsGroup.Setup(); item.m_Info.m_InventoryCellsGroup.SetupTansform(item, pocketGrid.m_Grid); } } } }
public void SortItemsBySize() { if (this.m_ActivePocket != BackpackPocket.Front && this.m_ActivePocket != BackpackPocket.Main) { return; } PocketGrid pocketGrid = (this.m_ActivePocket == BackpackPocket.Front) ? this.m_FrontPocketGrid : this.m_MainPocketGrid; this.m_TempSortItems.Clear(); foreach (Item item in this.m_Items) { if (item.m_Info.m_BackpackPocket == this.m_ActivePocket) { this.m_TempSortItems.Add(item); } } foreach (Item item2 in this.m_TempSortItems) { this.RemoveItem(item2, false); } this.m_TempSortItems.Sort(new Comparison <Item>(InventoryBackpack.CompareBySize)); foreach (Item item3 in this.m_TempSortItems) { ItemSlot itemSlot = null; for (int i = 0; i < this.m_Items.Count; i++) { Item item4 = this.m_Items[i]; if (item4.m_InventorySlot && !item4.m_CurrentSlot && item4.m_InventorySlot.CanInsertItem(item3)) { if (item4.m_Info.m_InventoryRotated != item3.m_Info.m_InventoryRotated) { Inventory3DManager.Get().RotateItem(item3, true); } itemSlot = item4.m_InventorySlot; break; } } if (itemSlot) { this.InsertItem(item3, itemSlot, null, true, true, false, true, true); } else { List <InventoryCellsGroup> list = new List <InventoryCellsGroup>(); int num = 0; int num2 = 0; item3.m_Info.m_InventoryRotated = false; pocketGrid.CalcRequiredCells(item3, ref num, ref num2); int num3 = 0; int num4 = 0; item3.m_Info.m_InventoryRotated = true; pocketGrid.CalcRequiredCells(item3, ref num3, ref num4); item3.m_Info.m_InventoryRotated = (num3 > num); int num5 = item3.m_Info.m_InventoryRotated ? num3 : num; int num6 = item3.m_Info.m_InventoryRotated ? num4 : num2; InventoryCell[,] cells = pocketGrid.m_Cells; int upperBound = cells.GetUpperBound(0); int upperBound2 = cells.GetUpperBound(1); for (int j = cells.GetLowerBound(0); j <= upperBound; j++) { for (int k = cells.GetLowerBound(1); k <= upperBound2; k++) { InventoryCell inventoryCell = cells[j, k]; if (inventoryCell.m_IndexX + num5 <= (int)pocketGrid.m_GridSize.x && inventoryCell.m_IndexY + num6 <= (int)pocketGrid.m_GridSize.y) { InventoryCellsGroup inventoryCellsGroup = new InventoryCellsGroup(this.m_ActivePocket); for (int l = inventoryCell.m_IndexX; l < inventoryCell.m_IndexX + num5; l++) { for (int m = inventoryCell.m_IndexY; m < inventoryCell.m_IndexY + num6; m++) { inventoryCellsGroup.m_Cells.Add(pocketGrid.m_Cells[l, m]); } } if (inventoryCellsGroup.m_Cells.Count != 0 && inventoryCellsGroup.IsFree()) { inventoryCellsGroup.Setup(); list.Add(inventoryCellsGroup); } } } } if (list.Count == 0) { this.InsertItem(item3, null, null, true, true, false, true, true); } else { InventoryCellsGroup inventoryCellsGroup2 = null; foreach (InventoryCellsGroup inventoryCellsGroup3 in list) { if (inventoryCellsGroup2 == null || inventoryCellsGroup3.m_Cells[0].m_IndexY < inventoryCellsGroup2.m_Cells[0].m_IndexY) { inventoryCellsGroup2 = inventoryCellsGroup3; } } foreach (InventoryCellsGroup inventoryCellsGroup4 in list) { if (inventoryCellsGroup4.m_Cells[0].m_IndexX > inventoryCellsGroup2.m_Cells[0].m_IndexX && inventoryCellsGroup4.m_Cells[0].m_IndexY == inventoryCellsGroup2.m_Cells[0].m_IndexY) { inventoryCellsGroup2 = inventoryCellsGroup4; } } InsertResult insertResult = this.InsertItem(item3, null, inventoryCellsGroup2, true, true, false, true, true); if (insertResult != InsertResult.Ok) { insertResult = this.InsertItem(item3, null, null, true, true, false, true, true); } if (insertResult != InsertResult.Ok) { DebugUtils.Assert(DebugUtils.AssertType.Info); } } } } }