| | 1 | | using DCL; |
| | 2 | | using DCL.Builder; |
| | 3 | | using DCL.Builder.Manifest; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Interface; |
| | 6 | | using System; |
| | 7 | | using System.Collections; |
| | 8 | | using System.Linq; |
| | 9 | | using Cysharp.Threading.Tasks; |
| | 10 | | using DCL.Configuration; |
| | 11 | | using UnityEngine; |
| | 12 | | using Variables.RealmsInfo; |
| | 13 | | using Environment = DCL.Environment; |
| | 14 | | using Object = UnityEngine.Object; |
| | 15 | |
|
| | 16 | | public class BuilderMainPanelController : IHUD, IBuilderMainPanelController |
| | 17 | | { |
| | 18 | | private const string DELETE_PROJECT_CONFIRM_TEXT = "Are you sure that you want to delete {0} project?"; |
| | 19 | | private const string CREATING_PROJECT_ERROR = "Error creating a new project: "; |
| | 20 | | private const string OBTAIN_PROJECT_ERROR = "Error obtaining the project: "; |
| | 21 | |
|
| | 22 | | private const string DUPLICATE_PROJECT_ERROR = "Error duplicating the project: "; |
| | 23 | | private const string PUBLISH_PROJECT_ERROR = "Error publishing the project: "; |
| | 24 | |
|
| | 25 | | private const string DELETE_PROJECT_ERROR = "Error deleting the project: "; |
| | 26 | | private const string DELETE_PROJECT_SUCCESS = "<b>{0}</b> has been deleted"; |
| | 27 | |
|
| | 28 | | private const string TESTING_ETH_ADDRESS = "0xDc13378daFca7Fe2306368A16BCFac38c80BfCAD"; |
| | 29 | | private const string TESTING_TLD = "org"; |
| | 30 | | private const string VIEW_PREFAB_PATH = "BuilderProjectsPanelDev"; |
| | 31 | |
|
| | 32 | | private const float CACHE_TIME_LAND = 5 * 60; |
| | 33 | | private const float CACHE_TIME_SCENES = 1 * 60; |
| | 34 | | private const float REFRESH_INTERVAL = 2 * 60; |
| | 35 | |
|
| | 36 | | internal IBuilderMainPanelView view; |
| | 37 | |
|
| | 38 | | private ISectionsController sectionsController; |
| | 39 | | private IProjectsController projectsController; |
| | 40 | | private IScenesViewController scenesViewController; |
| | 41 | | private ILandsController landsesController; |
| | 42 | | private UnpublishPopupController unpublishPopupController; |
| | 43 | |
|
| | 44 | | private INewProjectFlowController newProjectFlowController; |
| | 45 | |
|
| | 46 | | private SectionsHandler sectionsHandler; |
| | 47 | | private SceneContextMenuHandler sceneContextMenuHandler; |
| | 48 | | private LeftMenuHandler leftMenuHandler; |
| | 49 | | private LeftMenuSettingsViewHandler leftMenuSettingsViewHandler; |
| | 50 | |
|
| | 51 | | private ITheGraph theGraph; |
| | 52 | | private ICatalyst catalyst; |
| | 53 | |
|
| | 54 | | private bool isInitialized = false; |
| | 55 | | internal bool isFetchingLands = false; |
| | 56 | | internal bool isFetchingProjects = false; |
| | 57 | | private bool sendPlayerOpenPanelEvent = false; |
| | 58 | | private Coroutine fetchDataInterval; |
| | 59 | | private Promise<LandWithAccess[]> fetchLandPromise = null; |
| | 60 | | private Promise<ProjectData[]> fetchProjectsPromise = null; |
| | 61 | |
|
| | 62 | | public event Action OnJumpInOrEdit; |
| | 63 | |
|
| | 64 | | internal IContext context; |
| | 65 | |
|
| 48 | 66 | | BaseVariable<Transform> configureBuilderInFullscreenMenu => DataStore.i.exploreV2.configureBuilderInFullscreenMenu; |
| | 67 | |
|
| 16 | 68 | | public BuilderMainPanelController() |
| | 69 | | { |
| 16 | 70 | | SetView(Object.Instantiate(Resources.Load<BuilderMainPanelView>(VIEW_PREFAB_PATH))); |
| | 71 | |
|
| 16 | 72 | | configureBuilderInFullscreenMenu.OnChange += ConfigureBuilderInFullscreenMenuChanged; |
| 16 | 73 | | ConfigureBuilderInFullscreenMenuChanged(configureBuilderInFullscreenMenu.Get(), null); |
| 16 | 74 | | } |
| | 75 | |
|
| | 76 | | internal void SetView(IBuilderMainPanelView view) |
| | 77 | | { |
| 16 | 78 | | this.view = view; |
| 16 | 79 | | view.OnClosePressed += OnClose; |
| 16 | 80 | | view.OnBackPressed += OnBack; |
| 16 | 81 | | view.OnGuestConnectWallet += ConnectGuestWallet; |
| 16 | 82 | | } |
| | 83 | |
|
| 0 | 84 | | private void ConnectGuestWallet() { WebInterface.OpenURL(BIWSettings.GUEST_WALLET_INFO); } |
| | 85 | |
|
| | 86 | | private void OnBack() |
| | 87 | | { |
| 0 | 88 | | if (newProjectFlowController.IsActive()) |
| 0 | 89 | | newProjectFlowController.Hide(); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | public void Dispose() |
| | 93 | | { |
| 16 | 94 | | StopFetchInterval(); |
| | 95 | |
|
| 16 | 96 | | context.publisher.OnPublishFinish -= PublishFinish; |
| | 97 | |
|
| 16 | 98 | | sectionsController.OnRequestOpenUrl -= OpenUrl; |
| 16 | 99 | | sectionsController.OnRequestGoToCoords -= GoToCoords; |
| 16 | 100 | | sectionsController.OnRequestEditSceneAtCoords -= OnGoToEditScene; |
| 16 | 101 | | sectionsController.OnCreateProjectRequest -= newProjectFlowController.NewProject; |
| 16 | 102 | | sectionsController.OnSectionContentEmpty -= SectionContentEmpty; |
| 16 | 103 | | sectionsController.OnSectionContentNotEmpty -= SectionContentNotEmpty; |
| | 104 | |
|
| 16 | 105 | | scenesViewController.OnJumpInPressed -= GoToCoords; |
| 16 | 106 | | scenesViewController.OnRequestOpenUrl -= OpenUrl; |
| 16 | 107 | | scenesViewController.OnEditorPressed -= OnGoToEditScene; |
| 16 | 108 | | projectsController.OnEditorPressed -= GetManifestToEdit; |
| 16 | 109 | | projectsController.OnDeleteProject -= DeleteProject; |
| 16 | 110 | | projectsController.OnDuplicateProject -= DuplicateProject; |
| 16 | 111 | | projectsController.OnPublishProject -= PublishProject; |
| | 112 | |
|
| 16 | 113 | | newProjectFlowController.OnNewProjectCrated -= CreateNewProject; |
| | 114 | |
|
| 16 | 115 | | view.OnCreateProjectPressed -= newProjectFlowController.NewProject; |
| | 116 | |
|
| 16 | 117 | | DataStore.i.HUDs.builderProjectsPanelVisible.OnChange -= OnVisibilityChanged; |
| 16 | 118 | | DataStore.i.builderInWorld.unpublishSceneResult.OnChange -= OnSceneUnpublished; |
| 16 | 119 | | view.OnClosePressed -= OnClose; |
| 16 | 120 | | view.OnBackPressed -= OnBack; |
| 16 | 121 | | view.OnGuestConnectWallet -= ConnectGuestWallet; |
| | 122 | |
|
| 16 | 123 | | unpublishPopupController?.Dispose(); |
| | 124 | |
|
| 16 | 125 | | fetchLandPromise?.Dispose(); |
| 16 | 126 | | fetchProjectsPromise?.Dispose(); |
| | 127 | |
|
| 16 | 128 | | leftMenuSettingsViewHandler?.Dispose(); |
| 16 | 129 | | sectionsHandler?.Dispose(); |
| 16 | 130 | | sceneContextMenuHandler?.Dispose(); |
| 16 | 131 | | leftMenuHandler?.Dispose(); |
| | 132 | |
|
| 16 | 133 | | sectionsController?.Dispose(); |
| 16 | 134 | | scenesViewController?.Dispose(); |
| | 135 | |
|
| 16 | 136 | | newProjectFlowController?.Dispose(); |
| | 137 | |
|
| 16 | 138 | | configureBuilderInFullscreenMenu.OnChange -= ConfigureBuilderInFullscreenMenuChanged; |
| | 139 | |
|
| 16 | 140 | | view.Dispose(); |
| 16 | 141 | | } |
| | 142 | |
|
| | 143 | | public void Initialize(IContext context) |
| | 144 | | { |
| 0 | 145 | | Initialize(context,new SectionsController(view.GetSectionContainer()), |
| | 146 | | new ScenesViewController(view.GetSceneCardViewPrefab(), view.GetTransform()), |
| | 147 | | new LandsController(), |
| | 148 | | new ProjectsController(view.GetProjectCardView(), view.GetProjectCardViewContextMenu(), view.GetTransform()) |
| | 149 | | new NewProjectFlowController(), |
| | 150 | | Environment.i.platform.serviceProviders.theGraph, |
| | 151 | | Environment.i.platform.serviceProviders.catalyst); |
| 0 | 152 | | } |
| | 153 | |
|
| | 154 | | internal void Initialize(IContext context,ISectionsController sectionsController, |
| | 155 | | IScenesViewController scenesViewController, ILandsController landsesController, IProjectsController projectsCont |
| | 156 | | { |
| 16 | 157 | | if (isInitialized) |
| 0 | 158 | | return; |
| | 159 | |
|
| 16 | 160 | | isInitialized = true; |
| | 161 | |
|
| 16 | 162 | | this.context = context; |
| 16 | 163 | | this.context.publisher.OnPublishFinish += PublishFinish; |
| | 164 | |
|
| 16 | 165 | | this.sectionsController = sectionsController; |
| 16 | 166 | | this.scenesViewController = scenesViewController; |
| 16 | 167 | | this.landsesController = landsesController; |
| 16 | 168 | | this.projectsController = projectsController; |
| | 169 | |
|
| 16 | 170 | | this.newProjectFlowController = newProjectFlowController; |
| | 171 | |
|
| 16 | 172 | | this.theGraph = theGraph; |
| 16 | 173 | | this.catalyst = catalyst; |
| | 174 | |
|
| 16 | 175 | | this.unpublishPopupController = new UnpublishPopupController(context,view.GetUnpublishPopup()); |
| | 176 | |
|
| | 177 | | // set listeners for sections, setup searchbar for section, handle request for opening a new section |
| 16 | 178 | | sectionsHandler = new SectionsHandler(sectionsController, scenesViewController, landsesController, projectsContr |
| | 179 | | // handle if main panel or settings panel should be shown in current section |
| 16 | 180 | | leftMenuHandler = new LeftMenuHandler(view, sectionsController); |
| | 181 | | // handle project scene info on the left menu panel |
| 16 | 182 | | leftMenuSettingsViewHandler = new LeftMenuSettingsViewHandler(view.GetSettingsViewReferences(), scenesViewContro |
| | 183 | | // handle scene's context menu options |
| 16 | 184 | | sceneContextMenuHandler = new SceneContextMenuHandler(view.GetSceneCardViewContextMenu(), sectionsController, sc |
| | 185 | |
|
| 16 | 186 | | this.projectsController.SetSceneContextMenuHandler(sceneContextMenuHandler); |
| | 187 | |
|
| 16 | 188 | | SetView(); |
| | 189 | |
|
| 16 | 190 | | sectionsController.OnRequestOpenUrl += OpenUrl; |
| 16 | 191 | | sectionsController.OnRequestGoToCoords += GoToCoords; |
| 16 | 192 | | sectionsController.OnRequestEditSceneAtCoords += OnGoToEditScene; |
| 16 | 193 | | sectionsController.OnCreateProjectRequest += newProjectFlowController.NewProject; |
| 16 | 194 | | sectionsController.OnSectionContentEmpty += SectionContentEmpty; |
| 16 | 195 | | sectionsController.OnSectionContentNotEmpty += SectionContentNotEmpty; |
| | 196 | |
|
| 16 | 197 | | scenesViewController.OnJumpInPressed += GoToCoords; |
| 16 | 198 | | scenesViewController.OnRequestOpenUrl += OpenUrl; |
| 16 | 199 | | scenesViewController.OnEditorPressed += OnGoToEditScene; |
| 16 | 200 | | newProjectFlowController.OnNewProjectCrated += CreateNewProject; |
| | 201 | |
|
| 16 | 202 | | view.OnCreateProjectPressed += this.newProjectFlowController.NewProject; |
| 16 | 203 | | this.projectsController.OnEditorPressed += GetManifestToEdit; |
| 16 | 204 | | this.projectsController.OnDeleteProject += DeleteProject; |
| 16 | 205 | | this.projectsController.OnDuplicateProject += DuplicateProject; |
| 16 | 206 | | this.projectsController.OnPublishProject += PublishProject; |
| | 207 | |
|
| 16 | 208 | | DataStore.i.HUDs.builderProjectsPanelVisible.OnChange += OnVisibilityChanged; |
| 16 | 209 | | DataStore.i.builderInWorld.unpublishSceneResult.OnChange += OnSceneUnpublished; |
| 16 | 210 | | } |
| | 211 | |
|
| 0 | 212 | | private void SectionContentNotEmpty() { view.SetSearchViewVisible(true); } |
| | 213 | |
|
| 0 | 214 | | private void SectionContentEmpty() { view.SetSearchViewVisible(false); } |
| | 215 | |
|
| | 216 | | private void DuplicateProject(ProjectData data) |
| | 217 | | { |
| 0 | 218 | | Promise<Manifest> manifestPromise = context.builderAPIController.GetManifestById(data.id); |
| 0 | 219 | | manifestPromise.Then( (manifest) => |
| | 220 | | { |
| 0 | 221 | | DuplicateProject(data, manifest); |
| 0 | 222 | | }); |
| | 223 | |
|
| 0 | 224 | | manifestPromise.Catch( errorString => |
| | 225 | | { |
| 0 | 226 | | BIWUtils.ShowGenericNotification(DUPLICATE_PROJECT_ERROR + errorString); |
| 0 | 227 | | }); |
| | 228 | |
|
| 0 | 229 | | } |
| | 230 | |
|
| | 231 | | private async void DuplicateProject(ProjectData data, Manifest manifest) |
| | 232 | | { |
| 0 | 233 | | string url = BIWUrlUtils.GetBuilderProjecThumbnailUrl(data.id, data.thumbnail); |
| 0 | 234 | | Promise<Texture2D> screenshotPromise = new Promise<Texture2D>(); |
| 0 | 235 | | BIWUtils.MakeGetTextureCall(url, screenshotPromise); |
| | 236 | |
|
| 0 | 237 | | string scene_id = Guid.NewGuid().ToString(); |
| 0 | 238 | | manifest.project.title += " Copy"; |
| 0 | 239 | | manifest.project.id = Guid.NewGuid().ToString(); |
| 0 | 240 | | manifest.project.scene_id = scene_id; |
| 0 | 241 | | manifest.scene.id = scene_id; |
| 0 | 242 | | manifest.project.created_at = DateTime.UtcNow; |
| 0 | 243 | | manifest.project.updated_at = DateTime.UtcNow; |
| | 244 | |
|
| 0 | 245 | | screenshotPromise.Then(texture => |
| | 246 | | { |
| 0 | 247 | | context.builderAPIController.SetThumbnail(manifest.project.id, texture); |
| 0 | 248 | | }); |
| | 249 | |
|
| 0 | 250 | | Promise<bool> createPromise = context.builderAPIController.SetManifest(manifest); |
| 0 | 251 | | createPromise.Then(isOk => |
| | 252 | | { |
| 0 | 253 | | if (!isOk) |
| 0 | 254 | | BIWUtils.ShowGenericNotification(DUPLICATE_PROJECT_ERROR); |
| 0 | 255 | | }); |
| 0 | 256 | | createPromise.Catch(error => |
| | 257 | | { |
| 0 | 258 | | BIWUtils.ShowGenericNotification(DUPLICATE_PROJECT_ERROR + error); |
| 0 | 259 | | }); |
| | 260 | |
|
| 0 | 261 | | await createPromise; |
| 0 | 262 | | await screenshotPromise; |
| | 263 | |
|
| | 264 | | // We need to wait a bit before refreshing the projects so the server is able to process the data |
| 0 | 265 | | CoroutineStarter.Start(WaitASecondAndRefreshProjects()); |
| | 266 | |
|
| 0 | 267 | | BIWAnalytics.ProjectDuplicated(data.id, new Vector2Int(data.rows,data.cols)); |
| 0 | 268 | | } |
| | 269 | |
|
| | 270 | | private async void PublishProject(ProjectData data) |
| | 271 | | { |
| 0 | 272 | | Promise<Manifest> manifestPromise = context.builderAPIController.GetManifestById(data.id); |
| 0 | 273 | | manifestPromise.Then( (manifest) => |
| | 274 | | { |
| 0 | 275 | | manifest.project = data; |
| 0 | 276 | | PublishProject(manifest); |
| 0 | 277 | | }); |
| | 278 | |
|
| 0 | 279 | | manifestPromise.Catch( errorString => |
| | 280 | | { |
| 0 | 281 | | BIWUtils.ShowGenericNotification(PUBLISH_PROJECT_ERROR + errorString); |
| 0 | 282 | | }); |
| 0 | 283 | | } |
| | 284 | |
|
| | 285 | | private async void PublishProject(Manifest manifest) |
| | 286 | | { |
| 0 | 287 | | string url = BIWUrlUtils.GetBuilderProjecThumbnailUrl(manifest.project.id, manifest.project.thumbnail); |
| 0 | 288 | | Promise<Texture2D> screenshotPromise = new Promise<Texture2D>(); |
| 0 | 289 | | BIWUtils.MakeGetTextureCall(url, screenshotPromise); |
| | 290 | |
|
| 0 | 291 | | IBuilderScene builderScene = new BuilderScene(manifest, IBuilderScene.SceneType.PROJECT); |
| 0 | 292 | | builderScene.SetScene(ManifestTranslator.ManifestToParcelSceneWithOnlyData(manifest)); |
| 0 | 293 | | screenshotPromise.Then((texture2D => builderScene.sceneScreenshotTexture = texture2D)); |
| 0 | 294 | | await screenshotPromise; |
| 0 | 295 | | context.publisher.StartPublish(builderScene); |
| 0 | 296 | | } |
| | 297 | |
|
| | 298 | | private void DeleteProject(ProjectData data) |
| | 299 | | { |
| 0 | 300 | | string deleteText = DELETE_PROJECT_CONFIRM_TEXT.Replace("{0}", data.title); |
| | 301 | |
|
| 0 | 302 | | context.commonHUD.GetPopUp() |
| | 303 | | .ShowPopUpWithoutTitle(deleteText, "YES", "NO", () => |
| | 304 | | { |
| 0 | 305 | | Promise<bool> manifestPromise = context.builderAPIController.DeleteProject(data.id); |
| 0 | 306 | | manifestPromise.Then( (isOk) => |
| | 307 | | { |
| 0 | 308 | | if (isOk) |
| | 309 | | { |
| 0 | 310 | | string text = DELETE_PROJECT_SUCCESS.Replace("{0}", data.title); |
| 0 | 311 | | view.ShowToast(text); |
| 0 | 312 | | FetchProjectData(); |
| | 313 | | } |
| 0 | 314 | | }); |
| | 315 | |
|
| 0 | 316 | | manifestPromise.Catch( errorString => |
| | 317 | | { |
| 0 | 318 | | BIWUtils.ShowGenericNotification(DELETE_PROJECT_ERROR + errorString); |
| 0 | 319 | | }); |
| | 320 | |
|
| 0 | 321 | | BIWAnalytics.ProjectDeleted(data.id, new Vector2Int(data.rows,data.cols)); |
| 0 | 322 | | }, null); |
| 0 | 323 | | } |
| | 324 | |
|
| | 325 | | private void GetManifestToEdit(ProjectData data) |
| | 326 | | { |
| 0 | 327 | | Promise<Manifest> manifestPromise = context.builderAPIController.GetManifestById(data.id); |
| 0 | 328 | | manifestPromise.Then( OpenEditorFromManifest); |
| | 329 | |
|
| 0 | 330 | | manifestPromise.Catch( errorString => |
| | 331 | | { |
| 0 | 332 | | BIWUtils.ShowGenericNotification(OBTAIN_PROJECT_ERROR + errorString); |
| 0 | 333 | | }); |
| 0 | 334 | | } |
| | 335 | |
|
| | 336 | | private void CreateNewProject(ProjectData project) |
| | 337 | | { |
| 0 | 338 | | context.sceneManager.ShowBuilderLoading(); |
| 0 | 339 | | Promise<ProjectData> projectPromise = context.builderAPIController.CreateNewProject(project); |
| | 340 | |
|
| 0 | 341 | | projectPromise.Then( OpenEditorFromNewProject); |
| | 342 | |
|
| 0 | 343 | | projectPromise.Catch( errorString => |
| | 344 | | { |
| 0 | 345 | | context.sceneManager.HideBuilderLoading(); |
| 0 | 346 | | BIWUtils.ShowGenericNotification(CREATING_PROJECT_ERROR + errorString); |
| 0 | 347 | | }); |
| | 348 | |
|
| 0 | 349 | | BIWAnalytics.CreatedNewProject(project.title, project.description, new Vector2Int(project.rows,project.cols)); |
| 0 | 350 | | } |
| | 351 | |
|
| | 352 | | private void OpenEditorFromNewProject(ProjectData projectData) |
| | 353 | | { |
| 0 | 354 | | var manifest = BIWUtils.CreateManifestFromProject(projectData); |
| 0 | 355 | | DataStore.i.builderInWorld.lastProjectIdCreated.Set(manifest.project.id); |
| 0 | 356 | | OpenEditorFromManifest(manifest); |
| 0 | 357 | | } |
| | 358 | |
|
| 0 | 359 | | private void OpenEditorFromManifest(Manifest manifest) { context.sceneManager.StartFlowFromProject(manifest); } |
| | 360 | |
|
| | 361 | | public void SetVisibility(bool visible) |
| | 362 | | { |
| | 363 | | // Note: we set it here since the profile is not ready at the initialization part |
| 6 | 364 | | view.SetGuestMode(UserProfile.GetOwnUserProfile().isGuest); |
| 6 | 365 | | DataStore.i.HUDs.builderProjectsPanelVisible.Set(visible); |
| 6 | 366 | | } |
| | 367 | |
|
| | 368 | | private void OnVisibilityChanged(bool isVisible, bool prev) |
| | 369 | | { |
| 7 | 370 | | if (isVisible == prev) |
| 0 | 371 | | return; |
| | 372 | |
|
| 7 | 373 | | view.SetVisible(isVisible); |
| | 374 | |
|
| | 375 | | // Note: we set it here since the profile is not ready at the initialization part |
| 7 | 376 | | view.SetGuestMode(UserProfile.GetOwnUserProfile().isGuest); |
| | 377 | |
|
| 7 | 378 | | if (isVisible) |
| | 379 | | { |
| 4 | 380 | | if (DataStore.i.builderInWorld.landsWithAccess.Get() != null) |
| 4 | 381 | | PanelOpenEvent(DataStore.i.builderInWorld.landsWithAccess.Get()); |
| | 382 | | else |
| 0 | 383 | | sendPlayerOpenPanelEvent = true; |
| | 384 | |
|
| 4 | 385 | | sectionsController.OpenSection(SectionId.PROJECTS); |
| | 386 | |
|
| 4 | 387 | | FetchPanelInfo(); |
| 4 | 388 | | StartFetchInterval(); |
| 4 | 389 | | } |
| | 390 | | else |
| | 391 | | { |
| 3 | 392 | | StopFetchInterval(); |
| | 393 | | } |
| 3 | 394 | | } |
| | 395 | |
|
| | 396 | | private void OnClose() |
| | 397 | | { |
| 1 | 398 | | if (!view.IsVisible()) |
| 0 | 399 | | return; |
| | 400 | |
|
| 1 | 401 | | SetVisibility(false); |
| | 402 | |
|
| 1 | 403 | | LandWithAccess[] lands = landsesController.GetLands(); |
| 1 | 404 | | if (lands != null) |
| | 405 | | { |
| 1 | 406 | | Vector2Int totalLands = GetAmountOfLandsOwnedAndOperator(lands); |
| 1 | 407 | | BIWAnalytics.PlayerClosesPanel(totalLands.x, totalLands.y); |
| | 408 | | } |
| 1 | 409 | | } |
| | 410 | |
|
| | 411 | | private void PanelOpenEvent(LandWithAccess[] lands) |
| | 412 | | { |
| 4 | 413 | | Vector2Int totalLands = GetAmountOfLandsOwnedAndOperator(lands); |
| 4 | 414 | | BIWAnalytics.PlayerOpenPanel(totalLands.x, totalLands.y); |
| 4 | 415 | | } |
| | 416 | |
|
| | 417 | | /// <summary> |
| | 418 | | /// This counts the amount of lands that the user own and the amount of lands that the user operate |
| | 419 | | /// </summary> |
| | 420 | | /// <param name="lands"></param> |
| | 421 | | /// <returns>Vector2: X = amount of owned lands, Y = amount of operator lands</returns> |
| | 422 | | private Vector2Int GetAmountOfLandsOwnedAndOperator(LandWithAccess[] lands) |
| | 423 | | { |
| 5 | 424 | | int ownedLandsCount = 0; |
| 5 | 425 | | int operatorLandsCount = 0; |
| 18 | 426 | | foreach (var land in lands) |
| | 427 | | { |
| 4 | 428 | | if (land.role == LandRole.OWNER) |
| 4 | 429 | | ownedLandsCount++; |
| | 430 | | else |
| 0 | 431 | | operatorLandsCount++; |
| | 432 | | } |
| | 433 | |
|
| 5 | 434 | | return new Vector2Int(ownedLandsCount, operatorLandsCount); |
| | 435 | | } |
| | 436 | |
|
| | 437 | | private void SetView() |
| | 438 | | { |
| 16 | 439 | | scenesViewController.AddListener((ISceneListener) view); |
| 16 | 440 | | projectsController.AddListener((IProjectsListener) view); |
| 16 | 441 | | } |
| | 442 | |
|
| | 443 | | private void PublishFinish(bool isOk) |
| | 444 | | { |
| 0 | 445 | | if(isOk) |
| 0 | 446 | | FetchPanelInfo(0,0); |
| 0 | 447 | | } |
| | 448 | |
|
| 4 | 449 | | private void FetchPanelInfo() => FetchPanelInfo(CACHE_TIME_LAND, CACHE_TIME_SCENES); |
| | 450 | |
|
| | 451 | | private void FetchPanelInfo(float landCacheTime, float scenesCacheTime) |
| | 452 | | { |
| 4 | 453 | | if (isFetchingLands || isFetchingProjects) |
| 0 | 454 | | return; |
| | 455 | |
|
| 4 | 456 | | isFetchingLands = true; |
| 4 | 457 | | isFetchingProjects = true; |
| | 458 | |
|
| 4 | 459 | | var address = UserProfile.GetOwnUserProfile().ethAddress; |
| 4 | 460 | | var network = KernelConfig.i.Get().network; |
| | 461 | |
|
| | 462 | | #if UNITY_EDITOR |
| | 463 | | // NOTE: to be able to test in editor without getting a profile we hardcode an address here |
| 4 | 464 | | if (string.IsNullOrEmpty(address)) |
| | 465 | | { |
| 0 | 466 | | address = TESTING_ETH_ADDRESS; |
| 0 | 467 | | network = TESTING_TLD; |
| 0 | 468 | | DataStore.i.realm.playerRealm.Set(new CurrentRealmModel() |
| | 469 | | { |
| | 470 | | domain = $"https://peer.decentraland.{TESTING_TLD}", |
| | 471 | | contentServerUrl = $"https://peer.decentraland.{TESTING_TLD}/content", |
| | 472 | | }); |
| | 473 | | } |
| | 474 | | #endif |
| | 475 | |
|
| 4 | 476 | | sectionsController.SetFetchingDataStart(); |
| | 477 | |
|
| 4 | 478 | | fetchLandPromise = DeployedScenesFetcher.FetchLandsFromOwner(catalyst, theGraph, address, network, landCacheTime |
| 4 | 479 | | fetchLandPromise |
| | 480 | | .Then(LandsFetched) |
| | 481 | | .Catch(LandsFetchedError); |
| | 482 | |
|
| 4 | 483 | | FetchProjectData(); |
| 4 | 484 | | } |
| | 485 | |
|
| | 486 | | internal void FetchProjectData() |
| | 487 | | { |
| 4 | 488 | | sectionsController.SetFetchingDataStart<SectionProjectController>(); |
| 4 | 489 | | fetchProjectsPromise = BuilderPanelDataFetcher.FetchProjectData(context.builderAPIController); |
| 4 | 490 | | fetchProjectsPromise |
| | 491 | | .Then(ProjectsFetched) |
| | 492 | | .Catch(ProjectsFetchedError); |
| 4 | 493 | | } |
| | 494 | |
|
| | 495 | | internal void ProjectsFetched(ProjectData[] data) |
| | 496 | | { |
| 1 | 497 | | DataStore.i.builderInWorld.projectData.Set(data); |
| 1 | 498 | | isFetchingProjects = false; |
| 1 | 499 | | sectionsController.SetFetchingDataEnd<SectionProjectController>(); |
| 1 | 500 | | projectsController.SetProjects(data); |
| 1 | 501 | | UpdateProjectsDeploymentStatus(); |
| 1 | 502 | | } |
| | 503 | |
|
| | 504 | | internal void ProjectsFetchedError(string error) |
| | 505 | | { |
| 1 | 506 | | isFetchingProjects = false; |
| 1 | 507 | | sectionsController.SetFetchingDataEnd<SectionProjectController>(); |
| 1 | 508 | | projectsController.SetProjects(new ProjectData[] { }); |
| 1 | 509 | | BIWUtils.ShowGenericNotification(error); |
| 1 | 510 | | } |
| | 511 | |
|
| | 512 | | private void UpdateProjectsDeploymentStatus() |
| | 513 | | { |
| 2 | 514 | | if (isFetchingLands || isFetchingProjects) |
| 0 | 515 | | return; |
| | 516 | |
|
| 2 | 517 | | projectsController.UpdateDeploymentStatus(); |
| 2 | 518 | | } |
| | 519 | |
|
| | 520 | | internal void LandsFetchedError(string error) |
| | 521 | | { |
| 1 | 522 | | isFetchingLands = false; |
| 1 | 523 | | sectionsController.SetFetchingDataEnd<SectionLandController>(); |
| 1 | 524 | | sectionsController.SetFetchingDataEnd<SectionScenesController>(); |
| 1 | 525 | | landsesController.SetLands(new LandWithAccess[] { }); |
| 1 | 526 | | scenesViewController.SetScenes(new ISceneData[] { }); |
| 1 | 527 | | Debug.LogError(error); |
| 1 | 528 | | } |
| | 529 | |
|
| | 530 | | internal void LandsFetched(LandWithAccess[] lands) |
| | 531 | | { |
| 1 | 532 | | DataStore.i.builderInWorld.landsWithAccess.Set(lands.ToArray(), true); |
| 1 | 533 | | sectionsController.SetFetchingDataEnd<SectionLandController>(); |
| 1 | 534 | | sectionsController.SetFetchingDataEnd<SectionScenesController>(); |
| 1 | 535 | | isFetchingLands = false; |
| 1 | 536 | | UpdateProjectsDeploymentStatus(); |
| | 537 | |
|
| | 538 | | try |
| | 539 | | { |
| 1 | 540 | | ISceneData[] places = { }; |
| | 541 | |
|
| 1 | 542 | | if(lands.Length > 0) |
| 2 | 543 | | places = lands.Where(land => land.scenes != null && land.scenes.Count > 0) |
| 2 | 544 | | .Select(land => land.scenes.Where(scene => !scene.isEmpty).Select(scene => (IScen |
| 0 | 545 | | .Aggregate((i, j) => i.Concat(j)) |
| | 546 | | .ToArray(); |
| | 547 | |
|
| 0 | 548 | | if (sendPlayerOpenPanelEvent) |
| 0 | 549 | | PanelOpenEvent(lands); |
| | 550 | |
|
| 0 | 551 | | landsesController.SetLands(lands); |
| 0 | 552 | | scenesViewController.SetScenes(places); |
| 0 | 553 | | } |
| 1 | 554 | | catch (Exception e) |
| | 555 | | { |
| 1 | 556 | | Debug.Log("Error setting the lands and scenes "+ e); |
| 1 | 557 | | landsesController.SetLands(lands); |
| 1 | 558 | | scenesViewController.SetScenes(new ISceneData[] { }); |
| 1 | 559 | | } |
| 1 | 560 | | } |
| | 561 | |
|
| | 562 | | internal void GoToCoords(Vector2Int coords) |
| | 563 | | { |
| 1 | 564 | | WebInterface.GoTo(coords.x, coords.y); |
| 1 | 565 | | SetVisibility(false); |
| 1 | 566 | | OnJumpInOrEdit?.Invoke(); |
| 1 | 567 | | } |
| | 568 | |
|
| 0 | 569 | | private void OpenUrl(string url) { WebInterface.OpenURL(url); } |
| | 570 | |
|
| | 571 | | internal void OnGoToEditScene(Vector2Int coords) |
| | 572 | | { |
| 0 | 573 | | SetVisibility(false); |
| 0 | 574 | | context.sceneManager.StartFlowFromLandCoords(coords); |
| 0 | 575 | | } |
| | 576 | |
|
| | 577 | | private void StartFetchInterval() |
| | 578 | | { |
| 4 | 579 | | if (fetchDataInterval != null) |
| | 580 | | { |
| 0 | 581 | | StopFetchInterval(); |
| | 582 | | } |
| | 583 | |
|
| 4 | 584 | | fetchDataInterval = CoroutineStarter.Start(RefreshDataInterval()); |
| 4 | 585 | | } |
| | 586 | |
|
| | 587 | | private void StopFetchInterval() |
| | 588 | | { |
| 19 | 589 | | CoroutineStarter.Stop(fetchDataInterval); |
| 19 | 590 | | fetchDataInterval = null; |
| 19 | 591 | | } |
| | 592 | |
|
| | 593 | | IEnumerator RefreshDataInterval() |
| | 594 | | { |
| 0 | 595 | | while (true) |
| | 596 | | { |
| 4 | 597 | | yield return WaitForSecondsCache.Get(REFRESH_INTERVAL); |
| 0 | 598 | | FetchPanelInfo(); |
| | 599 | | } |
| | 600 | | } |
| | 601 | |
|
| | 602 | | IEnumerator WaitASecondAndRefreshProjects() |
| | 603 | | { |
| 0 | 604 | | yield return new WaitForSeconds(1f); |
| 0 | 605 | | FetchProjectData(); |
| 0 | 606 | | } |
| | 607 | |
|
| | 608 | | private void OnSceneUnpublished(PublishSceneResultPayload current, PublishSceneResultPayload previous) |
| | 609 | | { |
| 0 | 610 | | if (current.ok) |
| | 611 | | { |
| 0 | 612 | | FetchPanelInfo(CACHE_TIME_LAND, 0); |
| | 613 | | } |
| 0 | 614 | | } |
| | 615 | |
|
| 32 | 616 | | private void ConfigureBuilderInFullscreenMenuChanged(Transform currentParentTransform, Transform previousParentTrans |
| | 617 | | } |