Skip to content

Commit

Permalink
fix: block camera input (#2999)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Dec 13, 2024
1 parent 0beaaa9 commit 06b798a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Explorer/Assets/DCL/Chat/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CameraBlockerComponent>(cameraEntity);
inputBlock.Enable(InputMapComponent.Kind.CAMERA , InputMapComponent.Kind.SHORTCUTS , InputMapComponent.Kind.PLAYER);
inputBlock.Enable(InputMapComponent.BLOCK_USER_INPUT);
}

private void OnSubmitAction(InputAction.CallbackContext obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
9 changes: 9 additions & 0 deletions Explorer/Assets/DCL/Input/Component/InputMapComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ public struct InputMapComponent
{
public static readonly IReadOnlyList<Kind> VALUES = EnumUtils.Values<Kind>();

public static readonly Kind[] BLOCK_USER_INPUT =
{
Kind.IN_WORLD_CAMERA,
Kind.CAMERA,
Kind.SHORTCUTS,
Kind.PLAYER
};


[Flags]
public enum Kind
{
Expand Down
49 changes: 8 additions & 41 deletions Explorer/Assets/DCL/Input/ECSInputBlock.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Arch.Core;
using DCL.Input.Component;
using ECS.Abstract;
Expand All @@ -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();
Expand All @@ -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);
}
}
}
}
8 changes: 2 additions & 6 deletions Explorer/Assets/DCL/Input/IInputBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Input/Systems/ApplyInputMapsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 3 additions & 1 deletion Explorer/Assets/Scripts/Global/Dynamic/MainSceneLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit 06b798a

Please sign in to comment.