diff --git a/Explorer/Assets/DCL/Chat/ChatController.cs b/Explorer/Assets/DCL/Chat/ChatController.cs index 8df1c318d8..15774c5526 100644 --- a/Explorer/Assets/DCL/Chat/ChatController.cs +++ b/Explorer/Assets/DCL/Chat/ChatController.cs @@ -268,13 +268,13 @@ private void ToggleEmojiPanel() private void DisableUnwantedInputs() { world.AddOrGet(cameraEntity, new CameraBlockerComponent()); - inputBlock.Disable(InputMapComponent.Kind.CAMERA , InputMapComponent.Kind.SHORTCUTS , InputMapComponent.Kind.PLAYER); + inputBlock.Disable(InputMapComponent.BLOCK_USER_INPUT); } private void EnableUnwantedInputs() { world.TryRemove(cameraEntity); - inputBlock.Enable(InputMapComponent.Kind.CAMERA , InputMapComponent.Kind.SHORTCUTS , InputMapComponent.Kind.PLAYER); + inputBlock.Enable(InputMapComponent.BLOCK_USER_INPUT); } private void OnSubmitAction(InputAction.CallbackContext obj) diff --git a/Explorer/Assets/DCL/InWorldCamera/InWorldCamera/Systems/ToggleInWorldCameraActivitySystem.cs b/Explorer/Assets/DCL/InWorldCamera/InWorldCamera/Systems/ToggleInWorldCameraActivitySystem.cs index 4d65050ead..cb723df72b 100644 --- a/Explorer/Assets/DCL/InWorldCamera/InWorldCamera/Systems/ToggleInWorldCameraActivitySystem.cs +++ b/Explorer/Assets/DCL/InWorldCamera/InWorldCamera/Systems/ToggleInWorldCameraActivitySystem.cs @@ -228,14 +228,12 @@ private void SwitchCameraInput(Kind to) switch (to) { case Kind.IN_WORLD_CAMERA: - inputMapComponent.UnblockInput(Kind.IN_WORLD_CAMERA); inputMapComponent.BlockInput(Kind.PLAYER); inputMapComponent.BlockInput(Kind.SHORTCUTS); break; case Kind.PLAYER: inputMapComponent.UnblockInput(Kind.PLAYER); inputMapComponent.UnblockInput(Kind.SHORTCUTS); - inputMapComponent.BlockInput(Kind.IN_WORLD_CAMERA); break; } } diff --git a/Explorer/Assets/DCL/Input/Component/InputMapComponent.cs b/Explorer/Assets/DCL/Input/Component/InputMapComponent.cs index ecf1b19fdd..7902ea9960 100644 --- a/Explorer/Assets/DCL/Input/Component/InputMapComponent.cs +++ b/Explorer/Assets/DCL/Input/Component/InputMapComponent.cs @@ -9,6 +9,15 @@ public struct InputMapComponent { public static readonly IReadOnlyList VALUES = EnumUtils.Values(); + public static readonly Kind[] BLOCK_USER_INPUT = + { + Kind.IN_WORLD_CAMERA, + Kind.CAMERA, + Kind.SHORTCUTS, + Kind.PLAYER + }; + + [Flags] public enum Kind { diff --git a/Explorer/Assets/DCL/Input/ECSInputBlock.cs b/Explorer/Assets/DCL/Input/ECSInputBlock.cs index a750287a2c..bc60bfee71 100644 --- a/Explorer/Assets/DCL/Input/ECSInputBlock.cs +++ b/Explorer/Assets/DCL/Input/ECSInputBlock.cs @@ -1,3 +1,4 @@ +using System.Linq; using Arch.Core; using DCL.Input.Component; using ECS.Abstract; @@ -23,30 +24,6 @@ public void Disable(params InputMapComponent.Kind[] kinds) inputMapComponent.BlockInput(kind); } - public void Disable(InputMapComponent.Kind kind) - { - inputMap ??= globalWorld.CacheInputMap(); - ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.BlockInput(kind); - } - - public void Disable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2) - { - inputMap ??= globalWorld.CacheInputMap(); - ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.BlockInput(kind); - inputMapComponent.BlockInput(kind2); - } - - public void Disable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2, InputMapComponent.Kind kind3) - { - inputMap ??= globalWorld.CacheInputMap(); - ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.BlockInput(kind); - inputMapComponent.BlockInput(kind2); - inputMapComponent.BlockInput(kind3); - } - public void Enable(params InputMapComponent.Kind[] kinds) { inputMap ??= globalWorld.CacheInputMap(); @@ -56,28 +33,18 @@ public void Enable(params InputMapComponent.Kind[] kinds) inputMapComponent.UnblockInput(kind); } - public void Enable(InputMapComponent.Kind kind) + public void EnableAll(params InputMapComponent.Kind[] except) { inputMap ??= globalWorld.CacheInputMap(); ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.UnblockInput(kind); - } - public void Enable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2) - { - inputMap ??= globalWorld.CacheInputMap(); - ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.UnblockInput(kind); - inputMapComponent.UnblockInput(kind2); - } + foreach (var kind in InputMapComponent.VALUES) + { + if (except != null && except.Contains(kind)) + continue; - public void Enable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2, InputMapComponent.Kind kind3) - { - inputMap ??= globalWorld.CacheInputMap(); - ref InputMapComponent inputMapComponent = ref inputMap.Value.GetInputMapComponent(globalWorld); - inputMapComponent.UnblockInput(kind); - inputMapComponent.UnblockInput(kind2); - inputMapComponent.UnblockInput(kind3); + inputMapComponent.UnblockInput(kind); + } } } } diff --git a/Explorer/Assets/DCL/Input/IInputBlock.cs b/Explorer/Assets/DCL/Input/IInputBlock.cs index 0ab622095d..67a0db172c 100644 --- a/Explorer/Assets/DCL/Input/IInputBlock.cs +++ b/Explorer/Assets/DCL/Input/IInputBlock.cs @@ -5,14 +5,10 @@ namespace DCL.Input public interface IInputBlock { public void Disable(params InputMapComponent.Kind[] kinds); - public void Disable(InputMapComponent.Kind kind); - public void Disable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2); - public void Disable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2, InputMapComponent.Kind kind3); public void Enable(params InputMapComponent.Kind[] kinds); - public void Enable(InputMapComponent.Kind kind); - public void Enable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2); - public void Enable(InputMapComponent.Kind kind, InputMapComponent.Kind kind2, InputMapComponent.Kind kind3); + + public void EnableAll(params InputMapComponent.Kind[] except); } } diff --git a/Explorer/Assets/DCL/Input/Systems/ApplyInputMapsSystem.cs b/Explorer/Assets/DCL/Input/Systems/ApplyInputMapsSystem.cs index 0772381b0d..a21563d991 100644 --- a/Explorer/Assets/DCL/Input/Systems/ApplyInputMapsSystem.cs +++ b/Explorer/Assets/DCL/Input/Systems/ApplyInputMapsSystem.cs @@ -61,6 +61,9 @@ protected override void Update(float t) case InputMapComponent.Kind.SHORTCUTS: SetActionMapEnabled(isActive, dclInput.Shortcuts); break; + case InputMapComponent.Kind.IN_WORLD_CAMERA: + SetActionMapEnabled(isActive, dclInput.InWorldCamera); + break; } } } diff --git a/Explorer/Assets/DCL/SceneLoadingScreens/SceneLoadingScreenController.cs b/Explorer/Assets/DCL/SceneLoadingScreens/SceneLoadingScreenController.cs index 337a916429..a03591f0e0 100644 --- a/Explorer/Assets/DCL/SceneLoadingScreens/SceneLoadingScreenController.cs +++ b/Explorer/Assets/DCL/SceneLoadingScreens/SceneLoadingScreenController.cs @@ -256,12 +256,12 @@ private async UniTaskVoid RotateTipsOverTimeAsync(TimeSpan frequency, Cancellati private void BlockUnwantedInputs() { - inputBlock.Disable(InputMapComponent.Kind.CAMERA, InputMapComponent.Kind.SHORTCUTS, InputMapComponent.Kind.PLAYER); + inputBlock.Disable(InputMapComponent.BLOCK_USER_INPUT); } private void UnblockUnwantedInputs() { - inputBlock.Enable(InputMapComponent.Kind.CAMERA, InputMapComponent.Kind.SHORTCUTS, InputMapComponent.Kind.PLAYER); + inputBlock.Enable(InputMapComponent.BLOCK_USER_INPUT); } } } diff --git a/Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs b/Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs index 403ed31a1a..5613797e2d 100644 --- a/Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs +++ b/Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs @@ -261,7 +261,9 @@ private void RestoreInputs() { // We enable Inputs through the inputBlock so the block counters can be properly updated and the component Active flags are up-to-date as well // We restore all inputs except EmoteWheel and FreeCamera as they should be disabled by default - staticContainer!.InputBlock.Enable(InputMapComponent.Kind.SHORTCUTS, InputMapComponent.Kind.PLAYER, InputMapComponent.Kind.EMOTES, InputMapComponent.Kind.CAMERA); + staticContainer!.InputBlock.EnableAll(InputMapComponent.Kind.FREE_CAMERA, + InputMapComponent.Kind.EMOTE_WHEEL); + } [ContextMenu(nameof(ValidateSettingsAsync))]