| | 1 | | using System; |
| | 2 | | using System.Globalization; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class FriendRequestEntry : FriendEntryBase |
| | 8 | | { |
| | 9 | | [SerializeField] internal TMP_Text bodyMessage; |
| | 10 | | [SerializeField] internal TMP_Text requestDate; |
| | 11 | | [SerializeField] internal GameObject shortcutButtonsContainer; |
| | 12 | | [SerializeField] internal Button acceptButton; |
| | 13 | | [SerializeField] internal Button rejectButton; |
| | 14 | | [SerializeField] internal Button cancelButton; |
| | 15 | | [SerializeField] internal Button openButton; |
| | 16 | |
|
| 0 | 17 | | public bool isReceived { get; private set; } |
| | 18 | |
|
| | 19 | | public event Action<FriendRequestEntry> OnAccepted; |
| | 20 | | public event Action<FriendRequestEntry> OnRejected; |
| | 21 | | public event Action<FriendRequestEntry> OnCancelled; |
| | 22 | | public event Action<FriendRequestEntry> OnOpened; |
| | 23 | |
|
| | 24 | | public override void Awake() |
| | 25 | | { |
| 0 | 26 | | base.Awake(); |
| | 27 | |
|
| 0 | 28 | | acceptButton.onClick.RemoveAllListeners(); |
| 0 | 29 | | rejectButton.onClick.RemoveAllListeners(); |
| 0 | 30 | | cancelButton.onClick.RemoveAllListeners(); |
| 0 | 31 | | acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this)); |
| 0 | 32 | | rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this)); |
| 0 | 33 | | cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this)); |
| 0 | 34 | | openButton.onClick.AddListener(() => OnOpened?.Invoke(this)); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | public void Populate(FriendRequestEntryModel model) |
| | 38 | | { |
| 0 | 39 | | base.Populate(model); |
| 0 | 40 | | SetBodyMessage(model.bodyMessage); |
| 0 | 41 | | SetRequestDate(model.timestamp); |
| 0 | 42 | | SetReceived(model.isReceived); |
| 0 | 43 | | SetShortcutButtonsActive(model.isShortcutButtonsActive); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | public override void Populate(FriendEntryModel model) |
| | 47 | | { |
| 0 | 48 | | base.Populate(model); |
| | 49 | |
|
| 0 | 50 | | if (model is FriendRequestEntryModel requestModel) |
| | 51 | | { |
| 0 | 52 | | SetBodyMessage(requestModel.bodyMessage); |
| 0 | 53 | | SetRequestDate(requestModel.timestamp); |
| 0 | 54 | | SetReceived(requestModel.isReceived); |
| 0 | 55 | | SetShortcutButtonsActive(requestModel.isShortcutButtonsActive); |
| | 56 | | } |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | private void SetBodyMessage(string value) |
| | 60 | | { |
| 0 | 61 | | if (bodyMessage == null) |
| 0 | 62 | | return; |
| | 63 | |
|
| 0 | 64 | | bodyMessage.text = value; |
| 0 | 65 | | bodyMessage.gameObject.SetActive(!string.IsNullOrEmpty(value)); |
| 0 | 66 | | } |
| | 67 | |
|
| | 68 | | private void SetRequestDate(DateTime value) |
| | 69 | | { |
| 0 | 70 | | if (requestDate == null) |
| 0 | 71 | | return; |
| | 72 | |
|
| 0 | 73 | | DateTime localTime = value.ToLocalTime(); |
| 0 | 74 | | requestDate.text = localTime.ToString("MMM dd", new CultureInfo("en-US")).ToUpper(); |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void SetReceived(bool value) |
| | 78 | | { |
| 0 | 79 | | isReceived = value; |
| | 80 | |
|
| 0 | 81 | | if (isReceived) |
| 0 | 82 | | PopulateReceived(); |
| | 83 | | else |
| 0 | 84 | | PopulateSent(); |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | private void PopulateReceived() |
| | 88 | | { |
| 0 | 89 | | isReceived = true; |
| 0 | 90 | | cancelButton.gameObject.SetActive(false); |
| 0 | 91 | | acceptButton.gameObject.SetActive(true); |
| 0 | 92 | | rejectButton.gameObject.SetActive(true); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | private void PopulateSent() |
| | 96 | | { |
| 0 | 97 | | isReceived = false; |
| 0 | 98 | | cancelButton.gameObject.SetActive(true); |
| 0 | 99 | | acceptButton.gameObject.SetActive(false); |
| 0 | 100 | | rejectButton.gameObject.SetActive(false); |
| 0 | 101 | | } |
| | 102 | |
|
| | 103 | | private void SetShortcutButtonsActive(bool isActive) |
| | 104 | | { |
| 0 | 105 | | if (shortcutButtonsContainer != null) |
| 0 | 106 | | shortcutButtonsContainer.SetActive(isActive); |
| | 107 | |
|
| 0 | 108 | | if (requestDate != null) |
| 0 | 109 | | requestDate.gameObject.SetActive(!isActive); |
| 0 | 110 | | } |
| | 111 | | } |