Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game pad input to pause / continue game #138 #236

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OctoAwesome/OctoAwesome.Client/Screens/GameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private void RegisterKeyActions()
#region GamePad Input

private bool pressedGamepadInventory = false;
private bool pressedGamepadPause = false;
private bool pressedGamepadInteract = false;
private bool pressedGamepadApply = false;
private bool pressedGamepadJump = false;
Expand Down Expand Up @@ -333,6 +334,10 @@ private void HandleGamePad()
if (gamePadState.Buttons.Back == ButtonState.Pressed && !pressedGamepadInventory)
Manager.NavigateToScreen(new InventoryScreen(Manager));
pressedGamepadInventory = gamePadState.Buttons.Back == ButtonState.Pressed;

if (gamePadState.Buttons.Start == ButtonState.Pressed && !pressedGamepadPause)
Manager.NavigateToScreen(new PauseScreen(Manager));
pressedGamepadPause = gamePadState.Buttons.Start == ButtonState.Pressed;
}
}

Expand Down
26 changes: 23 additions & 3 deletions OctoAwesome/OctoAwesome.Client/Screens/PauseScreen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using engenious.Input;
using engenious;
using engenious.Input;
using MonoGameUi;
using OctoAwesome.Client.Components;
using System;

namespace OctoAwesome.Client.Screens
{
Expand All @@ -12,8 +14,8 @@ public PauseScreen(ScreenComponent manager) : base(manager)
{
assets = manager.Game.Assets;

// IsOverlay = true;
// Background = new BorderBrush(new Color(Color.Black, 0.5f));
//IsOverlay = true;
//Background = new BorderBrush(new Color(Color.Black, 0.5f));

Background = new TextureBrush(assets.LoadTexture(typeof(ScreenComponent), "background"), TextureBrushMode.Stretch);

Expand Down Expand Up @@ -70,5 +72,23 @@ protected override void OnKeyDown(KeyEventArgs args)

base.OnKeyDown(args);
}

private bool pressedGamepadBack = false;

protected override void OnUpdate(GameTime gameTime)
{
if (!IsActiveScreen) return;

try
{
var gamePadState = GamePad.GetState(0);
if (gamePadState.Buttons.Back == ButtonState.Pressed && !pressedGamepadBack)
Manager.NavigateBack();
pressedGamepadBack = gamePadState.Buttons.Back == ButtonState.Pressed;
}
catch (Exception) { }

base.OnUpdate(gameTime);
}
}
}