| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Linq; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.EventSystems; |
| | 7 | | using DCL.Configuration; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// Mapping for Trigger actions |
| | 11 | | /// </summary> |
| | 12 | | public enum DCLAction_Trigger |
| | 13 | | { |
| | 14 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 15 | | CameraChange = 100, |
| | 16 | | CursorUnlock = 101, |
| | 17 | |
|
| | 18 | | ToggleNavMap = 110, |
| | 19 | | ToggleFriends = 120, |
| | 20 | | CloseWindow = 121, |
| | 21 | | ToggleWorldChat = 122, |
| | 22 | | ToggleUIVisibility = 123, |
| | 23 | | ToggleControlsHud = 124, |
| | 24 | | ToggleSettings = 125, |
| | 25 | | ToggleStartMenu = 126, |
| | 26 | | ToggleVoiceChatRecording = 127, |
| | 27 | | ToggleAvatarEditorHud = 128, |
| | 28 | | ToggleQuestsPanelHud = 129, |
| | 29 | | ToggleAvatarNamesHud = 130, |
| | 30 | | TogglePlacesAndEventsHud = 131, |
| | 31 | |
|
| | 32 | | OpenExpressions = 200, |
| | 33 | | Expression_Wave = 201, |
| | 34 | | Expression_FistPump = 202, |
| | 35 | | Expression_Robot = 203, |
| | 36 | | Expression_RaiseHand = 204, |
| | 37 | | Expression_Clap = 205, |
| | 38 | | Expression_ThrowMoney = 206, |
| | 39 | | Expression_SendKiss = 207, |
| | 40 | | Expression_Dance = 208, |
| | 41 | | Expression_Hohoho = 209, |
| | 42 | | Expression_Snowfall = 210, |
| | 43 | |
|
| | 44 | | //Builder In World 4xx |
| | 45 | | BuildEditModeChange = 408, |
| | 46 | | BuildEditModeToggleUI = 409, |
| | 47 | | BuildEditModeToggleEntityList = 410, |
| | 48 | | BuildEditModeToggleCatalog = 411, |
| | 49 | | BuildEditModeToggleSceneInfo = 412, |
| | 50 | | BuildEditModeToggleChangeCamera = 413, |
| | 51 | | BuildEditModeToggleControls = 414, |
| | 52 | | BuildEditModeToggleSnapMode = 415, |
| | 53 | | BuildEditModeUndoAction = 417, |
| | 54 | | BuildEditModeRedoAction = 418, |
| | 55 | | BuildEditModeQuickBar1 = 419, |
| | 56 | | BuildEditModeQuickBar2 = 420, |
| | 57 | | BuildEditModeQuickBar3 = 421, |
| | 58 | | BuildEditModeQuickBar4 = 422, |
| | 59 | | BuildEditModeQuickBar5 = 423, |
| | 60 | | BuildEditModeQuickBar6 = 424, |
| | 61 | | BuildEditModeQuickBar7 = 425, |
| | 62 | | BuildEditModeQuickBar8 = 426, |
| | 63 | | BuildEditModeQuickBar9 = 427, |
| | 64 | | BuildEditModeDuplicate = 428, |
| | 65 | | BuildEditModeTranslate = 429, |
| | 66 | | BuildEditModeRotate = 430, |
| | 67 | | BuildEditModeScale = 431, |
| | 68 | | BuildEditModeDelete = 434, |
| | 69 | | BuildEditModeFocusSelectedEntities = 435, |
| | 70 | | BuildEditModeReset = 443, |
| | 71 | | BuildEditHideSelectedEntities = 444, |
| | 72 | | BuildEditShowAllEntities = 445, |
| | 73 | | BuildEditModeResetCamera = 446, |
| | 74 | | BuildEditModeZoomIn = 447, |
| | 75 | | BuildEditModeZoomOut = 448 |
| | 76 | | } |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Mapping for hold actions |
| | 80 | | /// </summary> |
| | 81 | | public enum DCLAction_Hold |
| | 82 | | { |
| | 83 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 84 | | Sprint = 1, |
| | 85 | | Jump = 2, |
| | 86 | | ZoomIn = 3, |
| | 87 | | ZoomOut = 4, |
| | 88 | | FreeCameraMode = 101, |
| | 89 | | VoiceChatRecording = 102, |
| | 90 | | DefaultConfirmAction = 300, |
| | 91 | | DefaultCancelAction = 301, |
| | 92 | | BuildEditModeMultiSelection = 432, |
| | 93 | | BuildEditModeSquareMultiSelection = 433, |
| | 94 | | BuildEditModeFirstPersonRotation = 436, |
| | 95 | | BuildEditModeCameraAdvanceFoward = 437, |
| | 96 | | BuildEditModeCameraAdvanceBack = 438, |
| | 97 | | BuildEditModeCameraAdvanceLeft = 439, |
| | 98 | | BuildEditModeCameraAdvanceRight = 440, |
| | 99 | | BuildEditModeCameraAdvanceUp = 441, |
| | 100 | | BuildEditModeCameraAdvanceDown = 442, |
| | 101 | | BuildEditModeCameraPan = 446 |
| | 102 | | } |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// Mapping for measurable actions |
| | 106 | | /// </summary> |
| | 107 | | public enum DCLAction_Measurable |
| | 108 | | { |
| | 109 | | //Remember to explicitly assign the value to each entry so we minimize issues with serialization + conflicts |
| | 110 | | CharacterXAxis = 1, |
| | 111 | | CharacterYAxis = 2, |
| | 112 | | CameraXAxis = 3, |
| | 113 | | CameraYAxis = 4, |
| | 114 | | MouseWheel = 5 |
| | 115 | | } |
| | 116 | |
|
| | 117 | | /// <summary> |
| | 118 | | /// Group of actions currently actived |
| | 119 | | /// </summary> |
| | 120 | | public enum InputTypeMode |
| | 121 | | { |
| | 122 | | OFF, |
| | 123 | | GENERAL, |
| | 124 | | BUILD_MODE_LOADING, |
| | 125 | | BUILD_MODE |
| | 126 | | } |
| | 127 | |
|
| | 128 | | /// <summary> |
| | 129 | | /// Input Controller will map inputs(keys/mouse/axis) to DCL actions, check if they can be triggered (modifiers) and rai |
| | 130 | | /// </summary> |
| | 131 | | public class InputController : MonoBehaviour |
| | 132 | | { |
| 1 | 133 | | public static bool ENABLE_THIRD_PERSON_CAMERA = true; |
| | 134 | |
|
| | 135 | | [Header("General Input")] |
| | 136 | | public InputAction_Trigger[] triggerTimeActions; |
| | 137 | |
|
| | 138 | | public InputAction_Hold[] holdActions; |
| | 139 | | public InputAction_Measurable[] measurableActions; |
| | 140 | |
|
| | 141 | | [Header("BuildMode Input")] |
| | 142 | | public InputAction_Trigger[] builderTriggerTimeActions; |
| | 143 | |
|
| | 144 | | public InputAction_Hold[] builderHoldActions; |
| | 145 | | public InputAction_Trigger[] loadingBuilderTriggerTimeActions; |
| | 146 | |
|
| 5563 | 147 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| 33360 | 148 | | bool allUIHidden => CommonScriptableObjects.allUIHidden.Get(); |
| 598 | 149 | | public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL; |
| | 150 | |
|
| | 151 | | private void Update() |
| | 152 | | { |
| 5563 | 153 | | if (!renderingEnabled) |
| | 154 | | { |
| 1 | 155 | | Stop_Measurable(measurableActions); |
| 1 | 156 | | return; |
| | 157 | | } |
| | 158 | |
|
| 5562 | 159 | | switch (inputTypeMode) |
| | 160 | | { |
| | 161 | | case InputTypeMode.OFF: |
| 0 | 162 | | Stop_Measurable(measurableActions); |
| 0 | 163 | | return; |
| | 164 | | case InputTypeMode.GENERAL: |
| 5560 | 165 | | Update_Trigger(triggerTimeActions); |
| 5560 | 166 | | Update_Hold(holdActions); |
| 5560 | 167 | | Update_Measurable(measurableActions); |
| 5560 | 168 | | break; |
| | 169 | | case InputTypeMode.BUILD_MODE_LOADING: |
| 2 | 170 | | Update_Trigger(loadingBuilderTriggerTimeActions); |
| 2 | 171 | | Stop_Measurable(measurableActions); |
| 2 | 172 | | break; |
| | 173 | | case InputTypeMode.BUILD_MODE: |
| 0 | 174 | | Update_Trigger(builderTriggerTimeActions); |
| 0 | 175 | | Update_Hold(builderHoldActions); |
| 0 | 176 | | Update_Measurable(measurableActions); |
| | 177 | | break; |
| | 178 | | } |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | /// <summary> |
| | 182 | | /// Map the trigger actions to inputs + modifiers and check if their events must be triggered |
| | 183 | | /// </summary> |
| | 184 | | public void Update_Trigger(InputAction_Trigger[] triggerTimeActions) |
| | 185 | | { |
| 278008 | 186 | | for (var i = 0; i < triggerTimeActions.Length; i++) |
| | 187 | | { |
| 133442 | 188 | | var action = triggerTimeActions[i]; |
| | 189 | |
|
| 133442 | 190 | | if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get()) |
| | 191 | | continue; |
| | 192 | |
|
| 133442 | 193 | | switch (action.GetDCLAction()) |
| | 194 | | { |
| | 195 | | case DCLAction_Trigger.CameraChange: |
| 5560 | 196 | | if (CommonScriptableObjects.cameraModeInputLocked.Get()) |
| | 197 | | break; |
| | 198 | |
|
| | 199 | | //Disable until the fine-tuning is ready |
| 5560 | 200 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| 5560 | 201 | | InputProcessor.FromKey(action, KeyCode.V, |
| | 202 | | modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 203 | | break; |
| | 204 | | case DCLAction_Trigger.CursorUnlock: |
| 5560 | 205 | | InputProcessor.FromMouseButtonUp(action, 1, InputProcessor.Modifier.NeedsPointerLocked); |
| | 206 | | #if !WEB_PLATFORM |
| 5560 | 207 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.NeedsPointerLocked |
| | 208 | | #endif |
| 5560 | 209 | | break; |
| | 210 | | case DCLAction_Trigger.ToggleNavMap: |
| 5560 | 211 | | if (allUIHidden) |
| | 212 | | break; |
| 5470 | 213 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5470 | 214 | | break; |
| | 215 | | case DCLAction_Trigger.ToggleFriends: |
| 5560 | 216 | | if (allUIHidden) |
| | 217 | | break; |
| 5470 | 218 | | InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None); |
| 5470 | 219 | | break; |
| | 220 | | case DCLAction_Trigger.ToggleWorldChat: |
| 5560 | 221 | | if (allUIHidden) |
| | 222 | | break; |
| 5470 | 223 | | InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None); |
| 5470 | 224 | | break; |
| | 225 | | case DCLAction_Trigger.ToggleUIVisibility: |
| 5560 | 226 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None); |
| 5560 | 227 | | break; |
| | 228 | | case DCLAction_Trigger.CloseWindow: |
| 5560 | 229 | | if (allUIHidden || DataStore.i.common.isSignUpFlow.Get()) |
| | 230 | | break; |
| 5470 | 231 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None); |
| 5470 | 232 | | break; |
| | 233 | | case DCLAction_Trigger.OpenExpressions: |
| 5560 | 234 | | if (allUIHidden) |
| | 235 | | break; |
| 5470 | 236 | | InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5470 | 237 | | break; |
| | 238 | | case DCLAction_Trigger.ToggleControlsHud: |
| 5560 | 239 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 240 | | break; |
| | 241 | | case DCLAction_Trigger.ToggleSettings: |
| 5560 | 242 | | InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 243 | | break; |
| | 244 | | case DCLAction_Trigger.ToggleStartMenu: |
| 5560 | 245 | | if (allUIHidden) |
| | 246 | | break; |
| 5470 | 247 | | InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.None); |
| 5470 | 248 | | break; |
| | 249 | | case DCLAction_Trigger.TogglePlacesAndEventsHud: |
| 5560 | 250 | | InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 251 | | break; |
| | 252 | | case DCLAction_Trigger.Expression_Wave: |
| 5560 | 253 | | InputProcessor.FromKey(action, KeyCode.Alpha1, |
| | 254 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 255 | | break; |
| | 256 | | case DCLAction_Trigger.Expression_FistPump: |
| 5560 | 257 | | InputProcessor.FromKey(action, KeyCode.Alpha2, |
| | 258 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 259 | | break; |
| | 260 | | case DCLAction_Trigger.Expression_Robot: |
| 5560 | 261 | | InputProcessor.FromKey(action, KeyCode.Alpha3, |
| | 262 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 263 | | break; |
| | 264 | | case DCLAction_Trigger.Expression_RaiseHand: |
| 5560 | 265 | | InputProcessor.FromKey(action, KeyCode.Alpha4, |
| | 266 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 267 | | break; |
| | 268 | | case DCLAction_Trigger.Expression_Clap: |
| 5560 | 269 | | InputProcessor.FromKey(action, KeyCode.Alpha5, |
| | 270 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 271 | | break; |
| | 272 | | case DCLAction_Trigger.Expression_ThrowMoney: |
| 5560 | 273 | | InputProcessor.FromKey(action, KeyCode.Alpha6, |
| | 274 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 275 | | break; |
| | 276 | | case DCLAction_Trigger.Expression_SendKiss: |
| 5560 | 277 | | InputProcessor.FromKey(action, KeyCode.Alpha7, |
| | 278 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 279 | | break; |
| | 280 | | case DCLAction_Trigger.BuildEditModeChange: |
| 5562 | 281 | | InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5562 | 282 | | break; |
| | 283 | | case DCLAction_Trigger.ToggleVoiceChatRecording: |
| 5560 | 284 | | InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 5560 | 285 | | break; |
| | 286 | | case DCLAction_Trigger.ToggleAvatarEditorHud: |
| 5560 | 287 | | InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 288 | | break; |
| | 289 | | case DCLAction_Trigger.BuildEditModeToggleUI: |
| 0 | 290 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 291 | | break; |
| | 292 | | case DCLAction_Trigger.BuildEditModeToggleChangeCamera: |
| 0 | 293 | | InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 294 | | break; |
| | 295 | | case DCLAction_Trigger.BuildEditModeToggleControls: |
| 0 | 296 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 297 | | break; |
| | 298 | | case DCLAction_Trigger.BuildEditModeToggleSnapMode: |
| 0 | 299 | | InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 300 | | break; |
| | 301 | | case DCLAction_Trigger.BuildEditModeRedoAction: |
| 0 | 302 | | InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 303 | | break; |
| | 304 | | case DCLAction_Trigger.BuildEditModeUndoAction: |
| 0 | 305 | | InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 306 | | break; |
| | 307 | | case DCLAction_Trigger.BuildEditModeQuickBar1: |
| 0 | 308 | | InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 309 | | break; |
| | 310 | | case DCLAction_Trigger.BuildEditModeQuickBar2: |
| 0 | 311 | | InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 312 | | break; |
| | 313 | | case DCLAction_Trigger.BuildEditModeQuickBar3: |
| 0 | 314 | | InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 315 | | break; |
| | 316 | | case DCLAction_Trigger.BuildEditModeQuickBar4: |
| 0 | 317 | | InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 318 | | break; |
| | 319 | | case DCLAction_Trigger.BuildEditModeQuickBar5: |
| 0 | 320 | | InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 321 | | break; |
| | 322 | | case DCLAction_Trigger.BuildEditModeQuickBar6: |
| 0 | 323 | | InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 324 | | break; |
| | 325 | | case DCLAction_Trigger.BuildEditModeQuickBar7: |
| 0 | 326 | | InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 327 | | break; |
| | 328 | | case DCLAction_Trigger.BuildEditModeQuickBar8: |
| 0 | 329 | | InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 330 | | break; |
| | 331 | | case DCLAction_Trigger.BuildEditModeQuickBar9: |
| 0 | 332 | | InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 333 | | break; |
| | 334 | | case DCLAction_Trigger.BuildEditModeDelete: |
| 0 | 335 | | InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 336 | | InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput |
| 0 | 337 | | break; |
| | 338 | | case DCLAction_Trigger.BuildEditModeDuplicate: |
| 0 | 339 | | InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 340 | | break; |
| | 341 | | case DCLAction_Trigger.BuildEditModeTranslate: |
| 0 | 342 | | InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 343 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 344 | | break; |
| | 345 | | case DCLAction_Trigger.BuildEditModeRotate: |
| 0 | 346 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 347 | | break; |
| | 348 | | case DCLAction_Trigger.BuildEditModeScale: |
| 0 | 349 | | InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 350 | | break; |
| | 351 | | case DCLAction_Trigger.BuildEditModeFocusSelectedEntities: |
| 0 | 352 | | InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 353 | | break; |
| | 354 | | case DCLAction_Trigger.BuildEditModeReset: |
| 0 | 355 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 356 | | break; |
| | 357 | | case DCLAction_Trigger.BuildEditHideSelectedEntities: |
| 0 | 358 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 0 | 359 | | break; |
| | 360 | | case DCLAction_Trigger.BuildEditShowAllEntities: |
| 0 | 361 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 362 | | break; |
| | 363 | | case DCLAction_Trigger.BuildEditModeResetCamera: |
| 0 | 364 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| 0 | 365 | | break; |
| | 366 | | case DCLAction_Trigger.BuildEditModeZoomIn: |
| 0 | 367 | | InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu |
| 0 | 368 | | break; |
| | 369 | | case DCLAction_Trigger.BuildEditModeZoomOut: |
| 0 | 370 | | InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp |
| 0 | 371 | | break; |
| | 372 | | case DCLAction_Trigger.ToggleQuestsPanelHud: |
| 5560 | 373 | | InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 374 | | break; |
| | 375 | | case DCLAction_Trigger.ToggleAvatarNamesHud: |
| 5560 | 376 | | InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| 5560 | 377 | | break; |
| | 378 | | default: |
| 0 | 379 | | throw new ArgumentOutOfRangeException(); |
| | 380 | | } |
| | 381 | | } |
| 5562 | 382 | | } |
| | 383 | |
|
| | 384 | | /// <summary> |
| | 385 | | /// Map the hold actions to inputs + modifiers and check if their events must be triggered |
| | 386 | | /// </summary> |
| | 387 | | private void Update_Hold(InputAction_Hold[] holdActions) |
| | 388 | | { |
| 111200 | 389 | | for (var i = 0; i < holdActions.Length; i++) |
| | 390 | | { |
| 50040 | 391 | | var action = holdActions[i]; |
| 50040 | 392 | | switch (action.GetDCLAction()) |
| | 393 | | { |
| | 394 | | case DCLAction_Hold.Sprint: |
| 5560 | 395 | | InputProcessor.FromKey(action, InputSettings.WalkButtonKeyCode, |
| | 396 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 397 | | break; |
| | 398 | | case DCLAction_Hold.Jump: |
| 5560 | 399 | | InputProcessor.FromKey(action, InputSettings.JumpButtonKeyCode, |
| | 400 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 401 | | break; |
| | 402 | | case DCLAction_Hold.ZoomIn: |
| 5560 | 403 | | InputProcessor.FromKey(action, KeyCode.KeypadPlus, InputProcessor.Modifier.None); |
| 5560 | 404 | | InputProcessor.FromKey(action, KeyCode.Plus, InputProcessor.Modifier.None); |
| 5560 | 405 | | break; |
| | 406 | | case DCLAction_Hold.ZoomOut: |
| 5560 | 407 | | InputProcessor.FromKey(action, KeyCode.KeypadMinus, InputProcessor.Modifier.None); |
| 5560 | 408 | | InputProcessor.FromKey(action, KeyCode.Minus, InputProcessor.Modifier.None); |
| 5560 | 409 | | break; |
| | 410 | | case DCLAction_Hold.FreeCameraMode: |
| | 411 | | //Disable until the fine-tuning is ready |
| 5560 | 412 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| 5560 | 413 | | InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked); |
| 5560 | 414 | | break; |
| | 415 | | case DCLAction_Hold.VoiceChatRecording: |
| | 416 | | // Push to talk functionality only triggers if no modifier key is pressed |
| 11120 | 417 | | InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null); |
| 11120 | 418 | | break; |
| | 419 | | case DCLAction_Hold.DefaultConfirmAction: |
| 5560 | 420 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None); |
| 5560 | 421 | | break; |
| | 422 | | case DCLAction_Hold.DefaultCancelAction: |
| 5560 | 423 | | InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None); |
| 5560 | 424 | | break; |
| | 425 | | case DCLAction_Hold.BuildEditModeMultiSelection: |
| 0 | 426 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 427 | | break; |
| | 428 | | case DCLAction_Hold.BuildEditModeSquareMultiSelection: |
| 0 | 429 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 430 | | break; |
| | 431 | | case DCLAction_Hold.BuildEditModeFirstPersonRotation: |
| 0 | 432 | | InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 433 | | break; |
| | 434 | | case DCLAction_Hold.BuildEditModeCameraAdvanceFoward: |
| 0 | 435 | | InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 436 | | InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 437 | | break; |
| | 438 | | case DCLAction_Hold.BuildEditModeCameraAdvanceBack: |
| 0 | 439 | | InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 440 | | InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 441 | | break; |
| | 442 | | case DCLAction_Hold.BuildEditModeCameraAdvanceLeft: |
| 0 | 443 | | InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 444 | | InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 445 | | break; |
| | 446 | | case DCLAction_Hold.BuildEditModeCameraAdvanceRight: |
| 0 | 447 | | InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 448 | | InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 449 | | break; |
| | 450 | | case DCLAction_Hold.BuildEditModeCameraAdvanceUp: |
| 0 | 451 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 452 | | break; |
| | 453 | | case DCLAction_Hold.BuildEditModeCameraAdvanceDown: |
| 0 | 454 | | InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 455 | | break; |
| | 456 | | case DCLAction_Hold.BuildEditModeCameraPan: |
| 0 | 457 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| 0 | 458 | | break; |
| | 459 | | default: |
| 0 | 460 | | throw new ArgumentOutOfRangeException(); |
| | 461 | | } |
| | 462 | | } |
| 5560 | 463 | | } |
| | 464 | |
|
| | 465 | | /// <summary> |
| | 466 | | /// Map the measurable actions to inputs + modifiers and check if their events must be triggered |
| | 467 | | /// </summary> |
| | 468 | | private void Update_Measurable(InputAction_Measurable[] measurableActions) |
| | 469 | | { |
| 66720 | 470 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 471 | | { |
| 27800 | 472 | | var action = measurableActions[i]; |
| 27800 | 473 | | switch (action.GetDCLAction()) |
| | 474 | | { |
| | 475 | | case DCLAction_Measurable.CharacterXAxis: |
| 5560 | 476 | | InputProcessor.FromAxis(action, "Horizontal", |
| | 477 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 478 | | break; |
| | 479 | | case DCLAction_Measurable.CharacterYAxis: |
| 5560 | 480 | | InputProcessor.FromAxis(action, "Vertical", |
| | 481 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| 5560 | 482 | | break; |
| | 483 | | case DCLAction_Measurable.CameraXAxis: |
| 5560 | 484 | | InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked); |
| 5560 | 485 | | break; |
| | 486 | | case DCLAction_Measurable.CameraYAxis: |
| 5560 | 487 | | InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked); |
| 5560 | 488 | | break; |
| | 489 | | case DCLAction_Measurable.MouseWheel: |
| 5560 | 490 | | InputProcessor.FromAxis(action, "Mouse ScrollWheel", modifiers: InputProcessor.Modifier.FocusNotInIn |
| 5560 | 491 | | break; |
| | 492 | | default: |
| 0 | 493 | | throw new ArgumentOutOfRangeException(); |
| | 494 | | } |
| | 495 | | } |
| 5560 | 496 | | } |
| | 497 | |
|
| | 498 | | private void Stop_Measurable(InputAction_Measurable[] measurableActions) |
| | 499 | | { |
| 36 | 500 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 501 | | { |
| 15 | 502 | | measurableActions[i].RaiseOnValueChanged(0); |
| | 503 | | } |
| 3 | 504 | | } |
| | 505 | | } |
| | 506 | |
|
| | 507 | | /// <summary> |
| | 508 | | /// Helper class that wraps the processing of inputs and modifiers to trigger actions events |
| | 509 | | /// </summary> |
| | 510 | | public static class InputProcessor |
| | 511 | | { |
| | 512 | | private static readonly KeyCode[] MODIFIER_KEYS = new[] { KeyCode.LeftControl, KeyCode.LeftAlt, KeyCode.LeftShift, K |
| | 513 | |
|
| | 514 | | [Flags] |
| | 515 | | public enum Modifier |
| | 516 | | { |
| | 517 | | //Set the values as bit masks |
| | 518 | | None = 0b0000000, // No modifier needed |
| | 519 | | NeedsPointerLocked = 0b0000001, // The pointer must be locked to the game |
| | 520 | | FocusNotInInput = 0b0000010, // The game focus cannot be in an input field |
| | 521 | | NotInStartMenu = 0b0000100 // The game focus cannot be in full-screen start menu |
| | 522 | | } |
| | 523 | |
|
| | 524 | | /// <summary> |
| | 525 | | /// Check if the modifier keys are pressed |
| | 526 | | /// </summary> |
| | 527 | | /// <param name="modifierKeys"> Keycodes modifiers</param> |
| | 528 | | /// <returns></returns> |
| | 529 | | public static Boolean PassModifierKeys(KeyCode[] modifierKeys) |
| | 530 | | { |
| | 531 | | for (var i = 0; i < MODIFIER_KEYS.Length; i++) |
| | 532 | | { |
| | 533 | | var keyCode = MODIFIER_KEYS[i]; |
| | 534 | | var pressed = Input.GetKey(keyCode); |
| | 535 | | if (modifierKeys == null) |
| | 536 | | { |
| | 537 | | if (pressed) |
| | 538 | | return false; |
| | 539 | | } |
| | 540 | | else |
| | 541 | | { |
| | 542 | | if (modifierKeys.Contains(keyCode) != pressed) |
| | 543 | | return false; |
| | 544 | | } |
| | 545 | | } |
| | 546 | |
|
| | 547 | | return true; |
| | 548 | | } |
| | 549 | |
|
| | 550 | | /// <summary> |
| | 551 | | /// Check if a miscellaneous modifiers are present. These modifiers are related to the meta-state of the application |
| | 552 | | /// they can be anything such as mouse pointer state, where the focus is, camera mode... |
| | 553 | | /// </summary> |
| | 554 | | /// <param name="modifiers"></param> |
| | 555 | | /// <returns></returns> |
| | 556 | | public static bool PassModifiers(Modifier modifiers) |
| | 557 | | { |
| | 558 | | if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.IsCursorLocked) |
| | 559 | | return false; |
| | 560 | |
|
| | 561 | | if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField()) |
| | 562 | | return false; |
| | 563 | |
|
| | 564 | | if (IsModifierSet(modifiers, Modifier.NotInStartMenu) && IsStartMenuVisible()) |
| | 565 | | return false; |
| | 566 | |
|
| | 567 | | return true; |
| | 568 | | } |
| | 569 | |
|
| | 570 | | private static bool IsStartMenuVisible() => DataStore.i.exploreV2.isOpen.Get(); |
| | 571 | |
|
| | 572 | | /// <summary> |
| | 573 | | /// Process an input action mapped to a keyboard key. |
| | 574 | | /// </summary> |
| | 575 | | /// <param name="action">Trigger Action to perform</param> |
| | 576 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 577 | | /// <param name="modifierKeys">KeyCodes required to perform the action</param> |
| | 578 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 579 | | public static void FromKey(InputAction_Trigger action, KeyCode key, KeyCode[] modifierKeys = null, |
| | 580 | | Modifier modifiers = Modifier.None) |
| | 581 | | { |
| | 582 | | if (!PassModifiers(modifiers)) |
| | 583 | | return; |
| | 584 | |
|
| | 585 | | if (!PassModifierKeys(modifierKeys)) |
| | 586 | | return; |
| | 587 | |
|
| | 588 | | if (Input.GetKeyDown(key)) |
| | 589 | | action.RaiseOnTriggered(); |
| | 590 | | } |
| | 591 | |
|
| | 592 | | /// <summary> |
| | 593 | | /// Process an input action mapped to a button. |
| | 594 | | /// </summary> |
| | 595 | | /// <param name="action">Trigger Action to perform</param> |
| | 596 | | /// <param name="mouseButtonIdx">Index of the mouse button mapped to this action</param> |
| | 597 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 598 | | public static void FromMouseButton(InputAction_Trigger action, int mouseButtonIdx, |
| | 599 | | Modifier modifiers = Modifier.None) |
| | 600 | | { |
| | 601 | | if (!PassModifiers(modifiers)) |
| | 602 | | return; |
| | 603 | |
|
| | 604 | | if (Input.GetMouseButton(mouseButtonIdx)) |
| | 605 | | action.RaiseOnTriggered(); |
| | 606 | | } |
| | 607 | |
|
| | 608 | | public static void FromMouseButtonUp(InputAction_Trigger action, int mouseButtonIdx, |
| | 609 | | Modifier modifiers = Modifier.None) |
| | 610 | | { |
| | 611 | | if (!PassModifiers(modifiers)) |
| | 612 | | return; |
| | 613 | |
|
| | 614 | | if (Input.GetMouseButtonUp(mouseButtonIdx)) |
| | 615 | | action.RaiseOnTriggered(); |
| | 616 | | } |
| | 617 | |
|
| | 618 | | /// <summary> |
| | 619 | | /// Process an input action mapped to a keyboard key |
| | 620 | | /// </summary> |
| | 621 | | /// <param name="action">Hold Action to perform</param> |
| | 622 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 623 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 624 | | public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers = Modifier.None) |
| | 625 | | { |
| | 626 | | if (!PassModifiers(modifiers)) |
| | 627 | | return; |
| | 628 | |
|
| | 629 | | if (Input.GetKeyDown(key)) |
| | 630 | | action.RaiseOnStarted(); |
| | 631 | | if (Input.GetKeyUp(key)) |
| | 632 | | action.RaiseOnFinished(); |
| | 633 | | } |
| | 634 | |
|
| | 635 | | /// <summary> |
| | 636 | | /// Process an input action mapped to a keyboard key |
| | 637 | | /// </summary> |
| | 638 | | /// <param name="action">Hold Action to perform</param> |
| | 639 | | /// <param name="key">KeyCode mapped to this action</param> |
| | 640 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 641 | | /// <param name="modifierKeys">KeyCodes required to perform the action</param> |
| | 642 | | public static void FromKey(InputAction_Hold action, KeyCode key, Modifier modifiers, KeyCode[] modifierKeys) |
| | 643 | | { |
| | 644 | | if (!PassModifierKeys(modifierKeys)) |
| | 645 | | return; |
| | 646 | |
|
| | 647 | | FromKey(action, key, modifiers); |
| | 648 | | } |
| | 649 | |
|
| | 650 | | /// <summary> |
| | 651 | | /// Process an input action mapped to a mouse button |
| | 652 | | /// </summary> |
| | 653 | | /// <param name="action">Hold Action to perform</param> |
| | 654 | | /// <param name="mouseButtonIdx">Index of the mouse button</param> |
| | 655 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 656 | | public static void FromMouse(InputAction_Hold action, int mouseButtonIdx, Modifier modifiers = Modifier.None) |
| | 657 | | { |
| | 658 | | if (!PassModifiers(modifiers)) |
| | 659 | | return; |
| | 660 | |
|
| | 661 | | if (Input.GetMouseButtonDown(mouseButtonIdx)) |
| | 662 | | action.RaiseOnStarted(); |
| | 663 | | if (Input.GetMouseButtonUp(mouseButtonIdx)) |
| | 664 | | action.RaiseOnFinished(); |
| | 665 | | } |
| | 666 | |
|
| | 667 | | /// <summary> |
| | 668 | | /// Process an input action mapped to an axis |
| | 669 | | /// </summary> |
| | 670 | | /// <param name="action">Measurable Action to perform</param> |
| | 671 | | /// <param name="axisName">Axis name</param> |
| | 672 | | /// <param name="modifiers">Miscellaneous modifiers required for this action</param> |
| | 673 | | public static void FromAxis(InputAction_Measurable action, string axisName, Modifier modifiers = Modifier.None) |
| | 674 | | { |
| | 675 | | if (!PassModifiers(modifiers)) |
| | 676 | | { |
| | 677 | | action.RaiseOnValueChanged(0); |
| | 678 | | return; |
| | 679 | | } |
| | 680 | |
|
| | 681 | | action.RaiseOnValueChanged(Input.GetAxis(axisName)); |
| | 682 | | } |
| | 683 | |
|
| | 684 | | /// <summary> |
| | 685 | | /// Bitwise check for the modifiers flags |
| | 686 | | /// </summary> |
| | 687 | | /// <param name="modifiers">Modifier to check</param> |
| | 688 | | /// <param name="value">Modifier mapped to a bit to check</param> |
| | 689 | | /// <returns></returns> |
| | 690 | | public static bool IsModifierSet(Modifier modifiers, Modifier value) |
| | 691 | | { |
| | 692 | | int flagsValue = (int)modifiers; |
| | 693 | | int flagValue = (int)value; |
| | 694 | |
|
| | 695 | | return (flagsValue & flagValue) != 0; |
| | 696 | | } |
| | 697 | |
|
| | 698 | | public static bool FocusIsInInputField() |
| | 699 | | { |
| | 700 | | if (EventSystem.current == null) |
| | 701 | | return false; |
| | 702 | |
|
| | 703 | | if (EventSystem.current.currentSelectedGameObject != null && |
| | 704 | | (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null || |
| | 705 | | EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null)) |
| | 706 | | { |
| | 707 | | return true; |
| | 708 | | } |
| | 709 | |
|
| | 710 | | return false; |
| | 711 | | } |
| | 712 | | } |