public void UpdateData(ICharacterData character)
        {
            this.character = character;
            int selectedIdx = CacheItemSelectionManager.SelectedUI != null?CacheItemSelectionManager.IndexOf(CacheItemSelectionManager.SelectedUI) : -1;

            CacheItemSelectionManager.DeselectSelectedUI();
            CacheItemSelectionManager.Clear();

            if (character == null)
            {
                CacheItemList.HideAll();
                return;
            }

            IList <CharacterItem> nonEquipItems = character.NonEquipItems;
            IList <CharacterItem> filteredItems = new List <CharacterItem>();
            List <int>            filterIndexes = new List <int>();
            // Filter items to show by specific item types
            int counter = 0;

            foreach (CharacterItem nonEquipItem in nonEquipItems)
            {
                if (nonEquipItem.GetItem() == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(nonEquipItem.GetItem().category) ||
                    filterCategories == null || filterCategories.Count == 0 ||
                    filterCategories.Contains(nonEquipItem.GetItem().category))
                {
                    if (filterItemTypes == null || filterItemTypes.Count == 0 ||
                        filterItemTypes.Contains(nonEquipItem.GetItem().itemType))
                    {
                        filteredItems.Add(nonEquipItem);
                        filterIndexes.Add(counter);
                    }
                }
                ++counter;
            }
            CacheItemList.Generate(filteredItems, (index, characterItem, ui) =>
            {
                UICharacterItem uiCharacterItem = ui.GetComponent <UICharacterItem>();
                uiCharacterItem.Setup(new CharacterItemTuple(characterItem, characterItem.level, InventoryType.NonEquipItems), this.character, filterIndexes[index]);
                uiCharacterItem.Show();
                UICharacterItemDragHandler dragHandler = uiCharacterItem.GetComponentInChildren <UICharacterItemDragHandler>();
                if (dragHandler != null)
                {
                    dragHandler.SetupForNonEquipItems(uiCharacterItem);
                }
                CacheItemSelectionManager.Add(uiCharacterItem);
                if (selectedIdx == index)
                {
                    uiCharacterItem.OnClickSelect();
                }
            });
        }
        public void UpdateData()
        {
            if (storageType == StorageType.None)
            {
                return;
            }

            int selectedIdx = CacheCharacterItemSelectionManager.SelectedUI != null?CacheCharacterItemSelectionManager.IndexOf(CacheCharacterItemSelectionManager.SelectedUI) : -1;

            CacheCharacterItemSelectionManager.DeselectSelectedUI();
            CacheCharacterItemSelectionManager.Clear();
            totalWeight = 0;
            usedSlots   = 0;
            IList <CharacterItem> characterItems = BasePlayerCharacterController.OwningCharacter.StorageItems;

            CacheCharacterItemList.Generate(characterItems, (index, characterItem, ui) =>
            {
                UICharacterItem uiCharacterItem = ui.GetComponent <UICharacterItem>();
                uiCharacterItem.Setup(new CharacterItemTuple(characterItem, characterItem.level, InventoryType.StorageItems), BasePlayerCharacterController.OwningCharacter, index);
                uiCharacterItem.Show();
                if (characterItem.NotEmptySlot())
                {
                    totalWeight += characterItem.GetItem().weight *characterItem.amount;
                    usedSlots++;
                }
                UICharacterItemDragHandler dragHandler = uiCharacterItem.GetComponentInChildren <UICharacterItemDragHandler>();
                if (dragHandler != null)
                {
                    dragHandler.SetupForStorageItems(uiCharacterItem);
                }
                CacheCharacterItemSelectionManager.Add(uiCharacterItem);
                if (selectedIdx == index)
                {
                    uiCharacterItem.OnClickSelect();
                }
            });
        }
Beispiel #3
0
        protected override void UpdateData()
        {
            CharacterHotkey characterHotkey = Data;
            Skill           skill           = characterHotkey.GetSkill();
            Item            item            = characterHotkey.GetItem();

            BasePlayerCharacterEntity owningCharacter = BasePlayerCharacterController.OwningCharacter;

            if (uiCharacterSkill == null && uiCharacterHotkeys != null && uiCharacterHotkeys.uiCharacterSkillPrefab != null)
            {
                uiCharacterSkill = Instantiate(uiCharacterHotkeys.uiCharacterSkillPrefab, transform);
                GenericUtils.SetAndStretchToParentSize(uiCharacterSkill.transform as RectTransform, transform as RectTransform);
                uiCharacterSkill.transform.SetAsFirstSibling();
            }

            if (uiCharacterItem == null && uiCharacterHotkeys != null && uiCharacterHotkeys.uiCharacterItemPrefab != null)
            {
                uiCharacterItem = Instantiate(uiCharacterHotkeys.uiCharacterItemPrefab, transform);
                GenericUtils.SetAndStretchToParentSize(uiCharacterItem.transform as RectTransform, transform as RectTransform);
                uiCharacterItem.transform.SetAsFirstSibling();
            }

            if (uiCharacterSkill != null)
            {
                if (skill == null)
                {
                    uiCharacterSkill.Hide();
                }
                else
                {
                    Dictionary <Skill, short> allSkills = owningCharacter.GetSkills();
                    short skillLevel = 0;
                    if (allSkills.TryGetValue(characterHotkey.GetSkill(), out skillLevel))
                    {
                        int            index          = owningCharacter.IndexOfSkill(characterHotkey.dataId);
                        CharacterSkill characterSkill = index >= 0 ? owningCharacter.Skills[index] : CharacterSkill.Create(characterHotkey.GetSkill(), skillLevel);
                        uiCharacterSkill.Setup(new CharacterSkillTuple(characterSkill, skillLevel), owningCharacter, index);
                        uiCharacterSkill.Show();
                        UICharacterSkillDragHandler dragHandler = uiCharacterSkill.GetComponentInChildren <UICharacterSkillDragHandler>();
                        if (dragHandler != null)
                        {
                            dragHandler.SetupForHotkey(this);
                        }
                    }
                    else
                    {
                        uiCharacterSkill.Hide();
                    }
                }
            }

            if (uiCharacterItem != null)
            {
                if (item == null)
                {
                    uiCharacterItem.Hide();
                }
                else
                {
                    int index = owningCharacter.IndexOfNonEquipItem(characterHotkey.dataId);
                    if (index >= 0 && index < owningCharacter.NonEquipItems.Count)
                    {
                        CharacterItem characterItem = owningCharacter.NonEquipItems[index];
                        uiCharacterItem.Setup(new CharacterItemTuple(characterItem, characterItem.level, InventoryType.NonEquipItems), owningCharacter, index);
                        uiCharacterItem.Show();
                        UICharacterItemDragHandler dragHandler = uiCharacterItem.GetComponentInChildren <UICharacterItemDragHandler>();
                        if (dragHandler != null)
                        {
                            dragHandler.SetupForHotkey(this);
                        }
                    }
                    else
                    {
                        uiCharacterItem.Hide();
                    }
                }
            }
        }