support controllers that aren't PlayerIndex.One

This commit is contained in:
Holly McFarland 2020-04-20 14:23:35 -04:00
parent 63fb57d3a3
commit 9a6a6079d4
2 changed files with 13 additions and 6 deletions

View File

@ -33,7 +33,8 @@ These are the plans for what I want to be customizable via .config modification
## Misc ## Misc
- Optionally assign "close" keybind to a combination of stick buttons ☐ - Optionally assign "close" keybind to a combination of stick buttons ☐
- Choose an XInput device instead of defaulting to whichever one is considered player 1 ☐ - Choose an XInput device instead of defaulting to whichever one is considered player 1 🗹
- "Press Start" prompt if ambiguous, save to config file? - ~~"Press Start" prompt if ambiguous, save to config file?~~
- Every frame, just use the controller with the lowest index and any input
- Keybinds to generate .config file and default images in execution folder ☐ - Keybinds to generate .config file and default images in execution folder ☐
- This would allow the distribution of just the .exe file. If someone wishes to customize, those default resources could be generated from the program - This would allow the distribution of just the .exe file. If someone wishes to customize, those default resources could be generated from the program

View File

@ -1,6 +1,7 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.IO; using System.IO;
@ -47,7 +48,6 @@ namespace sticky_viewer
private Texture2D C; private Texture2D C;
private Texture2D J; private Texture2D J;
private Texture2D S; private Texture2D S;
public Display() public Display()
{ {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
@ -149,7 +149,15 @@ namespace sticky_viewer
Exit(); Exit();
} }
GamePadDPad dpad = GamePad.GetState(PlayerIndex.One).DPad; // Find the controller being used currently
GamePadState emptyInput = new GamePadState();
GamePadState currentState = new GamePadState();
foreach (PlayerIndex p in Enum.GetValues(typeof(PlayerIndex)))
{
if ((currentState = GamePad.GetState(p)) != emptyInput) { break; }
}
GamePadDPad dpad = currentState.DPad;
if (dpad.Up == ButtonState.Pressed && dpad.Left == ButtonState.Pressed) if (dpad.Up == ButtonState.Pressed && dpad.Left == ButtonState.Pressed)
{ {
@ -188,8 +196,6 @@ namespace sticky_viewer
stick = neutral; stick = neutral;
} }
GamePadState currentState = GamePad.GetState(PlayerIndex.One);
Dictionary<string, bool> inputs = new Dictionary<string, bool>() Dictionary<string, bool> inputs = new Dictionary<string, bool>()
{ {
{"A", currentState.Buttons.A == ButtonState.Pressed}, {"A", currentState.Buttons.A == ButtonState.Pressed},