From fd49dfd9b543d2ab9f5631a7a30118d3f4b3cf4e Mon Sep 17 00:00:00 2001 From: lorenzo-ranciaffi Date: Wed, 22 Jan 2025 14:24:49 +0100 Subject: [PATCH] suggested changes --- .../UserProfileContextMenuControlSettings.cs | 4 +- .../GenericContextMenuUserProfileView.cs | 74 ++++++++++++------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/Configs/UserProfileContextMenuControlSettings.cs b/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/Configs/UserProfileContextMenuControlSettings.cs index 408f2ce57e..a03ea578a1 100644 --- a/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/Configs/UserProfileContextMenuControlSettings.cs +++ b/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/Configs/UserProfileContextMenuControlSettings.cs @@ -7,6 +7,8 @@ namespace DCL.UI.GenericContextMenu.Controls.Configs { public class UserProfileContextMenuControlSettings : IContextMenuControlSettings { + private static readonly RectOffset DEFAULT_HORIZONTAL_LAYOUT_PADDING = new (8, 8, 0, 0); + public enum FriendshipStatus { NONE, @@ -27,7 +29,7 @@ public UserProfileContextMenuControlSettings(ISystemClipboard systemClipboard, A { this.systemClipboard = systemClipboard; this.requestFriendshipAction = requestFriendshipAction; - this.horizontalLayoutPadding = horizontalLayoutPadding ?? new RectOffset(8, 8, 0, 0); + this.horizontalLayoutPadding = horizontalLayoutPadding ?? DEFAULT_HORIZONTAL_LAYOUT_PADDING; } public void SetInitialData(Profile profile, Color userColor, FriendshipStatus friendshipStatus) diff --git a/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/GenericContextMenuUserProfileView.cs b/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/GenericContextMenuUserProfileView.cs index cb893fea6d..06eb47cf5d 100644 --- a/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/GenericContextMenuUserProfileView.cs +++ b/Explorer/Assets/DCL/UI/GenericContextMenu/Controls/GenericContextMenuUserProfileView.cs @@ -9,6 +9,10 @@ namespace DCL.UI.GenericContextMenu.Controls { public class GenericContextMenuUserProfileView : GenericContextMenuComponentBase { + private const int USER_NAME_MIN_HEIGHT = 20; + private const int FACE_FRAME_MIN_HEIGHT = 60; + private const int FRIEND_BUTTON_MIN_HEIGHT = 40; + [field: SerializeField] public Image FaceFrame { get; private set; } [field: SerializeField] public Image FaceRim { get; private set; } [field: SerializeField] public TMP_Text UserName { get; private set; } @@ -41,22 +45,51 @@ public void Configure(UserProfileContextMenuControlSettings settings) { HorizontalLayoutComponent.padding = settings.horizontalLayoutPadding; - UserName.text = settings.profile.Name; - UserName.color = settings.userColor; - UserNameTag.text = $"#{settings.profile.UserId[^4..]}"; - UserAddress.text = $"{settings.profile.UserId[..5]}...{settings.profile.UserId[^5..]}"; + ConfigureUserNameAndTag(settings.profile.Name, settings.profile.UserId, settings.profile.HasClaimedName, settings.userColor); + ConfigureAddFriendButton(settings.friendshipStatus); + + RectTransformComponent.sizeDelta = new Vector2(RectTransformComponent.sizeDelta.x, CalculateComponentHeight()); + + CopyNameButton.onClick.AddListener(() => settings.systemClipboard.Set(settings.profile.Name)); + CopyAddressButton.onClick.AddListener(() => settings.systemClipboard.Set(settings.profile.UserId)); + AddFriendButton.onClick.AddListener(() => settings.requestFriendshipAction(settings.profile)); + } - UserNameTag.gameObject.SetActive(!settings.profile.HasClaimedName); - ClaimedNameBadge.gameObject.SetActive(settings.profile.HasClaimedName); - ClaimedNameBadgeSeparator.gameObject.SetActive(settings.profile.HasClaimedName); + private void ConfigureUserNameAndTag(string userName, string userAddress, bool hasClaimedName, Color userColor) + { + UserName.text = userName; + UserName.color = userColor; + UserNameTag.text = $"#{userAddress[^4..]}"; + UserAddress.text = $"{userAddress[..5]}...{userAddress[^5..]}"; - FaceFrame.color = settings.userColor; - settings.userColor.r += 0.3f; - settings.userColor.g += 0.3f; - settings.userColor.b += 0.3f; - FaceRim.color = settings.userColor; + UserNameTag.gameObject.SetActive(!hasClaimedName); + ClaimedNameBadge.gameObject.SetActive(hasClaimedName); + ClaimedNameBadgeSeparator.gameObject.SetActive(hasClaimedName); - switch (settings.friendshipStatus) + FaceFrame.color = userColor; + userColor.r += 0.3f; + userColor.g += 0.3f; + userColor.b += 0.3f; + FaceRim.color = userColor; + } + + private float CalculateComponentHeight() + { + float totalHeight = Math.Max(userNameRectTransform.rect.height, USER_NAME_MIN_HEIGHT) + + Math.Max(faceFrameRectTransform.rect.height, FACE_FRAME_MIN_HEIGHT) + + Math.Max(userAddressRectTransform.rect.height, USER_NAME_MIN_HEIGHT) + + HorizontalLayoutComponent.padding.bottom + + HorizontalLayoutComponent.padding.top + + (ContentVerticalLayout.spacing * 2); + if (AddFriendButton.gameObject.activeSelf) + totalHeight += Math.Max(addButtonRectTransform.rect.height, FRIEND_BUTTON_MIN_HEIGHT) + ContentVerticalLayout.spacing; + + return totalHeight; + } + + private void ConfigureAddFriendButton(UserProfileContextMenuControlSettings.FriendshipStatus friendshipStatus) + { + switch (friendshipStatus) { case UserProfileContextMenuControlSettings.FriendshipStatus.NONE: AddFriendButton.gameObject.SetActive(true); @@ -81,21 +114,6 @@ public void Configure(UserProfileContextMenuControlSettings settings) AddFriendButtonText.text = AddFriendText; break; } - - float totalHeight = Math.Max(userNameRectTransform.rect.height, 20) - + Math.Max(faceFrameRectTransform.rect.height, 60) - + Math.Max(userAddressRectTransform.rect.height, 20) - + HorizontalLayoutComponent.padding.bottom - + HorizontalLayoutComponent.padding.top - + (ContentVerticalLayout.spacing * 2); - if (AddFriendButton.gameObject.activeSelf) - totalHeight += Math.Max(addButtonRectTransform.rect.height, 40) + ContentVerticalLayout.spacing; - - RectTransformComponent.sizeDelta = new Vector2(RectTransformComponent.sizeDelta.x, totalHeight); - - CopyNameButton.onClick.AddListener(() => settings.systemClipboard.Set(settings.profile.Name)); - CopyAddressButton.onClick.AddListener(() => settings.systemClipboard.Set(settings.profile.UserId)); - AddFriendButton.onClick.AddListener(() => settings.requestFriendshipAction(settings.profile)); } public override void UnregisterListeners()