| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.Events; |
| | 4 | | using UnityEngine.UI; |
| | 5 | | using DCL.Interface; |
| | 6 | |
|
| | 7 | | public class PrivateChatWindowHUDView : MonoBehaviour |
| | 8 | | { |
| | 9 | | const string VIEW_PATH = "PrivateChatWindow"; |
| | 10 | |
|
| | 11 | | public Button backButton; |
| | 12 | | public Button minimizeButton; |
| | 13 | | public Button closeButton; |
| | 14 | | public JumpInButton jumpInButton; |
| | 15 | | public ChatHUDView chatHudView; |
| | 16 | | public PrivateChatWindowHUDController controller; |
| | 17 | | public TMP_Text windowTitleText; |
| | 18 | | public RawImage profilePictureImage; |
| | 19 | |
|
| | 20 | | public event System.Action OnPressBack; |
| | 21 | | public event System.Action OnMinimize; |
| | 22 | | public event System.Action OnClose; |
| | 23 | | public UnityAction<ChatMessage> OnSendMessage; |
| | 24 | |
|
| 0 | 25 | | public string userId { get; internal set; } |
| | 26 | |
|
| 16 | 27 | | void Awake() { chatHudView.OnSendMessage += ChatHUDView_OnSendMessage; } |
| | 28 | |
|
| 32 | 29 | | void OnEnable() { DCL.Helpers.Utils.ForceUpdateLayout(transform as RectTransform); } |
| | 30 | |
|
| | 31 | | public static PrivateChatWindowHUDView Create(PrivateChatWindowHUDController controller) |
| | 32 | | { |
| 8 | 33 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<PrivateChatWindowHUDView>(); |
| 8 | 34 | | view.Initialize(controller); |
| 8 | 35 | | return view; |
| | 36 | | } |
| | 37 | |
|
| | 38 | | private void Initialize(PrivateChatWindowHUDController controller) |
| | 39 | | { |
| 8 | 40 | | this.controller = controller; |
| 8 | 41 | | this.minimizeButton.onClick.AddListener(OnMinimizeButtonPressed); |
| 8 | 42 | | this.closeButton.onClick.AddListener(OnCloseButtonPressed); |
| 12 | 43 | | this.backButton.onClick.AddListener(() => { OnPressBack?.Invoke(); }); |
| 8 | 44 | | } |
| | 45 | |
|
| | 46 | | public void ChatHUDView_OnSendMessage(ChatMessage message) |
| | 47 | | { |
| 0 | 48 | | if (string.IsNullOrEmpty(message.body)) |
| 0 | 49 | | return; |
| | 50 | |
|
| 0 | 51 | | message.messageType = ChatMessage.Type.PRIVATE; |
| 0 | 52 | | message.recipient = controller.conversationUserName; |
| | 53 | |
|
| 0 | 54 | | OnSendMessage?.Invoke(message); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public void OnMinimizeButtonPressed() |
| | 58 | | { |
| 1 | 59 | | controller.SetVisibility(false); |
| 1 | 60 | | OnMinimize?.Invoke(); |
| 0 | 61 | | } |
| | 62 | |
|
| | 63 | | public void OnCloseButtonPressed() |
| | 64 | | { |
| 0 | 65 | | controller.SetVisibility(false); |
| 0 | 66 | | OnClose?.Invoke(); |
| 0 | 67 | | } |
| | 68 | |
|
| 14 | 69 | | public void ConfigureTitle(string targetUserName) { windowTitleText.text = targetUserName; } |
| | 70 | |
|
| 0 | 71 | | public void ConfigureAvatarSnapshot(Texture2D texture) { profilePictureImage.texture = texture; } |
| | 72 | |
|
| | 73 | | public void ConfigureUserId(string userId) |
| | 74 | | { |
| 7 | 75 | | this.userId = userId; |
| 7 | 76 | | jumpInButton.Initialize(FriendsController.i, userId); |
| 7 | 77 | | } |
| | 78 | | } |