-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DO NOT USE. Feat[gamepad_remapper]: start work on gamepad remapper
- Loading branch information
Showing
14 changed files
with
980 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...auncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/DefaultDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.kdt.pojavlaunch.customcontrols.gamepad; | ||
|
||
import net.kdt.pojavlaunch.GrabListener; | ||
|
||
import org.lwjgl.glfw.CallbackBridge; | ||
|
||
public class DefaultDataProvider implements GamepadDataProvider { | ||
public static final DefaultDataProvider INSTANCE = new DefaultDataProvider(); | ||
|
||
private DefaultDataProvider() { | ||
reloadGamepadMaps(); | ||
} | ||
|
||
@Override | ||
public GamepadMap getGameMap() { | ||
return GamepadMapStore.getGameMap(); | ||
} | ||
|
||
|
||
@Override | ||
public GamepadMap getMenuMap() { | ||
return GamepadMapStore.getMenuMap(); | ||
} | ||
|
||
@Override | ||
public boolean isGrabbing() { | ||
return CallbackBridge.isGrabbing(); | ||
} | ||
|
||
@Override | ||
public void attachGrabListener(GrabListener grabListener) { | ||
CallbackBridge.addGrabListener(grabListener); | ||
} | ||
|
||
@Override | ||
public void reloadGamepadMaps() { | ||
GamepadMapStore.load(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 15 additions & 31 deletions
46
...pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,30 @@ | ||
package net.kdt.pojavlaunch.customcontrols.gamepad; | ||
|
||
import android.view.KeyEvent; | ||
|
||
/** | ||
* Simple button able to store its state and some properties | ||
* This class corresponds to a button that does exist on the gamepad | ||
*/ | ||
public class GamepadButton { | ||
|
||
public int[] keycodes; | ||
public class GamepadButton extends GamepadEmulatedButton { | ||
public boolean isToggleable = false; | ||
private boolean mIsDown = false; | ||
private boolean mIsToggled = false; | ||
|
||
public void update(KeyEvent event){ | ||
boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); | ||
update(isKeyDown); | ||
} | ||
|
||
public void update(boolean isKeyDown){ | ||
if(isKeyDown != mIsDown){ | ||
mIsDown = isKeyDown; | ||
if(isToggleable){ | ||
if(isKeyDown){ | ||
mIsToggled = !mIsToggled; | ||
Gamepad.sendInput(keycodes, mIsToggled); | ||
} | ||
return; | ||
} | ||
Gamepad.sendInput(keycodes, mIsDown); | ||
@Override | ||
protected void onDownStateChanged(boolean isDown) { | ||
if(isToggleable && isDown){ | ||
mIsToggled = !mIsToggled; | ||
Gamepad.sendInput(keycodes, mIsToggled); | ||
return; | ||
} | ||
super.onDownStateChanged(isDown); | ||
} | ||
|
||
public void resetButtonState(){ | ||
if(mIsDown || mIsToggled){ | ||
@Override | ||
public void resetButtonState() { | ||
if(!mIsDown && mIsToggled) { | ||
Gamepad.sendInput(keycodes, false); | ||
mIsToggled = false; | ||
} else { | ||
super.resetButtonState(); | ||
} | ||
mIsDown = false; | ||
mIsToggled = false; | ||
} | ||
|
||
public boolean isDown(){ | ||
return isToggleable ? mIsToggled : mIsDown; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...auncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.kdt.pojavlaunch.customcontrols.gamepad; | ||
|
||
import net.kdt.pojavlaunch.GrabListener; | ||
|
||
public interface GamepadDataProvider { | ||
GamepadMap getMenuMap(); | ||
GamepadMap getGameMap(); | ||
boolean isGrabbing(); | ||
void attachGrabListener(GrabListener grabListener); | ||
void reloadGamepadMaps(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadEmulatedButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.kdt.pojavlaunch.customcontrols.gamepad; | ||
|
||
import android.view.KeyEvent; | ||
|
||
/** | ||
* This class corresponds to a button that does not physically exist on the gamepad, but is | ||
* emulated from other inputs on it (like WASD directional keys) | ||
*/ | ||
public class GamepadEmulatedButton { | ||
public short[] keycodes; | ||
protected boolean mIsDown = false; | ||
|
||
public void update(KeyEvent event) { | ||
boolean isKeyDown = (event.getAction() == KeyEvent.ACTION_DOWN); | ||
update(isKeyDown); | ||
} | ||
|
||
public void update(boolean isKeyDown){ | ||
if(isKeyDown != mIsDown){ | ||
mIsDown = isKeyDown; | ||
onDownStateChanged(mIsDown); | ||
} | ||
} | ||
|
||
public void resetButtonState() { | ||
if(mIsDown) Gamepad.sendInput(keycodes, false); | ||
mIsDown = false; | ||
} | ||
|
||
protected void onDownStateChanged(boolean isDown) { | ||
Gamepad.sendInput(keycodes, mIsDown); | ||
} | ||
} |
Oops, something went wrong.