mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-12 01:21:09 -07:00
Revamp the special key system to match v2 spirit:
- Fix special keys triggerring up to 16 times ! - Fix special keys not being properly toggleable - Moved special key handling into the ControlButton. - Removed the need for a listener. - Toggling the mouse doesn't affect the button text anymore.
This commit is contained in:
parent
28fa92f1cb
commit
c435db640a
8 changed files with 94 additions and 179 deletions
|
|
@ -3,142 +3,54 @@ package net.kdt.pojavlaunch;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import net.kdt.pojavlaunch.customcontrols.buttons.ControlButton;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||
|
||||
import org.lwjgl.glfw.*;
|
||||
import java.io.*;
|
||||
|
||||
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.DEFAULT_PREF;
|
||||
|
||||
public class MainActivity extends BaseMainActivity {
|
||||
public ControlLayout mControlLayout;
|
||||
|
||||
private View.OnClickListener mClickListener;
|
||||
private View.OnTouchListener mTouchListener;
|
||||
public static ControlLayout mControlLayout;
|
||||
|
||||
private FileObserver fileObserver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initLayout(R.layout.main_with_customctrl);
|
||||
super.ingameControlsEditorListener = new NavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.menu_ctrl_load:
|
||||
CustomControlsActivity.load(mControlLayout);
|
||||
break;
|
||||
case R.id.menu_ctrl_add:
|
||||
mControlLayout.addControlButton(new ControlData("New"));
|
||||
break;
|
||||
case R.id.menu_ctrl_add_drawer:
|
||||
mControlLayout.addDrawer(new ControlDrawerData());
|
||||
break;
|
||||
case R.id.menu_ctrl_selectdefault:
|
||||
CustomControlsActivity.dialogSelectDefaultCtrl(mControlLayout);
|
||||
break;
|
||||
case R.id.menu_ctrl_save:
|
||||
CustomControlsActivity.save(true,mControlLayout);
|
||||
break;
|
||||
}
|
||||
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
super.ingameControlsEditorListener = menuItem -> {
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.menu_ctrl_load:
|
||||
CustomControlsActivity.load(mControlLayout);
|
||||
break;
|
||||
case R.id.menu_ctrl_add:
|
||||
mControlLayout.addControlButton(new ControlData("New"));
|
||||
break;
|
||||
case R.id.menu_ctrl_add_drawer:
|
||||
mControlLayout.addDrawer(new ControlDrawerData());
|
||||
break;
|
||||
case R.id.menu_ctrl_selectdefault:
|
||||
CustomControlsActivity.dialogSelectDefaultCtrl(mControlLayout);
|
||||
break;
|
||||
case R.id.menu_ctrl_save:
|
||||
CustomControlsActivity.save(true,mControlLayout);
|
||||
break;
|
||||
}
|
||||
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
};
|
||||
|
||||
mClickListener = new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view instanceof ControlButton) {
|
||||
ControlButton button = (ControlButton) view;
|
||||
for(int keycode : button.getProperties().keycodes){
|
||||
switch (keycode) {
|
||||
case ControlData.SPECIALBTN_KEYBOARD:
|
||||
touchCharInput.switchKeyboardState();
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_TOGGLECTRL:
|
||||
mControlLayout.toggleControlVisible();
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_VIRTUALMOUSE:
|
||||
toggleMouse(button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mTouchListener = new View.OnTouchListener(){
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent e) {
|
||||
boolean isDown;
|
||||
switch (e.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN: // 0
|
||||
case MotionEvent.ACTION_POINTER_DOWN: // 5
|
||||
isDown = true;
|
||||
break;
|
||||
case MotionEvent.ACTION_UP: // 1
|
||||
case MotionEvent.ACTION_CANCEL: // 3
|
||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||
isDown = false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (view instanceof ControlButton) {
|
||||
ControlButton button = (ControlButton) view;
|
||||
for(int keycode : button.getProperties().keycodes) {
|
||||
switch (keycode) {
|
||||
case ControlData.SPECIALBTN_MOUSEPRI:
|
||||
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown);
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_MOUSEMID:
|
||||
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_MIDDLE, isDown);
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_MOUSESEC:
|
||||
if (CallbackBridge.isGrabbing()) {
|
||||
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
||||
} else {
|
||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown ? 1 : 0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
|
||||
setRightOverride(isDown);
|
||||
}
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_SCROLLDOWN:
|
||||
if (!isDown) CallbackBridge.sendScroll(0, 1d);
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_SCROLLUP:
|
||||
if (!isDown) CallbackBridge.sendScroll(0, -1d);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
fileObserver = new FileObserver(new File(Tools.DIR_GAME_NEW + "/options.txt"), FileObserver.MODIFY) {
|
||||
@Override
|
||||
public void onEvent(int i, @Nullable String s) {
|
||||
//FIXME Make sure the multithreading nature of this event doesn't cause any problems ?
|
||||
MCOptionUtils.load();
|
||||
getMcScale();
|
||||
}
|
||||
|
|
@ -147,7 +59,6 @@ public class MainActivity extends BaseMainActivity {
|
|||
fileObserver = new FileObserver(Tools.DIR_GAME_NEW + "/options.txt", FileObserver.MODIFY) {
|
||||
@Override
|
||||
public void onEvent(int i, @Nullable String s) {
|
||||
//FIXME Make sure the multithreading nature of this event doesn't cause any problems ?
|
||||
MCOptionUtils.load();
|
||||
getMcScale();
|
||||
}
|
||||
|
|
@ -156,19 +67,6 @@ public class MainActivity extends BaseMainActivity {
|
|||
|
||||
fileObserver.startWatching();
|
||||
|
||||
ControlData[] specialButtons = ControlData.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener
|
||||
= specialButtons[1].specialButtonListener
|
||||
= specialButtons[4].specialButtonListener
|
||||
= mClickListener;
|
||||
|
||||
specialButtons[2].specialButtonListener
|
||||
= specialButtons[3].specialButtonListener
|
||||
= specialButtons[5].specialButtonListener
|
||||
= specialButtons[6].specialButtonListener
|
||||
= specialButtons[7].specialButtonListener
|
||||
= mTouchListener;
|
||||
|
||||
mControlLayout = findViewById(R.id.main_control_layout);
|
||||
mControlLayout.setModifiable(false);
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue