Player can select job position now
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JobItemUITemplate : MonoBehaviour
|
||||
public class JobItemUITemplate : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _descreiption;
|
||||
@@ -11,10 +12,34 @@ public class JobItemUITemplate : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Image _icon;
|
||||
|
||||
public void SetItem(JobInfoSO item)
|
||||
private JobSelectorUI _parent;
|
||||
private JobInfoSO _item;
|
||||
public JobInfoSO Item=> _item;
|
||||
|
||||
public void SetItem(JobSelectorUI parent,JobInfoSO item)
|
||||
{
|
||||
_item= item;
|
||||
_parent = parent;
|
||||
_descreiption.text = item.Description;
|
||||
_sallary.text = $"{item.Salary}$";
|
||||
_icon.sprite = item.Icon;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
_parent.OnItemSelected(this);
|
||||
}
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
_parent.OnItemSelected(this);
|
||||
}
|
||||
|
||||
public void Click()
|
||||
{
|
||||
_parent.OnItemSelected(this);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -30,7 +27,9 @@ public class JobSelectorUI : MonoBehaviour
|
||||
private List<JobsListSO> _jobs;
|
||||
|
||||
private JobTabUITemplate _selectedTab;
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action onConfirm)
|
||||
private JobItemUITemplate _selectedItem;
|
||||
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
{
|
||||
UIManager.Instance.Freeze();
|
||||
|
||||
@@ -57,7 +56,7 @@ public class JobSelectorUI : MonoBehaviour
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke();
|
||||
onConfirm?.Invoke(_selectedItem.Item);
|
||||
Hide();
|
||||
});
|
||||
}
|
||||
@@ -78,7 +77,7 @@ public class JobSelectorUI : MonoBehaviour
|
||||
{
|
||||
var itemUI = Instantiate(_jobItemUItemplate, _itemsContainer);
|
||||
itemUI.gameObject.SetActive(true);
|
||||
itemUI.GetComponent<JobItemUITemplate>().SetItem((job));
|
||||
itemUI.GetComponent<JobItemUITemplate>().SetItem(this,job);
|
||||
}
|
||||
print($"selected {button.JobListItem.name}");
|
||||
}
|
||||
@@ -88,6 +87,12 @@ public class JobSelectorUI : MonoBehaviour
|
||||
print($"exit {button.JobListItem.name}");
|
||||
}
|
||||
|
||||
public void OnItemSelected(JobItemUITemplate button)
|
||||
{
|
||||
print($"selected job {button.Item.name}");
|
||||
_selectedItem = button;
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
UIManager.Instance.Unfreeze();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class UIManager : MonoBehaviour
|
||||
timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action onConfirm)
|
||||
public void ShowJobSelectionDialog(string title, Action onCancel, Action<JobInfoSO> onConfirm)
|
||||
{
|
||||
var jobSelector = Instantiate(_jobSelectorPrefab, transform);
|
||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||
|
||||
Reference in New Issue
Block a user