< Summary

Class:WorldChatWindowHUDView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowHUDView.cs
Covered lines:36
Uncovered lines:8
Coverable lines:44
Total lines:106
Line coverage:81.8% (36 of 44)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WorldChatWindowHUDView()0%110100%
Create()0%110100%
Awake()0%110100%
Initialize()0%110100%
OnCloseButtonPressed()0%2.152066.67%
DeactivatePreview()0%2.022083.33%
ActivatePreview()0%2.022083.33%
OnPointerClick(...)0%2100%
OnTextInputValueChanged(...)0%4.054085.71%
ChatHUDView_OnSendMessage(...)0%5.395075%
WaitAndUpdateInputText()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowHUDView.cs

#LineLine coverage
 1using System.Collections;
 2using DCL.Interface;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6using UnityEngine.Events;
 7
 8public class WorldChatWindowHUDView : MonoBehaviour, IPointerClickHandler
 9{
 10    const string VIEW_PATH = "World Chat Window";
 11
 12    public Button closeButton;
 13
 14    public ChatHUDView chatHudView;
 15
 16    public CanvasGroup group;
 17    public WorldChatWindowHUDController controller;
 018    public bool isInPreview { get; private set; }
 19
 20    public event UnityAction OnDeactivatePreview;
 21    public event UnityAction OnActivatePreview;
 22    public event UnityAction OnClose;
 23    public UnityAction<ChatMessage> OnSendMessage;
 24
 25    ChatMessage lastWhisperMessageSent;
 2026    string lastInputText = string.Empty;
 27
 28    public static WorldChatWindowHUDView Create()
 29    {
 1030        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<WorldChatWindowHUDView>();
 1031        view.Initialize();
 1032        return view;
 33    }
 34
 35    void Awake()
 36    {
 1037        chatHudView.OnSendMessage += ChatHUDView_OnSendMessage;
 1038        chatHudView.inputField.onValueChanged.AddListener(OnTextInputValueChanged);
 1039    }
 40
 2041    private void Initialize() { this.closeButton.onClick.AddListener(OnCloseButtonPressed); }
 42
 43    public void OnCloseButtonPressed()
 44    {
 145        controller.SetVisibility(false);
 146        OnClose?.Invoke();
 047    }
 48
 49    public void DeactivatePreview()
 50    {
 551        chatHudView.scrollRect.enabled = true;
 552        group.alpha = 1;
 553        isInPreview = false;
 554        chatHudView.SetFadeoutMode(false);
 555        OnDeactivatePreview?.Invoke();
 056    }
 57
 58    public void ActivatePreview()
 59    {
 360        chatHudView.scrollRect.enabled = false;
 361        group.alpha = 0;
 362        isInPreview = true;
 363        chatHudView.SetFadeoutMode(true);
 364        OnActivatePreview?.Invoke();
 065    }
 66
 067    public void OnPointerClick(PointerEventData eventData) { DeactivatePreview(); }
 68
 69    public void OnTextInputValueChanged(string text)
 70    {
 671        if (isInPreview)
 072            chatHudView.inputField.text = lastInputText;
 73        else
 674            lastInputText = chatHudView.inputField.text;
 75
 76
 677        if (!string.IsNullOrEmpty(controller.lastPrivateMessageReceivedSender) && text == "/r ")
 78        {
 179            chatHudView.inputField.text = $"/w {controller.lastPrivateMessageReceivedSender} ";
 180            chatHudView.inputField.MoveTextEnd(false);
 81        }
 682    }
 83
 84    public void ChatHUDView_OnSendMessage(ChatMessage message)
 85    {
 286        if (message.messageType == ChatMessage.Type.PRIVATE && !string.IsNullOrEmpty(message.body))
 287            lastWhisperMessageSent = message;
 88        else
 089            lastWhisperMessageSent = null;
 90
 291        if (lastWhisperMessageSent != null)
 292            StartCoroutine(WaitAndUpdateInputText($"/w {lastWhisperMessageSent.recipient} "));
 93        else
 094            StartCoroutine(WaitAndUpdateInputText(string.Empty));
 95
 296        OnSendMessage?.Invoke(message);
 297    }
 98
 99    IEnumerator WaitAndUpdateInputText(string newText)
 100    {
 2101        yield return null;
 102
 2103        chatHudView.inputField.text = newText;
 2104        chatHudView.inputField.caretPosition = newText.Length;
 2105    }
 106}