Skip to content

Commit

Permalink
Feat[gamepad_remapper]: restore cursor, add save functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Aug 22, 2024
1 parent 0d48477 commit a0ff100
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public boolean onTouchEvent(MotionEvent e) {
return mCurrentTouchProcessor.processTouchEvent(e);
}

private void createGamepad(View contextView, InputDevice inputDevice) {
mGamepad = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
}

/**
* The event for mouse/joystick movements
*/
Expand All @@ -212,9 +216,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) {
int mouseCursorIndex = -1;

if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null){
mGamepad = new Gamepad(this, event.getDevice(), DefaultDataProvider.INSTANCE);
}
if(mGamepad == null) createGamepad(this, event.getDevice());

mInputManager.handleMotionEventInput(getContext(), event, mGamepad);
return true;
Expand Down Expand Up @@ -286,9 +288,7 @@ public boolean processKeyEvent(KeyEvent event) {
}

if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null){
mGamepad = new Gamepad(this, event.getDevice(), DefaultDataProvider.INSTANCE);
}
if(mGamepad == null) createGamepad(this, event.getDevice());

mInputManager.handleKeyEventInput(getContext(), event, mGamepad);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class Gamepad implements GrabListener, GamepadHandler {

private final GamepadDataProvider mMapProvider;

public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider){
public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);

mScreenChoreographer = Choreographer.getInstance();
Expand Down Expand Up @@ -124,11 +124,12 @@ public void doFrame(long frameTimeNanos) {
mMapProvider = mapProvider;

CallbackBridge.sendCursorPos(CallbackBridge.windowWidth/2f, CallbackBridge.windowHeight/2f);
ViewParent parent = contextView.getParent();
if(parent instanceof FrameLayout) {
// ((FrameLayout)parent).addView(mPointerImageView);

if(showCursor) {
((FrameLayout)contextView.getParent()).addView(mPointerImageView);
}


placePointerView(CallbackBridge.physicalWidth/2, CallbackBridge.physicalHeight/2);

reloadGamepadMaps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.kdt.pojavlaunch.EfficientAndroidLWJGLKeycode;
import net.kdt.pojavlaunch.GrabListener;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.customcontrols.EditorExitable;

import android.os.Handler;
Expand Down Expand Up @@ -249,18 +250,22 @@ private void updateKeycodeLabel() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int selectionIndex, long selectionId) {
if(mAttachedPosition == -1) return;
short[] keycodes = mRealButtons[mAttachedPosition].keycodes;
int editedKeycodeIndex = -1;
for(int i = 0; i < mKeySpinners.length && i < keycodes.length; i++) {
for(int i = 0; i < mKeySpinners.length && i < mKeycodes.length; i++) {
if(!adapterView.equals(mKeySpinners[i])) continue;
editedKeycodeIndex = i;
break;
}
if(editedKeycodeIndex == -1) return;
int keycode_offset = selectionIndex - mSpecialKeycodeCount;
if(selectionIndex <= mSpecialKeycodeCount) keycodes[editedKeycodeIndex] = (short) (keycode_offset);
else keycodes[editedKeycodeIndex] = EfficientAndroidLWJGLKeycode.getValueByIndex(keycode_offset);
if(selectionIndex <= mSpecialKeycodeCount) mKeycodes[editedKeycodeIndex] = (short) (keycode_offset);
else mKeycodes[editedKeycodeIndex] = EfficientAndroidLWJGLKeycode.getValueByIndex(keycode_offset);
updateKeycodeLabel();
try {
GamepadMapStore.save();
}catch (Exception e) {
Tools.showError(adapterView.getContext(), e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -21,14 +22,12 @@
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
import net.kdt.pojavlaunch.customcontrols.gamepad.GamepadMapperAdapter;

import fr.spse.gamepad_remapper.GamepadHandler;
import fr.spse.gamepad_remapper.Remapper;
import fr.spse.gamepad_remapper.RemapperManager;
import fr.spse.gamepad_remapper.RemapperView;

public class GamepadMapperFragment extends Fragment implements View.OnKeyListener, View.OnGenericMotionListener, EditorExitable, AdapterView

.OnItemSelectedListener {
public class GamepadMapperFragment extends Fragment implements
View.OnKeyListener, View.OnGenericMotionListener,
EditorExitable, AdapterView.OnItemSelectedListener {
public static final String TAG = "GamepadMapperFragment";
private final RemapperView.Builder mRemapperViewBuilder = new RemapperView.Builder(null)
.remapA(true)
Expand Down Expand Up @@ -71,13 +70,16 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
mGrabStateSpinner.setOnItemSelectedListener(this);
}

private void createGamepad(View mainView, InputDevice inputDevice) {
mGamepad = new Gamepad(mainView, inputDevice, mMapperAdapter, false);
}

@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
Log.i("onKey", keyEvent.toString());
View mainView = getView();
if(!Gamepad.isGamepadEvent(keyEvent) || mainView == null) return false;
if(mGamepad == null) mGamepad = new Gamepad(mainView, keyEvent.getDevice(), mMapperAdapter);
if(mGamepad == null) createGamepad(mainView, keyEvent.getDevice());
mInputManager.handleKeyEventInput(mainView.getContext(), keyEvent, mGamepad);
return true;
}
Expand All @@ -87,7 +89,7 @@ public boolean onGenericMotion(View view, MotionEvent motionEvent) {
Log.i("onGenericMotion", motionEvent.toString());
View mainView = getView();
if(!Gamepad.isGamepadEvent(motionEvent) || mainView == null) return false;
if(mGamepad == null) mGamepad = new Gamepad(mainView, motionEvent.getDevice(), mMapperAdapter);
if(mGamepad == null) createGamepad(mainView, motionEvent.getDevice());
mInputManager.handleMotionEventInput(mainView.getContext(), motionEvent, mGamepad);
return true;
}
Expand Down

0 comments on commit a0ff100

Please sign in to comment.