Scriptum/Assets/Scripts/REFACTORING/Application/UI/Panel/TaskPanelController.cs
2022-11-28 00:52:47 +01:00

83 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class TaskPanelController : PanelController<Task>
{
protected override UIBaseManager<Task> FetchUiManager() // check if need return by ref
{
var uiManager = GameObject.FindObjectOfType<TaskUIManager>();
// uiManager.SetPanelController(gameObject); - unnecessary
return uiManager;
}
public override void BuildPanelContent(List<Task> elements)
{
base.BuildPanelContent(elements);
ClearSlots();
for (int i = 0; i < elements.Count; i++)
{
this.AddTask(elements[i]);
}
}
public void AddTask(Task _task)
{
// update TaskManager main list of task
//TaskManager.Instance.AddTask(_task);
// add task to local panel contant
GameObject newTaskBox = SetupTaskBox(_task);
// Set new Slot instance
ChildBoxList.Add(newTaskBox);
}
protected GameObject SetupTaskBox(Task _task)
{
if (ChildBoxTemplate == null)
throw new Exception("taskbox_template is empty");
GameObject _newTaskBox = MonoBehaviour.Instantiate(ChildBoxTemplate, _panelContent.transform.position, Quaternion.identity); //.GetComponent<TaskBox>();
_newTaskBox.transform.SetParent(_panelContent.transform);
_newTaskBox.transform.localScale = new Vector3(2.5f, 2.5f, 1.0f);
_newTaskBox.GetComponent<TaskBox>().SetTask(_task);
return _newTaskBox;
}
// Ignored methods
public override void BuildPanelSlots()
{
return;
}
public override GameObject BuildSlot(int key, GameObject _parent)
{
throw new NotImplementedException();
}
public override void ClearSlots()
{
foreach(var taskObj in ChildBoxList)
{
DestroyImmediate(taskObj);
}
ChildBoxList.Clear();
}
}