102 lines
2.7 KiB
C#
102 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class JobSelectorUI : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private TextMeshProUGUI _title;
|
|
[SerializeField]
|
|
private TextMeshProUGUI _description;
|
|
[SerializeField]
|
|
private Button _btnCancel;
|
|
[SerializeField]
|
|
private Button _btnOk;
|
|
|
|
[SerializeField]
|
|
private Transform _itemsContainer;
|
|
[SerializeField]
|
|
private Transform _tabsContainer;
|
|
[SerializeField]
|
|
private JobItemUITemplate _jobItemUItemplate;
|
|
[SerializeField]
|
|
private JobTabUITemplate _jobTabUItemplate;
|
|
[SerializeField]
|
|
private List<JobsListSO> _jobs;
|
|
|
|
private JobTabUITemplate _selectedTab;
|
|
public void ShowJobSelectionDialog(string title, string description, Action onCancel, Action onConfirm)
|
|
{
|
|
UIManager.Instance.Freeze();
|
|
|
|
gameObject.SetActive(true);
|
|
_title.text = title;
|
|
_description.text = description;
|
|
//Create Tabs
|
|
foreach (var job in _jobs)
|
|
{
|
|
var itemUI = Instantiate(_jobTabUItemplate, _tabsContainer);
|
|
itemUI.gameObject.SetActive(true);
|
|
itemUI.GetComponent<JobTabUITemplate>().SetItem(this,job);
|
|
}
|
|
//foreach (var job in _jobs.JobPositionsList)
|
|
//{
|
|
// var itemUI = Instantiate(_jobItemUItemplate, _container);
|
|
// itemUI.gameObject.SetActive(true);
|
|
// itemUI.GetComponent<JobItemUITemplate>().SetItem((job));
|
|
//}
|
|
|
|
_btnCancel.onClick.AddListener(() =>
|
|
{
|
|
onCancel?.Invoke();
|
|
Hide();
|
|
});
|
|
_btnOk.onClick.AddListener(() =>
|
|
{
|
|
onConfirm?.Invoke();
|
|
Hide();
|
|
});
|
|
}
|
|
|
|
public void OnTabEnter(JobTabUITemplate button)
|
|
{
|
|
print($"enter to {button.JobListItem.name}");
|
|
}
|
|
public void OnTabSelected(JobTabUITemplate button)
|
|
{
|
|
_selectedTab = button;
|
|
while (_itemsContainer.childCount > 0)
|
|
{
|
|
DestroyImmediate(_itemsContainer.GetChild(0).gameObject);
|
|
}
|
|
foreach (var job in _selectedTab.JobListItem.JobPositionsList)
|
|
{
|
|
var itemUI = Instantiate(_jobItemUItemplate, _itemsContainer);
|
|
itemUI.gameObject.SetActive(true);
|
|
itemUI.GetComponent<JobItemUITemplate>().SetItem((job));
|
|
}
|
|
print($"selected {button.JobListItem.name}");
|
|
}
|
|
|
|
public void OnTabExit(JobTabUITemplate button)
|
|
{
|
|
print($"exit {button.JobListItem.name}");
|
|
}
|
|
|
|
private void CloseDialog()
|
|
{
|
|
UIManager.Instance.Unfreeze();
|
|
Destroy(this);
|
|
}
|
|
|
|
private void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
CloseDialog();
|
|
}
|
|
}
|
|
|