| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.Events; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public interface IInspectorView |
| | 8 | | { |
| | 9 | | EntityListView entityList { get; set; } |
| | 10 | | List<BIWEntity> entities { get; } |
| | 11 | | ISceneLimitsController sceneLimitsController { get; } |
| | 12 | |
|
| | 13 | | event Action<EntityAction, BIWEntity, EntityListAdapter> OnEntityActionInvoked; |
| | 14 | | event Action<BIWEntity, string> OnEntityRename; |
| | 15 | |
|
| | 16 | | void ClearEntitiesList(); |
| | 17 | | void ConfigureSceneLimits(ISceneLimitsController sceneLimitsController); |
| | 18 | | void EntityActionInvoked(EntityAction action, BIWEntity entityToApply, EntityListAdapter adapter); |
| | 19 | | void EntityRename(BIWEntity entity, string newName); |
| | 20 | | void SetActive(bool isActive); |
| | 21 | | void SetCloseButtonsAction(UnityAction call); |
| | 22 | | void SetEntitiesList(List<BIWEntity> entities); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public class InspectorView : MonoBehaviour, IInspectorView |
| | 26 | | { |
| 0 | 27 | | public EntityListView entityList { get { return entityListView; } set { entityListView = value; } } |
| 0 | 28 | | public List<BIWEntity> entities => entitiesList; |
| 0 | 29 | | public ISceneLimitsController sceneLimitsController { get; internal set; } |
| | 30 | |
|
| | 31 | | public event Action<EntityAction, BIWEntity, EntityListAdapter> OnEntityActionInvoked; |
| | 32 | | public event Action<BIWEntity, string> OnEntityRename; |
| | 33 | |
|
| | 34 | | [SerializeField] internal EntityListView entityListView; |
| | 35 | | [SerializeField] internal SceneLimitsView sceneLimitsView; |
| | 36 | | [SerializeField] internal Button closeEntityListBtn; |
| | 37 | |
|
| | 38 | | internal List<BIWEntity> entitiesList; |
| | 39 | |
|
| | 40 | | private const string VIEW_PATH = "GodMode/Inspector/InspectorView"; |
| | 41 | |
|
| | 42 | | internal static InspectorView Create() |
| | 43 | | { |
| 8 | 44 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<InspectorView>(); |
| 8 | 45 | | view.gameObject.name = "_InspectorView"; |
| | 46 | |
|
| 8 | 47 | | return view; |
| | 48 | | } |
| | 49 | |
|
| | 50 | | private void Awake() |
| | 51 | | { |
| 8 | 52 | | entityListView.OnActionInvoked += EntityActionInvoked; |
| 8 | 53 | | entityListView.OnEntityRename += EntityRename; |
| 8 | 54 | | } |
| | 55 | |
|
| | 56 | | private void OnDestroy() |
| | 57 | | { |
| 8 | 58 | | entityListView.OnActionInvoked -= EntityActionInvoked; |
| 8 | 59 | | entityListView.OnEntityRename -= EntityRename; |
| | 60 | |
|
| 8 | 61 | | if (sceneLimitsController != null) |
| 1 | 62 | | sceneLimitsController.Dispose(); |
| 8 | 63 | | } |
| | 64 | |
|
| 18 | 65 | | private void OnEnable() { AudioScriptableObjects.dialogOpen.Play(); } |
| | 66 | |
|
| 18 | 67 | | private void OnDisable() { AudioScriptableObjects.dialogClose.Play(); } |
| | 68 | |
|
| 2 | 69 | | public void EntityActionInvoked(EntityAction action, BIWEntity entityToApply, EntityListAdapter adapter) { OnEntityA |
| | 70 | |
|
| 2 | 71 | | public void EntityRename(BIWEntity entity, string newName) { OnEntityRename?.Invoke(entity, newName); } |
| | 72 | |
|
| 0 | 73 | | public bool IsActive() { return gameObject.activeSelf; } |
| | 74 | |
|
| 4 | 75 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 76 | |
|
| 0 | 77 | | public void SetEntitiesList(List<BIWEntity> entities) { entitiesList = entities; } |
| | 78 | |
|
| 2 | 79 | | public void ClearEntitiesList() { entitiesList?.Clear(); } |
| | 80 | |
|
| 2 | 81 | | public void SetCloseButtonsAction(UnityAction call) { closeEntityListBtn.onClick.AddListener(call); } |
| | 82 | |
|
| | 83 | | public void ConfigureSceneLimits(ISceneLimitsController sceneLimitsController) |
| | 84 | | { |
| 1 | 85 | | this.sceneLimitsController = sceneLimitsController; |
| 1 | 86 | | this.sceneLimitsController.Initialize(sceneLimitsView); |
| 1 | 87 | | } |
| | 88 | | } |