| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Models; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | public class ActionEventAdapter : MonoBehaviour |
| | 11 | | { |
| | 12 | | public TMP_Dropdown entityDropDown; |
| | 13 | | public TMP_Dropdown actionDropDown; |
| | 14 | | public Button addActionBtn; |
| | 15 | | public SmartItemListView smartItemListView; |
| | 16 | |
|
| | 17 | | List<DCLBuilderInWorldEntity> entityList; |
| | 18 | |
|
| | 19 | | SmartItemComponent selectedComponent; |
| | 20 | | DCLBuilderInWorldEntity selectedEntity; |
| 0 | 21 | | List<DCLBuilderInWorldEntity> filteredList = new List<DCLBuilderInWorldEntity>(); |
| | 22 | |
|
| | 23 | | private void Start() |
| | 24 | | { |
| 0 | 25 | | entityDropDown.onValueChanged.AddListener(SelectedEntity); |
| 0 | 26 | | actionDropDown.onValueChanged.AddListener(GenerateParametersFromIndex); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public void SetContent(List<DCLBuilderInWorldEntity> entityList) |
| | 30 | | { |
| 0 | 31 | | this.entityList = entityList; |
| 0 | 32 | | filteredList = BuilderInWorldUtils.FilterEntitiesBySmartItemComponentAndActions(entityList); |
| | 33 | |
|
| 0 | 34 | | GenerateEntityDropdownContent(); |
| 0 | 35 | | SelectedEntity(0); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | void SelectedEntity(int number) |
| | 39 | | { |
| 0 | 40 | | if (!filteredList[number].rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent com |
| | 41 | | { |
| 0 | 42 | | return; |
| | 43 | | } |
| | 44 | |
|
| 0 | 45 | | selectedEntity = filteredList[number]; |
| 0 | 46 | | selectedComponent = (SmartItemComponent) component; |
| 0 | 47 | | GenerateActionDropdownContent(filteredList[number].GetSmartItemActions()); |
| | 48 | |
|
| 0 | 49 | | GenerateParametersFromSelectedOption(); |
| 0 | 50 | | } |
| | 51 | |
|
| 0 | 52 | | void GenerateParametersFromSelectedOption() { GenerateParametersFromIndex(actionDropDown.value); } |
| | 53 | |
|
| | 54 | | void GenerateParametersFromIndex(int index) |
| | 55 | | { |
| 0 | 56 | | string label = actionDropDown.options[index].text; |
| | 57 | |
|
| 0 | 58 | | SmartItemAction selectedAction = null; |
| 0 | 59 | | foreach (SmartItemAction action in selectedEntity.GetSmartItemActions()) |
| | 60 | | { |
| 0 | 61 | | if (action.label == label) |
| | 62 | | { |
| 0 | 63 | | selectedAction = action; |
| 0 | 64 | | break; |
| | 65 | | } |
| | 66 | | } |
| | 67 | |
|
| 0 | 68 | | smartItemListView.SetEntityList(entityList); |
| 0 | 69 | | smartItemListView.SetSmartItemParameters(selectedAction.parameters, selectedComponent.GetValues()); |
| 0 | 70 | | } |
| | 71 | |
|
| | 72 | | void GenerateActionDropdownContent(SmartItemAction[] actions) |
| | 73 | | { |
| 0 | 74 | | actionDropDown.ClearOptions(); |
| | 75 | |
|
| 0 | 76 | | actionDropDown.options = new List<TMP_Dropdown.OptionData>(); |
| | 77 | |
|
| | 78 | |
|
| 0 | 79 | | List<string> optionsLabelList = new List<string>(); |
| 0 | 80 | | foreach (SmartItemAction action in actions) |
| | 81 | | { |
| 0 | 82 | | optionsLabelList.Add(action.label); |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | actionDropDown.AddOptions(optionsLabelList); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | void GenerateEntityDropdownContent() |
| | 89 | | { |
| 0 | 90 | | entityDropDown.ClearOptions(); |
| | 91 | |
|
| 0 | 92 | | entityDropDown.options = new List<TMP_Dropdown.OptionData>(); |
| | 93 | |
|
| 0 | 94 | | List<string> optionsLabelList = new List<string>(); |
| 0 | 95 | | foreach (DCLBuilderInWorldEntity entity in filteredList) |
| | 96 | | { |
| 0 | 97 | | optionsLabelList.Add(entity.GetDescriptiveName()); |
| | 98 | | } |
| | 99 | |
|
| 0 | 100 | | entityDropDown.AddOptions(optionsLabelList); |
| 0 | 101 | | } |
| | 102 | | } |