diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java index cefb2d8bae..3c4a26f0ee 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java @@ -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 */ @@ -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; @@ -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; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java index 90b6d18f18..cb89fc375e 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/Gamepad.java @@ -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(); @@ -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(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java index d778ea2082..e386d65e91 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/gamepad/GamepadMapperAdapter.java @@ -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; @@ -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 diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java index 57e1515a0f..831e57a567 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/GamepadMapperFragment.java @@ -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; @@ -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) @@ -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; } @@ -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; }