| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | | using static PublicChannelEntry; |
| | 6 | |
|
| | 7 | | public class PublicChannelEntry : BaseComponentView, IComponentModelConfig<PublicChannelEntryModel> |
| | 8 | | { |
| | 9 | | [SerializeField] internal Button openChatButton; |
| | 10 | | [SerializeField] internal TMP_Text nameLabel; |
| | 11 | | [SerializeField] internal PublicChannelEntryModel model; |
| | 12 | | [SerializeField] internal UnreadNotificationBadge unreadNotifications; |
| | 13 | |
|
| | 14 | | private IChatController chatController; |
| | 15 | |
|
| 0 | 16 | | public PublicChannelEntryModel Model => model; |
| | 17 | |
|
| | 18 | | public event Action<PublicChannelEntry> OnOpenChat; |
| | 19 | |
|
| | 20 | | public static PublicChannelEntry Create() |
| | 21 | | { |
| 2 | 22 | | return Instantiate(Resources.Load<PublicChannelEntry>("SocialBarV1/PublicChannelElement")); |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public override void Awake() |
| | 26 | | { |
| 25 | 27 | | base.Awake(); |
| 27 | 28 | | openChatButton.onClick.AddListener(() => OnOpenChat?.Invoke(this)); |
| 25 | 29 | | } |
| | 30 | |
|
| | 31 | | public void Initialize(IChatController chatController) |
| | 32 | | { |
| 0 | 33 | | this.chatController = chatController; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public void Configure(PublicChannelEntryModel newModel) |
| | 37 | | { |
| 21 | 38 | | model = newModel; |
| 21 | 39 | | RefreshControl(); |
| 21 | 40 | | } |
| | 41 | |
|
| | 42 | | public override void RefreshControl() |
| | 43 | | { |
| 21 | 44 | | nameLabel.text = $"#{model.name}"; |
| 21 | 45 | | unreadNotifications.Initialize(chatController, model.channelId); |
| 21 | 46 | | } |
| | 47 | |
|
| | 48 | | [Serializable] |
| | 49 | | public class PublicChannelEntryModel : BaseComponentModel |
| | 50 | | { |
| | 51 | | public string channelId; |
| | 52 | | public string name; |
| | 53 | |
|
| 21 | 54 | | public PublicChannelEntryModel(string channelId, string name) |
| | 55 | | { |
| 21 | 56 | | this.channelId = channelId; |
| 21 | 57 | | this.name = name; |
| 21 | 58 | | } |
| | 59 | | } |
| | 60 | | } |