diff options
author | ClxS <slxxls92@gmail.com> | 2016-03-07 13:49:45 +0000 |
---|---|---|
committer | ClxS <slxxls92@gmail.com> | 2016-03-07 13:49:45 +0000 |
commit | 71bcfc11dea8c189152a9aa2534c87e1b1486018 (patch) | |
tree | fbfe5327353e0102dc2fc3b7bb6020e1010aee16 | |
parent | 49090c98fcdc11ca536de42875f50b763e83ce63 (diff) | |
download | SMAPI-71bcfc11dea8c189152a9aa2534c87e1b1486018.tar.gz SMAPI-71bcfc11dea8c189152a9aa2534c87e1b1486018.tar.bz2 SMAPI-71bcfc11dea8c189152a9aa2534c87e1b1486018.zip |
Partially completed events for gamepad input
-rw-r--r-- | StardewModdingAPI/Events/Controls.cs | 15 | ||||
-rw-r--r-- | StardewModdingAPI/Events/EventArgs.cs | 24 | ||||
-rw-r--r-- | StardewModdingAPI/Inheritance/SGame.cs | 52 | ||||
-rw-r--r-- | StardewModdingAPI/StardewModdingAPI.csproj | 13 |
4 files changed, 93 insertions, 11 deletions
diff --git a/StardewModdingAPI/Events/Controls.cs b/StardewModdingAPI/Events/Controls.cs index 8cf0f431..fa344bab 100644 --- a/StardewModdingAPI/Events/Controls.cs +++ b/StardewModdingAPI/Events/Controls.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,6 +14,8 @@ namespace StardewModdingAPI.Events public static event EventHandler<EventArgsKeyPressed> KeyPressed = delegate { };
public static event EventHandler<EventArgsKeyPressed> KeyReleased = delegate { };
public static event EventHandler<EventArgsMouseStateChanged> MouseChanged = delegate { };
+ public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed = delegate { };
+ public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased = delegate { };
public static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState)
{
@@ -33,5 +36,15 @@ namespace StardewModdingAPI.Events {
KeyReleased.Invoke(null, new EventArgsKeyPressed(key));
}
+
+ public static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons buttons)
+ {
+ ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, buttons));
+ }
+
+ public static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons buttons)
+ {
+ ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, buttons));
+ }
}
}
diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index 66d057a7..6c5e1401 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -30,7 +30,29 @@ namespace StardewModdingAPI.Events }
public Keys KeyPressed { get; private set; }
}
-
+
+ public class EventArgsControllerButtonPressed : EventArgs
+ {
+ public EventArgsControllerButtonPressed(PlayerIndex playerIndex, Buttons buttonPressed)
+ {
+ PlayerIndex = playerIndex;
+ ButtonPressed = buttonPressed;
+ }
+ public PlayerIndex PlayerIndex;
+ public Buttons ButtonPressed { get; private set; }
+ }
+
+ public class EventArgsControllerButtonReleased : EventArgs
+ {
+ public EventArgsControllerButtonReleased(PlayerIndex playerIndex, Buttons buttonReleased)
+ {
+ PlayerIndex = playerIndex;
+ ButtonReleased = buttonReleased;
+ }
+ public PlayerIndex PlayerIndex;
+ public Buttons ButtonReleased { get; private set; }
+ }
+
public class EventArgsMouseStateChanged : EventArgs
{
public EventArgsMouseStateChanged(MouseState priorState, MouseState newState)
diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index 120f4a6e..8da7c412 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -48,6 +48,40 @@ namespace StardewModdingAPI.Inheritance get { return PreviouslyPressedKeys.Where(x => !CurrentlyPressedKeys.Contains(x)).ToArray(); }
}
+ public Buttons[][] CurrentlyPressedButtons;
+ public Buttons[][] PreviouslyPressedButtons;
+
+ private bool WasButtonJustPressed(Buttons button, ButtonState buttonState, PlayerIndex stateIndex)
+ {
+ return buttonState == ButtonState.Pressed && !PreviouslyPressedButtons[(int)stateIndex].Contains(button);
+ }
+
+ public Buttons[] GetFramePressedButtons(PlayerIndex index)
+ {
+ GamePadState state = GamePad.GetState((PlayerIndex)index);
+ List<Buttons> buttons = new List<Buttons>();
+ if (state.IsConnected)
+ {
+ if (WasButtonJustPressed(Buttons.A, state.Buttons.A, index)) buttons.Add(Buttons.A);
+ if (WasButtonJustPressed(Buttons.B, state.Buttons.B, index)) buttons.Add(Buttons.B);
+ if (WasButtonJustPressed(Buttons.Back, state.Buttons.Back, index)) buttons.Add(Buttons.Back);
+ if (WasButtonJustPressed(Buttons.BigButton, state.Buttons.BigButton, index)) buttons.Add(Buttons.BigButton);
+ if (WasButtonJustPressed(Buttons.LeftShoulder, state.Buttons.LeftShoulder, index)) buttons.Add(Buttons.LeftShoulder);
+ if (WasButtonJustPressed(Buttons.LeftStick, state.Buttons.LeftStick, index)) buttons.Add(Buttons.LeftStick);
+ if (WasButtonJustPressed(Buttons.RightShoulder, state.Buttons.RightShoulder, index)) buttons.Add(Buttons.RightShoulder);
+ if (WasButtonJustPressed(Buttons.RightStick, state.Buttons.RightStick, index)) buttons.Add(Buttons.RightStick);
+ if (WasButtonJustPressed(Buttons.Start, state.Buttons.Start, index)) buttons.Add(Buttons.Start);
+ if (WasButtonJustPressed(Buttons.X, state.Buttons.X, index)) buttons.Add(Buttons.X);
+ if (WasButtonJustPressed(Buttons.Y, state.Buttons.Y, index)) buttons.Add(Buttons.Y);
+ if (WasButtonJustPressed(Buttons.DPadUp, state.DPad.Up, index)) buttons.Add(Buttons.DPadUp);
+ if (WasButtonJustPressed(Buttons.DPadDown, state.DPad.Down, index)) buttons.Add(Buttons.DPadDown);
+ if (WasButtonJustPressed(Buttons.DPadLeft, state.DPad.Left, index)) buttons.Add(Buttons.DPadLeft);
+ if (WasButtonJustPressed(Buttons.DPadRight, state.DPad.Right, index)) buttons.Add(Buttons.DPadRight);
+
+ }
+ return buttons.ToArray();
+ }
+
public int PreviousGameLocations { get; private set; }
public int PreviousLocationObjects { get; private set; }
public int PreviousItems_ { get; private set; }
@@ -246,6 +280,24 @@ namespace StardewModdingAPI.Inheritance foreach (Keys k in FrameReleasedKeys)
Events.ControlEvents.InvokeKeyReleased(k);
+ for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ {
+ foreach(Buttons b in GetFramePressedButtons(i))
+ {
+ Events.ControlEvents.InvokeButtonPressed(i, b);
+ }
+ }
+
+ for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
+ {
+ GamePadState state = GamePad.GetState(i);
+ if (state.IsConnected)
+ {
+ // TODO: Process state
+ }
+ }
+
+
if (KStateNow != KStatePrior)
{
Events.ControlEvents.InvokeKeyboardChanged(KStatePrior, KStateNow);
diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 5b962d44..c563174a 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -78,11 +78,8 @@ <Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
- <Reference Include="Stardew Valley, Version=1.0.5900.38427, Culture=neutral, processorArchitecture=x86">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
- <EmbedInteropTypes>False</EmbedInteropTypes>
- <Private>True</Private>
+ <Reference Include="Stardew Valley">
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\Stardew Valley.exe</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -93,10 +90,8 @@ <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
- <Reference Include="xTile, Version=2.0.4.0, Culture=neutral, processorArchitecture=x86">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>$(SteamInstallPath)\steamapps\common\Stardew Valley\xTile.dll</HintPath>
- <Private>True</Private>
+ <Reference Include="xTile">
+ <HintPath>D:\Games\steamapps\common\Stardew Valley\xTile.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
|