| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | namespace DCL.Builder |
| | 7 | | { |
| | 8 | | internal interface IBuilderMainPanelView : IDisposable |
| | 9 | | { |
| | 10 | | event Action OnBackToMainMenuPressed; |
| | 11 | | event Action OnClosePressed; |
| | 12 | | event Action OnBackPressed; |
| | 13 | | event Action OnCreateProjectPressed; |
| | 14 | | void SetVisible(bool visible); |
| | 15 | | bool IsVisible(); |
| | 16 | | void SetTogglOnWithoutNotify(SectionId sectionId); |
| | 17 | | void SetMainLeftPanel(); |
| | 18 | | void SetProjectSettingsLeftPanel(); |
| | 19 | | SceneCardView GetSceneCardViewPrefab(); |
| | 20 | | ProjectCardView GetProjectCardView(); |
| | 21 | | Transform GetSectionContainer(); |
| | 22 | | Transform GetTransform(); |
| | 23 | | SearchBarView GetSearchBar(); |
| | 24 | | LeftMenuSettingsViewReferences GetSettingsViewReferences(); |
| | 25 | | SceneCardViewContextMenu GetSceneCardViewContextMenu(); |
| | 26 | | IUnpublishPopupView GetUnpublishPopup(); |
| | 27 | | } |
| | 28 | |
|
| | 29 | | internal class BuilderMainPanelView : MonoBehaviour, IBuilderMainPanelView, ISceneListener, IProjectsListener |
| | 30 | | { |
| | 31 | | [Header("General")] |
| | 32 | | [SerializeField] internal Button closeButton; |
| | 33 | | [SerializeField] internal Button backgroundButton; |
| | 34 | | [SerializeField] internal Transform sectionsContainer; |
| | 35 | | [SerializeField] internal SceneCardViewContextMenu contextMenu; |
| | 36 | | [SerializeField] internal SearchBarView searchBarView; |
| | 37 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 38 | | [SerializeField] internal InputAction_Trigger closeTrigger; |
| | 39 | |
|
| | 40 | | [Header("Left-Panel Section Buttons")] |
| | 41 | | [SerializeField] internal LeftMenuButtonToggleView[] sectionToggles; |
| | 42 | |
|
| | 43 | | [Header("Left-Panel")] |
| | 44 | | [SerializeField] internal GameObject leftPanelMain; |
| | 45 | | [SerializeField] internal GameObject leftPanelProjectSettings; |
| | 46 | | [SerializeField] internal Button createSceneButton; |
| | 47 | | [SerializeField] internal Button importSceneButton; |
| | 48 | | [SerializeField] internal Button backToMainPanelButton; |
| | 49 | | [SerializeField] internal LeftMenuSettingsViewReferences settingsViewReferences; |
| | 50 | |
|
| | 51 | | [Header("Assets")] |
| | 52 | | [SerializeField] internal SceneCardView sceneCardViewPrefab; |
| | 53 | | [SerializeField] internal ProjectCardView projectCardView; |
| | 54 | |
|
| | 55 | | [Header("Popups")] |
| | 56 | | [SerializeField] internal UnpublishPopupView unpublishPopupView; |
| | 57 | |
|
| | 58 | | public event Action OnClosePressed; |
| | 59 | | public event Action OnBackPressed; |
| | 60 | | public event Action OnCreateProjectPressed; |
| | 61 | | public event Action OnImportScenePressed; |
| | 62 | | public event Action OnBackToMainMenuPressed; |
| | 63 | |
|
| | 64 | | private int scenesCount = 0; |
| | 65 | | private int projectScenesCount = 0; |
| | 66 | | private bool isDestroyed = false; |
| | 67 | |
|
| 1 | 68 | | public bool IsVisible() { return gameObject.activeSelf; } |
| | 69 | |
|
| | 70 | | void IBuilderMainPanelView.SetVisible(bool visible) |
| | 71 | | { |
| 7 | 72 | | if (visible) |
| | 73 | | { |
| 4 | 74 | | if (!gameObject.activeSelf) |
| | 75 | | { |
| 4 | 76 | | gameObject.SetActive(true); |
| | 77 | | } |
| 4 | 78 | | showHideAnimator.Show(); |
| 4 | 79 | | } |
| | 80 | | else |
| | 81 | | { |
| 3 | 82 | | showHideAnimator.Hide(); |
| | 83 | | } |
| 3 | 84 | | } |
| | 85 | |
|
| | 86 | | void IBuilderMainPanelView.SetTogglOnWithoutNotify(SectionId sectionId) |
| | 87 | | { |
| 40 | 88 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 89 | | { |
| 18 | 90 | | sectionToggles[i].SetIsOnWithoutNotify(sectionId == sectionToggles[i].openSection); |
| | 91 | | } |
| 2 | 92 | | } |
| | 93 | |
|
| | 94 | | void IBuilderMainPanelView.SetMainLeftPanel() |
| | 95 | | { |
| 1 | 96 | | leftPanelMain.SetActive(true); |
| 1 | 97 | | leftPanelProjectSettings.SetActive(false); |
| 1 | 98 | | } |
| | 99 | |
|
| | 100 | | void IBuilderMainPanelView.SetProjectSettingsLeftPanel() |
| | 101 | | { |
| 1 | 102 | | leftPanelMain.SetActive(false); |
| 1 | 103 | | leftPanelProjectSettings.SetActive(true); |
| 1 | 104 | | } |
| | 105 | |
|
| 0 | 106 | | ProjectCardView IBuilderMainPanelView.GetProjectCardView() { return projectCardView; } |
| | 107 | |
|
| 2 | 108 | | SceneCardView IBuilderMainPanelView.GetSceneCardViewPrefab() { return sceneCardViewPrefab; } |
| | 109 | |
|
| 0 | 110 | | Transform IBuilderMainPanelView.GetSectionContainer() { return sectionsContainer; } |
| | 111 | |
|
| 0 | 112 | | Transform IBuilderMainPanelView.GetTransform() { return transform; } |
| | 113 | |
|
| 17 | 114 | | SearchBarView IBuilderMainPanelView.GetSearchBar() { return searchBarView; } |
| | 115 | |
|
| 18 | 116 | | LeftMenuSettingsViewReferences IBuilderMainPanelView.GetSettingsViewReferences() { return settingsViewReferences |
| | 117 | |
|
| 18 | 118 | | SceneCardViewContextMenu IBuilderMainPanelView.GetSceneCardViewContextMenu() { return contextMenu; } |
| | 119 | |
|
| 17 | 120 | | IUnpublishPopupView IBuilderMainPanelView.GetUnpublishPopup() { return unpublishPopupView; } |
| | 121 | |
|
| | 122 | | public void Dispose() |
| | 123 | | { |
| 17 | 124 | | if (!isDestroyed) |
| | 125 | | { |
| 17 | 126 | | Destroy(gameObject); |
| | 127 | | } |
| 17 | 128 | | } |
| | 129 | |
|
| | 130 | | private void Awake() |
| | 131 | | { |
| 17 | 132 | | name = "_BuilderProjectsPanel"; |
| | 133 | |
|
| 18 | 134 | | closeButton.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 17 | 135 | | backgroundButton?.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 17 | 136 | | createSceneButton.onClick.AddListener(() => OnCreateProjectPressed?.Invoke()); |
| 17 | 137 | | importSceneButton.onClick.AddListener(() => OnImportScenePressed?.Invoke()); |
| 18 | 138 | | backToMainPanelButton.onClick.AddListener(() => OnBackToMainMenuPressed?.Invoke()); |
| 17 | 139 | | closeTrigger.OnTriggered += CloseTriggerOnOnTriggered; |
| | 140 | |
|
| 17 | 141 | | contextMenu.Hide(); |
| 17 | 142 | | gameObject.SetActive(false); |
| | 143 | |
|
| 340 | 144 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 145 | | { |
| 153 | 146 | | sectionToggles[i].Setup(); |
| | 147 | | } |
| 17 | 148 | | } |
| | 149 | |
|
| 34 | 150 | | private void OnDestroy() { isDestroyed = true; } |
| | 151 | |
|
| 17 | 152 | | private void CloseTriggerOnOnTriggered(DCLAction_Trigger action) { OnBackPressed?.Invoke(); } |
| | 153 | |
|
| 0 | 154 | | void ISceneListener.SetScenes(Dictionary<string, ISceneCardView> scenes) { scenesCount = scenes.Count; } |
| | 155 | |
|
| 0 | 156 | | void ISceneListener.SceneAdded(ISceneCardView scene) { scenesCount++; } |
| | 157 | |
|
| 0 | 158 | | void ISceneListener.SceneRemoved(ISceneCardView scene) { scenesCount--; } |
| | 159 | |
|
| 0 | 160 | | public void OnSetProjects(Dictionary<string, IProjectCardView> projects) { projectScenesCount = projects.Count; |
| | 161 | |
|
| 0 | 162 | | public void OnProjectAdded(IProjectCardView project) { projectScenesCount++; } |
| | 163 | |
|
| 0 | 164 | | public void OnProjectRemoved(IProjectCardView project) { projectScenesCount--; } |
| | 165 | | } |
| | 166 | | } |