using System; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; public class EquipmentPanelController : DraggablePanelController { [SerializeField] protected GameObject _panelAdditionalSlotsContent; protected override UIBaseManager> FetchUiManager() { return GameObject.FindObjectOfType(); } public override void BuildPanelSlots() { InitSlotsList(); } public void InitSlotsList() { _panelContent.transform.Find("equipment_slot_helmet").GetComponent()._PanelController = this; _panelContent.transform.Find("equipment_slot_armor").GetComponent()._PanelController = this; _panelContent.transform.Find("equipment_slot_weapon").GetComponent()._PanelController = this; _panelContent.transform.Find("equipment_slot_boots").GetComponent()._PanelController = this; _panelAdditionalSlotsContent.transform.Find("equipment_slot_ring").GetComponent()._PanelController = this; _panelAdditionalSlotsContent.transform.Find("equipment_slot_bracelet").GetComponent()._PanelController = this; _panelAdditionalSlotsContent.transform.Find("equipment_slot_necklet").GetComponent()._PanelController = this; _panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_i").GetComponent()._PanelController = this; _panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_ii").GetComponent()._PanelController = this; ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_helmet").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_armor").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_weapon").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_boots").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_bracelet").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklet").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_i").GetComponent())); ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_ii").GetComponent())); } public override GameObject BuildSlot(int key, GameObject _parent) { throw new NotImplementedException(); } // 2. Set up panel additn items to it //public void SetUp - in parent public override void BuildPanelContent(List> elements) { base.BuildPanelContent(elements); Debug.Log("Build content"); foreach (IndexValuePair element in elements) { Debug.Log($"key: {element.Key} - value: {element.Value}"); if(element.Value != null) ChildBoxList.Where(slot => ((EquipmentSlot)slot).type == (EquipmentPanelSlotsTypeEnum)element.Key).ToList().ForEach(slot => slot.SetItem((EquippableItem)element.Value)); } } public override void ClearSlots() { foreach (ItemSlot ChestSlot in ChildBoxList) { ChestSlot.ResetSlot(); } } public override void EndDrag(ItemSlot itemSlot) { Debug.Log("End Drag"); if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event return; DraggedSlotController.Instance.RemoveDraggedSlot(); if (!itemSlot.Item) ((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).ResetSlot(); else ((ItemSlot)ChildBoxList.Where(slot => slot.Number == itemSlot.Number).First()).SetItem(itemSlot.Item); var ChildBoxListCopy = new List>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new IndexValuePair(slot.Number, slot.Item)).ToList()); Debug.Log(ChildBoxListCopy.Count()); UiManager.RemoveAll(); Debug.Log(ChildBoxListCopy.Count()); foreach (IndexValuePair slot in ChildBoxListCopy) { if (slot.Value != null) { Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}"); UiManager.Add(new IndexValuePair(slot.Key, slot.Value)); } else { UiManager.Add(new IndexValuePair(slot.Key, null)); } } } }