Skip to content

Commit

Permalink
Add basic "pause" menu
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed Mar 16, 2024
1 parent 4417c19 commit b93aa5b
Show file tree
Hide file tree
Showing 9 changed files with 747 additions and 72 deletions.
574 changes: 569 additions & 5 deletions Assets/Prefabs/Input/Player.prefab

Large diffs are not rendered by default.

151 changes: 91 additions & 60 deletions Assets/ScriptableObjects/Input/PlayerControls.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Exit",
"type": "Button",
"id": "59e83c07-8e52-4bf8-9438-5a6d37054de2",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
Expand Down Expand Up @@ -284,7 +293,7 @@
{
"name": "",
"id": "0030f558-1dce-4039-95e4-2c065ead1db1",
"path": "<Keyboard>/escape",
"path": "<Keyboard>/backspace",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
Expand Down Expand Up @@ -478,6 +487,28 @@
"action": "LeftTab",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "9a1572fe-6205-45fc-8244-3502f75c7d39",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "846526c8-752a-4905-9e41-6ec6d2d80a37",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
}
]
},
Expand All @@ -494,15 +525,6 @@
"interactions": "",
"initialStateCheck": false
},
{
"name": "Cancel",
"type": "Button",
"id": "6c813086-0914-48e7-a994-f4c36f04f63c",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Move",
"type": "Value",
Expand Down Expand Up @@ -556,6 +578,15 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Exit",
"type": "Button",
"id": "6c813086-0914-48e7-a994-f4c36f04f63c",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
Expand All @@ -581,28 +612,6 @@
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "898c171c-67f9-4de3-b99e-3eea3e5a4dda",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "fe8cd325-d420-4946-a7f0-40e4e1c72e6e",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "65cc362b-78a9-46ba-b196-d471cbc76387",
Expand Down Expand Up @@ -800,6 +809,28 @@
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "898c171c-67f9-4de3-b99e-3eea3e5a4dda",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "fe8cd325-d420-4946-a7f0-40e4e1c72e6e",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
}
]
},
Expand All @@ -826,27 +857,27 @@
"initialStateCheck": true
},
{
"name": "Cancel",
"name": "Select",
"type": "Button",
"id": "9e0bf922-98f3-49e8-9ea8-7897bbb5249f",
"id": "81e31669-1c45-46b3-b49d-6daa89095b81",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Select",
"name": "Interact",
"type": "Button",
"id": "81e31669-1c45-46b3-b49d-6daa89095b81",
"id": "360c3d67-b75e-4f1a-8700-e3d62ef4f857",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Interact",
"name": "Exit",
"type": "Button",
"id": "360c3d67-b75e-4f1a-8700-e3d62ef4f857",
"id": "9e0bf922-98f3-49e8-9ea8-7897bbb5249f",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
Expand Down Expand Up @@ -942,28 +973,6 @@
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "4b0e4d83-9aaf-4d27-8ef7-830284a247cc",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "56f3ff90-eaed-417f-806b-5c5933c8b942",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Cancel",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "5d89d078-c0ba-4983-9a06-ce3dd87d1f5d",
Expand Down Expand Up @@ -1007,6 +1016,28 @@
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "4b0e4d83-9aaf-4d27-8ef7-830284a247cc",
"path": "<Gamepad>/select",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "56f3ff90-eaed-417f-806b-5c5933c8b942",
"path": "<Keyboard>/escape",
"interactions": "",
"processors": "",
"groups": "MouseAndKeyboard",
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Control&Input/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class InputManager : MonoBehaviour
// Menu-related
public InputEvent onSelect;
public InputEvent onCancel;
public InputEvent onExit;
public InputEvent onLeftTab;
public InputEvent onRightTab;
public InputEvent onAnyKey;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void AddListeners()
playerInput.actions["Join"].performed += AnyKey;
playerInput.actions["Select"].performed += Select;
playerInput.actions["Cancel"].performed += Cancel;
playerInput.actions["Exit"].performed += Exit;
playerInput.actions["Move"].performed += Move;
playerInput.actions["Move"].canceled += Move;
playerInput.actions["LeftTab"].performed += LeftTab;
Expand Down Expand Up @@ -159,6 +161,7 @@ private void RemoveAllListeners()
// Abusing that empty delegate bodies are defined as null to remove all invocation lists.
onSelect = null;
onCancel = null;
onExit = null;
onMovePerformed = null;
onMoveCanceled = null;
onLeftTab = null;
Expand Down Expand Up @@ -196,6 +199,11 @@ private void Cancel(InputAction.CallbackContext ctx)
onCancel?.Invoke(ctx);
}

