< Summary

Class:WorldChatWindowHUDView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowHUDView.cs
Covered lines:39
Uncovered lines:8
Coverable lines:47
Total lines:110
Line coverage:82.9% (39 of 47)
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.012087.5%
ActivatePreview()0%2.012085.71%
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;
 7using DCL;
 8
 9public class WorldChatWindowHUDView : MonoBehaviour, IPointerClickHandler
 10{
 11    const string VIEW_PATH = "World Chat Window";
 12
 13    public Button closeButton;
 14
 15    public ChatHUDView chatHudView;
 16
 17    public CanvasGroup group;
 18    public WorldChatWindowHUDController controller;
 019    public bool isInPreview { get; private set; }
 20
 21    public event UnityAction OnDeactivatePreview;
 22    public event UnityAction OnActivatePreview;
 23    public event UnityAction OnClose;
 24    public UnityAction<ChatMessage> OnSendMessage;
 25
 26    ChatMessage lastWhisperMessageSent;
 1127    string lastInputText = string.Empty;
 28
 29    public static WorldChatWindowHUDView Create()
 30    {
 1031        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<WorldChatWindowHUDView>();
 1032        view.Initialize();
 1033        return view;
 34    }
 35
 36    void Awake()
 37    {
 1038        chatHudView.OnSendMessage += ChatHUDView_OnSendMessage;
 1039        chatHudView.inputField.onValueChanged.AddListener(OnTextInputValueChanged);
 1040    }
 41
 2042    private void Initialize() { this.closeButton.onClick.AddListener(OnCloseButtonPressed); }
 43
 44    public void OnCloseButtonPressed()
 45    {
 146        controller.SetVisibility(false);
 147        OnClose?.Invoke();
 048    }
 49
 50    public void DeactivatePreview()
 51    {
 652        chatHudView.scrollRect.enabled = true;
 653        group.alpha = 1;
 654        DataStore.i.HUDs.chatInputVisible.Set(true);
 655        isInPreview = false;
 656        chatHudView.SetFadeoutMode(false);
 657        chatHudView.SetGotoPanelStatus(false);
 658        OnDeactivatePreview?.Invoke();
 059    }
 60
 61    public void ActivatePreview()
 62    {
 363        chatHudView.scrollRect.enabled = false;
 364        group.alpha = 0;
 365        DataStore.i.HUDs.chatInputVisible.Set(false);
 366        isInPreview = true;
 367        chatHudView.SetFadeoutMode(true);
 368        OnActivatePreview?.Invoke();
 069    }
 70
 071    public void OnPointerClick(PointerEventData eventData) { DeactivatePreview(); }
 72
 73    public void OnTextInputValueChanged(string text)
 74    {
 675        if (isInPreview)
 076            chatHudView.inputField.text = lastInputText;
 77        else
 678            lastInputText = chatHudView.inputField.text;
 79
 80
 681        if (!string.IsNullOrEmpty(controller.lastPrivateMessageReceivedSender) && text == "/r ")
 82        {
 183            chatHudView.inputField.text = $"/w {controller.lastPrivateMessageReceivedSender} ";
 184            chatHudView.inputField.MoveTextEnd(false);
 85        }
 686    }
 87
 88    public void ChatHUDView_OnSendMessage(ChatMessage message)
 89    {
 290        if (message.messageType == ChatMessage.Type.PRIVATE && !string.IsNullOrEmpty(message.body))
 291            lastWhisperMessageSent = message;
 92        else
 093            lastWhisperMessageSent = null;
 94
 295        if (lastWhisperMessageSent != null)
 296            StartCoroutine(WaitAndUpdateInputText($"/w {lastWhisperMessageSent.recipient} "));
 97        else
 098            StartCoroutine(WaitAndUpdateInputText(string.Empty));
 99
 2100        OnSendMessage?.Invoke(message);
 2101    }
 102
 103    IEnumerator WaitAndUpdateInputText(string newText)
 104    {
 2105        yield return null;
 106
 2107        chatHudView.inputField.text = newText;
 2108        chatHudView.inputField.caretPosition = newText.Length;
 2109    }
 110}