78 lines
2.8 KiB
C#
78 lines
2.8 KiB
C#
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
|
|
UpdatePanelContent();
|
|
}
|
|
|
|
public override void DoubleLeftMouseClick(ItemSlot itemSlot)
|
|
{
|
|
Debug.Log("Used item");
|
|
if(AllowToUseItemInPanel)
|
|
{
|
|
ItemEffectsManager.Instance.UseItemEffect(itemSlot, Type);
|
|
}
|
|
//itemSlot.Item?.InvokeEffectAction();
|
|
}
|
|
|
|
|
|
public override void BuildPanelContent(List<IndexValuePair<int, EquippableItem>> elements)
|
|
{
|
|
base.BuildPanelContent(elements);
|
|
|
|
ClearSlots();
|
|
}
|
|
|
|
public void UpdatePanelContent()
|
|
{
|
|
// 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<IndexValuePair<int, EquippableItem>>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new IndexValuePair<int, EquippableItem>(slot.Number, slot.Item)).ToList());
|
|
|
|
UiManager.RemoveAll();
|
|
|
|
foreach (IndexValuePair<int, EquippableItem> slot in ChildBoxListCopy)
|
|
{
|
|
if (slot.Value != null)
|
|
{
|
|
Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}");
|
|
UiManager.Add(new IndexValuePair<int, EquippableItem>(slot.Key, slot.Value));
|
|
}
|
|
else
|
|
{
|
|
UiManager.RemoveByPosition(slot.Key);
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
} |