Scriptum/Assets/Scripts/REFACTORING/Application/UI/Panel/EquipmentPanelController.cs
2022-11-24 03:03:30 +01:00

95 lines
3.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class EquipmentPanelController : DraggablePanelController
{
[SerializeField] protected GameObject _panelAdditionalSlotsContent;
protected override UIBaseManager<IndexValuePair<int, EquippableItem>> FetchUiManager()
{
return GameObject.FindObjectOfType<EquipmentUIManager>();
}
public override void BuildPanelSlots()
{
InitSlotsList();
}
public void InitSlotsList()
{
ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_helmet").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_armor").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_weapon").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelContent.transform.Find("equipment_slot_boots").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_bracelet").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklet").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_i").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_potion_ii").GetComponent<EquipmentSlot>()));
}
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<IndexValuePair<int, EquippableItem>> elements)
{
base.BuildPanelContent(elements);
Debug.Log("Build content");
foreach (IndexValuePair<int, EquippableItem> 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 virtual void EndDrag(ItemSlot itemSlot)
{
if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event
return;
DraggedSlotController.Instance.RemoveDraggedSlot();
Debug.Log(this);
// Rebuild/apply UiManager content (list of items) base on slots values after its updating
for (int i = 0; i < ChildBoxList.Count; i++)
{
if (ChildBoxList[i].Item != null)
{
UiManager.Add(new IndexValuePair<int, EquippableItem>(i, ChildBoxList[i].Item));
}
else
{
UiManager.RemoveByPosition(i);
}
}
}
}