| | 1 | | using DCL; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | |
|
| | 11 | | public class PlaceCardComponentView : BaseComponentView, IPlaceCardComponentView, IComponentModelConfig<PlaceCardCompone |
| | 12 | | { |
| | 13 | | internal const int THMBL_MARKETPLACE_WIDTH = 196; |
| | 14 | | internal const int THMBL_MARKETPLACE_HEIGHT = 143; |
| | 15 | | internal const int THMBL_MARKETPLACE_SIZEFACTOR = 50; |
| | 16 | | private const string NO_DESCRIPTION_TEXT = "No description."; |
| | 17 | | private const string PLACE_CATEGORIES_POOL_NAME = "PlaceCardModal_CategoriesPool"; |
| | 18 | | private const int PLACE_CATEGORIES_POOL_PREWARM = 5; |
| | 19 | |
|
| | 20 | | [Header("Assets References")] |
| | 21 | | [SerializeField] internal FriendHeadForPlaceCardComponentView friendHeadPrefab; |
| | 22 | | [SerializeField] internal UserProfile ownUserProfile; |
| | 23 | | [SerializeField] internal PlaceCategoryButton placeCategoryLabelPrefab; |
| | 24 | |
|
| | 25 | | [Header("Prefab References")] |
| | 26 | | [SerializeField] internal GameObject poiMark; |
| | 27 | | [SerializeField] internal ImageComponentView placeImage; |
| | 28 | | [SerializeField] internal TMP_Text placeNameOnIdleText; |
| | 29 | | [SerializeField] internal TMP_Text placeNameOnFocusText; |
| | 30 | | [SerializeField] internal TMP_Text placeDescText; |
| | 31 | | [SerializeField] internal TMP_Text placeAuthorOnIdleText; |
| | 32 | | [SerializeField] internal TMP_Text placeAuthorOnFocusText; |
| | 33 | | [SerializeField] internal RectTransform userVisitsAndRatingContainer; |
| | 34 | | [SerializeField] internal TMP_Text userVisitsText; |
| | 35 | | [SerializeField] internal TMP_Text userRatingText; |
| | 36 | | [SerializeField] internal RectTransform numberOfUsersContainer; |
| | 37 | | [SerializeField] internal TMP_Text numberOfUsersText; |
| | 38 | | [SerializeField] internal TMP_Text coordsText; |
| | 39 | | [SerializeField] internal Button modalBackgroundButton; |
| | 40 | | [SerializeField] internal ButtonComponentView closeCardButton; |
| | 41 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 42 | | [SerializeField] internal ButtonComponentView backgroundButton; |
| | 43 | | [SerializeField] internal ButtonComponentView infoButton; |
| | 44 | | [SerializeField] internal ButtonComponentView upvoteButton; |
| | 45 | | [SerializeField] internal ButtonComponentView downvoteButton; |
| | 46 | | [SerializeField] internal Button shareButton; |
| | 47 | | [SerializeField] internal GameObject upvoteOff; |
| | 48 | | [SerializeField] internal GameObject upvoteOn; |
| | 49 | | [SerializeField] internal GameObject downvoteOff; |
| | 50 | | [SerializeField] internal GameObject downvoteOn; |
| | 51 | | [SerializeField] internal TMP_Text totalVotesText; |
| | 52 | | [SerializeField] internal ButtonComponentView jumpinButton; |
| | 53 | | [SerializeField] internal GridContainerComponentView friendsGrid; |
| | 54 | | [SerializeField] internal GameObject imageContainer; |
| | 55 | | [SerializeField] internal GameObject placeInfoContainer; |
| | 56 | | [SerializeField] internal GameObject loadingSpinner; |
| | 57 | | [SerializeField] internal GameObject cardSelectionFrame; |
| | 58 | | [SerializeField] internal VerticalLayoutGroup contentVerticalLayout; |
| | 59 | | [SerializeField] internal VerticalLayoutGroup infoVerticalLayout; |
| | 60 | | [SerializeField] internal PlaceCardAnimatorBase cardAnimator; |
| | 61 | | [SerializeField] internal FavoriteButtonComponentView favoriteButton; |
| | 62 | | [SerializeField] internal GameObject favoriteButtonContainer; |
| | 63 | | [SerializeField] internal TMP_Text numberOfFavoritesText; |
| | 64 | | [SerializeField] internal TMP_Text updatedAtText; |
| | 65 | | [SerializeField] internal ScrollRect scroll; |
| | 66 | | [SerializeField] internal PlaceCopyContextualMenu placeCopyContextualMenu; |
| | 67 | | [SerializeField] internal TMP_Text ageRatingText; |
| | 68 | | [SerializeField] internal GameObject ageRatingOutline; |
| | 69 | | [SerializeField] internal Transform placeCategoriesGrid; |
| | 70 | | [SerializeField] internal List<GameObject> placeCategoriesGroup; |
| | 71 | |
|
| | 72 | | [Header("Configuration")] |
| | 73 | | [SerializeField] internal Sprite defaultPicture; |
| | 74 | | [SerializeField] internal bool isPlaceCardModal; |
| | 75 | | [SerializeField] internal PlaceCardComponentModel model; |
| | 76 | |
|
| 1534 | 77 | | public IFriendTrackerHandler friendsHandler { get; set; } |
| 188 | 78 | | internal MapInfoHandler mapInfoHandler { get; set; } |
| | 79 | |
|
| 2217 | 80 | | internal readonly Dictionary<string, BaseComponentView> currentFriendHeads = new (); |
| | 81 | |
|
| 119 | 82 | | public Button.ButtonClickedEvent onJumpInClick => jumpinButton != null ? jumpinButton.onClick : new Button.ButtonCli |
| 116 | 83 | | public Button.ButtonClickedEvent onInfoClick => infoButton != null ? infoButton.onClick : new Button.ButtonClickedEv |
| 116 | 84 | | public Button.ButtonClickedEvent onBackgroundClick => backgroundButton != null ? backgroundButton.onClick : new Butt |
| | 85 | |
|
| | 86 | | public event Action<string, bool> OnFavoriteChanged; |
| | 87 | |
|
| | 88 | | private bool thumbnailFromMarketPlaceRequested; |
| 2217 | 89 | | private readonly List<(string id, string nameToShow)> allPlaceCategories = new (); |
| | 90 | | private Pool placeCategoriesPool; |
| | 91 | |
|
| | 92 | | public event Action<string, bool?> OnVoteChanged; |
| | 93 | | public event Action<Vector2Int> OnPressedLinkCopy; |
| | 94 | | public event Action<Vector2Int, string> OnPressedTwitterButton; |
| | 95 | |
|
| | 96 | | public override void Awake() |
| | 97 | | { |
| 1198 | 98 | | base.Awake(); |
| | 99 | |
|
| 1198 | 100 | | if (placeImage != null) |
| 1198 | 101 | | placeImage.OnLoaded += OnPlaceImageLoaded; |
| | 102 | |
|
| 1198 | 103 | | if (cardSelectionFrame != null) |
| 1146 | 104 | | cardSelectionFrame.SetActive(false); |
| | 105 | |
|
| 1198 | 106 | | if (closeCardButton != null) |
| 52 | 107 | | closeCardButton.onClick.AddListener(CloseModal); |
| | 108 | |
|
| 1198 | 109 | | if (closeAction != null) |
| 52 | 110 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| | 111 | |
|
| 1198 | 112 | | if (modalBackgroundButton != null) |
| 52 | 113 | | modalBackgroundButton.onClick.AddListener(CloseModal); |
| | 114 | |
|
| 1198 | 115 | | if(upvoteButton != null) |
| 1198 | 116 | | upvoteButton.onClick.AddListener(() => ChangeVote(true)); |
| | 117 | |
|
| 1198 | 118 | | if(downvoteButton != null) |
| 1198 | 119 | | downvoteButton.onClick.AddListener(() => ChangeVote(false)); |
| | 120 | |
|
| 1198 | 121 | | if(shareButton != null) |
| 1 | 122 | | shareButton.onClick.AddListener(()=>ToggleContextMenu()); |
| | 123 | |
|
| 1198 | 124 | | if (placeCopyContextualMenu != null) |
| 1 | 125 | | placeCopyContextualMenu.OnTwitter += ClickedTwitter; |
| | 126 | |
|
| 1198 | 127 | | if (placeCopyContextualMenu != null) |
| 1 | 128 | | placeCopyContextualMenu.OnPlaceLinkCopied += CopiedLink; |
| | 129 | |
|
| 1198 | 130 | | CleanFriendHeadsItems(); |
| | 131 | |
|
| 1198 | 132 | | if (placeCategoryLabelPrefab != null) |
| 39 | 133 | | placeCategoriesPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(PLACE_CATEGORIES_POOL_NAME, placeCategory |
| 1198 | 134 | | } |
| | 135 | |
|
| | 136 | | private void ToggleContextMenu() |
| | 137 | | { |
| 0 | 138 | | placeCopyContextualMenu.Show(); |
| 0 | 139 | | } |
| | 140 | |
|
| | 141 | | private void CopiedLink() |
| | 142 | | { |
| 0 | 143 | | OnPressedLinkCopy?.Invoke(model.coords); |
| 0 | 144 | | } |
| | 145 | |
|
| | 146 | | private void ClickedTwitter() |
| | 147 | | { |
| 0 | 148 | | OnPressedTwitterButton?.Invoke(model.coords, model.placeInfo.title); |
| 0 | 149 | | } |
| | 150 | |
|
| | 151 | | private void ChangeVote(bool upvote) |
| | 152 | | { |
| 0 | 153 | | if (upvote) |
| | 154 | | { |
| 0 | 155 | | OnVoteChanged?.Invoke(model.placeInfo.id, model.isUpvote ? (bool?)null : true); |
| | 156 | |
|
| 0 | 157 | | if (ownUserProfile != null && ownUserProfile.isGuest) |
| 0 | 158 | | return; |
| | 159 | |
|
| 0 | 160 | | model.isUpvote = !model.isUpvote; |
| 0 | 161 | | model.isDownvote = false; |
| | 162 | | } |
| | 163 | | else |
| | 164 | | { |
| 0 | 165 | | OnVoteChanged?.Invoke(model.placeInfo.id, model.isDownvote ? (bool?)null : false); |
| | 166 | |
|
| 0 | 167 | | if (ownUserProfile != null && ownUserProfile.isGuest) |
| 0 | 168 | | return; |
| | 169 | |
|
| 0 | 170 | | model.isDownvote = !model.isDownvote; |
| 0 | 171 | | model.isUpvote = false; |
| | 172 | | } |
| 0 | 173 | | SetVoteButtons(model.isUpvote, model.isDownvote); |
| 0 | 174 | | } |
| | 175 | |
|
| | 176 | | public void Configure(PlaceCardComponentModel newModel) |
| | 177 | | { |
| 51 | 178 | | model = newModel; |
| | 179 | |
|
| 51 | 180 | | InitializeFriendsTracker(); |
| | 181 | |
|
| 51 | 182 | | if (mapInfoHandler != null) |
| 51 | 183 | | mapInfoHandler.SetMinimapSceneInfo(model.placeInfo); |
| | 184 | |
|
| 51 | 185 | | RefreshControl(); |
| 51 | 186 | | } |
| | 187 | |
|
| | 188 | | public override void RefreshControl() |
| | 189 | | { |
| 59 | 190 | | thumbnailFromMarketPlaceRequested = false; |
| | 191 | |
|
| 59 | 192 | | if (model == null) |
| 0 | 193 | | return; |
| | 194 | |
|
| 59 | 195 | | SetParcels(model.parcels); |
| | 196 | |
|
| 59 | 197 | | if (model.placePictureSprite != null) |
| 51 | 198 | | SetPlacePicture(model.placePictureSprite); |
| 8 | 199 | | else if (model.placePictureTexture != null) |
| 0 | 200 | | SetPlacePicture(model.placePictureTexture); |
| 8 | 201 | | else if (!string.IsNullOrEmpty(model.placePictureUri)) |
| 8 | 202 | | SetPlacePicture(model.placePictureUri); |
| | 203 | | else |
| 0 | 204 | | OnPlaceImageLoaded(null); |
| | 205 | |
|
| 59 | 206 | | SetPlaceName(model.placeName); |
| 59 | 207 | | SetPlaceDescription(model.placeDescription); |
| 59 | 208 | | SetPlaceAuthor(model.placeAuthor); |
| 59 | 209 | | SetUserVisits(model.userVisits); |
| 59 | 210 | | SetUserRating(model.userRating); |
| 59 | 211 | | SetNumberOfUsers(model.numberOfUsers); |
| 59 | 212 | | SetCoords(model.coords); |
| 59 | 213 | | SetFavoriteButton(model.isFavorite, model.placeInfo.id); |
| | 214 | |
|
| | 215 | | //Temporary untill the release of the functionality |
| 59 | 216 | | if (!DataStore.i.HUDs.enableFavoritePlaces.Get()) |
| | 217 | | { |
| 59 | 218 | | if(favoriteButtonContainer != null) |
| 59 | 219 | | favoriteButtonContainer.SetActive(false); |
| | 220 | | } |
| | 221 | |
|
| 59 | 222 | | SetVoteButtons(model.isUpvote, model.isDownvote); |
| 59 | 223 | | SetTotalVotes(model.totalVotes); |
| 59 | 224 | | SetNumberOfFavorites(model.numberOfFavorites); |
| 59 | 225 | | SetDeployedAt(model.deployedAt); |
| 59 | 226 | | SetIsPOI(model.isPOI); |
| 59 | 227 | | SetAgeRating(model.ageRating); |
| 59 | 228 | | SetAppearsOn(model.categories); |
| 59 | 229 | | ResetScrollPosition(); |
| 59 | 230 | | RebuildCardLayouts(); |
| 59 | 231 | | } |
| | 232 | |
|
| | 233 | | public void SetFavoriteButton(bool isFavorite, string placeId) |
| | 234 | | { |
| 59 | 235 | | model.isFavorite = isFavorite; |
| 59 | 236 | | model.placeInfo.id = placeId; |
| | 237 | |
|
| 59 | 238 | | if (favoriteButton == null) |
| 0 | 239 | | return; |
| 59 | 240 | | favoriteButton.gameObject.SetActive(true); |
| 59 | 241 | | favoriteButton.Configure(new FavoriteButtonComponentModel() |
| | 242 | | { |
| | 243 | | isFavorite = isFavorite, |
| | 244 | | placeUUID = placeId |
| | 245 | | }); |
| 59 | 246 | | ShowFavoriteButton(isFavorite); |
| | 247 | |
|
| 59 | 248 | | favoriteButton.OnFavoriteChange -= FavoriteValueChanged; |
| 59 | 249 | | favoriteButton.OnFavoriteChange += FavoriteValueChanged; |
| 59 | 250 | | } |
| | 251 | |
|
| | 252 | | public void SetVoteButtons(bool isUpvoted, bool isDownvoted) |
| | 253 | | { |
| 59 | 254 | | model.isUpvote = isUpvoted; |
| 59 | 255 | | model.isDownvote = isDownvoted; |
| | 256 | |
|
| 59 | 257 | | if(upvoteOn == null || upvoteOff == null || downvoteOn == null || downvoteOff == null) |
| 0 | 258 | | return; |
| | 259 | |
|
| 59 | 260 | | upvoteOn.SetActive(isUpvoted); |
| 59 | 261 | | upvoteOff.SetActive(!isUpvoted); |
| 59 | 262 | | downvoteOn.SetActive(isDownvoted); |
| 59 | 263 | | downvoteOff.SetActive(!isDownvoted); |
| 59 | 264 | | } |
| | 265 | |
|
| | 266 | | public void SetTotalVotes(int totalVotes) |
| | 267 | | { |
| 59 | 268 | | model.totalVotes = totalVotes; |
| | 269 | |
|
| 59 | 270 | | if (totalVotesText == null) |
| 57 | 271 | | return; |
| | 272 | |
|
| 2 | 273 | | totalVotesText.text = $"({totalVotes})"; |
| 2 | 274 | | } |
| | 275 | |
|
| | 276 | | public void SetNumberOfFavorites(int numberOfFavorites) |
| | 277 | | { |
| 59 | 278 | | model.numberOfFavorites = numberOfFavorites; |
| | 279 | |
|
| 59 | 280 | | if (numberOfFavoritesText != null) |
| 2 | 281 | | numberOfFavoritesText.text = FormatNumber(numberOfFavorites); |
| 59 | 282 | | } |
| | 283 | |
|
| | 284 | | public void SetDeployedAt(string updatedAt) |
| | 285 | | { |
| 59 | 286 | | model.deployedAt = updatedAt; |
| | 287 | |
|
| 59 | 288 | | if (updatedAtText == null) |
| 57 | 289 | | return; |
| | 290 | |
|
| 2 | 291 | | updatedAtText.text = DateTime.TryParse(updatedAt, out DateTime updateAtDT) ? |
| | 292 | | updateAtDT.ToString("dd/MM/yyyy") : |
| | 293 | | "-"; |
| 2 | 294 | | } |
| | 295 | |
|
| | 296 | | public void SetIsPOI(bool isPOI) |
| | 297 | | { |
| 107 | 298 | | model.isPOI = isPOI; |
| | 299 | |
|
| 107 | 300 | | if (poiMark == null) |
| 107 | 301 | | return; |
| | 302 | |
|
| 0 | 303 | | poiMark.SetActive(isPOI); |
| 0 | 304 | | } |
| | 305 | |
|
| | 306 | | public void SetActive(bool isActive) |
| | 307 | | { |
| 0 | 308 | | if (isActive) |
| | 309 | | { |
| 0 | 310 | | Show(); |
| | 311 | | } |
| | 312 | | else |
| | 313 | | { |
| 0 | 314 | | Hide(); |
| | 315 | | } |
| 0 | 316 | | } |
| | 317 | |
|
| | 318 | | public void SetAgeRating(SceneContentCategory contentCategory) |
| | 319 | | { |
| 59 | 320 | | model.ageRating = contentCategory; |
| | 321 | |
|
| 59 | 322 | | if (ageRatingText != null) |
| 2 | 323 | | ageRatingText.text = contentCategory switch |
| | 324 | | { |
| 0 | 325 | | SceneContentCategory.ADULT => "PG 18+", |
| 0 | 326 | | SceneContentCategory.RESTRICTED => "RESTRICTED", |
| 2 | 327 | | _ => "PG 13+", |
| | 328 | | }; |
| | 329 | |
|
| 59 | 330 | | if (ageRatingOutline != null) |
| 2 | 331 | | ageRatingOutline.SetActive(contentCategory != SceneContentCategory.RESTRICTED); |
| 59 | 332 | | } |
| | 333 | |
|
| | 334 | | public void SetAllPlaceCategories(List<(string id, string nameToShow)> placeCategories) |
| | 335 | | { |
| 0 | 336 | | allPlaceCategories.Clear(); |
| 0 | 337 | | allPlaceCategories.AddRange(placeCategories); |
| 0 | 338 | | } |
| | 339 | |
|
| | 340 | | public void SetAppearsOn(string[] categories) |
| | 341 | | { |
| 59 | 342 | | if (placeCategoriesPool == null) |
| 57 | 343 | | return; |
| | 344 | |
|
| 2 | 345 | | placeCategoriesPool.ReleaseAll(); |
| | 346 | |
|
| 2 | 347 | | if (categories == null) |
| 2 | 348 | | return; |
| | 349 | |
|
| 0 | 350 | | foreach (GameObject categoryItem in placeCategoriesGroup) |
| | 351 | | { |
| 0 | 352 | | if (categoryItem == null) |
| | 353 | | continue; |
| | 354 | |
|
| 0 | 355 | | categoryItem.SetActive(categories.Length > 0); |
| | 356 | | } |
| | 357 | |
|
| 0 | 358 | | if (placeCategoriesGrid == null) |
| 0 | 359 | | return; |
| | 360 | |
|
| 0 | 361 | | foreach (string category in categories) |
| | 362 | | { |
| 0 | 363 | | foreach ((string id, string nameToShow) categoryInfo in allPlaceCategories) |
| | 364 | | { |
| 0 | 365 | | if (categoryInfo.id != category) |
| | 366 | | continue; |
| | 367 | |
|
| 0 | 368 | | var categoryLabel = placeCategoriesPool.Get<PlaceCategoryButton>(); |
| 0 | 369 | | categoryLabel.transform.SetParent(placeCategoriesGrid.transform, false); |
| 0 | 370 | | categoryLabel.SetCategory(categoryInfo.id, categoryInfo.nameToShow); |
| 0 | 371 | | categoryLabel.SetStatus(false); |
| 0 | 372 | | break; |
| | 373 | | } |
| | 374 | | } |
| 0 | 375 | | } |
| | 376 | |
|
| | 377 | | private void FavoriteValueChanged(string placeUUID, bool isFavorite) |
| | 378 | | { |
| 0 | 379 | | OnFavoriteChanged?.Invoke(placeUUID, isFavorite); |
| | 380 | |
|
| 0 | 381 | | if (ownUserProfile != null && ownUserProfile.isGuest) |
| | 382 | | { |
| 0 | 383 | | favoriteButton.Configure(new FavoriteButtonComponentModel |
| | 384 | | { |
| | 385 | | placeUUID = placeUUID, |
| | 386 | | isFavorite = false, |
| | 387 | | }); |
| 0 | 388 | | return; |
| | 389 | | } |
| | 390 | |
|
| 0 | 391 | | model.isFavorite = true; |
| 0 | 392 | | model.placeInfo.id = placeUUID; |
| 0 | 393 | | } |
| | 394 | |
|
| | 395 | | public override void OnFocus() |
| | 396 | | { |
| 1 | 397 | | base.OnFocus(); |
| | 398 | |
|
| 1 | 399 | | if (cardSelectionFrame != null) |
| 1 | 400 | | cardSelectionFrame.SetActive(true); |
| | 401 | |
|
| 1 | 402 | | ShowFavoriteButton(true); |
| | 403 | |
|
| 1 | 404 | | if(cardAnimator != null) |
| 1 | 405 | | cardAnimator.Focus(); |
| 1 | 406 | | } |
| | 407 | |
|
| | 408 | | public override void OnLoseFocus() |
| | 409 | | { |
| 1301 | 410 | | base.OnLoseFocus(); |
| | 411 | |
|
| 1301 | 412 | | if (cardSelectionFrame != null) |
| 1249 | 413 | | cardSelectionFrame.SetActive(false); |
| | 414 | |
|
| 1301 | 415 | | ShowFavoriteButton(false); |
| | 416 | |
|
| 1301 | 417 | | if(cardAnimator != null) |
| 1249 | 418 | | cardAnimator.Idle(); |
| 1301 | 419 | | } |
| | 420 | |
|
| | 421 | | public override void Show(bool instant = false) |
| | 422 | | { |
| 3 | 423 | | base.Show(instant); |
| | 424 | |
|
| 3 | 425 | | DataStore.i.exploreV2.isSomeModalOpen.Set(true); |
| 3 | 426 | | } |
| | 427 | |
|
| | 428 | | public override void Hide(bool instant = false) |
| | 429 | | { |
| 275 | 430 | | base.Hide(instant); |
| | 431 | |
|
| 275 | 432 | | DataStore.i.exploreV2.isSomeModalOpen.Set(false); |
| 275 | 433 | | } |
| | 434 | |
|
| | 435 | | public override void Dispose() |
| | 436 | | { |
| 1390 | 437 | | base.Dispose(); |
| | 438 | |
|
| 1390 | 439 | | if (placeImage != null) |
| | 440 | | { |
| 1389 | 441 | | placeImage.OnLoaded -= OnPlaceImageLoaded; |
| 1389 | 442 | | placeImage.Dispose(); |
| | 443 | | } |
| | 444 | |
|
| 1390 | 445 | | if (closeCardButton != null) |
| 222 | 446 | | closeCardButton.onClick.RemoveAllListeners(); |
| | 447 | |
|
| 1390 | 448 | | if (closeAction != null) |
| 223 | 449 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| | 450 | |
|
| 1390 | 451 | | if (modalBackgroundButton != null) |
| 222 | 452 | | modalBackgroundButton.onClick.RemoveAllListeners(); |
| | 453 | |
|
| 1390 | 454 | | if (friendsHandler != null) |
| | 455 | | { |
| 21 | 456 | | friendsHandler.OnFriendAddedEvent -= OnFriendAdded; |
| 21 | 457 | | friendsHandler.OnFriendRemovedEvent -= OnFriendRemoved; |
| | 458 | | } |
| | 459 | |
|
| 1390 | 460 | | if (friendsGrid != null) |
| 1166 | 461 | | friendsGrid.Dispose(); |
| | 462 | |
|
| 1390 | 463 | | if(favoriteButton != null) |
| 1389 | 464 | | favoriteButton.OnFavoriteChange -= FavoriteValueChanged; |
| | 465 | |
|
| 1390 | 466 | | if (placeCopyContextualMenu != null) |
| 1 | 467 | | placeCopyContextualMenu.OnTwitter -= ClickedTwitter; |
| | 468 | |
|
| 1390 | 469 | | if (placeCopyContextualMenu != null) |
| 1 | 470 | | placeCopyContextualMenu.OnPlaceLinkCopied -= CopiedLink; |
| 1390 | 471 | | } |
| | 472 | |
|
| | 473 | | private void ShowFavoriteButton(bool show) |
| | 474 | | { |
| 1361 | 475 | | if(favoriteButton != null && !favoriteButton.IsFavorite()) |
| 1303 | 476 | | favoriteButton.gameObject.SetActive(show); |
| 1361 | 477 | | } |
| | 478 | |
|
| | 479 | | public void SetPlacePicture(Sprite sprite) |
| | 480 | | { |
| 52 | 481 | | if (sprite == null && defaultPicture != null) |
| 0 | 482 | | sprite = defaultPicture; |
| | 483 | |
|
| 52 | 484 | | model.placePictureSprite = sprite; |
| | 485 | |
|
| 52 | 486 | | if (placeImage == null) |
| 0 | 487 | | return; |
| | 488 | |
|
| 52 | 489 | | placeImage.SetImage(sprite); |
| 52 | 490 | | } |
| | 491 | |
|
| | 492 | | public void SetPlacePicture(Texture2D texture) |
| | 493 | | { |
| 1 | 494 | | if (texture == null && defaultPicture != null) |
| | 495 | | { |
| 0 | 496 | | SetPlacePicture(defaultPicture); |
| 0 | 497 | | return; |
| | 498 | | } |
| | 499 | |
|
| 1 | 500 | | model.placePictureTexture = texture; |
| | 501 | |
|
| 1 | 502 | | if (!Application.isPlaying) |
| 0 | 503 | | return; |
| | 504 | |
|
| 1 | 505 | | if (placeImage == null) |
| 0 | 506 | | return; |
| | 507 | |
|
| 1 | 508 | | placeImage.SetImage(texture); |
| 1 | 509 | | } |
| | 510 | |
|
| | 511 | | public void SetPlacePicture(string uri) |
| | 512 | | { |
| 9 | 513 | | if (string.IsNullOrEmpty(uri) && defaultPicture != null) |
| | 514 | | { |
| 0 | 515 | | SetPlacePicture(defaultPicture); |
| 0 | 516 | | return; |
| | 517 | | } |
| | 518 | |
|
| 9 | 519 | | model.placePictureUri = uri; |
| | 520 | |
|
| 9 | 521 | | if (!Application.isPlaying) |
| 0 | 522 | | return; |
| | 523 | |
|
| 9 | 524 | | if (placeImage == null) |
| 0 | 525 | | return; |
| | 526 | |
|
| 9 | 527 | | placeImage.SetImage(uri); |
| 9 | 528 | | } |
| | 529 | |
|
| | 530 | | public void SetPlaceName(string newText) |
| | 531 | | { |
| 60 | 532 | | model.placeName = newText; |
| | 533 | |
|
| 60 | 534 | | if (placeNameOnIdleText != null) |
| 60 | 535 | | placeNameOnIdleText.text = newText; |
| | 536 | |
|
| 60 | 537 | | if (placeNameOnFocusText != null) |
| 58 | 538 | | placeNameOnFocusText.text = newText; |
| 60 | 539 | | } |
| | 540 | |
|
| | 541 | | public void SetPlaceDescription(string newText) |
| | 542 | | { |
| 60 | 543 | | model.placeDescription = newText; |
| | 544 | |
|
| 60 | 545 | | if (placeDescText == null) |
| 57 | 546 | | return; |
| | 547 | |
|
| 3 | 548 | | placeDescText.text = string.IsNullOrEmpty(newText) ? NO_DESCRIPTION_TEXT : newText; |
| 3 | 549 | | } |
| | 550 | |
|
| | 551 | | public void SetPlaceAuthor(string newText) |
| | 552 | | { |
| 60 | 553 | | model.placeAuthor = newText; |
| | 554 | |
|
| 60 | 555 | | if (placeAuthorOnIdleText != null) |
| 60 | 556 | | placeAuthorOnIdleText.text = newText; |
| | 557 | |
|
| 60 | 558 | | if(placeAuthorOnFocusText != null) |
| 57 | 559 | | placeAuthorOnFocusText.text = newText; |
| 60 | 560 | | } |
| | 561 | |
|
| | 562 | | public void SetUserVisits(int userVisits) |
| | 563 | | { |
| 59 | 564 | | model.userVisits = userVisits; |
| | 565 | |
|
| 59 | 566 | | if (userVisitsText != null) |
| 59 | 567 | | userVisitsText.text = FormatNumber(userVisits); |
| 59 | 568 | | } |
| | 569 | |
|
| | 570 | | public void SetUserRating(float? userRating) |
| | 571 | | { |
| 59 | 572 | | model.userRating = userRating; |
| | 573 | |
|
| 59 | 574 | | if (userRatingText != null) |
| 59 | 575 | | userRatingText.text = userRating != null ? $"{userRating.Value * 100:0}%" : "-%"; |
| 59 | 576 | | } |
| | 577 | |
|
| | 578 | | public void SetNumberOfUsers(int newNumberOfUsers) |
| | 579 | | { |
| 60 | 580 | | model.numberOfUsers = newNumberOfUsers; |
| | 581 | |
|
| 60 | 582 | | if (numberOfUsersText != null) |
| 60 | 583 | | numberOfUsersText.text = FormatNumber(newNumberOfUsers); |
| | 584 | |
|
| 60 | 585 | | if (numberOfUsersContainer != null) |
| 58 | 586 | | numberOfUsersContainer.gameObject.SetActive(newNumberOfUsers > 0); |
| 60 | 587 | | } |
| | 588 | |
|
| | 589 | | public void SetCoords(Vector2Int newCoords) |
| | 590 | | { |
| 60 | 591 | | model.coords = newCoords; |
| | 592 | |
|
| 60 | 593 | | if (coordsText == null) |
| 57 | 594 | | return; |
| | 595 | |
|
| 3 | 596 | | coordsText.text = $"{newCoords.x},{newCoords.y}"; |
| 3 | 597 | | } |
| | 598 | |
|
| 120 | 599 | | public void SetParcels(Vector2Int[] parcels) { model.parcels = parcels; } |
| | 600 | |
|
| | 601 | | public void SetLoadingIndicatorVisible(bool isVisible) |
| | 602 | | { |
| 2 | 603 | | imageContainer.SetActive(!isVisible); |
| 2 | 604 | | placeInfoContainer.SetActive(!isVisible); |
| 2 | 605 | | loadingSpinner.SetActive(isVisible); |
| 2 | 606 | | } |
| | 607 | |
|
| | 608 | | internal void OnPlaceImageLoaded(Sprite sprite) |
| | 609 | | { |
| 0 | 610 | | if (sprite != null) |
| 0 | 611 | | return; |
| | 612 | |
|
| 0 | 613 | | if (!thumbnailFromMarketPlaceRequested) |
| | 614 | | { |
| 0 | 615 | | thumbnailFromMarketPlaceRequested = true; |
| 0 | 616 | | SetPlacePicture(MapUtils.GetMarketPlaceThumbnailUrl(model.parcels, THMBL_MARKETPLACE_WIDTH, THMBL_MARKETPLAC |
| | 617 | | } |
| | 618 | | else |
| | 619 | | { |
| 0 | 620 | | SetPlacePicture(sprite: null); |
| | 621 | | } |
| 0 | 622 | | } |
| | 623 | |
|
| | 624 | | internal void InitializeFriendsTracker() |
| | 625 | | { |
| 52 | 626 | | CleanFriendHeadsItems(); |
| | 627 | |
|
| 52 | 628 | | if (mapInfoHandler == null) |
| 16 | 629 | | mapInfoHandler = new MapInfoHandler(); |
| | 630 | |
|
| 52 | 631 | | if (friendsHandler == null) |
| | 632 | | { |
| 16 | 633 | | friendsHandler = new FriendsHandler(mapInfoHandler); |
| 16 | 634 | | friendsHandler.OnFriendAddedEvent += OnFriendAdded; |
| 16 | 635 | | friendsHandler.OnFriendRemovedEvent += OnFriendRemoved; |
| | 636 | | } |
| 52 | 637 | | } |
| | 638 | |
|
| | 639 | | internal void OnFriendAdded(UserProfile profile, Color backgroundColor) |
| | 640 | | { |
| 3 | 641 | | if (currentFriendHeads.ContainsKey(profile.userId)) |
| 0 | 642 | | return; |
| | 643 | |
|
| 3 | 644 | | BaseComponentView newFriend = InstantiateAndConfigureFriendHead( |
| | 645 | | new FriendHeadForPlaceCardComponentModel |
| | 646 | | { |
| | 647 | | userProfile = profile, |
| | 648 | | backgroundColor = backgroundColor |
| | 649 | | }, |
| | 650 | | friendHeadPrefab); |
| | 651 | |
|
| 3 | 652 | | if (friendsGrid != null) |
| 3 | 653 | | friendsGrid.AddItemWithResize(newFriend); |
| | 654 | |
|
| 3 | 655 | | currentFriendHeads.Add(profile.userId, newFriend); |
| 3 | 656 | | } |
| | 657 | |
|
| | 658 | | internal void OnFriendRemoved(UserProfile profile) |
| | 659 | | { |
| 1 | 660 | | if (!currentFriendHeads.ContainsKey(profile.userId)) |
| 0 | 661 | | return; |
| | 662 | |
|
| 1 | 663 | | if (friendsGrid != null) |
| 1 | 664 | | friendsGrid.RemoveItem(currentFriendHeads[profile.userId]); |
| | 665 | |
|
| 1 | 666 | | currentFriendHeads.Remove(profile.userId); |
| 1 | 667 | | } |
| | 668 | |
|
| | 669 | | internal void CleanFriendHeadsItems() |
| | 670 | | { |
| 1251 | 671 | | if (friendsGrid != null) |
| | 672 | | { |
| 1197 | 673 | | friendsGrid.RemoveItems(); |
| 1197 | 674 | | currentFriendHeads.Clear(); |
| | 675 | | } |
| 1251 | 676 | | } |
| | 677 | |
|
| | 678 | | internal BaseComponentView InstantiateAndConfigureFriendHead(FriendHeadForPlaceCardComponentModel friendInfo, Friend |
| | 679 | | { |
| 4 | 680 | | FriendHeadForPlaceCardComponentView friendHeadGO = GameObject.Instantiate(prefabToUse); |
| 4 | 681 | | friendHeadGO.Configure(friendInfo); |
| | 682 | |
|
| 4 | 683 | | return friendHeadGO; |
| | 684 | | } |
| | 685 | |
|
| | 686 | | private void RebuildCardLayouts() |
| | 687 | | { |
| 59 | 688 | | if (contentVerticalLayout != null) |
| 2 | 689 | | Utils.ForceRebuildLayoutImmediate(contentVerticalLayout.transform as RectTransform); |
| | 690 | |
|
| 59 | 691 | | if (infoVerticalLayout != null) |
| 2 | 692 | | Utils.ForceRebuildLayoutImmediate(infoVerticalLayout.transform as RectTransform); |
| | 693 | |
|
| 59 | 694 | | if (numberOfUsersContainer != null) |
| 57 | 695 | | Utils.ForceRebuildLayoutImmediate(numberOfUsersContainer); |
| | 696 | |
|
| 59 | 697 | | if (userVisitsAndRatingContainer != null) |
| 57 | 698 | | Utils.ForceRebuildLayoutImmediate(userVisitsAndRatingContainer); |
| 59 | 699 | | } |
| | 700 | |
|
| 8 | 701 | | internal void CloseModal() { Hide(); } |
| | 702 | |
|
| 6 | 703 | | internal void OnCloseActionTriggered(DCLAction_Trigger action) { CloseModal(); } |
| | 704 | |
|
| | 705 | | private static string FormatNumber(int num) |
| | 706 | | { |
| 121 | 707 | | if (num < 1000) |
| 121 | 708 | | return num.ToString(); |
| | 709 | |
|
| 0 | 710 | | float divided = num / 1000.0f; |
| 0 | 711 | | divided = (int)(divided * 100) / 100f; |
| 0 | 712 | | return $"{divided:F2}k"; |
| | 713 | | } |
| | 714 | |
|
| | 715 | | private void ResetScrollPosition() |
| | 716 | | { |
| 59 | 717 | | if (scroll == null) |
| 57 | 718 | | return; |
| | 719 | |
|
| 2 | 720 | | scroll.verticalNormalizedPosition = 1; |
| 2 | 721 | | } |
| | 722 | | } |