Options Dialog refactor for more generic
This commit is contained in:
@@ -3,8 +3,9 @@ using UnityEngine;
|
||||
public class OfficeTable : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private JobsListSO _jobPositionsSO;
|
||||
|
||||
private DialogCategorySO _dialogOptionsSO;
|
||||
[SerializeField]
|
||||
private DialogSO _dialogSO;
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Talk].IsEnabled = true;
|
||||
@@ -12,7 +13,7 @@ public class OfficeTable : BaseInteractableObject
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
GameManager.Instance.UI.ShowJobSelectionDialog("Job agency", null, OnConfirm);
|
||||
GameManager.Instance.UI.ShowTabObtionsDialog(_dialogSO, null, OnConfirm);
|
||||
}
|
||||
|
||||
private void OnConfirm(JobInfoSO selectedJob)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using Assets.Scripts.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
public class SecretaryDesk : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private DialogSO _dialogSO;
|
||||
[SerializeField]
|
||||
private DialogCategorySO _dialogOptionsSO;
|
||||
|
||||
protected override void PrepareMenuActions()
|
||||
{
|
||||
_menuActions[RadialMenuActions.Talk].IsEnabled = true;
|
||||
}
|
||||
|
||||
protected override void InteractAction(RadialMenuActions interactAction)
|
||||
{
|
||||
GameManager.Instance.UI.ShowTabObtionsDialog(_dialogSO, null, OnConfirm);
|
||||
}
|
||||
|
||||
private void OnConfirm(IDialogOption selectedOption)
|
||||
{
|
||||
//_player.JobPosition = (selectedOption as EducationInfoSO).JobPosition;
|
||||
print($"player selected position is {_player.JobPosition}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05e7f5c95d24c174ba832e4264e9d224
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Interfaces
|
||||
{
|
||||
public interface IDialogItemUI
|
||||
{
|
||||
void SetItem(DialogOptionsUI parent, IDialogOption item);
|
||||
}
|
||||
public class IDialogOption: ScriptableObject
|
||||
{
|
||||
public Sprite Icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d84ba9398a2968044a2323f3fe5c241a
|
||||
@@ -0,0 +1,11 @@
|
||||
using Assets.Scripts.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class DialogCategorySO : ScriptableObject
|
||||
{
|
||||
public string Title;
|
||||
public Sprite Icon;
|
||||
public List<IDialogOption> OptionsList;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Assets.Scripts.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class DialogSO : ScriptableObject
|
||||
{
|
||||
public string Title;
|
||||
public MonoBehaviour UITemplate;
|
||||
public List<DialogCategorySO> CategoriesSO;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf7ee1c503cbe524b8a52dc86566b3b6
|
||||
@@ -0,0 +1,10 @@
|
||||
using Assets.Scripts.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class EducationInfoSO : IDialogOption
|
||||
{
|
||||
public string Description;
|
||||
public float Price;
|
||||
public EducationSkill Skill;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ba71c02cddb93d408c7c1b2f9846099
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +1,11 @@
|
||||
using UnityEngine;
|
||||
using Assets.Scripts.Interfaces;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class JobInfoSO : ScriptableObject
|
||||
public class JobInfoSO : IDialogOption
|
||||
{
|
||||
public string Description;
|
||||
public float Salary;
|
||||
public Sprite Icon;
|
||||
public JobPositions JobPosition;
|
||||
public EducationSkill MinimumEducationSkill;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 5e5ea608dd4175941b878e8e1a585970, type: 3}
|
||||
m_Name: Clerk
|
||||
m_EditorClassIdentifier:
|
||||
Icon: {fileID: 0}
|
||||
Description: Clerk
|
||||
Salary: 5
|
||||
Icon: {fileID: 0}
|
||||
JobPosition: 2
|
||||
MinimumEducationSkill: 1
|
||||
JobPosition: 0
|
||||
MinimumEducationSkill: 0
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bf7ee1c503cbe524b8a52dc86566b3b6, type: 3}
|
||||
m_Name: JobAgency
|
||||
m_EditorClassIdentifier:
|
||||
Title: Job Agency
|
||||
UITemplate: {fileID: 4899774397145829728, guid: 3fd1d54e5064a0841972b791abc6919f,
|
||||
type: 3}
|
||||
CategoriesSO:
|
||||
- {fileID: 11400000, guid: 137a0a77aa02f614ead909f23a670e95, type: 2}
|
||||
- {fileID: 11400000, guid: f0d3baaabf19f9a4a80e227316362d84, type: 2}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c330d22202c025408b0fcf250a57d15
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,8 +12,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 5e5ea608dd4175941b878e8e1a585970, type: 3}
|
||||
m_Name: Manager
|
||||
m_EditorClassIdentifier:
|
||||
Icon: {fileID: 0}
|
||||
Description: Manager
|
||||
Salary: 9
|
||||
Icon: {fileID: 0}
|
||||
JobPosition: 4
|
||||
MinimumEducationSkill: 3
|
||||
JobPosition: 0
|
||||
MinimumEducationSkill: 0
|
||||
|
||||
@@ -12,8 +12,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 5e5ea608dd4175941b878e8e1a585970, type: 3}
|
||||
m_Name: ManagerAssistant
|
||||
m_EditorClassIdentifier:
|
||||
Icon: {fileID: 0}
|
||||
Description: Manager assistaint
|
||||
Salary: 6
|
||||
Icon: {fileID: 0}
|
||||
JobPosition: 3
|
||||
MinimumEducationSkill: 2
|
||||
JobPosition: 0
|
||||
MinimumEducationSkill: 0
|
||||
|
||||
@@ -12,9 +12,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: f667daa0686227b49a9ca2ebd6326a98, type: 3}
|
||||
m_Name: Minimarket
|
||||
m_EditorClassIdentifier:
|
||||
Place: Shop
|
||||
Title: Mini market
|
||||
Icon: {fileID: 21300000, guid: c5e761867408abd48bdbfcc36c949f44, type: 3}
|
||||
JobPositionsList:
|
||||
OptionsList:
|
||||
- {fileID: 11400000, guid: c7452dc6dfb2cc040a6d0e543db6b671, type: 2}
|
||||
- {fileID: 11400000, guid: 36ad6fbffd0cc574aaf7d76308d965a1, type: 2}
|
||||
- {fileID: 11400000, guid: 4381db145ac80514c957374e20392b3b, type: 2}
|
||||
- {fileID: 11400000, guid: 36ad6fbffd0cc574aaf7d76308d965a1, type: 2}
|
||||
|
||||
@@ -12,9 +12,9 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: f667daa0686227b49a9ca2ebd6326a98, type: 3}
|
||||
m_Name: Office
|
||||
m_EditorClassIdentifier:
|
||||
Place: Office
|
||||
Title: Office
|
||||
Icon: {fileID: 21300000, guid: c5e761867408abd48bdbfcc36c949f44, type: 3}
|
||||
JobPositionsList:
|
||||
OptionsList:
|
||||
- {fileID: 11400000, guid: 9dd346cdfec57ee47ad1c06a925769bb, type: 2}
|
||||
- {fileID: 11400000, guid: 36ad6fbffd0cc574aaf7d76308d965a1, type: 2}
|
||||
- {fileID: 11400000, guid: 4381db145ac80514c957374e20392b3b, type: 2}
|
||||
- {fileID: 11400000, guid: 36ad6fbffd0cc574aaf7d76308d965a1, type: 2}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class JobsListSO : ScriptableObject
|
||||
{
|
||||
public string Place;
|
||||
public Sprite Icon;
|
||||
public List<JobInfoSO> JobPositionsList;
|
||||
}
|
||||
+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