fix(HotbarView): #37

This commit is contained in:
tomikun
2026-07-18 22:58:43 +08:00
parent 6257d58d65
commit 3bd4077117
3 changed files with 16 additions and 0 deletions

View File

@@ -501,6 +501,10 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
Tools.runOnUiThread(()-> mServiceBinder.isActive = false);
}
public void setmLastIndex(int a){
mHotbarView.setmLastIndex(a);
}
private void dialogSendCustomKey() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.control_customkey);

View File

@@ -97,6 +97,10 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
setLayoutParams(marginLayoutParams);
}
public void setmLastIndex(int mLastIndex) {
this.mLastIndex = mLastIndex;
}
@SuppressWarnings("ClickableViewAccessibility") // performClick does not report coordinates.
@Override
public boolean onTouchEvent(MotionEvent event) {

View File

@@ -8,6 +8,7 @@ import android.content.*;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Choreographer;
import android.view.KeyEvent;
import android.view.MotionEvent;
import androidx.annotation.Keep;
@@ -93,6 +94,13 @@ public class CallbackBridge {
if(isDown){
SDLActivity.onNativeKeyDown(EfficientAndroidLWJGLKeycode.getAndroidKeycode(keycode));
} else SDLActivity.onNativeKeyUp(EfficientAndroidLWJGLKeycode.getAndroidKeycode(keycode));
// If not in GUI and pressed a hotbar key, update HotbarView's last index for gesture
// detection. This is still faulty but should be less so.
if (isGrabbing()){
if (keycode >= LwjglGlfwKeycode.GLFW_KEY_0 && keycode <= LwjglGlfwKeycode.GLFW_KEY_9){
((MainActivity) SDLActivity.getContext()).setmLastIndex(keycode - LwjglGlfwKeycode.GLFW_KEY_0);
}
}
}
public static void sendChar(char keychar, int modifiers){