mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-19 21:10:11 -07:00
[Input pipe] Use EditText to handle input events, with support input unicodes
This commit is contained in:
parent
cc47a72bc2
commit
ae50740ff4
10 changed files with 251 additions and 712 deletions
|
|
@ -7,131 +7,107 @@ import android.widget.*;
|
|||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
import java.io.*;
|
||||
import com.google.gson.*;
|
||||
|
||||
public class MainActivity extends BaseMainActivity implements OnClickListener, OnTouchListener {
|
||||
private Button upButton,
|
||||
downButton, leftButton,
|
||||
rightButton, jumpButton,
|
||||
primaryButton, secondaryButton,
|
||||
debugButton, shiftButton,
|
||||
keyboardButton, inventoryButton,
|
||||
talkButton, thirdPersonButton,
|
||||
zoomButton, listPlayersButton,
|
||||
toggleControlButton;
|
||||
|
||||
private Button[] controlButtons;
|
||||
|
||||
public class MainActivity extends BaseMainActivity {
|
||||
private ControlLayout mControlLayout;
|
||||
|
||||
private View.OnClickListener mClickListener;
|
||||
private View.OnTouchListener mTouchListener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
initLayout(R.layout.main);
|
||||
|
||||
this.upButton = findButton(R.id.control_up);
|
||||
this.downButton = findButton(R.id.control_down);
|
||||
this.leftButton = findButton(R.id.control_left);
|
||||
this.rightButton = findButton(R.id.control_right);
|
||||
this.jumpButton = findButton(R.id.control_jump);
|
||||
this.primaryButton = findButton(R.id.control_primary);
|
||||
this.secondaryButton = findButton(R.id.control_secondary);
|
||||
this.debugButton = findButton(R.id.control_debug);
|
||||
this.shiftButton = findButton(R.id.control_shift);
|
||||
this.keyboardButton = findButton(R.id.control_keyboard);
|
||||
this.inventoryButton = findButton(R.id.control_inventory);
|
||||
this.talkButton = findButton(R.id.control_talk);
|
||||
this.thirdPersonButton = findButton(R.id.control_thirdperson);
|
||||
this.zoomButton = findButton(R.id.control_zoom);
|
||||
this.listPlayersButton = findButton(R.id.control_listplayers);
|
||||
this.toggleControlButton = findButton(R.id.control_togglecontrol);
|
||||
this.controlButtons = new Button[]{
|
||||
upButton, downButton, leftButton, rightButton,
|
||||
jumpButton, primaryButton, secondaryButton,
|
||||
debugButton, shiftButton, keyboardButton,
|
||||
inventoryButton, talkButton, thirdPersonButton,
|
||||
listPlayersButton
|
||||
initLayout(R.layout.main_with_customctrl);
|
||||
|
||||
mClickListener = new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view instanceof ControlButton) {
|
||||
ControlButton button = (ControlButton) view;
|
||||
switch (button.getProperties().keycode) {
|
||||
case ControlData.SPECIALBTN_KEYBOARD:
|
||||
showKeyboard();
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_TOGGLECTRL:
|
||||
mControlLayout.toggleControlVisible();
|
||||
break;
|
||||
|
||||
case ControlData.SPECIALBTN_VIRTUALMOUSE:
|
||||
toggleMouse(button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
this.toggleControlButton.setOnClickListener(this);
|
||||
this.zoomButton.setVisibility(mVersionInfo.optifineLib == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
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;
|
||||
switch (button.getProperties().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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
ControlData[] specialButtons = ControlData.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener
|
||||
= specialButtons[1].specialButtonListener
|
||||
= specialButtons[4].specialButtonListener
|
||||
= mClickListener;
|
||||
|
||||
specialButtons[2].specialButtonListener
|
||||
= specialButtons[3].specialButtonListener
|
||||
= specialButtons[5].specialButtonListener
|
||||
= mTouchListener;
|
||||
|
||||
mControlLayout = findViewById(R.id.main_control_layout);
|
||||
mControlLayout.setModifiable(false);
|
||||
try {
|
||||
mControlLayout.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(this, th);
|
||||
}
|
||||
|
||||
// toggleGui(null);
|
||||
onClick(toggleControlButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.control_togglecontrol: {
|
||||
/*
|
||||
switch(overlayView.getVisibility()){
|
||||
case View.VISIBLE: overlayView.setVisibility(View.GONE);
|
||||
break;
|
||||
case View.GONE: overlayView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
*/
|
||||
|
||||
for (Button button : controlButtons) {
|
||||
button.setVisibility(button.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
zoomButton.setVisibility((zoomButton.getVisibility() == View.GONE && mVersionInfo.optifineLib != null) ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onTouch(View v, 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;
|
||||
}
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.control_up: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_W, 0, isDown); break;
|
||||
case R.id.control_left: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_A, 0, isDown); break;
|
||||
case R.id.control_down: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_S, 0, isDown); break;
|
||||
case R.id.control_right: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_D, 0, isDown); break;
|
||||
case R.id.control_jump: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_SPACE, 0, isDown); break;
|
||||
case R.id.control_primary: sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, isDown); break;
|
||||
case R.id.control_secondary:
|
||||
if (CallbackBridge.isGrabbing()) {
|
||||
sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown);
|
||||
} else {
|
||||
/*
|
||||
if (!isDown) {
|
||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
}
|
||||
*/
|
||||
|
||||
CallbackBridge.putMouseEventWithCoords(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, isDown ? 1 : 0, CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
|
||||
setRightOverride(isDown);
|
||||
} break;
|
||||
case R.id.control_debug: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_F3, 0, isDown); break;
|
||||
case R.id.control_shift: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, 0, isDown); break;
|
||||
case R.id.control_inventory: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_E, 0, isDown); break;
|
||||
case R.id.control_talk: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_T, 0, isDown); break;
|
||||
case R.id.control_keyboard: showKeyboard(); break;
|
||||
case R.id.control_thirdperson: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_F5, 0, isDown); break;
|
||||
case R.id.control_zoom: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_C, 0, isDown); break;
|
||||
case R.id.control_listplayers: sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_TAB, 0, isDown); break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Button findButton(int id) {
|
||||
Button button = (Button) findViewById(id);
|
||||
button.setOnTouchListener(this);
|
||||
button.setFocusable(false);
|
||||
button.setFocusableInTouchMode(false);
|
||||
return button;
|
||||
mControlLayout.toggleControlVisible();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue