| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | | using System; |
| | 7 | |
|
| | 8 | | public class BIWInputHandler : BIWController |
| | 9 | | { |
| | 10 | | [Header("Design variables")] |
| 198 | 11 | | public float msBetweenInputInteraction = 200; |
| | 12 | |
|
| | 13 | | [Header("References")] |
| | 14 | | public BuilderInWorldController builderInWorldController; |
| | 15 | | public ActionController actionController; |
| | 16 | | public BIWModeController biwModeController; |
| | 17 | | public BuilderInWorldInputWrapper builderInputWrapper; |
| | 18 | | public BIWOutlinerController outlinerController; |
| | 19 | | public BuilderInWorldEntityHandler builderInWorldEntityHandler; |
| | 20 | |
|
| | 21 | | [Header("InputActions")] |
| | 22 | | [SerializeField] |
| | 23 | | internal InputAction_Trigger editModeChangeInputAction; |
| | 24 | |
|
| | 25 | | [SerializeField] |
| | 26 | | internal InputAction_Trigger toggleRedoActionInputAction; |
| | 27 | |
|
| | 28 | | [SerializeField] |
| | 29 | | internal InputAction_Trigger toggleUndoActionInputAction; |
| | 30 | |
|
| | 31 | | [SerializeField] |
| | 32 | | internal InputAction_Hold multiSelectionInputAction; |
| | 33 | |
|
| | 34 | | private InputAction_Hold.Started multiSelectionStartDelegate; |
| | 35 | | private InputAction_Hold.Finished multiSelectionFinishedDelegate; |
| | 36 | |
|
| | 37 | | private InputAction_Trigger.Triggered redoDelegate; |
| | 38 | | private InputAction_Trigger.Triggered undoDelegate; |
| | 39 | |
|
| | 40 | | private bool isMultiSelectionActive = false; |
| | 41 | |
|
| | 42 | | private float nexTimeToReceiveInput; |
| | 43 | |
|
| | 44 | | void Start() |
| | 45 | | { |
| 0 | 46 | | editModeChangeInputAction.OnTriggered += OnEditModeChangeAction; |
| | 47 | |
|
| 0 | 48 | | redoDelegate = (action) => RedoAction(); |
| 0 | 49 | | undoDelegate = (action) => UndoAction(); |
| | 50 | |
|
| 0 | 51 | | toggleRedoActionInputAction.OnTriggered += redoDelegate; |
| 0 | 52 | | toggleUndoActionInputAction.OnTriggered += undoDelegate; |
| | 53 | |
|
| 0 | 54 | | multiSelectionStartDelegate = (action) => StartMultiSelection(); |
| 0 | 55 | | multiSelectionFinishedDelegate = (action) => EndMultiSelection(); |
| | 56 | |
|
| 0 | 57 | | BuilderInWorldInputWrapper.OnMouseClick += MouseClick; |
| 0 | 58 | | BuilderInWorldInputWrapper.OnMouseClickOnUI += MouseClickOnUI; |
| 0 | 59 | | biwModeController.OnInputDone += InputDone; |
| | 60 | |
|
| 0 | 61 | | multiSelectionInputAction.OnStarted += multiSelectionStartDelegate; |
| 0 | 62 | | multiSelectionInputAction.OnFinished += multiSelectionFinishedDelegate; |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | private void OnDestroy() |
| | 66 | | { |
| 0 | 67 | | editModeChangeInputAction.OnTriggered -= OnEditModeChangeAction; |
| | 68 | |
|
| 0 | 69 | | toggleRedoActionInputAction.OnTriggered -= redoDelegate; |
| 0 | 70 | | toggleUndoActionInputAction.OnTriggered -= undoDelegate; |
| | 71 | |
|
| 0 | 72 | | multiSelectionInputAction.OnStarted -= multiSelectionStartDelegate; |
| 0 | 73 | | multiSelectionInputAction.OnFinished -= multiSelectionFinishedDelegate; |
| | 74 | |
|
| 0 | 75 | | BuilderInWorldInputWrapper.OnMouseClick -= MouseClick; |
| 0 | 76 | | BuilderInWorldInputWrapper.OnMouseClickOnUI -= MouseClickOnUI; |
| 0 | 77 | | biwModeController.OnInputDone -= InputDone; |
| 0 | 78 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 79 | | { |
| 0 | 80 | | HUDController.i.builderInWorldMainHud.OnStopInput -= StopInput; |
| 0 | 81 | | HUDController.i.builderInWorldMainHud.OnResumeInput -= ResumeInput; |
| | 82 | | } |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | public override void Init() |
| | 86 | | { |
| 9 | 87 | | base.Init(); |
| 9 | 88 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 89 | | { |
| 0 | 90 | | HUDController.i.builderInWorldMainHud.OnStopInput += StopInput; |
| 0 | 91 | | HUDController.i.builderInWorldMainHud.OnResumeInput += ResumeInput; |
| | 92 | | } |
| 9 | 93 | | } |
| | 94 | |
|
| | 95 | | protected override void FrameUpdate() |
| | 96 | | { |
| 0 | 97 | | base.FrameUpdate(); |
| | 98 | |
|
| 0 | 99 | | if (Time.timeSinceLevelLoad < nexTimeToReceiveInput) |
| 0 | 100 | | return; |
| | 101 | |
|
| 0 | 102 | | if (Utils.isCursorLocked || biwModeController.IsGodModeActive()) |
| 0 | 103 | | CheckEditModeInput(); |
| 0 | 104 | | biwModeController.CheckInput(); |
| 0 | 105 | | } |
| | 106 | |
|
| | 107 | | public override void EnterEditMode(ParcelScene scene) |
| | 108 | | { |
| 0 | 109 | | base.EnterEditMode(scene); |
| 0 | 110 | | builderInputWrapper.gameObject.SetActive(true); |
| 0 | 111 | | } |
| | 112 | |
|
| | 113 | | public override void ExitEditMode() |
| | 114 | | { |
| 0 | 115 | | base.ExitEditMode(); |
| 0 | 116 | | builderInputWrapper.gameObject.SetActive(false); |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | private void CheckEditModeInput() |
| | 120 | | { |
| 0 | 121 | | outlinerController.CheckOutline(); |
| | 122 | |
|
| 0 | 123 | | if (builderInWorldEntityHandler.IsAnyEntitySelected()) |
| | 124 | | { |
| 0 | 125 | | biwModeController.CheckInputSelectedEntities(); |
| | 126 | | } |
| 0 | 127 | | } |
| | 128 | |
|
| | 129 | | private void StartMultiSelection() |
| | 130 | | { |
| 0 | 131 | | isMultiSelectionActive = true; |
| 0 | 132 | | builderInWorldEntityHandler.SetMultiSelectionActive(isMultiSelectionActive); |
| 0 | 133 | | Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); |
| 0 | 134 | | biwModeController.StartMultiSelection(); |
| 0 | 135 | | } |
| | 136 | |
|
| | 137 | | private void EndMultiSelection() |
| | 138 | | { |
| 0 | 139 | | isMultiSelectionActive = false; |
| 0 | 140 | | builderInWorldEntityHandler.SetMultiSelectionActive(isMultiSelectionActive); |
| 0 | 141 | | biwModeController.EndMultiSelection(); |
| 0 | 142 | | outlinerController.CancelUnselectedOutlines(); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | private void MouseClick(int buttonID, Vector3 position) |
| | 146 | | { |
| 0 | 147 | | if (!isEditModeActive) |
| 0 | 148 | | return; |
| | 149 | |
|
| 0 | 150 | | if (Time.timeSinceLevelLoad < nexTimeToReceiveInput) |
| 0 | 151 | | return; |
| | 152 | |
|
| 0 | 153 | | if (!BuilderInWorldUtils.IsPointerOverUIElement()) |
| 0 | 154 | | HUDController.i.builderInWorldMainHud.HideExtraBtns(); |
| | 155 | |
|
| 0 | 156 | | if (Utils.isCursorLocked || biwModeController.IsGodModeActive()) |
| | 157 | | { |
| 0 | 158 | | if (buttonID == 0) |
| | 159 | | { |
| 0 | 160 | | MouseClickDetected(); |
| 0 | 161 | | InputDone(); |
| 0 | 162 | | return; |
| | 163 | | } |
| 0 | 164 | | outlinerController.CheckOutline(); |
| | 165 | | } |
| 0 | 166 | | } |
| | 167 | |
|
| 0 | 168 | | private void MouseClickOnUI(int buttonID, Vector3 position) { HUDController.i.builderInWorldMainHud.HideExtraBtns(); |
| | 169 | |
|
| 0 | 170 | | public bool IsMultiSelectionActive() => isMultiSelectionActive; |
| | 171 | |
|
| 0 | 172 | | private void OnEditModeChangeAction(DCLAction_Trigger action) { builderInWorldController.ChangeEditModeStatusByShort |
| | 173 | |
|
| | 174 | | private void RedoAction() |
| | 175 | | { |
| 0 | 176 | | actionController.TryToRedoAction(); |
| 0 | 177 | | InputDone(); |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | private void UndoAction() |
| | 181 | | { |
| 0 | 182 | | InputDone(); |
| | 183 | |
|
| 0 | 184 | | if (biwModeController.ShouldCancelUndoAction()) |
| 0 | 185 | | return; |
| | 186 | |
|
| 0 | 187 | | actionController.TryToUndoAction(); |
| 0 | 188 | | } |
| | 189 | |
|
| 0 | 190 | | private void MouseClickDetected() { biwModeController.MouseClickDetected(); } |
| | 191 | |
|
| 0 | 192 | | private void InputDone() { nexTimeToReceiveInput = Time.timeSinceLevelLoad + msBetweenInputInteraction / 1000; } |
| | 193 | |
|
| 0 | 194 | | private void StopInput() { builderInputWrapper.StopInput(); } |
| | 195 | |
|
| 0 | 196 | | private void ResumeInput() { builderInputWrapper.ResumeInput(); } |
| | 197 | | } |