| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | public class SmartItemActionParameter : SmartItemUIParameterAdapter, IEntityListHandler |
| | 11 | | { |
| | 12 | | public ActionsListView actionsListView; |
| | 13 | | public Button addActionBtn; |
| | 14 | |
|
| | 15 | | private List<DCLBuilderInWorldEntity> alreadyFilterList; |
| | 16 | |
|
| | 17 | | private void Start() |
| | 18 | | { |
| 0 | 19 | | addActionBtn.onClick.AddListener(CreateEventAction); |
| 0 | 20 | | actionsListView.OnActionableRemove += RemoveActionable; |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | private void RemoveActionable(SmartItemActionable actionable) |
| | 24 | | { |
| 0 | 25 | | var actionsGeneric = GetParameterValue(); |
| 0 | 26 | | if (actionsGeneric == null || !(actionsGeneric is List<SmartItemActionable>)) |
| 0 | 27 | | return; |
| | 28 | |
|
| 0 | 29 | | SmartItemActionable actionableToRemove = null; |
| 0 | 30 | | List<SmartItemActionable> actions = (List<SmartItemActionable>)actionsGeneric; |
| 0 | 31 | | foreach (SmartItemActionable actionableItem in actions) |
| | 32 | | { |
| 0 | 33 | | if (actionable.actionableId == actionableItem.actionableId) |
| 0 | 34 | | actionableToRemove = actionableItem; |
| | 35 | | } |
| 0 | 36 | | actions.Remove(actionableToRemove); |
| | 37 | |
|
| 0 | 38 | | SetParameterValue(actions); |
| 0 | 39 | | } |
| | 40 | |
|
| 0 | 41 | | public void SetEntityList(List<DCLBuilderInWorldEntity> entitiesList) { this.alreadyFilterList = entitiesList; } |
| | 42 | |
|
| | 43 | | public override void SetInfo() |
| | 44 | | { |
| 0 | 45 | | base.SetInfo(); |
| | 46 | |
|
| 0 | 47 | | KEY_NAME = currentParameter.id; |
| | 48 | |
|
| 0 | 49 | | var actionsGeneric = GetParameterValue(); |
| 0 | 50 | | if (actionsGeneric == null || !(actionsGeneric is List<SmartItemActionable>)) |
| 0 | 51 | | return; |
| 0 | 52 | | List<SmartItemActionable> actions = (List<SmartItemActionable>)actionsGeneric; |
| | 53 | |
|
| 0 | 54 | | foreach (SmartItemActionable smartItemAction in actions) |
| | 55 | | { |
| 0 | 56 | | AddEventAction(smartItemAction); |
| | 57 | | } |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | public void AddEventAction(SmartItemActionable action) |
| | 61 | | { |
| 0 | 62 | | if (alreadyFilterList.Count <= 0) |
| 0 | 63 | | return; |
| | 64 | |
|
| 0 | 65 | | SmartItemActionEvent actionEvent = new SmartItemActionEvent(); |
| 0 | 66 | | actionEvent.entityList = alreadyFilterList; |
| 0 | 67 | | actionEvent.smartItemActionable = action; |
| | 68 | |
|
| 0 | 69 | | if (currentValues.ContainsKey(action.actionableId)) |
| 0 | 70 | | actionEvent.values = (Dictionary<object, object>) currentValues[action.actionableId]; |
| | 71 | | else |
| 0 | 72 | | actionEvent.values = new Dictionary<object, object>(); |
| | 73 | |
|
| 0 | 74 | | actionsListView.AddActionEventAdapter(actionEvent); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | public void CreateEventAction() |
| | 78 | | { |
| 0 | 79 | | var actionsGeneric = GetParameterValue(); |
| | 80 | |
|
| | 81 | | List<SmartItemActionable> actions; |
| | 82 | |
|
| 0 | 83 | | if (actionsGeneric != null && (actionsGeneric is List<SmartItemActionable>)) |
| 0 | 84 | | actions = (List<SmartItemActionable>)actionsGeneric; |
| | 85 | | else |
| 0 | 86 | | actions = new List<SmartItemActionable>(); |
| | 87 | |
|
| 0 | 88 | | SmartItemActionable action = new SmartItemActionable(); |
| 0 | 89 | | action.actionableId = Guid.NewGuid().ToString(); |
| 0 | 90 | | actions.Add(action); |
| 0 | 91 | | AddEventAction(action); |
| 0 | 92 | | SetParameterValue(actions); |
| 0 | 93 | | } |
| | 94 | | } |