| | 1 | | using DCl.Social.Friends; |
| | 2 | | using DCL.Social.Friends; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class ReceivedFriendRequestsNotificationBadge : MonoBehaviour |
| | 7 | | { |
| | 8 | | [SerializeField] private TextMeshProUGUI notificationText; |
| | 9 | | [SerializeField] private GameObject notificationContainer; |
| 56 | 10 | | [SerializeField] private int maxNumberToShow = 9; |
| | 11 | |
|
| | 12 | | private IFriendsController friendsController; |
| | 13 | | private int currentUnreadMessagesValue; |
| | 14 | |
|
| | 15 | | public int CurrentUnreadMessages |
| | 16 | | { |
| 0 | 17 | | get => currentUnreadMessagesValue; |
| | 18 | | set |
| | 19 | | { |
| 30 | 20 | | currentUnreadMessagesValue = value; |
| | 21 | |
|
| 30 | 22 | | if (currentUnreadMessagesValue > 0) |
| | 23 | | { |
| 0 | 24 | | notificationContainer.SetActive(true); |
| 0 | 25 | | notificationText.text = currentUnreadMessagesValue <= maxNumberToShow |
| | 26 | | ? currentUnreadMessagesValue.ToString() |
| | 27 | | : $"+{maxNumberToShow}"; |
| | 28 | | } |
| | 29 | | else |
| | 30 | | { |
| 30 | 31 | | notificationContainer.SetActive(false); |
| | 32 | | } |
| 30 | 33 | | } |
| | 34 | | } |
| | 35 | |
|
| | 36 | | private void Start() |
| | 37 | | { |
| 29 | 38 | | Initialize(FriendsController.i); |
| 29 | 39 | | } |
| | 40 | |
|
| | 41 | | private void OnEnable() |
| | 42 | | { |
| 35 | 43 | | UpdateReceivedRequests(); |
| 35 | 44 | | } |
| | 45 | |
|
| | 46 | | public void Initialize(IFriendsController friendsController) |
| | 47 | | { |
| 29 | 48 | | if (friendsController == null) return; |
| 29 | 49 | | this.friendsController = friendsController; |
| 29 | 50 | | friendsController.OnTotalFriendRequestUpdated += UpdateReceivedRequests; |
| 29 | 51 | | UpdateReceivedRequests(); |
| 29 | 52 | | } |
| | 53 | |
|
| | 54 | | private void OnDestroy() |
| | 55 | | { |
| 34 | 56 | | if (friendsController != null) |
| 29 | 57 | | friendsController.OnTotalFriendRequestUpdated -= UpdateReceivedRequests; |
| 34 | 58 | | } |
| | 59 | |
|
| | 60 | | private void UpdateReceivedRequests(int totalReceivedFriendRequests, int totalSentFriendRequests) => |
| 0 | 61 | | CurrentUnreadMessages = totalReceivedFriendRequests; |
| | 62 | |
|
| | 63 | | private void UpdateReceivedRequests() |
| | 64 | | { |
| 98 | 65 | | if (friendsController == null) return; |
| 30 | 66 | | CurrentUnreadMessages = friendsController.TotalReceivedFriendRequestCount; |
| 30 | 67 | | } |
| | 68 | | } |