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(); }
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); } } } } }