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