Options Dialog refactor for more generic
This commit is contained in:
+24
-26
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JobSelectorUI : MonoBehaviour
|
||||
public class DialogOptionsUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
@@ -22,28 +21,30 @@ public class JobSelectorUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private JobItemUITemplate _jobItemUItemplate;
|
||||
[SerializeField]
|
||||
private JobTabUITemplate _jobTabUItemplate;
|
||||
[SerializeField]
|
||||
private List<JobsListSO> _jobs;
|
||||
|
||||
private JobTabUITemplate _selectedTab;
|
||||
private DialogTabUITemplate _dialogTabUI;
|
||||
|
||||
private DialogTabUITemplate _selectedTab;
|
||||
private JobItemUITemplate _selectedItem;
|
||||
private DialogSO _dialogSO;
|
||||
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
public void ShowCategoriesDialog(DialogSO dialogSO, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
{
|
||||
GameManager.Instance.UI.Freeze();
|
||||
|
||||
_dialogSO = dialogSO;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
_title.text = _dialogSO.Title;
|
||||
|
||||
//Create Tabs
|
||||
for (int count = 0; count < _jobs.Count; count++)
|
||||
for (int count = 0; count < _dialogSO.CategoriesSO.Count; count++)
|
||||
{
|
||||
JobsListSO job = _jobs[count];
|
||||
var itemUI = Instantiate(_jobTabUItemplate, _tabsContainer);
|
||||
var dialogOption = _dialogSO.CategoriesSO[count];
|
||||
var itemUI = Instantiate(_dialogTabUI, _tabsContainer);
|
||||
itemUI.gameObject.SetActive(true);
|
||||
var template = itemUI.GetComponent<JobTabUITemplate>();
|
||||
template.SetItem(this, job);
|
||||
var template = itemUI.GetComponent<DialogTabUITemplate>();
|
||||
|
||||
template.SetItem(this, dialogOption);
|
||||
if (count== 0) {
|
||||
OnTabSelected(template);
|
||||
}
|
||||
@@ -61,30 +62,28 @@ public class JobSelectorUI : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
public void OnTabEnter(JobTabUITemplate button)
|
||||
public void OnTabEnter(DialogTabUITemplate button)
|
||||
{
|
||||
print($"enter to {button.JobListItem.name}");
|
||||
print($"enter to {button.DialogOption.name}");
|
||||
}
|
||||
public void OnTabSelected(JobTabUITemplate button)
|
||||
public void OnTabSelected(DialogTabUITemplate button)
|
||||
{
|
||||
_selectedTab = button;
|
||||
_subTitle.text = _selectedTab.JobListItem.Place;
|
||||
_subTitle.text = _selectedTab.DialogOption.Title;
|
||||
while (_itemsContainer.childCount > 0)
|
||||
{
|
||||
DestroyImmediate(_itemsContainer.GetChild(0).gameObject);
|
||||
}
|
||||
foreach (var job in _selectedTab.JobListItem.JobPositionsList)
|
||||
foreach (var job in _selectedTab.DialogOption.OptionsList)
|
||||
{
|
||||
var itemUI = Instantiate(_jobItemUItemplate, _itemsContainer);
|
||||
var itemUI = Instantiate(_dialogSO.UITemplate, _itemsContainer);
|
||||
itemUI.gameObject.SetActive(true);
|
||||
itemUI.GetComponent<JobItemUITemplate>().SetItem(this,job);
|
||||
itemUI.GetComponent<JobItemUITemplate>().SetItem(this, job);
|
||||
}
|
||||
print($"selected {button.JobListItem.name}");
|
||||
}
|
||||
|
||||
public void OnTabExit(JobTabUITemplate button)
|
||||
public void OnTabExit(DialogTabUITemplate button)
|
||||
{
|
||||
print($"exit {button.JobListItem.name}");
|
||||
}
|
||||
|
||||
public void OnItemSelected(JobItemUITemplate button)
|
||||
@@ -104,5 +103,4 @@ public class JobSelectorUI : MonoBehaviour
|
||||
gameObject.SetActive(false);
|
||||
CloseDialog();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+7
-7
@@ -3,22 +3,22 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JobTabUITemplate : MonoBehaviour, IPointerEnterHandler,IPointerClickHandler, IPointerExitHandler
|
||||
public class DialogTabUITemplate : MonoBehaviour, IPointerEnterHandler,IPointerClickHandler, IPointerExitHandler
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _description;
|
||||
[SerializeField]
|
||||
private Image _icon;
|
||||
|
||||
public JobsListSO JobListItem=> _jobListItem;
|
||||
private JobsListSO _jobListItem;
|
||||
public DialogCategorySO DialogOption=> _dialogOption;
|
||||
private DialogCategorySO _dialogOption;
|
||||
|
||||
private JobSelectorUI _parent;
|
||||
public void SetItem(JobSelectorUI parent, JobsListSO jobListItem)
|
||||
private DialogOptionsUI _parent;
|
||||
public void SetItem(DialogOptionsUI parent, DialogCategorySO dialogOption)
|
||||
{
|
||||
_jobListItem = jobListItem;
|
||||
_dialogOption = dialogOption;
|
||||
_parent = parent;
|
||||
_icon.sprite = jobListItem.Icon;
|
||||
_icon.sprite = _dialogOption.Icon;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
@@ -1,9 +1,10 @@
|
||||
using Assets.Scripts.Interfaces;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JobItemUITemplate : MonoBehaviour, IPointerEnterHandler
|
||||
public class JobItemUITemplate : MonoBehaviour, IDialogItemUI ,IPointerEnterHandler
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _descreiption;
|
||||
@@ -15,18 +16,18 @@ public class JobItemUITemplate : MonoBehaviour, IPointerEnterHandler
|
||||
[SerializeField]
|
||||
private Button _button;
|
||||
|
||||
private JobSelectorUI _parent;
|
||||
private DialogOptionsUI _parent;
|
||||
private JobInfoSO _item;
|
||||
public JobInfoSO Item=> _item;
|
||||
|
||||
public void SetItem(JobSelectorUI parent,JobInfoSO item)
|
||||
public void SetItem(DialogOptionsUI parent,IDialogOption item)
|
||||
{
|
||||
_item= item;
|
||||
_item= item as JobInfoSO;
|
||||
_parent = parent;
|
||||
_descreiption.text = item.Description;
|
||||
_sallary.text = $"{item.Salary}$";
|
||||
_descreiption.text = _item.Description;
|
||||
_sallary.text = $"{_item.Salary}$";
|
||||
_icon.sprite = item.Icon;
|
||||
_button.enabled = Player.Instance.Education>=item.MinimumEducationSkill;
|
||||
_button.enabled = Player.Instance.Education>= _item.MinimumEducationSkill;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class UISystem : MonoBehaviour
|
||||
[SerializeField]
|
||||
private TimeSliderUI _timeSliderPrefab;
|
||||
[SerializeField]
|
||||
private JobSelectorUI _jobSelectorPrefab;
|
||||
private DialogOptionsUI _DialogUIPrefab;
|
||||
[SerializeField]
|
||||
private GameObject _blurOverlay;
|
||||
[SerializeField]
|
||||
@@ -27,10 +27,10 @@ public class UISystem : MonoBehaviour
|
||||
timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
public void ShowTabObtionsDialog(DialogSO dialogSO, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
{
|
||||
var jobSelector = Instantiate(_jobSelectorPrefab, transform);
|
||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||
var dialog = Instantiate(_DialogUIPrefab, transform);
|
||||
dialog.ShowCategoriesDialog(dialogSO, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public async UniTask<RadialMenuActions> ShowItemPopupMenu(Dictionary<RadialMenuActions, RadialMenuActionDescription> actions)
|
||||
|
||||
Reference in New Issue
Block a user