Esempio n. 1
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();
                    }
                }
            }
        }
Esempio n. 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 void OnDrop(PointerEventData eventData)
        {
            if (uiCharacterHotkey == null)
            {
                Debug.LogWarning("[UICharacterHotkeyDropHandler] `uiCharacterHotkey` is empty");
                return;
            }
            if (RectTransformUtility.RectangleContainsScreenPoint(DropRect, Input.mousePosition))
            {
                UIDragHandler dragHandler = eventData.pointerDrag.GetComponent <UIDragHandler>();
                if (dragHandler != null && !dragHandler.isDropped)
                {
                    dragHandler.isDropped = true;
                    // Get owing character
                    BasePlayerCharacterEntity owningCharacter = BasePlayerCharacterController.OwningCharacter;
                    if (owningCharacter == null)
                    {
                        return;
                    }

                    string     swappingHotkeyId = string.Empty;
                    HotkeyType swappingType     = HotkeyType.None;
                    int        swappingDataId   = 0;
                    // If dragged item UI
                    UICharacterItemDragHandler draggedItemUI = dragHandler as UICharacterItemDragHandler;
                    if (draggedItemUI != null)
                    {
                        if (draggedItemUI.sourceLocation == UICharacterItemDragHandler.SourceLocation.Hotkey)
                        {
                            swappingHotkeyId = draggedItemUI.uiCharacterHotkey.Data.hotkeyId;
                            swappingType     = uiCharacterHotkey.Data.type;
                            swappingDataId   = uiCharacterHotkey.Data.dataId;
                        }

                        if (uiCharacterHotkey.CanAssignCharacterItem(draggedItemUI.CacheUI.Data.characterItem))
                        {
                            // Assign item to hotkey
                            owningCharacter.RequestAssignHotkey(uiCharacterHotkey.Data.hotkeyId, HotkeyType.Item, draggedItemUI.CacheUI.Data.characterItem.dataId);
                        }

                        if (draggedItemUI.sourceLocation == UICharacterItemDragHandler.SourceLocation.Hotkey)
                        {
                            // Swap key
                            owningCharacter.RequestAssignHotkey(swappingHotkeyId, swappingType, swappingDataId);
                        }
                    }
                    // If dragged skill UI
                    UICharacterSkillDragHandler draggedSkillUI = dragHandler as UICharacterSkillDragHandler;
                    if (draggedSkillUI != null)
                    {
                        if (draggedSkillUI.sourceLocation == UICharacterSkillDragHandler.SourceLocation.Hotkey)
                        {
                            swappingHotkeyId = draggedSkillUI.uiCharacterHotkey.Data.hotkeyId;
                            swappingType     = uiCharacterHotkey.Data.type;
                            swappingDataId   = uiCharacterHotkey.Data.dataId;
                        }

                        if (uiCharacterHotkey.CanAssignCharacterSkill(draggedSkillUI.CacheUI.Data.characterSkill))
                        {
                            // Assign item to hotkey
                            owningCharacter.RequestAssignHotkey(uiCharacterHotkey.Data.hotkeyId, HotkeyType.Skill, draggedSkillUI.CacheUI.Data.characterSkill.dataId);
                        }

                        if (draggedSkillUI.sourceLocation == UICharacterSkillDragHandler.SourceLocation.Hotkey)
                        {
                            // Swap key
                            owningCharacter.RequestAssignHotkey(swappingHotkeyId, swappingType, swappingDataId);
                        }
                    }
                }
            }
        }