| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.UI; |
| | 3 | |
|
| | 4 | | public class FriendRequestEntry : FriendEntryBase |
| | 5 | | { |
| | 6 | | [SerializeField] internal Button acceptButton; |
| | 7 | | [SerializeField] internal Button rejectButton; |
| | 8 | | [SerializeField] internal Button cancelButton; |
| | 9 | |
|
| 0 | 10 | | public bool isReceived { get; private set; } |
| | 11 | |
|
| | 12 | | public event System.Action<FriendRequestEntry> OnAccepted; |
| | 13 | | public event System.Action<FriendRequestEntry> OnRejected; |
| | 14 | | public event System.Action<FriendRequestEntry> OnCancelled; |
| | 15 | |
|
| | 16 | | public override void Awake() |
| | 17 | | { |
| 17 | 18 | | base.Awake(); |
| | 19 | |
|
| 17 | 20 | | acceptButton.onClick.RemoveAllListeners(); |
| 17 | 21 | | rejectButton.onClick.RemoveAllListeners(); |
| 17 | 22 | | cancelButton.onClick.RemoveAllListeners(); |
| 18 | 23 | | acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this)); |
| 18 | 24 | | rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this)); |
| 18 | 25 | | cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this)); |
| 17 | 26 | | } |
| | 27 | |
|
| | 28 | | public void Populate(FriendRequestEntryModel model) |
| | 29 | | { |
| 12 | 30 | | base.Populate(model); |
| 12 | 31 | | SetReceived(model.isReceived); |
| 12 | 32 | | } |
| | 33 | |
|
| | 34 | | public override void Populate(FriendEntryModel model) |
| | 35 | | { |
| 0 | 36 | | base.Populate(model); |
| | 37 | |
|
| 0 | 38 | | if (model is FriendRequestEntryModel requestModel) |
| 0 | 39 | | SetReceived(requestModel.isReceived); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | private void SetReceived(bool value) |
| | 43 | | { |
| 12 | 44 | | isReceived = value; |
| | 45 | |
|
| 12 | 46 | | if (isReceived) |
| 5 | 47 | | PopulateReceived(); |
| | 48 | | else |
| 7 | 49 | | PopulateSent(); |
| 7 | 50 | | } |
| | 51 | |
|
| | 52 | | private void PopulateReceived() |
| | 53 | | { |
| 5 | 54 | | isReceived = true; |
| 5 | 55 | | cancelButton.gameObject.SetActive(false); |
| 5 | 56 | | acceptButton.gameObject.SetActive(true); |
| 5 | 57 | | rejectButton.gameObject.SetActive(true); |
| 5 | 58 | | } |
| | 59 | |
|
| | 60 | | private void PopulateSent() |
| | 61 | | { |
| 7 | 62 | | isReceived = false; |
| 7 | 63 | | cancelButton.gameObject.SetActive(true); |
| 7 | 64 | | acceptButton.gameObject.SetActive(false); |
| 7 | 65 | | rejectButton.gameObject.SetActive(false); |
| 7 | 66 | | } |
| | 67 | | } |