| | 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 | | { |
| | 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 | |
|
| | 147 | | bool renderingEnabled => CommonScriptableObjects.rendererState.Get(); |
| | 148 | | bool allUIHidden => CommonScriptableObjects.allUIHidden.Get(); |
| | 149 | | public InputTypeMode inputTypeMode { get; set; } = InputTypeMode.GENERAL; |
| | 150 | |
|
| | 151 | | private void Update() |
| | 152 | | { |
| | 153 | | if (!renderingEnabled) |
| | 154 | | { |
| | 155 | | Stop_Measurable(measurableActions); |
| | 156 | | return; |
| | 157 | | } |
| | 158 | |
|
| | 159 | | switch (inputTypeMode) |
| | 160 | | { |
| | 161 | | case InputTypeMode.OFF: |
| | 162 | | Stop_Measurable(measurableActions); |
| | 163 | | return; |
| | 164 | | case InputTypeMode.GENERAL: |
| | 165 | | Update_Trigger(triggerTimeActions); |
| | 166 | | Update_Hold(holdActions); |
| | 167 | | Update_Measurable(measurableActions); |
| | 168 | | break; |
| | 169 | | case InputTypeMode.BUILD_MODE_LOADING: |
| | 170 | | Update_Trigger(loadingBuilderTriggerTimeActions); |
| | 171 | | Stop_Measurable(measurableActions); |
| | 172 | | break; |
| | 173 | | case InputTypeMode.BUILD_MODE: |
| | 174 | | Update_Trigger(builderTriggerTimeActions); |
| | 175 | | Update_Hold(builderHoldActions); |
| | 176 | | Update_Measurable(measurableActions); |
| | 177 | | break; |
| | 178 | | } |
| | 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 | | { |
| | 186 | | for (var i = 0; i < triggerTimeActions.Length; i++) |
| | 187 | | { |
| | 188 | | var action = triggerTimeActions[i]; |
| | 189 | |
|
| | 190 | | if (action.isTriggerBlocked != null && action.isTriggerBlocked.Get()) |
| | 191 | | continue; |
| | 192 | |
|
| | 193 | | switch (action.GetDCLAction()) |
| | 194 | | { |
| | 195 | | case DCLAction_Trigger.CameraChange: |
| | 196 | | if (CommonScriptableObjects.cameraModeInputLocked.Get()) |
| | 197 | | break; |
| | 198 | |
|
| | 199 | | //Disable until the fine-tuning is ready |
| | 200 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| | 201 | | InputProcessor.FromKey(action, KeyCode.V, |
| | 202 | | modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 203 | | break; |
| | 204 | | case DCLAction_Trigger.CursorUnlock: |
| | 205 | | InputProcessor.FromMouseButtonUp(action, 1, InputProcessor.Modifier.NeedsPointerLocked); |
| | 206 | | #if !WEB_PLATFORM |
| | 207 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.NeedsPointerLocked |
| | 208 | | #endif |
| | 209 | | break; |
| | 210 | | case DCLAction_Trigger.ToggleNavMap: |
| | 211 | | if (allUIHidden) |
| | 212 | | break; |
| | 213 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 214 | | break; |
| | 215 | | case DCLAction_Trigger.ToggleFriends: |
| | 216 | | if (allUIHidden) |
| | 217 | | break; |
| | 218 | | InputProcessor.FromKey(action, KeyCode.L, modifiers: InputProcessor.Modifier.None); |
| | 219 | | break; |
| | 220 | | case DCLAction_Trigger.ToggleWorldChat: |
| | 221 | | if (allUIHidden) |
| | 222 | | break; |
| | 223 | | InputProcessor.FromKey(action, KeyCode.Return, modifiers: InputProcessor.Modifier.None); |
| | 224 | | break; |
| | 225 | | case DCLAction_Trigger.ToggleUIVisibility: |
| | 226 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.None); |
| | 227 | | break; |
| | 228 | | case DCLAction_Trigger.CloseWindow: |
| | 229 | | if (allUIHidden || DataStore.i.common.isSignUpFlow.Get()) |
| | 230 | | break; |
| | 231 | | InputProcessor.FromKey(action, KeyCode.Escape, modifiers: InputProcessor.Modifier.None); |
| | 232 | | break; |
| | 233 | | case DCLAction_Trigger.OpenExpressions: |
| | 234 | | if (allUIHidden) |
| | 235 | | break; |
| | 236 | | InputProcessor.FromKey(action, KeyCode.B, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 237 | | break; |
| | 238 | | case DCLAction_Trigger.ToggleControlsHud: |
| | 239 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 240 | | break; |
| | 241 | | case DCLAction_Trigger.ToggleSettings: |
| | 242 | | InputProcessor.FromKey(action, KeyCode.P, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 243 | | break; |
| | 244 | | case DCLAction_Trigger.ToggleStartMenu: |
| | 245 | | if (allUIHidden) |
| | 246 | | break; |
| | 247 | | InputProcessor.FromKey(action, KeyCode.Tab, modifiers: InputProcessor.Modifier.None); |
| | 248 | | break; |
| | 249 | | case DCLAction_Trigger.TogglePlacesAndEventsHud: |
| | 250 | | InputProcessor.FromKey(action, KeyCode.X, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 251 | | break; |
| | 252 | | case DCLAction_Trigger.Expression_Wave: |
| | 253 | | InputProcessor.FromKey(action, KeyCode.Alpha1, |
| | 254 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 255 | | break; |
| | 256 | | case DCLAction_Trigger.Expression_FistPump: |
| | 257 | | InputProcessor.FromKey(action, KeyCode.Alpha2, |
| | 258 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 259 | | break; |
| | 260 | | case DCLAction_Trigger.Expression_Robot: |
| | 261 | | InputProcessor.FromKey(action, KeyCode.Alpha3, |
| | 262 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 263 | | break; |
| | 264 | | case DCLAction_Trigger.Expression_RaiseHand: |
| | 265 | | InputProcessor.FromKey(action, KeyCode.Alpha4, |
| | 266 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 267 | | break; |
| | 268 | | case DCLAction_Trigger.Expression_Clap: |
| | 269 | | InputProcessor.FromKey(action, KeyCode.Alpha5, |
| | 270 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 271 | | break; |
| | 272 | | case DCLAction_Trigger.Expression_ThrowMoney: |
| | 273 | | InputProcessor.FromKey(action, KeyCode.Alpha6, |
| | 274 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 275 | | break; |
| | 276 | | case DCLAction_Trigger.Expression_SendKiss: |
| | 277 | | InputProcessor.FromKey(action, KeyCode.Alpha7, |
| | 278 | | modifiers: InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 279 | | break; |
| | 280 | | case DCLAction_Trigger.BuildEditModeChange: |
| | 281 | | InputProcessor.FromKey(action, KeyCode.K, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 282 | | break; |
| | 283 | | case DCLAction_Trigger.ToggleVoiceChatRecording: |
| | 284 | | InputProcessor.FromKey(action, KeyCode.T, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 285 | | break; |
| | 286 | | case DCLAction_Trigger.ToggleAvatarEditorHud: |
| | 287 | | InputProcessor.FromKey(action, KeyCode.I, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 288 | | break; |
| | 289 | | case DCLAction_Trigger.BuildEditModeToggleUI: |
| | 290 | | InputProcessor.FromKey(action, KeyCode.U, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 291 | | break; |
| | 292 | | case DCLAction_Trigger.BuildEditModeToggleChangeCamera: |
| | 293 | | InputProcessor.FromKey(action, KeyCode.V, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 294 | | break; |
| | 295 | | case DCLAction_Trigger.BuildEditModeToggleControls: |
| | 296 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 297 | | break; |
| | 298 | | case DCLAction_Trigger.BuildEditModeToggleSnapMode: |
| | 299 | | InputProcessor.FromKey(action, KeyCode.O, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 300 | | break; |
| | 301 | | case DCLAction_Trigger.BuildEditModeRedoAction: |
| | 302 | | InputProcessor.FromKey(action, KeyCode.Y, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 303 | | break; |
| | 304 | | case DCLAction_Trigger.BuildEditModeUndoAction: |
| | 305 | | InputProcessor.FromKey(action, KeyCode.Z, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 306 | | break; |
| | 307 | | case DCLAction_Trigger.BuildEditModeQuickBar1: |
| | 308 | | InputProcessor.FromKey(action, KeyCode.Alpha1, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 309 | | break; |
| | 310 | | case DCLAction_Trigger.BuildEditModeQuickBar2: |
| | 311 | | InputProcessor.FromKey(action, KeyCode.Alpha2, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 312 | | break; |
| | 313 | | case DCLAction_Trigger.BuildEditModeQuickBar3: |
| | 314 | | InputProcessor.FromKey(action, KeyCode.Alpha3, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 315 | | break; |
| | 316 | | case DCLAction_Trigger.BuildEditModeQuickBar4: |
| | 317 | | InputProcessor.FromKey(action, KeyCode.Alpha4, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 318 | | break; |
| | 319 | | case DCLAction_Trigger.BuildEditModeQuickBar5: |
| | 320 | | InputProcessor.FromKey(action, KeyCode.Alpha5, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 321 | | break; |
| | 322 | | case DCLAction_Trigger.BuildEditModeQuickBar6: |
| | 323 | | InputProcessor.FromKey(action, KeyCode.Alpha6, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 324 | | break; |
| | 325 | | case DCLAction_Trigger.BuildEditModeQuickBar7: |
| | 326 | | InputProcessor.FromKey(action, KeyCode.Alpha7, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 327 | | break; |
| | 328 | | case DCLAction_Trigger.BuildEditModeQuickBar8: |
| | 329 | | InputProcessor.FromKey(action, KeyCode.Alpha8, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 330 | | break; |
| | 331 | | case DCLAction_Trigger.BuildEditModeQuickBar9: |
| | 332 | | InputProcessor.FromKey(action, KeyCode.Alpha9, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 333 | | break; |
| | 334 | | case DCLAction_Trigger.BuildEditModeDelete: |
| | 335 | | InputProcessor.FromKey(action, KeyCode.Delete, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 336 | | InputProcessor.FromKey(action, KeyCode.Backspace, modifiers: InputProcessor.Modifier.FocusNotInInput |
| | 337 | | break; |
| | 338 | | case DCLAction_Trigger.BuildEditModeDuplicate: |
| | 339 | | InputProcessor.FromKey(action, KeyCode.D, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 340 | | break; |
| | 341 | | case DCLAction_Trigger.BuildEditModeTranslate: |
| | 342 | | InputProcessor.FromKey(action, KeyCode.G, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 343 | | InputProcessor.FromKey(action, KeyCode.M, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 344 | | break; |
| | 345 | | case DCLAction_Trigger.BuildEditModeRotate: |
| | 346 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 347 | | break; |
| | 348 | | case DCLAction_Trigger.BuildEditModeScale: |
| | 349 | | InputProcessor.FromKey(action, KeyCode.S, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 350 | | break; |
| | 351 | | case DCLAction_Trigger.BuildEditModeFocusSelectedEntities: |
| | 352 | | InputProcessor.FromKey(action, KeyCode.F, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 353 | | break; |
| | 354 | | case DCLAction_Trigger.BuildEditModeReset: |
| | 355 | | InputProcessor.FromKey(action, KeyCode.R, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 356 | | break; |
| | 357 | | case DCLAction_Trigger.BuildEditHideSelectedEntities: |
| | 358 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 359 | | break; |
| | 360 | | case DCLAction_Trigger.BuildEditShowAllEntities: |
| | 361 | | InputProcessor.FromKey(action, KeyCode.H, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 362 | | break; |
| | 363 | | case DCLAction_Trigger.BuildEditModeResetCamera: |
| | 364 | | InputProcessor.FromKey(action, KeyCode.C, modifiers: InputProcessor.Modifier.FocusNotInInput, modifi |
| | 365 | | break; |
| | 366 | | case DCLAction_Trigger.BuildEditModeZoomIn: |
| | 367 | | InputProcessor.FromKey(action, KeyCode.KeypadPlus, modifiers: InputProcessor.Modifier.FocusNotInInpu |
| | 368 | | break; |
| | 369 | | case DCLAction_Trigger.BuildEditModeZoomOut: |
| | 370 | | InputProcessor.FromKey(action, KeyCode.KeypadMinus, modifiers: InputProcessor.Modifier.FocusNotInInp |
| | 371 | | break; |
| | 372 | | case DCLAction_Trigger.ToggleQuestsPanelHud: |
| | 373 | | InputProcessor.FromKey(action, KeyCode.J, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 374 | | break; |
| | 375 | | case DCLAction_Trigger.ToggleAvatarNamesHud: |
| | 376 | | InputProcessor.FromKey(action, KeyCode.N, modifiers: InputProcessor.Modifier.FocusNotInInput); |
| | 377 | | break; |
| | 378 | | default: |
| | 379 | | throw new ArgumentOutOfRangeException(); |
| | 380 | | } |
| | 381 | | } |
| | 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 | | { |
| | 389 | | for (var i = 0; i < holdActions.Length; i++) |
| | 390 | | { |
| | 391 | | var action = holdActions[i]; |
| | 392 | | switch (action.GetDCLAction()) |
| | 393 | | { |
| | 394 | | case DCLAction_Hold.Sprint: |
| | 395 | | InputProcessor.FromKey(action, InputSettings.WalkButtonKeyCode, |
| | 396 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 397 | | break; |
| | 398 | | case DCLAction_Hold.Jump: |
| | 399 | | InputProcessor.FromKey(action, InputSettings.JumpButtonKeyCode, |
| | 400 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 401 | | break; |
| | 402 | | case DCLAction_Hold.ZoomIn: |
| | 403 | | InputProcessor.FromKey(action, KeyCode.KeypadPlus, InputProcessor.Modifier.None); |
| | 404 | | InputProcessor.FromKey(action, KeyCode.Plus, InputProcessor.Modifier.None); |
| | 405 | | break; |
| | 406 | | case DCLAction_Hold.ZoomOut: |
| | 407 | | InputProcessor.FromKey(action, KeyCode.KeypadMinus, InputProcessor.Modifier.None); |
| | 408 | | InputProcessor.FromKey(action, KeyCode.Minus, InputProcessor.Modifier.None); |
| | 409 | | break; |
| | 410 | | case DCLAction_Hold.FreeCameraMode: |
| | 411 | | //Disable until the fine-tuning is ready |
| | 412 | | if (ENABLE_THIRD_PERSON_CAMERA) |
| | 413 | | InputProcessor.FromKey(action, KeyCode.Y, InputProcessor.Modifier.NeedsPointerLocked); |
| | 414 | | break; |
| | 415 | | case DCLAction_Hold.VoiceChatRecording: |
| | 416 | | // Push to talk functionality only triggers if no modifier key is pressed |
| | 417 | | InputProcessor.FromKey(action, KeyCode.T, InputProcessor.Modifier.FocusNotInInput, null); |
| | 418 | | break; |
| | 419 | | case DCLAction_Hold.DefaultConfirmAction: |
| | 420 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.None); |
| | 421 | | break; |
| | 422 | | case DCLAction_Hold.DefaultCancelAction: |
| | 423 | | InputProcessor.FromKey(action, KeyCode.F, InputProcessor.Modifier.None); |
| | 424 | | break; |
| | 425 | | case DCLAction_Hold.BuildEditModeMultiSelection: |
| | 426 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| | 427 | | break; |
| | 428 | | case DCLAction_Hold.BuildEditModeSquareMultiSelection: |
| | 429 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| | 430 | | break; |
| | 431 | | case DCLAction_Hold.BuildEditModeFirstPersonRotation: |
| | 432 | | InputProcessor.FromKey(action, KeyCode.R, InputProcessor.Modifier.FocusNotInInput); |
| | 433 | | break; |
| | 434 | | case DCLAction_Hold.BuildEditModeCameraAdvanceFoward: |
| | 435 | | InputProcessor.FromKey(action, KeyCode.UpArrow, InputProcessor.Modifier.FocusNotInInput); |
| | 436 | | InputProcessor.FromKey(action, KeyCode.W, InputProcessor.Modifier.FocusNotInInput); |
| | 437 | | break; |
| | 438 | | case DCLAction_Hold.BuildEditModeCameraAdvanceBack: |
| | 439 | | InputProcessor.FromKey(action, KeyCode.DownArrow, InputProcessor.Modifier.FocusNotInInput); |
| | 440 | | InputProcessor.FromKey(action, KeyCode.S, InputProcessor.Modifier.FocusNotInInput); |
| | 441 | | break; |
| | 442 | | case DCLAction_Hold.BuildEditModeCameraAdvanceLeft: |
| | 443 | | InputProcessor.FromKey(action, KeyCode.LeftArrow, InputProcessor.Modifier.FocusNotInInput); |
| | 444 | | InputProcessor.FromKey(action, KeyCode.A, InputProcessor.Modifier.FocusNotInInput); |
| | 445 | | break; |
| | 446 | | case DCLAction_Hold.BuildEditModeCameraAdvanceRight: |
| | 447 | | InputProcessor.FromKey(action, KeyCode.RightArrow, InputProcessor.Modifier.FocusNotInInput); |
| | 448 | | InputProcessor.FromKey(action, KeyCode.D, InputProcessor.Modifier.FocusNotInInput); |
| | 449 | | break; |
| | 450 | | case DCLAction_Hold.BuildEditModeCameraAdvanceUp: |
| | 451 | | InputProcessor.FromKey(action, KeyCode.E, InputProcessor.Modifier.FocusNotInInput); |
| | 452 | | break; |
| | 453 | | case DCLAction_Hold.BuildEditModeCameraAdvanceDown: |
| | 454 | | InputProcessor.FromKey(action, KeyCode.Q, InputProcessor.Modifier.FocusNotInInput); |
| | 455 | | break; |
| | 456 | | case DCLAction_Hold.BuildEditModeCameraPan: |
| | 457 | | InputProcessor.FromKey(action, KeyCode.LeftShift, InputProcessor.Modifier.FocusNotInInput); |
| | 458 | | break; |
| | 459 | | default: |
| | 460 | | throw new ArgumentOutOfRangeException(); |
| | 461 | | } |
| | 462 | | } |
| | 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 | | { |
| | 470 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 471 | | { |
| | 472 | | var action = measurableActions[i]; |
| | 473 | | switch (action.GetDCLAction()) |
| | 474 | | { |
| | 475 | | case DCLAction_Measurable.CharacterXAxis: |
| | 476 | | InputProcessor.FromAxis(action, "Horizontal", |
| | 477 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 478 | | break; |
| | 479 | | case DCLAction_Measurable.CharacterYAxis: |
| | 480 | | InputProcessor.FromAxis(action, "Vertical", |
| | 481 | | InputProcessor.Modifier.FocusNotInInput | InputProcessor.Modifier.NotInStartMenu); |
| | 482 | | break; |
| | 483 | | case DCLAction_Measurable.CameraXAxis: |
| | 484 | | InputProcessor.FromAxis(action, "Mouse X", InputProcessor.Modifier.NeedsPointerLocked); |
| | 485 | | break; |
| | 486 | | case DCLAction_Measurable.CameraYAxis: |
| | 487 | | InputProcessor.FromAxis(action, "Mouse Y", InputProcessor.Modifier.NeedsPointerLocked); |
| | 488 | | break; |
| | 489 | | case DCLAction_Measurable.MouseWheel: |
| | 490 | | InputProcessor.FromAxis(action, "Mouse ScrollWheel", modifiers: InputProcessor.Modifier.FocusNotInIn |
| | 491 | | break; |
| | 492 | | default: |
| | 493 | | throw new ArgumentOutOfRangeException(); |
| | 494 | | } |
| | 495 | | } |
| | 496 | | } |
| | 497 | |
|
| | 498 | | private void Stop_Measurable(InputAction_Measurable[] measurableActions) |
| | 499 | | { |
| | 500 | | for (var i = 0; i < measurableActions.Length; i++) |
| | 501 | | { |
| | 502 | | measurableActions[i].RaiseOnValueChanged(0); |
| | 503 | | } |
| | 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 | | { |
| 1 | 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 | | { |
| 1351320 | 531 | | for (var i = 0; i < MODIFIER_KEYS.Length; i++) |
| | 532 | | { |
| 542752 | 533 | | var keyCode = MODIFIER_KEYS[i]; |
| 542752 | 534 | | var pressed = Input.GetKey(keyCode); |
| 542752 | 535 | | if (modifierKeys == null) |
| | 536 | | { |
| 531632 | 537 | | if (pressed) |
| 0 | 538 | | return false; |
| | 539 | | } |
| | 540 | | else |
| | 541 | | { |
| 11120 | 542 | | if (modifierKeys.Contains(keyCode) != pressed) |
| 5560 | 543 | | return false; |
| | 544 | | } |
| | 545 | | } |
| | 546 | |
|
| 132908 | 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 | | { |
| 227422 | 558 | | if (IsModifierSet(modifiers, Modifier.NeedsPointerLocked) && !DCL.Helpers.Utils.IsCursorLocked) |
| 27770 | 559 | | return false; |
| | 560 | |
|
| 199652 | 561 | | if (IsModifierSet(modifiers, Modifier.FocusNotInInput) && FocusIsInInputField()) |
| 0 | 562 | | return false; |
| | 563 | |
|
| 199652 | 564 | | if (IsModifierSet(modifiers, Modifier.NotInStartMenu) && IsStartMenuVisible()) |
| 0 | 565 | | return false; |
| | 566 | |
|
| 199652 | 567 | | return true; |
| | 568 | | } |
| | 569 | |
|
| 61160 | 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 | | { |
| 132902 | 582 | | if (!PassModifiers(modifiers)) |
| 5554 | 583 | | return; |
| | 584 | |
|
| 127348 | 585 | | if (!PassModifierKeys(modifierKeys)) |
| 5560 | 586 | | return; |
| | 587 | |
|
| 121788 | 588 | | if (Input.GetKeyDown(key)) |
| 0 | 589 | | action.RaiseOnTriggered(); |
| 121788 | 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 | | { |
| 0 | 601 | | if (!PassModifiers(modifiers)) |
| 0 | 602 | | return; |
| | 603 | |
|
| 0 | 604 | | if (Input.GetMouseButton(mouseButtonIdx)) |
| 0 | 605 | | action.RaiseOnTriggered(); |
| 0 | 606 | | } |
| | 607 | |
|
| | 608 | | public static void FromMouseButtonUp(InputAction_Trigger action, int mouseButtonIdx, |
| | 609 | | Modifier modifiers = Modifier.None) |
| | 610 | | { |
| 5560 | 611 | | if (!PassModifiers(modifiers)) |
| 5554 | 612 | | return; |
| | 613 | |
|
| 6 | 614 | | if (Input.GetMouseButtonUp(mouseButtonIdx)) |
| 0 | 615 | | action.RaiseOnTriggered(); |
| 6 | 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 | | { |
| 61160 | 626 | | if (!PassModifiers(modifiers)) |
| 5554 | 627 | | return; |
| | 628 | |
|
| 55606 | 629 | | if (Input.GetKeyDown(key)) |
| 0 | 630 | | action.RaiseOnStarted(); |
| 55606 | 631 | | if (Input.GetKeyUp(key)) |
| 0 | 632 | | action.RaiseOnFinished(); |
| 55606 | 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 | | { |
| 11120 | 644 | | if (!PassModifierKeys(modifierKeys)) |
| 0 | 645 | | return; |
| | 646 | |
|
| 11120 | 647 | | FromKey(action, key, modifiers); |
| 11120 | 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 | | { |
| 0 | 658 | | if (!PassModifiers(modifiers)) |
| 0 | 659 | | return; |
| | 660 | |
|
| 0 | 661 | | if (Input.GetMouseButtonDown(mouseButtonIdx)) |
| 0 | 662 | | action.RaiseOnStarted(); |
| 0 | 663 | | if (Input.GetMouseButtonUp(mouseButtonIdx)) |
| 0 | 664 | | action.RaiseOnFinished(); |
| 0 | 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 | | { |
| 27800 | 675 | | if (!PassModifiers(modifiers)) |
| | 676 | | { |
| 11108 | 677 | | action.RaiseOnValueChanged(0); |
| 11108 | 678 | | return; |
| | 679 | | } |
| | 680 | |
|
| 16692 | 681 | | action.RaiseOnValueChanged(Input.GetAxis(axisName)); |
| 16692 | 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 | | { |
| 0 | 692 | | int flagsValue = (int)modifiers; |
| 0 | 693 | | int flagValue = (int)value; |
| | 694 | |
|
| 0 | 695 | | return (flagsValue & flagValue) != 0; |
| | 696 | | } |
| | 697 | |
|
| | 698 | | public static bool FocusIsInInputField() |
| | 699 | | { |
| 138822 | 700 | | if (EventSystem.current == null) |
| 125147 | 701 | | return false; |
| | 702 | |
|
| 13675 | 703 | | if (EventSystem.current.currentSelectedGameObject != null && |
| | 704 | | (EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null || |
| | 705 | | EventSystem.current.currentSelectedGameObject.GetComponent<UnityEngine.UI.InputField>() != null)) |
| | 706 | | { |
| 0 | 707 | | return true; |
| | 708 | | } |
| | 709 | |
|
| 13675 | 710 | | return false; |
| | 711 | | } |
| | 712 | | } |