mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
[Experimental] Implemented Custom controls
This commit is contained in:
parent
2516c051bd
commit
19b046db97
@ -62,6 +62,13 @@
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"/>
|
||||
|
||||
<activity
|
||||
android:launchMode="standard"
|
||||
android:multiprocess="true"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:name=".CustomCtrlMainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"/>
|
||||
|
||||
<activity
|
||||
android:screenOrientation="sensorLandscape"
|
||||
|
@ -12,123 +12,123 @@ import com.kdt.mcgui.*;
|
||||
|
||||
public class MineActivity extends BaseActivity implements View.OnClickListener
|
||||
{
|
||||
private int topId = 150001;
|
||||
private boolean showBeforeView = true;
|
||||
|
||||
private ImageButton menu;
|
||||
private LinearLayout content, undertop;
|
||||
private int topId = 150001;
|
||||
private boolean showBeforeView = true;
|
||||
|
||||
private ImageButton menu;
|
||||
private LinearLayout content, undertop;
|
||||
|
||||
private LayoutInflater li;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
this.onCreate(savedInstanceState, true);
|
||||
}
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState, boolean showBeforeView) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.showBeforeView = showBeforeView;
|
||||
if (showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
}
|
||||
|
||||
private void mcUIInit() {
|
||||
RelativeLayout root = new RelativeLayout(this);
|
||||
LinearLayout top = new LinearLayout(this);
|
||||
top.setId(topId);
|
||||
private LayoutInflater li;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
this.onCreate(savedInstanceState, true);
|
||||
}
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState, boolean showBeforeView) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.showBeforeView = showBeforeView;
|
||||
if (showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
}
|
||||
|
||||
private void mcUIInit() {
|
||||
RelativeLayout root = new RelativeLayout(this);
|
||||
LinearLayout top = new LinearLayout(this);
|
||||
top.setId(topId);
|
||||
|
||||
content = new LinearLayout(this);
|
||||
RelativeLayout btm = new RelativeLayout(this);
|
||||
content = new LinearLayout(this);
|
||||
RelativeLayout btm = new RelativeLayout(this);
|
||||
|
||||
li = LayoutInflater.from(this);
|
||||
li.inflate(R.layout.top_bar, top, true);
|
||||
li.inflate(R.layout.bottom_bar, btm, true);
|
||||
|
||||
FontChanger.changeFonts(btm);
|
||||
li = LayoutInflater.from(this);
|
||||
li.inflate(R.layout.top_bar, top, true);
|
||||
li.inflate(R.layout.bottom_bar, btm, true);
|
||||
|
||||
FontChanger.changeFonts(btm);
|
||||
|
||||
// replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang));
|
||||
Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang));
|
||||
// Locale l = getResources().getConfiguration().locale;
|
||||
|
||||
RelativeLayout.LayoutParams conLay = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
conLay.addRule(root.BELOW, topId);
|
||||
conLay.bottomMargin = 66;
|
||||
// replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang));
|
||||
Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang));
|
||||
// Locale l = getResources().getConfiguration().locale;
|
||||
|
||||
RelativeLayout.LayoutParams conLay = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
||||
conLay.addRule(root.BELOW, topId);
|
||||
conLay.bottomMargin = 66;
|
||||
|
||||
content.setLayoutParams(conLay);
|
||||
content.setLayoutParams(conLay);
|
||||
|
||||
root.addView(top, new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
root.addView(content);
|
||||
root.addView(btm);
|
||||
root.addView(top, new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
root.addView(content);
|
||||
root.addView(btm);
|
||||
|
||||
super.setContentView(root);
|
||||
super.setContentView(root);
|
||||
|
||||
TextView ver = (TextView) findViewById(R.id.bottombar_version_view);
|
||||
TextView ver = (TextView) findViewById(R.id.bottombar_version_view);
|
||||
|
||||
menu = (ImageButton) findViewById(R.id.topbar_navmenu_icon);
|
||||
setMenuVisible(false);
|
||||
|
||||
undertop = (LinearLayout) findViewById(R.id.topbar_undertop_view);
|
||||
menu = (ImageButton) findViewById(R.id.topbar_navmenu_icon);
|
||||
setMenuVisible(false);
|
||||
|
||||
undertop = (LinearLayout) findViewById(R.id.topbar_undertop_view);
|
||||
|
||||
try {
|
||||
ver.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
||||
} catch (PackageManager.NameNotFoundException e) {} // Never happend!
|
||||
try {
|
||||
ver.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
|
||||
} catch (PackageManager.NameNotFoundException e) {} // Never happend!
|
||||
|
||||
setClick(R.id.topbar_help_text);
|
||||
setClick(R.id.topbar_logo);
|
||||
setClick(R.id.bottombar_author_logo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int resource)
|
||||
{
|
||||
if (!showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
|
||||
li.inflate(resource, content, true);
|
||||
FontChanger.changeFonts(content);
|
||||
}
|
||||
setClick(R.id.topbar_help_text);
|
||||
setClick(R.id.topbar_logo);
|
||||
setClick(R.id.bottombar_author_logo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int resource)
|
||||
{
|
||||
if (!showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
|
||||
li.inflate(resource, content, true);
|
||||
FontChanger.changeFonts(content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view)
|
||||
{
|
||||
if (!showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
|
||||
content.addView(view);
|
||||
if (view instanceof ViewGroup) {
|
||||
FontChanger.changeFonts((ViewGroup) view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
switch (view.getId()) {
|
||||
case R.id.topbar_help_text: Tools.openURL(this, "https://www.minecraft.net/help");
|
||||
break;
|
||||
case R.id.topbar_logo: Tools.openURL(this, "https://www.minecraft.net");
|
||||
break;
|
||||
case R.id.bottombar_author_logo: Tools.openURL(this, "https://mojang.com");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setUndertopView(View view) {
|
||||
if (undertop.getChildCount() > 0) {
|
||||
undertop.removeAllViews();
|
||||
}
|
||||
undertop.addView(view);
|
||||
}
|
||||
|
||||
public void setMenuVisible(boolean value) {
|
||||
menu.setVisibility(value ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void setClick(int id) {
|
||||
findViewById(id).setOnClickListener(this);
|
||||
}
|
||||
@Override
|
||||
public void setContentView(View view)
|
||||
{
|
||||
if (!showBeforeView) {
|
||||
mcUIInit();
|
||||
}
|
||||
|
||||
content.addView(view);
|
||||
if (view instanceof ViewGroup) {
|
||||
FontChanger.changeFonts((ViewGroup) view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
switch (view.getId()) {
|
||||
case R.id.topbar_help_text: Tools.openURL(this, "https://www.minecraft.net/help");
|
||||
break;
|
||||
case R.id.topbar_logo: Tools.openURL(this, "https://www.minecraft.net");
|
||||
break;
|
||||
case R.id.bottombar_author_logo: Tools.openURL(this, "https://mojang.com");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setUndertopView(View view) {
|
||||
if (undertop.getChildCount() > 0) {
|
||||
undertop.removeAllViews();
|
||||
}
|
||||
undertop.addView(view);
|
||||
}
|
||||
|
||||
public void setMenuVisible(boolean value) {
|
||||
menu.setVisibility(value ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void setClick(int id) {
|
||||
findViewById(id).setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.utils.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class BaseMainActivity extends LoggableActivity implements OnTouchListener {
|
||||
public class BaseMainActivity extends LoggableActivity {
|
||||
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
|
||||
|
||||
public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ";
|
||||
@ -106,11 +106,11 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
|
||||
// private static Collection<? extends Provider.Service> rsaPkcs1List;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
// @Override
|
||||
public void onCreate(Bundle savedInstanceState, int resId)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
setContentView(resId);
|
||||
|
||||
try {
|
||||
// FIXME: is it safe fot multi thread?
|
||||
@ -196,14 +196,6 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
|
||||
this.minecraftGLView = (MinecraftGLView) findViewById(R.id.main_game_render_view);
|
||||
|
||||
ControlData[] specialButtons = ControlData.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener = new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showKeyboard();
|
||||
}
|
||||
};
|
||||
|
||||
// toggleGui(null);
|
||||
this.drawerLayout.closeDrawers();
|
||||
|
||||
@ -649,9 +641,14 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
|
||||
minecraftGLView.setOnHoverListener(new View.OnHoverListener(){
|
||||
@Override
|
||||
public boolean onHover(View p1, MotionEvent p2) {
|
||||
public boolean onHover(View v, MotionEvent e) {
|
||||
if (!CallbackBridge.isGrabbing() && mIsResuming) {
|
||||
return glTouchListener.onTouch(p1, p2);
|
||||
// return glTouchListener.onTouch(v, e);
|
||||
int x = ((int) e.getX()) / scaleFactor;
|
||||
int y = ((int) e.getY()) / scaleFactor;
|
||||
CallbackBridge.mouseX = x;
|
||||
CallbackBridge.mouseY = y;
|
||||
CallbackBridge.sendCursorPos(x, y);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -804,56 +801,6 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static void fullyExit() {
|
||||
System.exit(0);
|
||||
}
|
||||
@ -1102,16 +1049,6 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
.show();
|
||||
}
|
||||
|
||||
protected Button findButton(int id) {
|
||||
Button button = (Button) findViewById(id);
|
||||
button.setWidth((int) (button.getWidth() * Tools.currentDisplayMetrics.scaledDensity));
|
||||
button.setHeight((int) (button.getHeight() * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setOnTouchListener(this);
|
||||
button.setFocusable(false);
|
||||
button.setFocusableInTouchMode(false);
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Prevent back
|
||||
@ -1133,7 +1070,7 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
|
||||
((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||
}
|
||||
|
||||
private void setRightOverride(boolean val) {
|
||||
protected void setRightOverride(boolean val) {
|
||||
this.rightOverride = val;
|
||||
// this.secondaryButton.setBackgroundDrawable(this.rightOverride ? this.secondaryButtonColorBackground : this.secondaryButtonDefaultBackground);
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ public class CustomControlsActivity extends BaseActivity
|
||||
|
||||
public boolean isModified = false;
|
||||
|
||||
private Gson gson;
|
||||
private String selectedName = "new_control";
|
||||
|
||||
@Override
|
||||
@ -36,8 +35,6 @@ public class CustomControlsActivity extends BaseActivity
|
||||
|
||||
mPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
ctrlLayout = (ControlLayout) findViewById(R.id.customctrl_controllayout);
|
||||
|
||||
// Menu
|
||||
@ -206,7 +203,7 @@ public class CustomControlsActivity extends BaseActivity
|
||||
|
||||
private void loadControl(String path) {
|
||||
try {
|
||||
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class);
|
||||
mCtrl = Tools.GLOBAL_GSON.fromJson(Tools.read(path), CustomControls.class);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
|
||||
selectedName = new File(path).getName();
|
||||
|
@ -0,0 +1,101 @@
|
||||
package net.kdt.pojavlaunch;
|
||||
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import android.view.View.*;
|
||||
import android.widget.*;
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class CustomCtrlMainActivity extends BaseMainActivity implements OnClickListener, OnTouchListener {
|
||||
private CustomControls mControl;
|
||||
private ControlLayout mControlLayout;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState, R.layout.main_with_customctrl);
|
||||
|
||||
ControlData[] specialButtons = ControlData.getSpecialButtons();
|
||||
for (ControlData specialButton : specialButtons) {
|
||||
specialButton.specialButtonListener = this;
|
||||
}
|
||||
|
||||
mControlLayout = findViewById(R.id.main_control_layout);
|
||||
mControl = new CustomControls();
|
||||
mControlLayout.setModifiable(false);
|
||||
loadControl(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
|
||||
mControlLayout.loadLayout(mControl);
|
||||
|
||||
// toggleGui(null);
|
||||
mControlLayout.toggleControlVisible();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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_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;
|
||||
}
|
||||
|
||||
private void loadControl(String path) {
|
||||
try {
|
||||
mControl = Tools.GLOBAL_GSON.fromJson(Tools.read(path), CustomControls.class);
|
||||
mControlLayout.loadLayout(mControl);
|
||||
} catch (Exception e) {
|
||||
Tools.showError(this, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,10 @@ import android.view.*;
|
||||
import android.view.View.*;
|
||||
import android.widget.*;
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
public class MainActivity extends BaseMainActivity implements OnClickListener {
|
||||
public class MainActivity extends BaseMainActivity implements OnClickListener, OnTouchListener {
|
||||
private Button upButton,
|
||||
downButton, leftButton,
|
||||
rightButton, jumpButton,
|
||||
@ -21,7 +23,7 @@ public class MainActivity extends BaseMainActivity implements OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState, R.layout.main);
|
||||
|
||||
this.upButton = findButton(R.id.control_up);
|
||||
this.downButton = findButton(R.id.control_down);
|
||||
@ -76,4 +78,64 @@ public class MainActivity extends BaseMainActivity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.setWidth((int) (button.getWidth() * Tools.currentDisplayMetrics.scaledDensity));
|
||||
button.setHeight((int) (button.getHeight() * LauncherPreferences.PREF_BUTTONSIZE));
|
||||
button.setOnTouchListener(this);
|
||||
button.setFocusable(false);
|
||||
button.setFocusableInTouchMode(false);
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ public class ControlData implements Cloneable
|
||||
private static ControlData[] SPECIAL_BUTTONS;
|
||||
private static String[] SPECIAL_BUTTON_NAME_ARRAY;
|
||||
|
||||
// Internal usage only
|
||||
public boolean isHideable;
|
||||
|
||||
/**
|
||||
* Both fields below are dynamic position data, auto updates
|
||||
* X and Y position, unlike the original one which uses fixed
|
||||
@ -135,7 +138,13 @@ public class ControlData implements Cloneable
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (!isDynamicBtn) {
|
||||
if (keycode < 0) {
|
||||
for (ControlData data : getSpecialButtons()) {
|
||||
if (keycode == data.keycode) {
|
||||
specialButtonListener = data.specialButtonListener;
|
||||
}
|
||||
}
|
||||
} if (!isDynamicBtn) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.view.*;
|
||||
import com.google.gson.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import android.support.v7.app.*;
|
||||
import java.util.*;
|
||||
|
||||
public class ControlLayout extends FrameLayout
|
||||
{
|
||||
@ -13,6 +14,7 @@ public class ControlLayout extends FrameLayout
|
||||
private CustomControls mLayout;
|
||||
private CustomControlsActivity mActivity;
|
||||
private boolean mControlVisible = false;
|
||||
|
||||
public ControlLayout(Context ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
@ -41,7 +43,8 @@ public class ControlLayout extends FrameLayout
|
||||
public void loadLayout(CustomControls controlLayout) {
|
||||
mLayout = controlLayout;
|
||||
removeAllViews();
|
||||
for (ControlData button : controlLayout.button) {
|
||||
for (ControlData button : controlLayout.mControlDataList) {
|
||||
button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
||||
addControlView(button);
|
||||
}
|
||||
|
||||
@ -49,7 +52,7 @@ public class ControlLayout extends FrameLayout
|
||||
}
|
||||
|
||||
public void addControlButton(ControlData controlButton) {
|
||||
mLayout.button.add(controlButton);
|
||||
mLayout.mControlDataList.add(controlButton);
|
||||
addControlView(controlButton);
|
||||
}
|
||||
|
||||
@ -62,7 +65,7 @@ public class ControlLayout extends FrameLayout
|
||||
}
|
||||
|
||||
public void removeControlButton(ControlButton controlButton) {
|
||||
mLayout.button.remove(controlButton.getProperties());
|
||||
mLayout.mControlDataList.remove(controlButton.getProperties());
|
||||
controlButton.setVisibility(View.GONE);
|
||||
removeView(controlButton);
|
||||
|
||||
@ -84,7 +87,7 @@ public class ControlLayout extends FrameLayout
|
||||
mControlVisible = !mControlVisible;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View view = getChildAt(i);
|
||||
if (view instanceof ControlButton && ((ControlButton) view).getProperties().keycode != ControlData.SPECIALBTN_TOGGLECTRL) {
|
||||
if (view instanceof ControlButton && ((ControlButton) view).getProperties().isHideable) {
|
||||
((ControlButton) view).setVisibility(mControlVisible ? (((ControlButton) view).getProperties().hidden ? View.INVISIBLE : View.VISIBLE) : View.GONE);
|
||||
}
|
||||
}
|
||||
@ -97,7 +100,9 @@ public class ControlLayout extends FrameLayout
|
||||
if (v instanceof ControlButton) {
|
||||
ControlButton cv = ((ControlButton) v);
|
||||
cv.setModifiable(z);
|
||||
// cv.setVisibility(cv.getProperties().hidden ? View.INVISIBLE : View.VISIBLE);
|
||||
if (!z) {
|
||||
cv.setAlpha(cv.getProperties().hidden ? 0f : 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,39 +7,48 @@ import org.lwjgl.glfw.*;
|
||||
|
||||
public class CustomControls
|
||||
{
|
||||
public List<ControlData> button;
|
||||
public List<ControlData> mControlDataList;
|
||||
public CustomControls() {
|
||||
this(new ArrayList<ControlData>());
|
||||
}
|
||||
|
||||
public CustomControls(List<ControlData> button) {
|
||||
this.button = button;
|
||||
public CustomControls(List<ControlData> mControlDataList) {
|
||||
this.mControlDataList = mControlDataList;
|
||||
}
|
||||
|
||||
// Generate default control
|
||||
public CustomControls(Context ctx) {
|
||||
this();
|
||||
this.button.add(ControlData.getSpecialButtons()[0].clone()); // Keyboard
|
||||
this.button.add(ControlData.getSpecialButtons()[1].clone()); // GUI
|
||||
this.button.add(ControlData.getSpecialButtons()[2].clone()); // Primary Mouse button
|
||||
this.button.add(ControlData.getSpecialButtons()[3].clone()); // Secondary Mouse button
|
||||
this.button.add(ControlData.getSpecialButtons()[4].clone()); // Virtual mouse toggle
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[0].clone()); // Keyboard
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[1].clone()); // GUI
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[2].clone()); // Primary Mouse mControlDataList
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[3].clone()); // Secondary Mouse mControlDataList
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[4].clone()); // Virtual mouse toggle
|
||||
|
||||
this.button.add(new ControlData(ctx, R.string.control_debug, LWJGLGLFWKeycode.GLFW_KEY_F3, "${margin}", "${margin}", false));
|
||||
this.button.add(new ControlData(ctx, R.string.control_chat, LWJGLGLFWKeycode.GLFW_KEY_T, "${margin} * 2 + ${width}", "${margin}", false));
|
||||
this.button.add(new ControlData(ctx, R.string.control_listplayers, LWJGLGLFWKeycode.GLFW_KEY_TAB, "${margin} * 4 + ${width} * 3", "${margin}", false));
|
||||
this.button.add(new ControlData(ctx, R.string.control_thirdperson, LWJGLGLFWKeycode.GLFW_KEY_F5, "${margin}", "${height} + ${margin}", false));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_debug, LWJGLGLFWKeycode.GLFW_KEY_F3, "${margin}", "${margin}", false));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_chat, LWJGLGLFWKeycode.GLFW_KEY_T, "${margin} * 2 + ${width}", "${margin}", false));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_listplayers, LWJGLGLFWKeycode.GLFW_KEY_TAB, "${margin} * 4 + ${width} * 3", "${margin}", false));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_thirdperson, LWJGLGLFWKeycode.GLFW_KEY_F5, "${margin}", "${height} + ${margin}", false));
|
||||
|
||||
this.button.add(new ControlData(ctx, R.string.control_up, LWJGLGLFWKeycode.GLFW_KEY_W, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 3 - ${height} * 3", true));
|
||||
this.button.add(new ControlData(ctx, R.string.control_left, LWJGLGLFWKeycode.GLFW_KEY_A, "${margin}", "${screen_height} - ${margin} * 2 - ${height} * 2", true));
|
||||
this.button.add(new ControlData(ctx, R.string.control_down, LWJGLGLFWKeycode.GLFW_KEY_S, "${margin} * 2 + ${width}", "${screen_height} - ${margin} - ${width}", true));
|
||||
this.button.add(new ControlData(ctx, R.string.control_right, LWJGLGLFWKeycode.GLFW_KEY_D, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_up, LWJGLGLFWKeycode.GLFW_KEY_W, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 3 - ${height} * 3", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_left, LWJGLGLFWKeycode.GLFW_KEY_A, "${margin}", "${screen_height} - ${margin} * 2 - ${height} * 2", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_down, LWJGLGLFWKeycode.GLFW_KEY_S, "${margin} * 2 + ${width}", "${screen_height} - ${margin} - ${width}", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_right, LWJGLGLFWKeycode.GLFW_KEY_D, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
|
||||
this.button.add(new ControlData(ctx, R.string.control_inventory, LWJGLGLFWKeycode.GLFW_KEY_E, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} - ${width}", true));
|
||||
this.button.add(new ControlData(ctx, R.string.control_shift, LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
this.button.add(new ControlData(ctx, R.string.control_jump, LWJGLGLFWKeycode.GLFW_KEY_SPACE, "${screen_width} - ${margin} * 3 - ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_inventory, LWJGLGLFWKeycode.GLFW_KEY_E, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} - ${width}", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_shift, LWJGLGLFWKeycode.GLFW_KEY_LEFT_SHIFT, "${margin} * 2 + ${width}", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_jump, LWJGLGLFWKeycode.GLFW_KEY_SPACE, "${screen_width} - ${margin} * 3 - ${width} * 2", "${screen_height} - ${margin} * 2 - ${width} * 2", true));
|
||||
|
||||
}
|
||||
|
||||
public ControlData findControlData(int keycode) {
|
||||
for (ControlData data : mControlDataList) {
|
||||
if (data.keycode == keycode) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void save(String path) throws Exception {
|
||||
Tools.write(path, Tools.GLOBAL_GSON.toJson(this));
|
||||
|
@ -229,7 +229,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
|
||||
jvmArgs.add("-Xms128M");
|
||||
jvmArgs.add("-Xmx1G");
|
||||
*/
|
||||
Intent mainIntent = new Intent(mActivity, MainActivity.class);
|
||||
Intent mainIntent = new Intent(mActivity, CustomCtrlMainActivity.class /* MainActivity.class */);
|
||||
// mainIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
mainIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
|
114
app/src/main/res/layout/main_with_customctrl.xml
Normal file
114
app/src/main/res/layout/main_with_customctrl.xml
Normal file
@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:id="@+id/main_drawer_options"
|
||||
android:keepScreenOn="true">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<net.kdt.pojavlaunch.customcontrols.ControlLayout
|
||||
android:id="@+id/main_control_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<net.kdt.pojavlaunch.MinecraftGLView
|
||||
android:id="@+id/main_game_render_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/main_touchpad"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_height="27dp"
|
||||
android:layout_width="18dp"
|
||||
android:src="@drawable/mouse_pointer"
|
||||
android:id="@+id/main_mouse_pointer"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</net.kdt.pojavlaunch.customcontrols.ControlLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/content_log_layout"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_height="84px"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:background="#555555">
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/control_viewout"
|
||||
android:paddingLeft="30px"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_height="84px"
|
||||
android:layout_width="84px"
|
||||
android:src="@android:drawable/ic_delete"
|
||||
android:onClick="closeLogOutput"
|
||||
android:layout_alignParentRight="true"
|
||||
android:id="@+id/content_log_close_button"/>
|
||||
|
||||
<ToggleButton
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_toLeftOf="@id/content_log_close_button"
|
||||
android:id="@+id/content_log_toggle_log"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<ScrollView
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/content_log_scroll"
|
||||
android:alpha="0.8"
|
||||
android:background="#000000">
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:textIsSelectable="true"/>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="PointerCapture debug"
|
||||
android:id="@+id/content_text_debug"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:fitsSystemWindows="false"
|
||||
app:menu="@menu/menu_runopt"
|
||||
android:id="@+id/main_navigation_view"/>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user