Пример #1
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();
        }
Пример #2
0
        public void UpdateData(ICharacterData character)
        {
            this.character = character;
            int selectedSkillId = CacheSkillSelectionManager.SelectedUI != null ? CacheSkillSelectionManager.SelectedUI.Skill.DataId : 0;

            CacheSkillSelectionManager.DeselectSelectedUI();
            CacheSkillSelectionManager.Clear();

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

            // All skills included equipment skill levels
            displayingSkills = character.GetSkills();

            BaseCharacter database = character.GetDatabase();

            if (database != null)
            {
                CharacterSkill tempCharacterSkill;
                Skill          tempSkill;
                int            tempIndexOfSkill;
                short          tempLevel;
                // Combine skills from database (skill that can level up) and equipment skills
                Dictionary <Skill, short> skillLevels = new Dictionary <Skill, short>();
                skillLevels = GameDataHelpers.CombineSkills(skillLevels, database.CacheSkillLevels);
                skillLevels = GameDataHelpers.CombineSkills(skillLevels, character.GetEquipmentSkills());
                // Filter skills to show by specific skill types / categories
                Dictionary <Skill, short> filteredSkillLevels = new Dictionary <Skill, short>();
                foreach (KeyValuePair <Skill, short> skillLevel in skillLevels)
                {
                    if (string.IsNullOrEmpty(skillLevel.Key.category) ||
                        filterCategories == null || filterCategories.Count == 0 ||
                        filterCategories.Contains(skillLevel.Key.category))
                    {
                        if (filterSkillTypes == null || filterSkillTypes.Count == 0 ||
                            filterSkillTypes.Contains(skillLevel.Key.skillType))
                        {
                            filteredSkillLevels.Add(skillLevel.Key, skillLevel.Value);
                        }
                    }
                }
                skillLevels = filteredSkillLevels;
                // Generate UIs
                CacheSkillList.Generate(skillLevels, (index, skillLevel, ui) =>
                {
                    UICharacterSkill uiCharacterSkill = ui.GetComponent <UICharacterSkill>();
                    tempSkill        = skillLevel.Key;
                    tempIndexOfSkill = character.IndexOfSkill(tempSkill.DataId);
                    // Set character skill data
                    if (tempIndexOfSkill >= 0)
                    {
                        tempCharacterSkill = character.Skills[tempIndexOfSkill];
                    }
                    else
                    {
                        tempCharacterSkill = CharacterSkill.Create(tempSkill, 0);
                    }
                    // Set skill level data
                    tempLevel = 0;
                    if (displayingSkills.ContainsKey(tempSkill))
                    {
                        tempLevel = displayingSkills[tempSkill];
                    }
                    // Set UI data
                    uiCharacterSkill.Setup(new CharacterSkillTuple(tempCharacterSkill, tempLevel), character, tempIndexOfSkill);
                    uiCharacterSkill.Show();
                    UICharacterSkillDragHandler dragHandler = uiCharacterSkill.GetComponentInChildren <UICharacterSkillDragHandler>();
                    if (dragHandler != null)
                    {
                        dragHandler.SetupForSkills(uiCharacterSkill);
                    }
                    CacheSkillSelectionManager.Add(uiCharacterSkill);
                    if (selectedSkillId == skillLevel.Key.DataId)
                    {
                        uiCharacterSkill.OnClickSelect();
                    }
                });
            }
        }
        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();
        }