| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | | using DCL.Builder; |
| | 6 | |
|
| | 7 | | namespace DCL.Builder |
| | 8 | | { |
| | 9 | | internal interface IBuilderMainPanelView : IDisposable |
| | 10 | | { |
| | 11 | | event Action OnGuestConnectWallet; |
| | 12 | | event Action OnBackToMainMenuPressed; |
| | 13 | | event Action OnClosePressed; |
| | 14 | | event Action OnBackPressed; |
| | 15 | | event Action OnCreateProjectPressed; |
| | 16 | | void SetVisible(bool visible); |
| | 17 | | void SetSearchViewVisible(bool visible); |
| | 18 | | bool IsVisible(); |
| | 19 | | void SetTogglOnWithoutNotify(SectionId sectionId); |
| | 20 | | void SetMainLeftPanel(); |
| | 21 | | void SetProjectSettingsLeftPanel(); |
| | 22 | | void ShowToast(string text); |
| | 23 | | SceneCardView GetSceneCardViewPrefab(); |
| | 24 | | ProjectCardView GetProjectCardView(); |
| | 25 | | Transform GetSectionContainer(); |
| | 26 | | Transform GetTransform(); |
| | 27 | | SearchBarView GetSearchBar(); |
| | 28 | | LeftMenuSettingsViewReferences GetSettingsViewReferences(); |
| | 29 | | SceneCardViewContextMenu GetSceneCardViewContextMenu(); |
| | 30 | | ProjectContextMenuView GetProjectCardViewContextMenu(); |
| | 31 | | IUnpublishPopupView GetUnpublishPopup(); |
| | 32 | | void SetAsFullScreenMenuMode(Transform parentTransform); |
| | 33 | | void SetGuestMode(bool active); |
| | 34 | | } |
| | 35 | |
|
| | 36 | | internal class BuilderMainPanelView : MonoBehaviour, IBuilderMainPanelView, ISceneListener, IProjectsListener |
| | 37 | | { |
| | 38 | | [Header("General")] |
| | 39 | | [SerializeField] internal Button closeButton; |
| | 40 | | [SerializeField] internal Button backgroundButton; |
| | 41 | | [SerializeField] internal Transform sectionsContainer; |
| | 42 | | [SerializeField] internal SceneCardViewContextMenu contextMenu; |
| | 43 | | [SerializeField] internal ProjectContextMenuView projectContextMenu; |
| | 44 | | [SerializeField] internal SearchBarView searchBarView; |
| | 45 | | [SerializeField] internal ShowHideAnimator showHideAnimator; |
| | 46 | | [SerializeField] internal InputAction_Trigger closeTrigger; |
| | 47 | | [SerializeField] internal GameObject guestModeGameObject; |
| | 48 | | [SerializeField] internal GameObject sectionGameObject; |
| | 49 | | [SerializeField] internal Toast toastView; |
| | 50 | |
|
| | 51 | | [Header("Left-Panel Section Buttons")] |
| | 52 | | [SerializeField] internal LeftMenuButtonToggleView[] sectionToggles; |
| | 53 | |
|
| | 54 | | [Header("Left-Panel")] |
| | 55 | | [SerializeField] internal GameObject leftPanelMain; |
| | 56 | | [SerializeField] internal GameObject leftPanelProjectSettings; |
| | 57 | | [SerializeField] internal Button createSceneButton; |
| | 58 | | [SerializeField] internal Button importSceneButton; |
| | 59 | | [SerializeField] internal Button backToMainPanelButton; |
| | 60 | | [SerializeField] internal Button connectWalletButton; |
| | 61 | | [SerializeField] internal LeftMenuSettingsViewReferences settingsViewReferences; |
| | 62 | |
|
| | 63 | | [Header("Assets")] |
| | 64 | | [SerializeField] internal SceneCardView sceneCardViewPrefab; |
| | 65 | | [SerializeField] internal ProjectCardView projectCardView; |
| | 66 | |
|
| | 67 | | [Header("Popups")] |
| | 68 | | [SerializeField] internal UnpublishPopupView unpublishPopupView; |
| | 69 | |
|
| | 70 | | public event Action OnGuestConnectWallet; |
| | 71 | | public event Action OnClosePressed; |
| | 72 | | public event Action OnBackPressed; |
| | 73 | | public event Action OnCreateProjectPressed; |
| | 74 | | public event Action OnImportScenePressed; |
| | 75 | | public event Action OnBackToMainMenuPressed; |
| | 76 | |
|
| | 77 | | private int scenesCount = 0; |
| | 78 | | private int projectScenesCount = 0; |
| | 79 | | private bool isDestroyed = false; |
| | 80 | |
|
| 0 | 81 | | public void SetSearchViewVisible(bool visible) => searchBarView.gameObject.SetActive(visible); |
| | 82 | |
|
| 1 | 83 | | public bool IsVisible() { return gameObject.activeSelf; } |
| | 84 | |
|
| | 85 | | void IBuilderMainPanelView.SetVisible(bool visible) |
| | 86 | | { |
| 7 | 87 | | if (visible) |
| | 88 | | { |
| 4 | 89 | | if (!gameObject.activeSelf) |
| | 90 | | { |
| 4 | 91 | | gameObject.SetActive(true); |
| | 92 | | } |
| 4 | 93 | | showHideAnimator.Show(); |
| 4 | 94 | | } |
| | 95 | | else |
| | 96 | | { |
| 3 | 97 | | showHideAnimator.Hide(); |
| | 98 | | } |
| 3 | 99 | | } |
| | 100 | |
|
| | 101 | | void IBuilderMainPanelView.SetTogglOnWithoutNotify(SectionId sectionId) |
| | 102 | | { |
| 32 | 103 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 104 | | { |
| 14 | 105 | | sectionToggles[i].SetIsOnWithoutNotify(sectionId == sectionToggles[i].openSection); |
| | 106 | | } |
| 2 | 107 | | } |
| | 108 | |
|
| | 109 | | void IBuilderMainPanelView.SetMainLeftPanel() |
| | 110 | | { |
| 1 | 111 | | leftPanelMain.SetActive(true); |
| 1 | 112 | | leftPanelProjectSettings.SetActive(false); |
| 1 | 113 | | } |
| | 114 | |
|
| | 115 | | void IBuilderMainPanelView.SetProjectSettingsLeftPanel() |
| | 116 | | { |
| 1 | 117 | | leftPanelMain.SetActive(false); |
| 1 | 118 | | leftPanelProjectSettings.SetActive(true); |
| 1 | 119 | | } |
| | 120 | |
|
| 0 | 121 | | ProjectCardView IBuilderMainPanelView.GetProjectCardView() { return projectCardView; } |
| | 122 | |
|
| 2 | 123 | | SceneCardView IBuilderMainPanelView.GetSceneCardViewPrefab() { return sceneCardViewPrefab; } |
| | 124 | |
|
| 0 | 125 | | Transform IBuilderMainPanelView.GetSectionContainer() { return sectionsContainer; } |
| | 126 | |
|
| 0 | 127 | | Transform IBuilderMainPanelView.GetTransform() { return transform; } |
| | 128 | |
|
| 16 | 129 | | SearchBarView IBuilderMainPanelView.GetSearchBar() { return searchBarView; } |
| | 130 | |
|
| 17 | 131 | | LeftMenuSettingsViewReferences IBuilderMainPanelView.GetSettingsViewReferences() { return settingsViewReferences |
| | 132 | |
|
| 17 | 133 | | SceneCardViewContextMenu IBuilderMainPanelView.GetSceneCardViewContextMenu() { return contextMenu; } |
| 0 | 134 | | public ProjectContextMenuView GetProjectCardViewContextMenu() { return projectContextMenu; } |
| | 135 | |
|
| 16 | 136 | | IUnpublishPopupView IBuilderMainPanelView.GetUnpublishPopup() { return unpublishPopupView; } |
| | 137 | |
|
| | 138 | | public void Dispose() |
| | 139 | | { |
| 16 | 140 | | if (!isDestroyed) |
| | 141 | | { |
| 16 | 142 | | Destroy(gameObject); |
| | 143 | | } |
| 16 | 144 | | } |
| | 145 | |
|
| | 146 | | private void Awake() |
| | 147 | | { |
| 16 | 148 | | name = "_BuilderProjectsPanel"; |
| | 149 | |
|
| 17 | 150 | | closeButton.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 16 | 151 | | backgroundButton?.onClick.AddListener(() => OnClosePressed?.Invoke()); |
| 16 | 152 | | createSceneButton.onClick.AddListener(() => OnCreateProjectPressed?.Invoke()); |
| 16 | 153 | | importSceneButton.onClick.AddListener(() => OnImportScenePressed?.Invoke()); |
| 17 | 154 | | backToMainPanelButton.onClick.AddListener(() => OnBackToMainMenuPressed?.Invoke()); |
| 16 | 155 | | connectWalletButton.onClick.AddListener(() => OnGuestConnectWallet?.Invoke()); |
| 16 | 156 | | closeTrigger.OnTriggered += CloseTriggerOnOnTriggered; |
| | 157 | |
|
| 16 | 158 | | contextMenu.Hide(); |
| 16 | 159 | | gameObject.SetActive(false); |
| | 160 | |
|
| 256 | 161 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 162 | | { |
| 112 | 163 | | sectionToggles[i].Setup(); |
| | 164 | | } |
| 16 | 165 | | } |
| | 166 | |
|
| 32 | 167 | | private void OnDestroy() { isDestroyed = true; } |
| | 168 | |
|
| | 169 | | public void SetGuestMode(bool active) |
| | 170 | | { |
| 13 | 171 | | if (active) |
| | 172 | | { |
| 0 | 173 | | guestModeGameObject.SetActive(true); |
| 0 | 174 | | sectionGameObject.SetActive(false); |
| 0 | 175 | | createSceneButton.interactable = false; |
| | 176 | |
|
| 0 | 177 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 178 | | { |
| 0 | 179 | | sectionToggles[i].Disable(); |
| | 180 | | } |
| 0 | 181 | | } |
| | 182 | | else |
| | 183 | | { |
| 13 | 184 | | guestModeGameObject.SetActive(false); |
| 13 | 185 | | sectionGameObject.SetActive(true); |
| 13 | 186 | | createSceneButton.interactable = true; |
| | 187 | |
|
| 208 | 188 | | for (int i = 0; i < sectionToggles.Length; i++) |
| | 189 | | { |
| 91 | 190 | | sectionToggles[i].Enable(); |
| | 191 | | } |
| | 192 | | } |
| 13 | 193 | | } |
| | 194 | |
|
| | 195 | | public void ShowToast(string text) |
| | 196 | | { |
| 0 | 197 | | toastView.SetText(text); |
| 0 | 198 | | toastView.Show(false); |
| 0 | 199 | | } |
| | 200 | |
|
| 16 | 201 | | private void CloseTriggerOnOnTriggered(DCLAction_Trigger action) { OnBackPressed?.Invoke(); } |
| | 202 | |
|
| 0 | 203 | | void ISceneListener.SetScenes(Dictionary<string, ISceneCardView> scenes) { scenesCount = scenes.Count; } |
| | 204 | |
|
| 0 | 205 | | void ISceneListener.SceneAdded(ISceneCardView scene) { scenesCount++; } |
| | 206 | |
|
| 0 | 207 | | void ISceneListener.SceneRemoved(ISceneCardView scene) { scenesCount--; } |
| | 208 | |
|
| 0 | 209 | | public void OnSetProjects(Dictionary<string, IProjectCardView> projects) { projectScenesCount = projects.Count; |
| | 210 | |
|
| 0 | 211 | | public void OnProjectAdded(IProjectCardView project) { projectScenesCount++; } |
| | 212 | |
|
| 0 | 213 | | public void OnProjectRemoved(IProjectCardView project) { projectScenesCount--; } |
| | 214 | |
|
| | 215 | | public void SetAsFullScreenMenuMode(Transform parentTransform) |
| | 216 | | { |
| 16 | 217 | | if (parentTransform == null) |
| 16 | 218 | | return; |
| | 219 | |
|
| 0 | 220 | | transform.SetParent(parentTransform); |
| 0 | 221 | | transform.localScale = Vector3.one; |
| | 222 | |
|
| 0 | 223 | | RectTransform rectTransform = transform as RectTransform; |
| 0 | 224 | | rectTransform.anchorMin = Vector2.zero; |
| 0 | 225 | | rectTransform.anchorMax = Vector2.one; |
| 0 | 226 | | rectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 227 | | rectTransform.localPosition = Vector2.zero; |
| 0 | 228 | | rectTransform.offsetMax = Vector2.zero; |
| 0 | 229 | | rectTransform.offsetMin = Vector2.zero; |
| 0 | 230 | | } |
| | 231 | | } |
| | 232 | | } |