2022-11-19 17:02:31 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ChestPanelController : WarehousePanelController
|
|
|
|
|
{
|
2022-12-22 03:38:00 +01:00
|
|
|
|
|
2022-11-24 03:03:30 +01:00
|
|
|
|
protected override UIBaseManager<IndexValuePair<int, EquippableItem>> FetchUiManager()
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
|
|
|
|
return GameObject.FindObjectOfType<ChestContentUIManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build panel sunction
|
|
|
|
|
// - setup - main function to build panel on screen
|
|
|
|
|
// - setPanelISlots - build slots on panel dependiong on declared amount
|
|
|
|
|
// - setPanelItems - invoking building items on slots
|
|
|
|
|
|
|
|
|
|
// api for drag and drop
|
|
|
|
|
// - set item on position
|
|
|
|
|
// - remove item from position
|
|
|
|
|
// - find item in warehouse
|
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
AllowToUseItemInPanel = false;
|
2022-12-22 03:38:00 +01:00
|
|
|
|
|
|
|
|
|
Type = PanelTypeEnum.Chest;
|
2022-12-19 03:34:45 +01:00
|
|
|
|
}
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
|
|
// 1. Prepare empty panel
|
|
|
|
|
public override void BuildPanelSlots()
|
|
|
|
|
{
|
|
|
|
|
if (_panelContent == null)
|
|
|
|
|
throw new Exception("Panel content is not attaches");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int _position = 0; _position < UiManager.SLOTS_NUMBER; _position++)
|
|
|
|
|
{
|
|
|
|
|
//ISlot newSlot = SetupSlot(_position, _panel);
|
|
|
|
|
GameObject newSlot = BuildSlot(_position, _panelContent);
|
|
|
|
|
|
|
|
|
|
// Set new Slot instance
|
|
|
|
|
ChildBoxList.Add(newSlot.GetComponent<ChestSlot>());
|
|
|
|
|
|
|
|
|
|
// Assign events
|
|
|
|
|
ChildBoxList[_position] = SetupDragAndDropToSlot(ChildBoxList[_position]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override GameObject BuildSlot(int key, GameObject _parent)
|
|
|
|
|
{
|
|
|
|
|
if (ChildBoxTemplate == null)
|
|
|
|
|
throw new Exception("chestslotbox_template is empty");
|
|
|
|
|
|
|
|
|
|
GameObject _newItemSlot = MonoBehaviour.Instantiate(ChildBoxTemplate, _parent.transform.position, Quaternion.identity); //.GetComponent<InventorySlot>();
|
|
|
|
|
|
|
|
|
|
_newItemSlot.transform.SetParent(_parent.transform);
|
|
|
|
|
_newItemSlot.transform.localScale = new Vector3(1.15f, 1.15f, 1.15f);
|
|
|
|
|
|
|
|
|
|
_newItemSlot.GetComponent<ChestSlot>().SetupSlot(key, null, this);
|
|
|
|
|
|
|
|
|
|
return _newItemSlot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Set up panel additn items to it
|
2022-11-24 03:03:30 +01:00
|
|
|
|
public override void SetUp(List<IndexValuePair<int, EquippableItem>> elements)
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
|
|
|
|
// Build panel content template
|
|
|
|
|
BuildPanelSlots();
|
|
|
|
|
|
|
|
|
|
// Fill with items
|
|
|
|
|
BuildPanelContent(elements);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-24 03:03:30 +01:00
|
|
|
|
public override void BuildPanelContent(List<IndexValuePair<int, EquippableItem>> elements)
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
base.BuildPanelContent(elements);
|
|
|
|
|
|
|
|
|
|
Debug.Log("Build content");
|
2022-11-24 03:03:30 +01:00
|
|
|
|
foreach (IndexValuePair<int, EquippableItem> element in elements)
|
2022-11-19 17:02:31 +01:00
|
|
|
|
{
|
2022-11-24 03:03:30 +01:00
|
|
|
|
Debug.Log($"key: {element.Key} - value: {element.Value} - type: {element.Value.EquipmentType}");
|
2022-11-19 17:02:31 +01:00
|
|
|
|
ChildBoxList[element.Key].SetItem(new EquippableItem(element.Value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Chest content manager
|
|
|
|
|
// gest new elements list after open chest
|
|
|
|
|
// remove: -> remove from list, (binding) update list in chest
|