예제 #1
0
        static private void ChangeSorting(Players.Data player)
        {
            // Cache
            Transform stashPanelHolder           = GetStashPanel(player.UI);
            InventoryContentDisplay inventory    = GetPlayerStashInventoryPanel(stashPanelHolder).GetComponent <InventoryContentDisplay>();
            ContainerDisplay        chestDisplay = GetChestStashInventoryPanel(stashPanelHolder).GetComponent <ContainerDisplay>();

            // Sort
            ItemListDisplay.SortingType nextSorting = default;
            switch (chestDisplay.m_lastSortingType)
            {
            case ItemListDisplay.SortingType.ByList: nextSorting = ItemListDisplay.SortingType.ByWeight; break;

            case ItemListDisplay.SortingType.ByWeight: nextSorting = ItemListDisplay.SortingType.ByDurability; break;

            case ItemListDisplay.SortingType.ByDurability: nextSorting = ItemListDisplay.SortingType.ByList; break;
            }
            foreach (var containerDisplay in new[] { inventory.m_pouchDisplay, inventory.m_bagDisplay, chestDisplay })
            {
                containerDisplay.SortBy(nextSorting);
            }
            UpdateStashName(player);

            // Select first
            GameObject selectedObject = EventSystem.current.GetCurrentSelectedGameObject(player.ID);

            if (selectedObject != null &&
                selectedObject.TryGetComponent(out ItemDisplay currentItem) &&
                currentItem.ParentItemListDisplay != null)
            {
                currentItem.ParentItemListDisplay.m_assignedDisplays.First().OnSelect();
            }
        }
예제 #2
0
        static private void SwitchToStash(Players.Data player)
        {
            if (EventSystem.current.GetCurrentSelectedGameObject(player.ID).TryGetComponent(out ItemDisplay currentItem) &&
                currentItem.m_refItem == null)
            {
                return;
            }

            // Cache
            ContainerDisplay   chest      = GetChestStashInventoryPanel(GetStashPanel(player.UI)).GetComponent <ContainerDisplay>();
            List <ItemDisplay> chestItems = chest.m_assignedDisplays;
            int currentID = chestItems.IndexOf(currentItem);

            // Execute
            if (currentID >= chestItems.Count - 1)
            {
                chestItems.First().OnSelect();
            }
            else if (currentID >= 0)
            {
                int nextID = currentID + chestItems.Count / 2;
                if (chestItems.IsIndexValid(nextID))
                {
                    chestItems[nextID].OnSelect();
                }
                else
                {
                    chestItems.Last().OnSelect();
                }
            }
            else if (chestItems.IsNotEmpty())
            {
                chestItems.First().OnSelect();
            }
        }
예제 #3
0
        static private void UpdateStashName(Players.Data player)
        {
            // Cache
            Transform        stashPanelHolder = GetStashPanel(player.UI);
            ContainerDisplay chestDisplay     = GetChestStashInventoryPanel(stashPanelHolder).GetComponent <ContainerDisplay>();
            Text             stashTitle       = GetChestStashTitle(stashPanelHolder).GetComponent <Text>();

            // Execute
            stashTitle.text = "Stash";
            switch (chestDisplay.m_lastSortingType)
            {
            case ItemListDisplay.SortingType.ByList: break;

            case ItemListDisplay.SortingType.ByWeight: stashTitle.text += "<color=lime> (sorted by Weight)</color>"; break;

            case ItemListDisplay.SortingType.ByDurability: stashTitle.text += "<color=orange> (sorted by Durability)</color>"; break;
            }
        }
예제 #4
0
        // Utility
        static private void SwitchToInventory(Players.Data player)
        {
            if (EventSystem.current.GetCurrentSelectedGameObject(player.ID).TryGetComponent(out ItemDisplay currentItem) &&
                currentItem.m_refItem == null)
            {
                return;
            }

            // Cache
            InventoryContentDisplay inventory  = GetPlayerStashInventoryPanel(GetStashPanel(player.UI)).GetComponent <InventoryContentDisplay>();
            List <ItemDisplay>      pouchItems = inventory.m_pouchDisplay.m_assignedDisplays;
            List <ItemDisplay>      bagItems   = inventory.m_bagDisplay.m_assignedDisplays;
            int currentID = bagItems.IndexOf(currentItem);

            // Execute
            if (currentID >= bagItems.Count - 1)
            {
                bagItems.First().OnSelect();
            }
            else if (currentID >= 0)
            {
                int nextID = currentID + bagItems.Count / 2;
                if (bagItems.IsIndexValid(nextID))
                {
                    bagItems[nextID].OnSelect();
                }
                else
                {
                    bagItems.Last().OnSelect();
                }
            }
            else if (bagItems.IsNotEmpty())
            {
                bagItems.First().OnSelect();
            }
            else if (pouchItems.IsNotEmpty())
            {
                pouchItems.First().OnSelect();
            }
        }
예제 #5
0
        static private void FindSameItemInOtherPanel(Players.Data player)
        {
            if (EventSystem.current.GetCurrentSelectedGameObject(player.ID).TryGetComponent(out ItemDisplay currentItem) && currentItem.m_refItem == null)
            {
                return;
            }

            // Cache
            Transform stashPanelHolder         = GetStashPanel(player.UI);
            InventoryContentDisplay inventory  = GetPlayerStashInventoryPanel(stashPanelHolder).GetComponent <InventoryContentDisplay>();
            List <ItemDisplay>      chestItems = GetChestStashInventoryPanel(stashPanelHolder).GetComponent <ContainerDisplay>().m_assignedDisplays;
            List <ItemDisplay>      bagItems   = inventory.m_bagDisplay.m_assignedDisplays;
            List <ItemDisplay>      pouchItems = inventory.m_pouchDisplay.m_assignedDisplays;

            // Execute
            ItemDisplay foundItem;

            if (currentItem.IsContainedIn(chestItems))
            {
                foundItem = FindItemInContainerDisplay(currentItem, bagItems);
                if (foundItem == null)
                {
                    foundItem = FindItemInContainerDisplay(currentItem, pouchItems);
                }
            }
            else if (currentItem.IsContainedIn(bagItems) || currentItem.IsContainedIn(pouchItems))
            {
                foundItem = FindItemInContainerDisplay(currentItem, chestItems);
            }
            else
            {
                return;
            }

            foundItem.OnSelect();
        }