using System; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; public abstract class WarehousePanelController : DraggablePanelController { public override void EndDrag(ItemSlot itemSlot) { if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event return; DraggedSlotController.Instance.RemoveDraggedSlot(); // 1. Remove from slot - for case where EndDrag and Drop work on differen UiManager's // Important: clear slot not only reset itemn!!! 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); // 2. Rebuild/apply UiManager content (list of items) base on slots values after its updating // 2.1 Make copy because Add -> base.Add() -> base.Add() -> UpdateList() rebuild content ad pass "new" list (in this case with only one - firtst passed - item) to ChestContentUiMangaer.Element var ChildBoxListCopy = new List>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new IndexValuePair(slot.Number, slot.Item)).ToList()); UiManager.RemoveAll(); 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.RemoveByPosition(slot.Key); } } } public override void BuildPanelContent(List> elements) { base.BuildPanelContent(elements); ClearSlots(); } public override void ClearSlots() { foreach (ItemSlot ChestSlot in ChildBoxList) { ChestSlot.ResetSlot(); } } public abstract override void BuildPanelSlots(); public abstract override GameObject BuildSlot(int key, GameObject _parent); }