private void Exit(InputAction.CallbackContext ctx)
{
onExit?.Invoke(ctx);
}

private void LeftTab(InputAction.CallbackContext ctx)
{
onLeftTab?.Invoke(ctx);
Expand Down
12 changes: 8 additions & 4 deletions Assets/Scripts/Control&Input/PlayerInputManagerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public void ChangeInputMaps(string mapNameOrId)
{
playerInputs.ForEach(playerInput =>
{
playerInput.playerInput.SwitchCurrentActionMap(mapNameOrId);
playerInput.RemoveListeners();
playerInput.AddListeners();
ChangeInputMapForPlayer(mapNameOrId, playerInput);
// Free the playerInputs from their mortail coils (Player prefab or similar assets)
var previousParent = playerInput.transform.parent;
playerInput.transform.parent = null;
Expand All @@ -91,4 +88,11 @@ public void ChangeInputMaps(string mapNameOrId)
Destroy(previousParent.gameObject);
});
}

public void ChangeInputMapForPlayer(string mapNameOrId, InputManager playerInput)
{
playerInput.playerInput.SwitchCurrentActionMap(mapNameOrId);
playerInput.RemoveListeners();
playerInput.AddListeners();
}
}
9 changes: 7 additions & 2 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class PlayerMovement : MonoBehaviour
[SerializeField]
protected LayerMask steppingIgnoreMask;

public bool ShouldNotRespondToInputs = false;


protected virtual void Start()
{
Expand Down Expand Up @@ -344,6 +346,8 @@ protected void UpdatePosition(Vector3 input)

private void UpdateRotation()
{
if (ShouldNotRespondToInputs)
return;
var lookSpeedFactor = inputManager.ZoomActive
? inputManager.IsMouseAndKeyboard ? LookSpeedZoom * mouseZoomSpeedFactor : LookSpeedZoom
: lookSpeed;
Expand All @@ -369,7 +373,7 @@ protected void UpdateAnimatorParameters()
animator.SetFloat("Right", Vector3.Dot(body.velocity, transform.right) / maxVelocityBeforeExtraDamping);
}

void OnDrawGizmos()
private void OnDrawGizmos()
{
if (!hitbox) return;
var extents = new Vector3(1, 1.5f + airThreshold, 1);
Expand Down Expand Up @@ -427,14 +431,15 @@ private void OnStepDetected(RaycastHit raycastHit, Vector3 rayDirection)
}
}
}

protected virtual void FixedUpdate()
{
if (FindSteppingGround() && body.velocity.magnitude > 0.08f)
{
FindStep();
}

var positionInput = new Vector3(inputManager.moveInput.x, 0, inputManager.moveInput.y);
var positionInput = ShouldNotRespondToInputs ? Vector3.zero : new Vector3(inputManager.moveInput.x, 0, inputManager.moveInput.y);
UpdatePosition(positionInput);
// Limit velocity when not grounded
if (state == PlayerState.GROUNDED)
Expand Down
8 changes: 7 additions & 1 deletion Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ void OnDeath(HealthController healthController, float damage, DamageInfo info)
playerShadow.gameObject.SetActive(false);
}

private void OnPause(InputAction.CallbackContext ctx)
{
hudController?.PauseMenu?.SetPlayerInput(inputManager, this);
}

protected void TurnIntoRagdoll(DamageInfo info)
{
GetComponent<Rigidbody>().GetAccumulatedForce();
Expand Down Expand Up @@ -209,6 +214,7 @@ public void SetPlayerInput(InputManager playerInput)
inputManager.onSelect += TryPlaceBid;
inputManager.onFirePerformed += TryPlaceBid;
inputManager.onInteract += Interact;
inputManager.onExit += OnPause;
// Set camera on canvas
var canvas = hudController.GetComponent<Canvas>();
canvas.worldCamera = inputManager.GetComponentInChildren<Camera>();
Expand All @@ -218,7 +224,7 @@ public void SetPlayerInput(InputManager playerInput)
var meshRenderer = meshBase.GetComponentInChildren<SkinnedMeshRenderer>().material.color = identity.color;
}

void OnDestroy()
private void OnDestroy()
{
if (healthController)
{
Expand Down
Loading

0 comments on commit b93aa5b

Please sign in to comment.