| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | namespace DCL.Builder |
| | 8 | | { |
| | 9 | | [Serializable] |
| | 10 | | internal class LeftMenuSettingsViewReferences |
| | 11 | | { |
| | 12 | | public TextMeshProUGUI titleLabel; |
| | 13 | | public RawImageFillParent thumbnail; |
| | 14 | | public GameObject coordsContainer; |
| | 15 | | public GameObject sizeContainer; |
| | 16 | | public GameObject entitiesCountContainer; |
| | 17 | | public TextMeshProUGUI coordsText; |
| | 18 | | public TextMeshProUGUI sizeText; |
| | 19 | | public TextMeshProUGUI entitiesCountText; |
| | 20 | | public GameObject avatarThumbnailContainer; |
| | 21 | | public RawImage avatarImage; |
| | 22 | | public TextMeshProUGUI authorNameText; |
| | 23 | | public LeftMenuButtonToggleView adminsMenuToggle; |
| | 24 | | } |
| | 25 | |
|
| | 26 | | internal class LeftMenuSettingsViewHandler : IDisposable |
| | 27 | | { |
| | 28 | | internal const string PROJECT_TITLE = "Project settings"; |
| | 29 | | internal const string SCENE_TITLE = "Scene settings"; |
| | 30 | |
|
| | 31 | | private readonly LeftMenuSettingsViewReferences viewReferences; |
| | 32 | | private readonly IScenesViewController scenesViewController; |
| | 33 | | private readonly Texture defaultThumbnail; |
| | 34 | |
|
| | 35 | | private AssetPromise_Texture promiseAvatarThumbnail; |
| | 36 | | private AssetPromise_Texture promiseSceneThumbnail; |
| | 37 | |
|
| 17 | 38 | | public LeftMenuSettingsViewHandler(LeftMenuSettingsViewReferences viewReferences, IScenesViewController scenesVi |
| | 39 | | { |
| 17 | 40 | | this.viewReferences = viewReferences; |
| 17 | 41 | | this.scenesViewController = scenesViewController; |
| | 42 | |
|
| 17 | 43 | | defaultThumbnail = viewReferences.thumbnail.texture; |
| | 44 | |
|
| 17 | 45 | | scenesViewController.OnProjectSelected += SelectProject; |
| 17 | 46 | | } |
| | 47 | |
|
| | 48 | | public void Dispose() |
| | 49 | | { |
| 17 | 50 | | scenesViewController.OnProjectSelected -= SelectProject; |
| | 51 | |
|
| 17 | 52 | | if (promiseAvatarThumbnail != null) |
| | 53 | | { |
| 0 | 54 | | AssetPromiseKeeper_Texture.i.Forget(promiseAvatarThumbnail); |
| | 55 | | } |
| 17 | 56 | | if (promiseSceneThumbnail != null) |
| | 57 | | { |
| 0 | 58 | | AssetPromiseKeeper_Texture.i.Forget(promiseSceneThumbnail); |
| | 59 | | } |
| | 60 | |
|
| 17 | 61 | | promiseAvatarThumbnail = null; |
| 17 | 62 | | promiseSceneThumbnail = null; |
| 17 | 63 | | } |
| | 64 | |
|
| | 65 | | void SetProjectData(ISceneData sceneData) |
| | 66 | | { |
| 2 | 67 | | viewReferences.titleLabel.text = sceneData.isDeployed ? SCENE_TITLE : PROJECT_TITLE; |
| 2 | 68 | | viewReferences.coordsContainer.SetActive(sceneData.isDeployed); |
| 2 | 69 | | viewReferences.sizeContainer.SetActive(!sceneData.isDeployed); |
| 2 | 70 | | viewReferences.entitiesCountContainer.SetActive(!sceneData.isDeployed); |
| 2 | 71 | | viewReferences.coordsText.text = $"{sceneData.coords.x},{sceneData.coords.y}"; |
| 2 | 72 | | viewReferences.sizeText.text = $"{sceneData.size.x},{sceneData.size.y}m"; |
| 2 | 73 | | viewReferences.entitiesCountText.text = sceneData.entitiesCount.ToString(); |
| 2 | 74 | | viewReferences.authorNameText.text = sceneData.authorName; |
| 2 | 75 | | viewReferences.adminsMenuToggle.gameObject.SetActive(sceneData.isDeployed); |
| | 76 | |
|
| 2 | 77 | | SetThumbnails(sceneData); |
| 2 | 78 | | } |
| | 79 | |
|
| | 80 | | void SetThumbnails(ISceneData sceneData) |
| | 81 | | { |
| 2 | 82 | | if (string.IsNullOrEmpty(sceneData.authorThumbnail)) |
| | 83 | | { |
| 2 | 84 | | viewReferences.avatarThumbnailContainer.SetActive(false); |
| 2 | 85 | | } |
| | 86 | | else |
| | 87 | | { |
| 0 | 88 | | if (promiseAvatarThumbnail != null) |
| | 89 | | { |
| 0 | 90 | | AssetPromiseKeeper_Texture.i.Forget(promiseAvatarThumbnail); |
| | 91 | | } |
| | 92 | |
|
| 0 | 93 | | promiseAvatarThumbnail = new AssetPromise_Texture(sceneData.authorThumbnail); |
| 0 | 94 | | promiseAvatarThumbnail.OnFailEvent += (asset, error) => viewReferences.avatarThumbnailContainer.SetActiv |
| 0 | 95 | | promiseAvatarThumbnail.OnSuccessEvent += asset => |
| | 96 | | { |
| 0 | 97 | | viewReferences.avatarThumbnailContainer.SetActive(true); |
| 0 | 98 | | viewReferences.avatarImage.texture = asset.texture; |
| 0 | 99 | | }; |
| 0 | 100 | | AssetPromiseKeeper_Texture.i.Keep(promiseAvatarThumbnail); |
| | 101 | | } |
| | 102 | |
|
| 2 | 103 | | if (string.IsNullOrEmpty(sceneData.thumbnailUrl)) |
| | 104 | | { |
| 2 | 105 | | viewReferences.thumbnail.texture = defaultThumbnail; |
| 2 | 106 | | } |
| | 107 | | else |
| | 108 | | { |
| 0 | 109 | | if (promiseSceneThumbnail != null) |
| | 110 | | { |
| 0 | 111 | | AssetPromiseKeeper_Texture.i.Forget(promiseSceneThumbnail); |
| | 112 | | } |
| | 113 | |
|
| 0 | 114 | | promiseSceneThumbnail = new AssetPromise_Texture(sceneData.thumbnailUrl); |
| 0 | 115 | | promiseSceneThumbnail.OnFailEvent += (asset, error) => viewReferences.thumbnail.texture = defaultThumbna |
| 0 | 116 | | promiseSceneThumbnail.OnSuccessEvent += asset => |
| | 117 | | { |
| 0 | 118 | | viewReferences.thumbnail.texture = asset.texture; |
| 0 | 119 | | }; |
| 0 | 120 | | AssetPromiseKeeper_Texture.i.Keep(promiseSceneThumbnail); |
| | 121 | | } |
| 0 | 122 | | } |
| | 123 | |
|
| 4 | 124 | | private void SelectProject(ISceneCardView sceneCardView) { SetProjectData(sceneCardView.SceneData); } |
| | 125 | | } |
| | 126 | | } |