| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public interface IExploreV2MenuComponentView : IDisposable |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// It will be triggered when the view is fully initialized. |
| | 9 | | /// </summary> |
| | 10 | | event Action OnInitialized; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// It will be triggered when the close button is clicked. |
| | 14 | | /// </summary> |
| | 15 | | event Action<bool> OnCloseButtonPressed; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// It will be triggered when a section is open. |
| | 19 | | /// </summary> |
| | 20 | | event Action<ExploreSection> OnSectionOpen; |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// It will be triggered after the show animation has finished. |
| | 24 | | /// </summary> |
| | 25 | | event Action OnAfterShowAnimation; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Real viewer component. |
| | 29 | | /// </summary> |
| | 30 | | IRealmViewerComponentView currentRealmViewer { get; } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Profile card component. |
| | 34 | | /// </summary> |
| | 35 | | IProfileCardComponentView currentProfileCard { get; } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Places and Events section component. |
| | 39 | | /// </summary> |
| | 40 | | IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Transform used to positionate the top menu tooltips. |
| | 44 | | /// </summary> |
| | 45 | | RectTransform currentTopMenuTooltipReference { get; } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Transform used to positionate the places and events section tooltips. |
| | 49 | | /// </summary> |
| | 50 | | RectTransform currentPlacesAndEventsTooltipReference { get; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Transform used to positionate the backpack section tooltips. |
| | 54 | | /// </summary> |
| | 55 | | RectTransform currentBackpackTooltipReference { get; } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// Transform used to positionate the map section tooltips. |
| | 59 | | /// </summary> |
| | 60 | | RectTransform currentMapTooltipReference { get; } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Transform used to positionate the builder section tooltips. |
| | 64 | | /// </summary> |
| | 65 | | RectTransform currentBuilderTooltipReference { get; } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Transform used to positionate the quest section tooltips. |
| | 69 | | /// </summary> |
| | 70 | | RectTransform currentQuestTooltipReference { get; } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Transform used to positionate the settings section tooltips. |
| | 74 | | /// </summary> |
| | 75 | | RectTransform currentSettingsTooltipReference { get; } |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Transform used to positionate the profile section tooltips. |
| | 79 | | /// </summary> |
| | 80 | | RectTransform currentProfileCardTooltipReference { get; } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// Shows/Hides the game object of the explore menu. |
| | 84 | | /// </summary> |
| | 85 | | /// <param name="isActive">True to show it.</param> |
| | 86 | | void SetVisible(bool isActive); |
| | 87 | |
|
| | 88 | | /// <summary> |
| | 89 | | /// It is called after the show animation has finished. |
| | 90 | | /// </summary> |
| | 91 | | void OnAfterShowAnimationCompleted(); |
| | 92 | |
|
| | 93 | | /// <summary> |
| | 94 | | /// Open a section. |
| | 95 | | /// </summary> |
| | 96 | | /// <param name="section">Section to go.</param> |
| | 97 | | void GoToSection(ExploreSection section); |
| | 98 | |
|
| | 99 | | /// <summary> |
| | 100 | | /// Activates/Deactivates a section in the selector. |
| | 101 | | /// </summary> |
| | 102 | | /// <param name="section">Section to activate/deactivate.</param> |
| | 103 | | /// <param name="isActive">True for activating.</param> |
| | 104 | | void SetSectionActive(ExploreSection section, bool isActive); |
| | 105 | |
|
| | 106 | | /// <summary> |
| | 107 | | /// Check if a section is actived or not. |
| | 108 | | /// </summary> |
| | 109 | | /// <param name="section">Section to check.</param> |
| | 110 | | /// <returns></returns> |
| | 111 | | bool IsSectionActive(ExploreSection section); |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// Configures a encapsulated section. |
| | 115 | | /// </summary> |
| | 116 | | /// <param name="section">Section to configure.</param> |
| | 117 | | /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param> |
| | 118 | | void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag); |
| | 119 | | } |
| | 120 | |
|
| | 121 | | public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView |
| | 122 | | { |
| | 123 | | [Header("Top Menu")] |
| | 124 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 125 | | [SerializeField] internal ProfileCardComponentView profileCard; |
| | 126 | | [SerializeField] internal RealmViewerComponentView realmViewer; |
| | 127 | | [SerializeField] internal ButtonComponentView closeMenuButton; |
| | 128 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 129 | |
|
| | 130 | | [Header("Sections")] |
| | 131 | | [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection; |
| | 132 | | [SerializeField] internal FeatureEncapsulatorComponentView backpackSection; |
| | 133 | | [SerializeField] internal FeatureEncapsulatorComponentView mapSection; |
| | 134 | | [SerializeField] internal FeatureEncapsulatorComponentView builderSection; |
| | 135 | | [SerializeField] internal FeatureEncapsulatorComponentView questSection; |
| | 136 | | [SerializeField] internal FeatureEncapsulatorComponentView settingsSection; |
| | 137 | |
|
| | 138 | | [Header("Tutorial References")] |
| | 139 | | [SerializeField] internal RectTransform profileCardTooltipReference; |
| | 140 | |
|
| | 141 | | internal const ExploreSection DEFAULT_SECTION = ExploreSection.Explore; |
| | 142 | |
|
| 0 | 143 | | public IRealmViewerComponentView currentRealmViewer => realmViewer; |
| 0 | 144 | | public IProfileCardComponentView currentProfileCard => profileCard; |
| 0 | 145 | | public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection; |
| 0 | 146 | | public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo |
| 0 | 147 | | public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor |
| 0 | 148 | | public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv |
| 0 | 149 | | public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot; |
| 0 | 150 | | public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot |
| 0 | 151 | | public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot; |
| 0 | 152 | | public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv |
| 0 | 153 | | public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference; |
| | 154 | |
|
| | 155 | | public event Action OnInitialized; |
| | 156 | | public event Action<bool> OnCloseButtonPressed; |
| | 157 | | public event Action<ExploreSection> OnSectionOpen; |
| | 158 | | public event Action OnAfterShowAnimation; |
| | 159 | |
|
| | 160 | | internal RectTransform profileCardRectTranform; |
| | 161 | |
|
| | 162 | | public override void Start() |
| | 163 | | { |
| 39 | 164 | | profileCardRectTranform = profileCard.GetComponent<RectTransform>(); |
| | 165 | |
|
| 39 | 166 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false); |
| | 167 | |
|
| 39 | 168 | | CreateSectionSelectorMappings(); |
| 39 | 169 | | ConfigureCloseButton(); |
| | 170 | |
|
| 39 | 171 | | OnInitialized?.Invoke(); |
| 0 | 172 | | } |
| | 173 | |
|
| | 174 | | public override void Update() |
| | 175 | | { |
| 0 | 176 | | CheckIfProfileCardShouldBeClosed(); |
| 0 | 177 | | } |
| | 178 | |
|
| | 179 | | public override void RefreshControl() |
| | 180 | | { |
| 0 | 181 | | placesAndEventsSection.RefreshControl(); |
| 0 | 182 | | backpackSection.RefreshControl(); |
| 0 | 183 | | mapSection.RefreshControl(); |
| 0 | 184 | | builderSection.RefreshControl(); |
| 0 | 185 | | questSection.RefreshControl(); |
| 0 | 186 | | settingsSection.RefreshControl(); |
| 0 | 187 | | } |
| | 188 | |
|
| | 189 | | public override void Dispose() |
| | 190 | | { |
| 78 | 191 | | base.Dispose(); |
| | 192 | |
|
| 78 | 193 | | RemoveSectionSelectorMappings(); |
| 78 | 194 | | closeMenuButton.onClick.RemoveAllListeners(); |
| 78 | 195 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| 78 | 196 | | } |
| | 197 | |
|
| | 198 | | public void SetVisible(bool isActive) |
| | 199 | | { |
| 2 | 200 | | if (isActive) |
| | 201 | | { |
| 1 | 202 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true); |
| 1 | 203 | | Show(); |
| 1 | 204 | | GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get()); |
| 1 | 205 | | } |
| | 206 | | else |
| | 207 | | { |
| 1 | 208 | | Hide(); |
| 1 | 209 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 210 | | } |
| 1 | 211 | | } |
| | 212 | |
|
| | 213 | | public void OnAfterShowAnimationCompleted() |
| | 214 | | { |
| 0 | 215 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false); |
| 0 | 216 | | OnAfterShowAnimation?.Invoke(); |
| 0 | 217 | | } |
| | 218 | |
|
| | 219 | | public void GoToSection(ExploreSection section) |
| | 220 | | { |
| 7 | 221 | | if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section) |
| 6 | 222 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)section); |
| | 223 | |
|
| 7 | 224 | | sectionSelector.GetSection((int)section)?.SelectToggle(true); |
| | 225 | |
|
| 7 | 226 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 7 | 227 | | AudioScriptableObjects.listItemAppear.ResetPitch(); |
| 7 | 228 | | } |
| | 229 | |
|
| 24 | 230 | | public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc |
| | 231 | |
|
| 0 | 232 | | public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); } |
| | 233 | |
|
| | 234 | | public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag) |
| | 235 | | { |
| 5 | 236 | | FeatureEncapsulatorComponentView sectionView = null; |
| | 237 | | switch (section) |
| | 238 | | { |
| | 239 | | case ExploreSection.Backpack: |
| 1 | 240 | | sectionView = backpackSection; |
| 1 | 241 | | break; |
| | 242 | | case ExploreSection.Map: |
| 1 | 243 | | sectionView = mapSection; |
| 1 | 244 | | break; |
| | 245 | | case ExploreSection.Builder: |
| 1 | 246 | | sectionView = builderSection; |
| 1 | 247 | | break; |
| | 248 | | case ExploreSection.Quest: |
| 1 | 249 | | sectionView = questSection; |
| 1 | 250 | | break; |
| | 251 | | case ExploreSection.Settings: |
| 1 | 252 | | sectionView = settingsSection; |
| | 253 | | break; |
| | 254 | | } |
| | 255 | |
|
| 5 | 256 | | sectionView?.EncapsulateFeature(featureConfiguratorFlag); |
| 5 | 257 | | } |
| | 258 | |
|
| | 259 | | internal void CreateSectionSelectorMappings() |
| | 260 | | { |
| 51 | 261 | | sectionSelector.GetSection((int)ExploreSection.Explore) |
| | 262 | | ?.onSelect.AddListener((isOn) => |
| | 263 | | { |
| 8 | 264 | | if (isOn) |
| | 265 | | { |
| 3 | 266 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false); |
| 3 | 267 | | OnSectionOpen?.Invoke(ExploreSection.Explore); |
| | 268 | | } |
| 6 | 269 | | }); |
| | 270 | |
|
| 51 | 271 | | sectionSelector.GetSection((int)ExploreSection.Backpack) |
| | 272 | | ?.onSelect.AddListener((isOn) => |
| | 273 | | { |
| 2 | 274 | | if (isOn) |
| | 275 | | { |
| 2 | 276 | | backpackSection.Show(); |
| 2 | 277 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false); |
| 2 | 278 | | OnSectionOpen?.Invoke(ExploreSection.Backpack); |
| 1 | 279 | | } |
| | 280 | | else |
| 0 | 281 | | backpackSection.Hide(); |
| 0 | 282 | | }); |
| | 283 | |
|
| 51 | 284 | | sectionSelector.GetSection((int)ExploreSection.Map) |
| | 285 | | ?.onSelect.AddListener((isOn) => |
| | 286 | | { |
| 2 | 287 | | if (isOn) |
| | 288 | | { |
| 2 | 289 | | mapSection.Show(); |
| 2 | 290 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false); |
| 2 | 291 | | OnSectionOpen?.Invoke(ExploreSection.Map); |
| 1 | 292 | | } |
| | 293 | | else |
| 0 | 294 | | mapSection.Hide(); |
| 0 | 295 | | }); |
| | 296 | |
|
| 51 | 297 | | sectionSelector.GetSection((int)ExploreSection.Builder) |
| | 298 | | ?.onSelect.AddListener((isOn) => |
| | 299 | | { |
| 2 | 300 | | if (isOn) |
| | 301 | | { |
| 2 | 302 | | builderSection.Show(); |
| 2 | 303 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false); |
| 2 | 304 | | OnSectionOpen?.Invoke(ExploreSection.Builder); |
| 1 | 305 | | } |
| | 306 | | else |
| 0 | 307 | | builderSection.Hide(); |
| 0 | 308 | | }); |
| | 309 | |
|
| 51 | 310 | | sectionSelector.GetSection((int)ExploreSection.Quest) |
| | 311 | | ?.onSelect.AddListener((isOn) => |
| | 312 | | { |
| 2 | 313 | | if (isOn) |
| | 314 | | { |
| 2 | 315 | | questSection.Show(); |
| 2 | 316 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false); |
| 2 | 317 | | OnSectionOpen?.Invoke(ExploreSection.Quest); |
| 1 | 318 | | } |
| | 319 | | else |
| 0 | 320 | | questSection.Hide(); |
| 0 | 321 | | }); |
| | 322 | |
|
| 51 | 323 | | sectionSelector.GetSection((int)ExploreSection.Settings) |
| | 324 | | ?.onSelect.AddListener((isOn) => |
| | 325 | | { |
| 2 | 326 | | if (isOn) |
| | 327 | | { |
| 2 | 328 | | settingsSection.Show(); |
| 2 | 329 | | DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false); |
| 2 | 330 | | OnSectionOpen?.Invoke(ExploreSection.Settings); |
| 1 | 331 | | } |
| | 332 | | else |
| 0 | 333 | | settingsSection.Hide(); |
| 0 | 334 | | }); |
| 51 | 335 | | } |
| | 336 | |
|
| | 337 | | internal void RemoveSectionSelectorMappings() |
| | 338 | | { |
| 84 | 339 | | sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners(); |
| 84 | 340 | | sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners(); |
| 84 | 341 | | sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners(); |
| 84 | 342 | | sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners(); |
| 84 | 343 | | sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners(); |
| 84 | 344 | | sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners(); |
| 84 | 345 | | } |
| | 346 | |
|
| | 347 | | internal void ConfigureCloseButton() |
| | 348 | | { |
| 43 | 349 | | closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false)); |
| 41 | 350 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| 41 | 351 | | } |
| | 352 | |
|
| 6 | 353 | | internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); } |
| | 354 | |
|
| | 355 | | internal void CheckIfProfileCardShouldBeClosed() |
| | 356 | | { |
| 0 | 357 | | if (!DataStore.i.exploreV2.profileCardIsOpen.Get()) |
| 0 | 358 | | return; |
| | 359 | |
|
| 0 | 360 | | if (Input.GetMouseButton(0) && |
| | 361 | | !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, Camera.main |
| | 362 | | !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse |
| | 363 | | { |
| 0 | 364 | | DataStore.i.exploreV2.profileCardIsOpen.Set(false); |
| | 365 | | } |
| 0 | 366 | | } |
| | 367 | |
|
| | 368 | | internal static ExploreV2MenuComponentView Create() |
| | 369 | | { |
| 0 | 370 | | ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get |
| 0 | 371 | | exploreV2View.name = "_ExploreV2"; |
| | 372 | |
|
| 0 | 373 | | return exploreV2View; |
| | 374 | | } |
| | 375 | | } |