Skip to content

Commit

Permalink
suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-ranciaffi committed Jan 22, 2025
1 parent a6b9638 commit fd49dfd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand Down

0 comments on commit fd49dfd

Please sign in to comment.