| | 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 | | void SetAsFullScreenMenuMode(Transform parentTransform); |
| | 28 | | } |
| | 29 | |
|
| | 30 | | internal class BuilderMainPanelView : MonoBehaviour, IBuilderMainPanelView, ISceneListener, IProjectsListener |
| | 31 | | { |
| | 32 | | [Header("General")] |
| | 33 | | [SerializeField] internal Button closeButton; |
| | 34 | | [SerializeField] internal Button backgroundButton; |
| | 35 | | [SerializeField] internal Transform sectionsContainer; |
| | 36 | | [SerializeField] internal SceneCardViewContextMenu contextMenu; |
| | 37 | | [SerializeField] internal SearchBarView searchBarView; |
| | 38 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 39 | | [SerializeField] internal InputAction_Trigger closeTrigger; |
| | 40 | |
|
| | 41 | | [Header("Left-Panel Section Buttons")] |
| | 42 | | [SerializeField] internal LeftMenuButtonToggleView[] sectionToggles; |
| | 43 | |
|
| | 44 | | [Header("Left-Panel")] |
| | 45 | | [SerializeField] internal GameObject leftPanelMain; |
| | 46 | | [SerializeField] internal GameObject leftPanelProjectSettings; |
| | 47 | | [SerializeField] internal Button createSceneButton; |
| | 48 | | [SerializeField] internal Button importSceneButton; |
| | 49 | | [SerializeField] internal Button backToMainPanelButton; |
| | 50 | | [SerializeField] internal LeftMenuSettingsViewReferences settingsViewReferences; |
| | 51 | |
|
| | 52 | | [Header("Assets")] |
| | 53 | | [SerializeField] internal SceneCardView sceneCardViewPrefab; |
| | 54 | | [SerializeField] internal ProjectCardView projectCardView; |
| | 55 | |
|
| | 56 | | [Header("Popups")] |
| | 57 | | [SerializeField] internal UnpublishPopupView unpublishPopupView; |
| | 58 | |
|
| | 59 | | public event Action OnClosePressed; |
| | 60 | | public event Action OnBackPressed; |
| | 61 | | public event Action OnCreateProjectPressed; |
| | 62 | | public event Action OnImportScenePressed; |
| | 63 | | public event Action OnBackToMainMenuPressed; |
| | 64 | |
|
| | 65 | | private int scenesCount = 0; |
| | 66 | | private int projectScenesCount = 0; |
| | 67 | | private bool isDestroyed = false; |
| | 68 | |
|
| 1 | 69 | | public bool IsVisible() { return gameObject.activeSelf; } |
| | 70 | |
|
| | 71 | | void IBuilderMainPanelView.SetVisible(bool visible) |
| | 72 | | { |
| 7 | 73 | | if (visible) |
| | 74 | | { |
| 4 | 75 | | if (!gameObject.activeSelf) |
| | 76 | | { |
| 4 | 77 | | gameObject.SetActive(true); |
| | 78 | | } |
| 4 | 79 | | showHideAnimator.Show(); |
| 4 | 80 | | } |
| | 81 | | else |
| | 82 | | { |
| 3 | 83 | | showHideAnimator.Hide(); |
| | 84 | | } |
| 3 | 85 | | } |
| | 86 | |
|
| | 87 | | void IBuilderMainPanelView.SetTogglOnWithoutNotify(SectionId sectionId) |
| | 88 | | { |
| 40 | 89 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 90 | | { |
| 18 | 91 | | sectionToggles[i].SetIsOnWithoutNotify(sectionId == sectionToggles[i].openSection); |
| | 92 | | } |
| 2 | 93 | | } |
| | 94 | |
|
| | 95 | | void IBuilderMainPanelView.SetMainLeftPanel() |
| | 96 | | { |
| 1 | 97 | | leftPanelMain.SetActive(true); |
| 1 | 98 | | leftPanelProjectSettings.SetActive(false); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | void IBuilderMainPanelView.SetProjectSettingsLeftPanel() |
| | 102 | | { |
| 1 | 103 | | leftPanelMain.SetActive(false); |
| 1 | 104 | | leftPanelProjectSettings.SetActive(true); |
| 1 | 105 | | } |
| | 106 | |
|
| 0 | 107 | | ProjectCardView IBuilderMainPanelView.GetProjectCardView() { return projectCardView; } |
| | 108 | |
|
| 2 | 109 | | SceneCardView IBuilderMainPanelView.GetSceneCardViewPrefab() { return sceneCardViewPrefab; } |
| | 110 | |
|
| 0 | 111 | | Transform IBuilderMainPanelView.GetSectionContainer() { return sectionsContainer; } |
| | 112 | |
|
| 0 | 113 | | Transform IBuilderMainPanelView.GetTransform() { return transform; } |
| | 114 | |
|
| 17 | 115 | | SearchBarView IBuilderMainPanelView.GetSearchBar() { return searchBarView; } |
| | 116 | |
|
| 18 | 117 | | LeftMenuSettingsViewReferences IBuilderMainPanelView.GetSettingsViewReferences() { return settingsViewReferences |
| | 118 | |
|
| 18 | 119 | | SceneCardViewContextMenu IBuilderMainPanelView.GetSceneCardViewContextMenu() { return contextMenu; } |
| | 120 | |
|
| 17 | 121 | | IUnpublishPopupView IBuilderMainPanelView.GetUnpublishPopup() { return unpublishPopupView; } |
| | 122 | |
|
| | 123 | | public void Dispose() |
| | 124 | | { |
| 17 | 125 | | if (!isDestroyed) |
| | 126 | | { |
| 17 | 127 | | Destroy(gameObject); |
| | 128 | | } |
| 17 | 129 | | } |
| | 130 | |
|
| | 131 | | private void Awake() |
| | 132 | | { |
| 17 | 133 | | name = "_BuilderProjectsPanel"; |
| | 134 | |
|
| 18 | 135 | | closeButton.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 17 | 136 | | backgroundButton?.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 17 | 137 | | createSceneButton.onClick.AddListener(() => OnCreateProjectPressed?.Invoke()); |
| 17 | 138 | | importSceneButton.onClick.AddListener(() => OnImportScenePressed?.Invoke()); |
| 18 | 139 | | backToMainPanelButton.onClick.AddListener(() => OnBackToMainMenuPressed?.Invoke()); |
| 17 | 140 | | closeTrigger.OnTriggered += CloseTriggerOnOnTriggered; |
| | 141 | |
|
| 17 | 142 | | contextMenu.Hide(); |
| 17 | 143 | | gameObject.SetActive(false); |
| | 144 | |
|
| 340 | 145 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 146 | | { |
| 153 | 147 | | sectionToggles[i].Setup(); |
| | 148 | | } |
| 17 | 149 | | } |
| | 150 | |
|
| 34 | 151 | | private void OnDestroy() { isDestroyed = true; } |
| | 152 | |
|
| 17 | 153 | | private void CloseTriggerOnOnTriggered(DCLAction_Trigger action) { OnBackPressed?.Invoke(); } |
| | 154 | |
|
| 0 | 155 | | void ISceneListener.SetScenes(Dictionary<string, ISceneCardView> scenes) { scenesCount = scenes.Count; } |
| | 156 | |
|
| 0 | 157 | | void ISceneListener.SceneAdded(ISceneCardView scene) { scenesCount++; } |
| | 158 | |
|
| 0 | 159 | | void ISceneListener.SceneRemoved(ISceneCardView scene) { scenesCount--; } |
| | 160 | |
|
| 0 | 161 | | public void OnSetProjects(Dictionary<string, IProjectCardView> projects) { projectScenesCount = projects.Count; |
| | 162 | |
|
| 0 | 163 | | public void OnProjectAdded(IProjectCardView project) { projectScenesCount++; } |
| | 164 | |
|
| 0 | 165 | | public void OnProjectRemoved(IProjectCardView project) { projectScenesCount--; } |
| | 166 | |
|
| | 167 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 168 | | { |
| 17 | 169 | | if (parentTransform == null) |
| 17 | 170 | | return; |
| | 171 | |
|
| 0 | 172 | | transform.SetParent(parentTransform); |
| 0 | 173 | | transform.localScale = Vector3.one; |
| | 174 | |
|
| 0 | 175 | | RectTransform rectTransform = transform as RectTransform; |
| 0 | 176 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 177 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 178 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 179 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 180 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 181 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 182 | | } |
| | 183 | | } |
| | 184 | | } |