Scriptum/Assets/Scripts/REFACTORING/Application/UI/Panel/EquipmentPanelController.cs

136 lines
5.8 KiB
C#
Raw Normal View History

2022-11-24 03:03:30 +01:00
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>();
}
2022-12-22 03:38:00 +01:00
private void Start()
{
AllowToUseItemInPanel = false;
Type = PanelTypeEnum.Shop;
}
2022-11-24 03:03:30 +01:00
public override void BuildPanelSlots()
{
InitSlotsList();
}
public void InitSlotsList()
{
2022-11-27 21:28:55 +01:00
_panelContent.transform.Find("equipment_slot_helmet").GetComponent<EquipmentSlot>()._PanelController = this;
_panelContent.transform.Find("equipment_slot_armor").GetComponent<EquipmentSlot>()._PanelController = this;
_panelContent.transform.Find("equipment_slot_weapon").GetComponent<EquipmentSlot>()._PanelController = this;
_panelContent.transform.Find("equipment_slot_boots").GetComponent<EquipmentSlot>()._PanelController = this;
2022-12-29 14:25:07 +01:00
_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_i").GetComponent<EquipmentSlot>()._PanelController = this;
_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklace_i").GetComponent<EquipmentSlot>()._PanelController = this;
_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklace_ii").GetComponent<EquipmentSlot>()._PanelController = this;
_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_ii").GetComponent<EquipmentSlot>()._PanelController = this;
_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_iii").GetComponent<EquipmentSlot>()._PanelController = this;
2022-11-27 21:28:55 +01:00
2022-11-24 03:03:30 +01:00
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>()));
2022-12-29 14:25:07 +01:00
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_i").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklace_i").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_necklace_ii").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_ii").GetComponent<EquipmentSlot>()));
ChildBoxList.Add(SetupDragAndDropToSlot(_panelAdditionalSlotsContent.transform.Find("equipment_slot_ring_iii").GetComponent<EquipmentSlot>()));
2022-11-24 03:03:30 +01:00
}
public override GameObject BuildSlot(int key, GameObject _parent) { throw new NotImplementedException(); }
// 2. Set up panel additn items to it
//public void SetUp - in parent
2023-01-03 22:48:05 +01:00
/// <summary>
/// elements: List<
/// IndexValuePair<
/// int: dropped slot number,
/// EquippableItem: dragged item
/// >
/// >
/// </summary>
/// <param name="elements"></param>
2022-11-24 03:03:30 +01:00
public override void BuildPanelContent(List<IndexValuePair<int, EquippableItem>> elements)
{
base.BuildPanelContent(elements);
foreach (IndexValuePair<int, EquippableItem> element in elements)
{
2023-01-03 22:48:05 +01:00
//Debug.Log($"key: {element.Key} - {(EquipmentPanelSlotsTypeEnum)element.Key}");
if (element.Value != null)
{
// slot type != element.key
// element.Key IS DROPPED SLOT number
// ChildBoxList order IS CONSTANT
// elements HAVE mixed order
2022-11-24 03:03:30 +01:00
2023-01-03 22:48:05 +01:00
// there is error - ChildBoxList.Where(slot => ((EquipmentSlot)slot).type == (EquipmentPanelSlotsTypeEnum)element.Key).ToList().ForEach(slot => slot.SetItem((EquippableItem)element.Value));
// FIX
ChildBoxList[element.Key].SetItem((EquippableItem)element.Value);
}
2022-11-24 03:03:30 +01:00
}
}
public override void ClearSlots()
{
foreach (ItemSlot ChestSlot in ChildBoxList)
{
ChestSlot.ResetSlot();
}
}
2022-11-27 21:28:55 +01:00
public override void EndDrag(ItemSlot itemSlot)
2022-11-24 03:03:30 +01:00
{
if (!DraggedSlotController.Instance.IsDragged()) // if there was nothing dragged - ignore event
return;
DraggedSlotController.Instance.RemoveDraggedSlot();
2023-01-03 22:48:05 +01:00
2022-11-27 21:28:55 +01:00
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<IndexValuePair<int, EquippableItem>>(ChildBoxList.Where(slot => slot.Item != null).Select(slot => new IndexValuePair<int, EquippableItem>(slot.Number, slot.Item)).ToList());
UiManager.RemoveAll();
2022-11-24 03:03:30 +01:00
2022-11-27 21:28:55 +01:00
foreach (IndexValuePair<int, EquippableItem> slot in ChildBoxListCopy)
2022-11-24 03:03:30 +01:00
{
2022-11-27 21:28:55 +01:00
if (slot.Value != null)
2022-11-24 03:03:30 +01:00
{
2023-01-03 22:48:05 +01:00
// Debug.Log($"Slot nr: {slot.Key} with item: {slot.Value}");
2022-11-27 21:28:55 +01:00
UiManager.Add(new IndexValuePair<int, EquippableItem>(slot.Key, slot.Value));
2022-11-24 03:03:30 +01:00
}
else
{
UiManager.Add(new IndexValuePair<int, EquippableItem>(slot.Key, null)); // ONLY DIFFERENCE BETWEEN UpdatePanelContent()
2022-11-24 03:03:30 +01:00
}
}
}
}