| | 1 | | using DCL.Components; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class ActionsListView : ListView<SmartItemActionEvent> |
| | 7 | | { |
| | 8 | | public SmartItemActionEventAdapter adapter; |
| | 9 | | public System.Action<SmartItemActionable> OnActionableRemove; |
| | 10 | |
|
| | 11 | | public override void AddAdapters() |
| | 12 | | { |
| 0 | 13 | | base.AddAdapters(); |
| | 14 | |
|
| 0 | 15 | | foreach (SmartItemActionEvent actionEvent in contentList) |
| | 16 | | { |
| 0 | 17 | | SmartItemActionEventAdapter adapter = Instantiate(this.adapter, contentPanelTransform).GetComponent<SmartIte |
| 0 | 18 | | adapter.OnActionableRemove += RemoveActionable; |
| 0 | 19 | | adapter.SetContent(actionEvent); |
| | 20 | | } |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | public override void RemoveAdapters() |
| | 24 | | { |
| 0 | 25 | | for (int i = 0; i < contentPanelTransform.transform.childCount; i++) |
| | 26 | | { |
| 0 | 27 | | SmartItemActionEventAdapter toRemove = contentPanelTransform.transform.GetChild(i).gameObject.GetComponent<S |
| 0 | 28 | | RemoveAdapter(toRemove); |
| | 29 | | } |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | private void RemoveAdapter(SmartItemActionEventAdapter adapter) |
| | 33 | | { |
| 0 | 34 | | adapter.OnActionableRemove -= RemoveActionable; |
| 0 | 35 | | Destroy(adapter.gameObject); |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | public void AddActionEventAdapter(SmartItemActionEvent actionEvent) |
| | 39 | | { |
| 0 | 40 | | contentList.Add(actionEvent); |
| 0 | 41 | | RefreshDisplay(); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private void RemoveActionable(SmartItemActionEventAdapter actionable) |
| | 45 | | { |
| 0 | 46 | | contentList.Remove(actionable.GetContent()); |
| 0 | 47 | | OnActionableRemove?.Invoke(actionable.GetContent().smartItemActionable); |
| 0 | 48 | | RemoveAdapter(actionable); |
| 0 | 49 | | } |
| | 50 | | } |