< Summary

Class:SceneInfoView
Assembly:ExploreHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ExploreHUD/Scripts/HighlightScenes/SceneInfoView.cs
Covered lines:19
Uncovered lines:55
Coverable lines:74
Total lines:166
Line coverage:25.6% (19 of 74)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Show()0%6200%
Show(...)0%2100%
Hide()0%2100%
Hide(...)0%6200%
SetSceneView(...)0%12300%
SetMapInfoData(...)0%2100%
SetThumbnail(...)0%2100%
Awake()0%110100%
OnDestroy()0%110100%
Update()0%6200%
OnHidden(...)0%2100%
OnInfoButtonPointerDown(...)0%12300%
OnInfoButtonPointerExit()0%2100%
OnPointerEnter()0%2100%
OnPointerExit()0%2100%
OnJumpIn(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ExploreHUD/Scripts/HighlightScenes/SceneInfoView.cs

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.UI;
 3using TMPro;
 4
 5internal class SceneInfoView : MonoBehaviour
 6{
 7    [SerializeField] float idleTime;
 8    [SerializeField] RawImageFillParent thumbnail;
 9    [SerializeField] TextMeshProUGUI sceneName;
 10    [SerializeField] TextMeshProUGUI coordinates;
 11    [SerializeField] TextMeshProUGUI creatorName;
 12    [SerializeField] TextMeshProUGUI description;
 13    [SerializeField] Button_OnPointerDown jumpIn;
 14    [SerializeField] ShowHideAnimator showHideAnimator;
 15    [SerializeField] UIHoverCallback hoverArea;
 16    [SerializeField] GameObject loadingSpinner;
 17
 18    private float timer;
 19    private RectTransform thisRT;
 20    private RectTransform parentRT;
 21    private HotSceneCellView baseSceneView;
 22
 23    public void Show()
 24    {
 025        if (!gameObject.activeSelf)
 26        {
 027            gameObject.SetActive(true);
 28
 029            AudioScriptableObjects.dialogOpen.Play(true);
 30        }
 031        showHideAnimator.Show();
 032        this.enabled = false;
 033    }
 34
 35    public void Show(Vector2 position)
 36    {
 037        thisRT.anchoredPosition = position;
 038        Show();
 039    }
 40
 041    public void Hide() { Hide(false); }
 42
 43    public void Hide(bool instant)
 44    {
 045        if (instant)
 46        {
 047            showHideAnimator.Hide(true);
 48
 049            AudioScriptableObjects.dialogClose.Play(true);
 050        }
 51        else
 52        {
 053            timer = idleTime;
 054            this.enabled = true;
 55        }
 056    }
 57
 58    void SetSceneView(HotSceneCellView sceneView)
 59    {
 060        if (baseSceneView)
 61        {
 062            baseSceneView.OnThumbnailSet -= SetThumbnail;
 63        }
 64
 065        baseSceneView = sceneView;
 66
 067        SetMapInfoData(sceneView.mapInfoHandler);
 68
 069        thumbnail.texture = sceneView.thumbnailHandler.texture;
 070        bool hasThumbnail = thumbnail.texture != null;
 071        loadingSpinner.SetActive(!hasThumbnail);
 072        if (!hasThumbnail)
 73        {
 074            sceneView.OnThumbnailSet += SetThumbnail;
 75        }
 076    }
 77
 78    void SetMapInfoData(IMapDataView mapInfoView)
 79    {
 080        sceneName.text = mapInfoView.name;
 081        coordinates.text = $"{mapInfoView.baseCoord.x},{mapInfoView.baseCoord.y}";
 082        creatorName.text = mapInfoView.creator;
 083        description.text = mapInfoView.description;
 084    }
 85
 86    void SetThumbnail(Texture2D thumbnailTexture)
 87    {
 088        thumbnail.texture = thumbnailTexture;
 089        loadingSpinner.SetActive(thumbnailTexture != null);
 090    }
 91
 92    void Awake()
 93    {
 494        thisRT = (RectTransform)transform;
 495        parentRT = (RectTransform)transform.parent;
 96
 497        this.enabled = false;
 498        gameObject.SetActive(false);
 99
 4100        jumpIn.onPointerDown += () =>
 101        {
 0102            if (baseSceneView)
 103            {
 0104                baseSceneView.JumpInPressed();
 105            }
 0106        };
 107
 4108        hoverArea.OnPointerEnter += OnPointerEnter;
 4109        hoverArea.OnPointerExit += OnPointerExit;
 110
 4111        HotSceneCellView.OnInfoButtonPointerDown += OnInfoButtonPointerDown;
 4112        HotSceneCellView.OnInfoButtonPointerExit += OnInfoButtonPointerExit;
 4113        HotSceneCellView.OnJumpIn += OnJumpIn;
 114
 4115        showHideAnimator.OnWillFinishHide += OnHidden;
 4116    }
 117
 118    void OnDestroy()
 119    {
 4120        hoverArea.OnPointerEnter -= OnPointerEnter;
 4121        hoverArea.OnPointerExit -= OnPointerExit;
 122
 4123        HotSceneCellView.OnInfoButtonPointerDown -= OnInfoButtonPointerDown;
 4124        HotSceneCellView.OnInfoButtonPointerExit -= OnInfoButtonPointerExit;
 4125        HotSceneCellView.OnJumpIn -= OnJumpIn;
 126
 4127        showHideAnimator.OnWillFinishHide -= OnHidden;
 4128    }
 129
 130    void Update()
 131    {
 0132        timer -= Time.deltaTime;
 0133        if (timer <= 0)
 134        {
 0135            showHideAnimator.Hide();
 0136            this.enabled = false;
 137
 0138            AudioScriptableObjects.dialogClose.Play(true);
 139        }
 0140    }
 141
 0142    void OnHidden(ShowHideAnimator animator) { baseSceneView = null; }
 143
 144    void OnInfoButtonPointerDown(HotSceneCellView sceneView)
 145    {
 0146        if (sceneView == baseSceneView)
 0147            return;
 148
 149
 0150        SetSceneView(sceneView);
 151
 152        Vector2 localpoint;
 0153        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRT, Input.mousePosition, null, out localpoint)
 154        {
 0155            Show(localpoint);
 156        }
 0157    }
 158
 0159    void OnInfoButtonPointerExit() { Hide(); }
 160
 0161    void OnPointerEnter() { Show(); }
 162
 0163    void OnPointerExit() { Hide(); }
 164
 0165    void OnJumpIn(Vector2Int coords, string serverName, string layerName) { gameObject.SetActive(false); }
 166}