Пример #1
0
        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();
                }
            });
        }
Пример #2
0
        public override void Show()
        {
            CacheSkillSelectionManager.eventOnSelect.RemoveListener(OnSelectCharacterSkill);
            CacheSkillSelectionManager.eventOnSelect.AddListener(OnSelectCharacterSkill);
            CacheItemSelectionManager.eventOnSelect.RemoveListener(OnSelectCharacterItem);
            CacheItemSelectionManager.eventOnSelect.AddListener(OnSelectCharacterItem);
            var owningCharacter = BasePlayerCharacterController.OwningCharacter;

            if (owningCharacter == null)
            {
                CacheSkillList.HideAll();
                CacheItemList.HideAll();
                return;
            }
            var filterSkills    = new List <CharacterSkill>();
            var filterItems     = new List <CharacterItem>();
            var characterSkills = owningCharacter.Skills;
            var characterItems  = owningCharacter.NonEquipItems;

            foreach (var characterSkill in characterSkills)
            {
                var skill = characterSkill.GetSkill();
                if (skill != null && characterSkill.level > 0 &&
                    (skill.skillType == SkillType.Active || skill.skillType == SkillType.CraftItem))
                {
                    filterSkills.Add(characterSkill);
                }
            }
            foreach (var characterItem in characterItems)
            {
                var item = characterItem.GetItem();
                if (item != null && characterItem.level > 0 && characterItem.amount > 0 &&
                    (item.IsPotion() || item.IsBuilding() || item.IsPet()))
                {
                    filterItems.Add(characterItem);
                }
            }
            CacheSkillList.Generate(filterSkills, (index, characterSkill, ui) =>
            {
                var uiCharacterSkill = ui.GetComponent <UICharacterSkill>();
                uiCharacterSkill.Setup(new SkillTuple(characterSkill.GetSkill(), characterSkill.level), null, -1);
                uiCharacterSkill.Show();
                CacheSkillSelectionManager.Add(uiCharacterSkill);
            });
            CacheItemList.Generate(filterItems, (index, characterItem, ui) =>
            {
                var uiCharacterItem = ui.GetComponent <UICharacterItem>();
                uiCharacterItem.Setup(new CharacterItemTuple(characterItem, characterItem.level, string.Empty), null, -1);
                uiCharacterItem.Show();
                CacheItemSelectionManager.Add(uiCharacterItem);
            });
            base.Show();
        }
        public override void Show()
        {
            CacheSkillSelectionManager.eventOnSelect.RemoveListener(OnSelectCharacterSkill);
            CacheSkillSelectionManager.eventOnSelect.AddListener(OnSelectCharacterSkill);
            CacheItemSelectionManager.eventOnSelect.RemoveListener(OnSelectCharacterItem);
            CacheItemSelectionManager.eventOnSelect.AddListener(OnSelectCharacterItem);
            BasePlayerCharacterEntity owningCharacter = BasePlayerCharacterController.OwningCharacter;

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

            // Skills
            List <CharacterSkill> filterSkills        = new List <CharacterSkill>();
            List <int>            filterSkillsIndexes = new List <int>();
            // Items
            List <CharacterItem> filterItems        = new List <CharacterItem>();
            List <int>           filterItemsIndexes = new List <int>();

            CharacterSkill tempCharacterSkill;

            foreach (KeyValuePair <Skill, short> characterSkill in owningCharacter.CacheSkills)
            {
                tempCharacterSkill = CharacterSkill.Create(characterSkill.Key, characterSkill.Value);
                if (uiCharacterHotkey.CanAssignCharacterSkill(tempCharacterSkill))
                {
                    filterSkills.Add(tempCharacterSkill);
                    filterSkillsIndexes.Add(owningCharacter.IndexOfSkill(tempCharacterSkill.dataId));
                }
            }

            int counter = 0;

            foreach (CharacterItem characterItem in owningCharacter.NonEquipItems)
            {
                if (uiCharacterHotkey.CanAssignCharacterItem(characterItem))
                {
                    filterItems.Add(characterItem);
                    filterItemsIndexes.Add(counter);
                }
                ++counter;
            }

            CacheSkillList.Generate(filterSkills, (index, characterSkill, ui) =>
            {
                UICharacterSkill uiCharacterSkill = ui.GetComponent <UICharacterSkill>();
                uiCharacterSkill.Setup(new CharacterSkillTuple(characterSkill, characterSkill.level), null, filterSkillsIndexes[index]);
                uiCharacterSkill.Show();
                CacheSkillSelectionManager.Add(uiCharacterSkill);
            });

            CacheItemList.Generate(filterItems, (index, characterItem, ui) =>
            {
                UICharacterItem uiCharacterItem = ui.GetComponent <UICharacterItem>();
                uiCharacterItem.Setup(new CharacterItemTuple(characterItem, characterItem.level, InventoryType.NonEquipItems), null, filterItemsIndexes[index]);
                uiCharacterItem.Show();
                CacheItemSelectionManager.Add(uiCharacterItem);
            });
            base.Show();
        }