< Summary

Class:TopActionsButtonsView
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/GodMode/TopActionsButtons/TopActionsButtonsView.cs
Covered lines:121
Uncovered lines:25
Coverable lines:146
Total lines:394
Line coverage:82.8% (121 of 146)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TopActionsButtonsView()0%110100%
Create()0%110100%
Awake()0%110100%
OnDestroy()0%220100%
ConfigureExtraActions(...)0%110100%
OnChangeModeClick(...)0%220100%
OnExtraClick(...)0%220100%
OnTranslateClick(...)0%220100%
OnSnapModeClick(...)0%6200%
SetSnapActive(...)0%330100%
SetGizmosActive(...)0%550100%
SetActionsInteractable(...)0%110100%
SetUndoInteractable(...)0%2100%
SetRedoInteractable(...)0%2100%
OnRotateClick(...)0%220100%
OnScaleClick(...)0%220100%
OnUndoClick()0%220100%
OnRedoClick()0%220100%
OnDuplicateClick(...)0%220100%
OnDeleteClick(...)0%220100%
OnLogOutClick(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/GodMode/TopActionsButtons/TopActionsButtonsView.cs

#LineLine coverage
 1using System;
 2using DCL.Configuration;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7public interface ITopActionsButtonsView
 8{
 9    event Action OnChangeModeClicked,
 10                 OnExtraClicked,
 11                 OnTranslateClicked,
 12                 OnRotateClicked,
 13                 OnScaleClicked,
 14                 OnUndoClicked,
 15                 OnRedoClicked,
 16                 OnDuplicateClicked,
 17                 OnDeleteClicked,
 18                 OnLogOutClicked,
 19                 OnSnapModeClicked,
 20                 OnPointerExit;
 21
 22    event Action<BaseEventData, string> OnChangeCameraModePointerEnter,
 23                                        OnTranslatePointerEnter,
 24                                        OnRotatePointerEnter,
 25                                        OnScalePointerEnter,
 26                                        OnUndoPointerEnter,
 27                                        OnRedoPointerEnter,
 28                                        OnDuplicatePointerEnter,
 29                                        OnDeletePointerEnter,
 30                                        OnMoreActionsPointerEnter,
 31                                        OnLogoutPointerEnter,
 32                                        OnSnapModePointerEnter;
 33
 34    void ConfigureExtraActions(IExtraActionsController extraActionsController);
 35    void OnChangeModeClick(DCLAction_Trigger action);
 36    void OnDeleteClick(DCLAction_Trigger action);
 37    void OnDuplicateClick(DCLAction_Trigger action);
 38    void OnExtraClick(DCLAction_Trigger action);
 39    void OnLogOutClick(DCLAction_Trigger action);
 40    void OnRotateClick(DCLAction_Trigger action);
 41    void OnScaleClick(DCLAction_Trigger action);
 42    void OnTranslateClick(DCLAction_Trigger action);
 43    void SetGizmosActive(string gizmos);
 44    void SetActionsInteractable(bool isActive);
 45    void SetUndoInteractable(bool isActive);
 46    void SetRedoInteractable(bool isActive);
 47    void SetSnapActive(bool isActive);
 48}
 49
 50public class TopActionsButtonsView : MonoBehaviour, ITopActionsButtonsView
 51{
 52    public event Action OnChangeModeClicked,
 53                        OnExtraClicked,
 54                        OnTranslateClicked,
 55                        OnRotateClicked,
 56                        OnScaleClicked,
 57                        OnUndoClicked,
 58                        OnRedoClicked,
 59                        OnDuplicateClicked,
 60                        OnDeleteClicked,
 61                        OnLogOutClicked,
 62                        OnSnapModeClicked,
 63                        OnPointerExit;
 64
 65    public event Action<BaseEventData, string> OnChangeCameraModePointerEnter,
 66                                               OnTranslatePointerEnter,
 67                                               OnRotatePointerEnter,
 68                                               OnScalePointerEnter,
 69                                               OnUndoPointerEnter,
 70                                               OnRedoPointerEnter,
 71                                               OnDuplicatePointerEnter,
 72                                               OnDeletePointerEnter,
 73                                               OnMoreActionsPointerEnter,
 74                                               OnLogoutPointerEnter,
 75                                               OnSnapModePointerEnter;
 76
 77    [Header("Buttons")]
 78    [SerializeField] internal Button changeModeBtn;
 79
 80    [SerializeField] internal Button extraBtn;
 81    [SerializeField] internal Button translateBtn;
 82    [SerializeField] internal Button rotateBtn;
 83    [SerializeField] internal Button scaleBtn;
 84    [SerializeField] internal Button undoBtn;
 85    [SerializeField] internal Button redoBtn;
 86    [SerializeField] internal Button duplicateBtn;
 87    [SerializeField] internal Button deleteBtn;
 88    [SerializeField] internal Button logOutBtn;
 89    [SerializeField] internal Button snapModeBtn;
 90
 91    [Header("Input Actions")]
 92    [SerializeField] internal InputAction_Trigger toggleChangeCameraInputAction;
 93
 94    [SerializeField] internal InputAction_Trigger toggleTranslateInputAction;
 95    [SerializeField] internal InputAction_Trigger toggleRotateInputAction;
 96    [SerializeField] internal InputAction_Trigger toggleScaleInputAction;
 97    [SerializeField] internal InputAction_Trigger toggleDuplicateInputAction;
 98    [SerializeField] internal InputAction_Trigger toggleDeleteInputAction;
 99
 100    [Header("Event Triggers")]
 101    [SerializeField] internal EventTrigger changeCameraModeEventTrigger;
 102
 103    [SerializeField] internal EventTrigger translateEventTrigger;
 104    [SerializeField] internal EventTrigger rotateEventTrigger;
 105    [SerializeField] internal EventTrigger scaleEventTrigger;
 106    [SerializeField] internal EventTrigger undoEventTrigger;
 107    [SerializeField] internal EventTrigger redoEventTrigger;
 108    [SerializeField] internal EventTrigger duplicateEventTrigger;
 109    [SerializeField] internal EventTrigger deleteEventTrigger;
 110    [SerializeField] internal EventTrigger moreActionsEventTrigger;
 111    [SerializeField] internal EventTrigger logoutEventTrigger;
 112    [SerializeField] internal EventTrigger snapModeEventTrigger;
 113
 114    [Header("Tooltip Texts")]
 40115    [SerializeField] internal string changeCameraModeTooltipText = "Change Camera (V)";
 116
 40117    [SerializeField] internal string translateTooltipText = "Translate (M)";
 40118    [SerializeField] internal string rotateTooltipText = "Rotate (R)";
 40119    [SerializeField] internal string scaleTooltipText = "Scale (G)";
 40120    [SerializeField] internal string undoTooltipText = "Undo (Shift+Z)";
 40121    [SerializeField] internal string redoTooltipText = "Redo (Shift+Y)";
 40122    [SerializeField] internal string duplicateTooltipText = "Duplicate (Shift+D)";
 40123    [SerializeField] internal string deleteTooltipText = "Delete (Del) or (Backspace)";
 40124    [SerializeField] internal string moreActionsTooltipText = "Extra Actions";
 40125    [SerializeField] internal string logoutTooltipText = "Exit from edition";
 40126    [SerializeField] internal string snapModeTooltipText = "Toggle Snapping (O)";
 127
 128    [Header("Sub-Views")]
 129    [SerializeField] internal ExtraActionsView extraActionsView;
 130
 131    [Header("Images")]
 132    [SerializeField] internal Image translateGizmosBtnImg;
 133
 134    [SerializeField] internal Image rotateGizmosBtnImg;
 135    [SerializeField] internal Image scaleGizmosBtnImg;
 136    [SerializeField] internal Image snapModeBtnImg;
 137
 138    [Header("Colors")]
 139    [SerializeField] internal Color normalBtnImgColor;
 140
 141    [SerializeField] internal Color selectedBtnImgColor;
 142
 143    private DCLAction_Trigger dummyActionTrigger = new DCLAction_Trigger();
 144    internal IExtraActionsController extraActionsController;
 145
 146    private const string VIEW_PATH = "GodMode/TopActionsButtons/TopActionsButtonsView";
 147
 148    internal static TopActionsButtonsView Create()
 149    {
 19150        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<TopActionsButtonsView>();
 19151        view.gameObject.name = "_TopActionsButtonsView";
 152
 19153        return view;
 154    }
 155
 156    private void Awake()
 157    {
 38158        changeModeBtn.onClick.AddListener(() => OnChangeModeClick(dummyActionTrigger));
 38159        translateBtn.onClick.AddListener(() => OnTranslateClick(dummyActionTrigger));
 38160        rotateBtn.onClick.AddListener(() => OnRotateClick(dummyActionTrigger));
 38161        scaleBtn.onClick.AddListener(() => OnScaleClick(dummyActionTrigger));
 38162        undoBtn.onClick.AddListener(OnUndoClick);
 38163        redoBtn.onClick.AddListener(OnRedoClick);
 38164        duplicateBtn.onClick.AddListener(() => OnDuplicateClick(dummyActionTrigger));
 38165        deleteBtn.onClick.AddListener(() => OnDeleteClick(dummyActionTrigger));
 38166        logOutBtn.onClick.AddListener(() => OnLogOutClick(dummyActionTrigger));
 38167        extraBtn.onClick.AddListener(() => OnExtraClick(dummyActionTrigger));
 38168        snapModeBtn.onClick.AddListener(() => OnSnapModeClick(dummyActionTrigger));
 169
 38170        BIWUtils.ConfigureEventTrigger(
 171            changeCameraModeEventTrigger,
 172            EventTriggerType.PointerEnter,
 0173            (eventData) => OnChangeCameraModePointerEnter?.Invoke(eventData, changeCameraModeTooltipText));
 174
 38175        BIWUtils.ConfigureEventTrigger(
 176            changeCameraModeEventTrigger,
 177            EventTriggerType.PointerExit,
 0178            (eventData) => OnPointerExit?.Invoke());
 179
 38180        BIWUtils.ConfigureEventTrigger(
 181            translateEventTrigger,
 182            EventTriggerType.PointerEnter,
 0183            (eventData) => OnTranslatePointerEnter?.Invoke(eventData, translateTooltipText));
 184
 38185        BIWUtils.ConfigureEventTrigger(
 186            translateEventTrigger,
 187            EventTriggerType.PointerExit,
 0188            (eventData) => OnPointerExit?.Invoke());
 189
 38190        BIWUtils.ConfigureEventTrigger(
 191            rotateEventTrigger,
 192            EventTriggerType.PointerEnter,
 0193            (eventData) => OnRotatePointerEnter?.Invoke(eventData, rotateTooltipText));
 194
 38195        BIWUtils.ConfigureEventTrigger(
 196            rotateEventTrigger,
 197            EventTriggerType.PointerExit,
 0198            (eventData) => OnPointerExit?.Invoke());
 199
 38200        BIWUtils.ConfigureEventTrigger(
 201            scaleEventTrigger,
 202            EventTriggerType.PointerEnter,
 0203            (eventData) => OnScalePointerEnter?.Invoke(eventData, scaleTooltipText));
 204
 38205        BIWUtils.ConfigureEventTrigger(
 206            scaleEventTrigger,
 207            EventTriggerType.PointerExit,
 0208            (eventData) => OnPointerExit?.Invoke());
 209
 38210        BIWUtils.ConfigureEventTrigger(
 211            undoEventTrigger,
 212            EventTriggerType.PointerEnter,
 0213            (eventData) => OnUndoPointerEnter?.Invoke(eventData, undoTooltipText));
 214
 38215        BIWUtils.ConfigureEventTrigger(
 216            undoEventTrigger,
 217            EventTriggerType.PointerExit,
 0218            (eventData) => OnPointerExit?.Invoke());
 219
 38220        BIWUtils.ConfigureEventTrigger(
 221            redoEventTrigger,
 222            EventTriggerType.PointerEnter,
 0223            (eventData) => OnRedoPointerEnter?.Invoke(eventData, redoTooltipText));
 224
 38225        BIWUtils.ConfigureEventTrigger(
 226            redoEventTrigger,
 227            EventTriggerType.PointerExit,
 0228            (eventData) => OnPointerExit?.Invoke());
 229
 38230        BIWUtils.ConfigureEventTrigger(
 231            duplicateEventTrigger,
 232            EventTriggerType.PointerEnter,
 0233            (eventData) => OnDuplicatePointerEnter?.Invoke(eventData, duplicateTooltipText));
 234
 38235        BIWUtils.ConfigureEventTrigger(
 236            duplicateEventTrigger,
 237            EventTriggerType.PointerExit,
 0238            (eventData) => OnPointerExit?.Invoke());
 239
 38240        BIWUtils.ConfigureEventTrigger(
 241            deleteEventTrigger,
 242            EventTriggerType.PointerEnter,
 0243            (eventData) => OnDeletePointerEnter?.Invoke(eventData, deleteTooltipText));
 244
 38245        BIWUtils.ConfigureEventTrigger(
 246            deleteEventTrigger,
 247            EventTriggerType.PointerExit,
 0248            (eventData) => OnPointerExit?.Invoke());
 249
 38250        BIWUtils.ConfigureEventTrigger(
 251            moreActionsEventTrigger,
 252            EventTriggerType.PointerEnter,
 0253            (eventData) => OnMoreActionsPointerEnter?.Invoke(eventData, moreActionsTooltipText));
 254
 38255        BIWUtils.ConfigureEventTrigger(
 256            moreActionsEventTrigger,
 257            EventTriggerType.PointerExit,
 0258            (eventData) => OnPointerExit?.Invoke());
 259
 38260        BIWUtils.ConfigureEventTrigger(
 261            logoutEventTrigger,
 262            EventTriggerType.PointerEnter,
 0263            (eventData) => OnLogoutPointerEnter?.Invoke(eventData, logoutTooltipText));
 264
 38265        BIWUtils.ConfigureEventTrigger(
 266            logoutEventTrigger,
 267            EventTriggerType.PointerExit,
 0268            (eventData) => OnPointerExit?.Invoke());
 269
 38270        BIWUtils.ConfigureEventTrigger(
 271            snapModeEventTrigger,
 272            EventTriggerType.PointerEnter,
 0273            (eventData) => OnSnapModePointerEnter?.Invoke(eventData, snapModeTooltipText));
 274
 38275        BIWUtils.ConfigureEventTrigger(
 276            snapModeEventTrigger,
 277            EventTriggerType.PointerExit,
 0278            (eventData) => OnPointerExit?.Invoke());
 279
 280        //TODO: This should be reactivate when we activate the first person camera
 281        //  toggleChangeCameraInputAction.OnTriggered += OnChangeModeClick;
 38282        toggleTranslateInputAction.OnTriggered += OnTranslateClick;
 38283        toggleRotateInputAction.OnTriggered += OnRotateClick;
 38284        toggleScaleInputAction.OnTriggered += OnScaleClick;
 38285        toggleDuplicateInputAction.OnTriggered += OnDuplicateClick;
 38286        toggleDeleteInputAction.OnTriggered += OnDeleteClick;
 38287    }
 288
 289    private void OnDestroy()
 290    {
 38291        changeModeBtn.onClick.RemoveAllListeners();
 38292        translateBtn.onClick.RemoveAllListeners();
 38293        rotateBtn.onClick.RemoveAllListeners();
 38294        scaleBtn.onClick.RemoveAllListeners();
 38295        undoBtn.onClick.RemoveAllListeners();
 38296        redoBtn.onClick.RemoveAllListeners();
 38297        duplicateBtn.onClick.RemoveAllListeners();
 38298        deleteBtn.onClick.RemoveAllListeners();
 38299        logOutBtn.onClick.RemoveAllListeners();
 38300        extraBtn.onClick.RemoveAllListeners();
 38301        snapModeBtn.onClick.RemoveAllListeners();
 302
 38303        BIWUtils.RemoveEventTrigger(changeCameraModeEventTrigger, EventTriggerType.PointerEnter);
 38304        BIWUtils.RemoveEventTrigger(changeCameraModeEventTrigger, EventTriggerType.PointerExit);
 38305        BIWUtils.RemoveEventTrigger(translateEventTrigger, EventTriggerType.PointerEnter);
 38306        BIWUtils.RemoveEventTrigger(translateEventTrigger, EventTriggerType.PointerExit);
 38307        BIWUtils.RemoveEventTrigger(rotateEventTrigger, EventTriggerType.PointerEnter);
 38308        BIWUtils.RemoveEventTrigger(rotateEventTrigger, EventTriggerType.PointerExit);
 38309        BIWUtils.RemoveEventTrigger(scaleEventTrigger, EventTriggerType.PointerEnter);
 38310        BIWUtils.RemoveEventTrigger(scaleEventTrigger, EventTriggerType.PointerExit);
 38311        BIWUtils.RemoveEventTrigger(undoEventTrigger, EventTriggerType.PointerEnter);
 38312        BIWUtils.RemoveEventTrigger(undoEventTrigger, EventTriggerType.PointerExit);
 38313        BIWUtils.RemoveEventTrigger(redoEventTrigger, EventTriggerType.PointerEnter);
 38314        BIWUtils.RemoveEventTrigger(redoEventTrigger, EventTriggerType.PointerExit);
 38315        BIWUtils.RemoveEventTrigger(duplicateEventTrigger, EventTriggerType.PointerEnter);
 38316        BIWUtils.RemoveEventTrigger(duplicateEventTrigger, EventTriggerType.PointerExit);
 38317        BIWUtils.RemoveEventTrigger(deleteEventTrigger, EventTriggerType.PointerEnter);
 38318        BIWUtils.RemoveEventTrigger(deleteEventTrigger, EventTriggerType.PointerExit);
 38319        BIWUtils.RemoveEventTrigger(moreActionsEventTrigger, EventTriggerType.PointerEnter);
 38320        BIWUtils.RemoveEventTrigger(moreActionsEventTrigger, EventTriggerType.PointerExit);
 38321        BIWUtils.RemoveEventTrigger(logoutEventTrigger, EventTriggerType.PointerEnter);
 38322        BIWUtils.RemoveEventTrigger(logoutEventTrigger, EventTriggerType.PointerExit);
 38323        BIWUtils.RemoveEventTrigger(snapModeEventTrigger, EventTriggerType.PointerEnter);
 38324        BIWUtils.RemoveEventTrigger(snapModeEventTrigger, EventTriggerType.PointerExit);
 325
 38326        toggleChangeCameraInputAction.OnTriggered -= OnChangeModeClick;
 38327        toggleTranslateInputAction.OnTriggered -= OnTranslateClick;
 38328        toggleRotateInputAction.OnTriggered -= OnRotateClick;
 38329        toggleScaleInputAction.OnTriggered -= OnScaleClick;
 38330        toggleDuplicateInputAction.OnTriggered -= OnDuplicateClick;
 38331        toggleDeleteInputAction.OnTriggered -= OnDeleteClick;
 332
 38333        if (extraActionsController != null)
 1334            extraActionsController.Dispose();
 38335    }
 336
 337    public void ConfigureExtraActions(IExtraActionsController extraActionsController)
 338    {
 1339        this.extraActionsController = extraActionsController;
 1340        this.extraActionsController.Initialize(extraActionsView);
 1341    }
 342
 2343    public void OnChangeModeClick(DCLAction_Trigger action) { OnChangeModeClicked?.Invoke(); }
 344
 2345    public void OnExtraClick(DCLAction_Trigger action) { OnExtraClicked?.Invoke(); }
 346
 2347    public void OnTranslateClick(DCLAction_Trigger action) { OnTranslateClicked?.Invoke(); }
 0348    public void OnSnapModeClick(DCLAction_Trigger action) { OnSnapModeClicked?.Invoke(); }
 349
 4350    public void SetSnapActive(bool isActive) { snapModeBtnImg.color = isActive ? selectedBtnImgColor : normalBtnImgColor
 351
 352    public void SetGizmosActive(string gizmos)
 353    {
 4354        translateGizmosBtnImg.color = normalBtnImgColor;
 4355        rotateGizmosBtnImg.color = normalBtnImgColor;
 4356        scaleGizmosBtnImg.color = normalBtnImgColor;
 357
 358        switch (gizmos)
 359        {
 360            case BIWSettings.TRANSLATE_GIZMO_NAME:
 1361                translateGizmosBtnImg.color = selectedBtnImgColor;
 1362                break;
 363            case BIWSettings.ROTATE_GIZMO_NAME:
 1364                rotateGizmosBtnImg.color = selectedBtnImgColor;
 1365                break;
 366            case BIWSettings.SCALE_GIZMO_NAME:
 1367                scaleGizmosBtnImg.color = selectedBtnImgColor;
 368                break;
 369        }
 1370    }
 371
 372    public void SetActionsInteractable(bool isActive)
 373    {
 2374        duplicateBtn.interactable = isActive;
 2375        deleteBtn.interactable = isActive;
 2376    }
 377
 0378    public void SetUndoInteractable(bool isActive) { undoBtn.interactable = isActive; }
 379
 0380    public void SetRedoInteractable(bool isActive) { redoBtn.interactable = isActive; }
 381
 2382    public void OnRotateClick(DCLAction_Trigger action) { OnRotateClicked?.Invoke(); }
 383
 2384    public void OnScaleClick(DCLAction_Trigger action) { OnScaleClicked?.Invoke(); }
 385
 2386    public void OnUndoClick() { OnUndoClicked?.Invoke(); }
 2387    public void OnRedoClick() { OnRedoClicked?.Invoke(); }
 388
 2389    public void OnDuplicateClick(DCLAction_Trigger action) { OnDuplicateClicked?.Invoke(); }
 390
 2391    public void OnDeleteClick(DCLAction_Trigger action) { OnDeleteClicked?.Invoke(); }
 392
 2393    public void OnLogOutClick(DCLAction_Trigger action) { OnLogOutClicked?.Invoke(); }
 394}