109 lines
2.9 KiB
C#
109 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class JobSelectorUI : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private TextMeshProUGUI _title;
|
|
[SerializeField]
|
|
private TextMeshProUGUI _subTitle;
|
|
[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;
|
|
private JobItemUITemplate _selectedItem;
|
|
|
|
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
|
|
{
|
|
UIManager.Instance.Freeze();
|
|
|
|
gameObject.SetActive(true);
|
|
_title.text = title;
|
|
|
|
//Create Tabs
|
|
for (int count = 0; count < _jobs.Count; count++)
|
|
{
|
|
JobsListSO job = _jobs[count];
|
|
var itemUI = Instantiate(_jobTabUItemplate, _tabsContainer);
|
|
itemUI.gameObject.SetActive(true);
|
|
var template = itemUI.GetComponent<JobTabUITemplate>();
|
|
template.SetItem(this, job);
|
|
if (count== 0) {
|
|
OnTabSelected(template);
|
|
}
|
|
}
|
|
|
|
_btnCancel.onClick.AddListener(() =>
|
|
{
|
|
onCancel?.Invoke();
|
|
Hide();
|
|
});
|
|
_btnOk.onClick.AddListener(() =>
|
|
{
|
|
onConfirm?.Invoke(_selectedItem.Item);
|
|
Hide();
|
|
});
|
|
}
|
|
|
|
public void OnTabEnter(JobTabUITemplate button)
|
|
{
|
|
print($"enter to {button.JobListItem.name}");
|
|
}
|
|
public void OnTabSelected(JobTabUITemplate button)
|
|
{
|
|
_selectedTab = button;
|
|
_subTitle.text = _selectedTab.JobListItem.Place;
|
|
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(this,job);
|
|
}
|
|
print($"selected {button.JobListItem.name}");
|
|
}
|
|
|
|
public void OnTabExit(JobTabUITemplate button)
|
|
{
|
|
print($"exit {button.JobListItem.name}");
|
|
}
|
|
|
|
public void OnItemSelected(JobItemUITemplate button)
|
|
{
|
|
print($"selected job {button.Item.name}");
|
|
_selectedItem = button;
|
|
}
|
|
|
|
private void CloseDialog()
|
|
{
|
|
UIManager.Instance.Unfreeze();
|
|
Destroy(this);
|
|
}
|
|
|
|
private void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
CloseDialog();
|
|
}
|
|
}
|
|
|