[Experimental] Implemented Custom controls

This commit is contained in:
khanhduytran0 2020-11-20 11:15:58 +07:00
parent 2516c051bd
commit 19b046db97
11 changed files with 455 additions and 214 deletions

View File

@ -63,6 +63,13 @@
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|keyboard|navigation"/> 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 <activity
android:screenOrientation="sensorLandscape" android:screenOrientation="sensorLandscape"
android:name=".prefs.LauncherPreferenceActivity" android:name=".prefs.LauncherPreferenceActivity"

View File

@ -12,123 +12,123 @@ import com.kdt.mcgui.*;
public class MineActivity extends BaseActivity implements View.OnClickListener public class MineActivity extends BaseActivity implements View.OnClickListener
{ {
private int topId = 150001; private int topId = 150001;
private boolean showBeforeView = true; private boolean showBeforeView = true;
private ImageButton menu; private ImageButton menu;
private LinearLayout content, undertop; private LinearLayout content, undertop;
private LayoutInflater li; private LayoutInflater li;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
this.onCreate(savedInstanceState, true); this.onCreate(savedInstanceState, true);
} }
protected void onCreate(Bundle savedInstanceState, boolean showBeforeView) { protected void onCreate(Bundle savedInstanceState, boolean showBeforeView) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.showBeforeView = showBeforeView; this.showBeforeView = showBeforeView;
if (showBeforeView) { if (showBeforeView) {
mcUIInit(); mcUIInit();
} }
} }
private void mcUIInit() { private void mcUIInit() {
RelativeLayout root = new RelativeLayout(this); RelativeLayout root = new RelativeLayout(this);
LinearLayout top = new LinearLayout(this); LinearLayout top = new LinearLayout(this);
top.setId(topId); top.setId(topId);
content = new LinearLayout(this); content = new LinearLayout(this);
RelativeLayout btm = new RelativeLayout(this); RelativeLayout btm = new RelativeLayout(this);
li = LayoutInflater.from(this); li = LayoutInflater.from(this);
li.inflate(R.layout.top_bar, top, true); li.inflate(R.layout.top_bar, top, true);
li.inflate(R.layout.bottom_bar, btm, true); li.inflate(R.layout.bottom_bar, btm, true);
FontChanger.changeFonts(btm); FontChanger.changeFonts(btm);
// replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang)); // replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang));
Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang)); Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang));
// Locale l = getResources().getConfiguration().locale; // Locale l = getResources().getConfiguration().locale;
RelativeLayout.LayoutParams conLay = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams conLay = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
conLay.addRule(root.BELOW, topId); conLay.addRule(root.BELOW, topId);
conLay.bottomMargin = 66; 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(top, new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
root.addView(content); root.addView(content);
root.addView(btm); 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); menu = (ImageButton) findViewById(R.id.topbar_navmenu_icon);
setMenuVisible(false); setMenuVisible(false);
undertop = (LinearLayout) findViewById(R.id.topbar_undertop_view); undertop = (LinearLayout) findViewById(R.id.topbar_undertop_view);
try { try {
ver.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName); ver.setText(getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
} catch (PackageManager.NameNotFoundException e) {} // Never happend! } catch (PackageManager.NameNotFoundException e) {} // Never happend!
setClick(R.id.topbar_help_text); setClick(R.id.topbar_help_text);
setClick(R.id.topbar_logo); setClick(R.id.topbar_logo);
setClick(R.id.bottombar_author_logo); setClick(R.id.bottombar_author_logo);
} }
@Override @Override
public void setContentView(int resource) public void setContentView(int resource)
{ {
if (!showBeforeView) { if (!showBeforeView) {
mcUIInit(); mcUIInit();
} }
li.inflate(resource, content, true); li.inflate(resource, content, true);
FontChanger.changeFonts(content); FontChanger.changeFonts(content);
} }
@Override @Override
public void setContentView(View view) public void setContentView(View view)
{ {
if (!showBeforeView) { if (!showBeforeView) {
mcUIInit(); mcUIInit();
} }
content.addView(view); content.addView(view);
if (view instanceof ViewGroup) { if (view instanceof ViewGroup) {
FontChanger.changeFonts((ViewGroup) view); FontChanger.changeFonts((ViewGroup) view);
} }
} }
@Override @Override
public void onClick(View view) public void onClick(View view)
{ {
switch (view.getId()) { switch (view.getId()) {
case R.id.topbar_help_text: Tools.openURL(this, "https://www.minecraft.net/help"); case R.id.topbar_help_text: Tools.openURL(this, "https://www.minecraft.net/help");
break; break;
case R.id.topbar_logo: Tools.openURL(this, "https://www.minecraft.net"); case R.id.topbar_logo: Tools.openURL(this, "https://www.minecraft.net");
break; break;
case R.id.bottombar_author_logo: Tools.openURL(this, "https://mojang.com"); case R.id.bottombar_author_logo: Tools.openURL(this, "https://mojang.com");
break; break;
} }
} }
public void setUndertopView(View view) { public void setUndertopView(View view) {
if (undertop.getChildCount() > 0) { if (undertop.getChildCount() > 0) {
undertop.removeAllViews(); undertop.removeAllViews();
} }
undertop.addView(view); undertop.addView(view);
} }
public void setMenuVisible(boolean value) { public void setMenuVisible(boolean value) {
menu.setVisibility(value ? View.VISIBLE : View.GONE); menu.setVisibility(value ? View.VISIBLE : View.GONE);
} }
public void setClick(int id) { public void setClick(int id) {
findViewById(id).setOnClickListener(this); findViewById(id).setOnClickListener(this);
} }
} }

View File

@ -20,7 +20,7 @@ import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*; import net.kdt.pojavlaunch.utils.*;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;
public class BaseMainActivity extends LoggableActivity implements OnTouchListener { public class BaseMainActivity extends LoggableActivity {
public static volatile ClipboardManager GLOBAL_CLIPBOARD; public static volatile ClipboardManager GLOBAL_CLIPBOARD;
public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "; public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ";
@ -106,11 +106,11 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
// private static Collection<? extends Provider.Service> rsaPkcs1List; // private static Collection<? extends Provider.Service> rsaPkcs1List;
@Override // @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState, int resId)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main); setContentView(resId);
try { try {
// FIXME: is it safe fot multi thread? // 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); 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); // toggleGui(null);
this.drawerLayout.closeDrawers(); this.drawerLayout.closeDrawers();
@ -649,9 +641,14 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
minecraftGLView.setOnHoverListener(new View.OnHoverListener(){ minecraftGLView.setOnHoverListener(new View.OnHoverListener(){
@Override @Override
public boolean onHover(View p1, MotionEvent p2) { public boolean onHover(View v, MotionEvent e) {
if (!CallbackBridge.isGrabbing() && mIsResuming) { 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; return true;
} }
@ -804,56 +801,6 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
super.onPause(); 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() { public static void fullyExit() {
System.exit(0); System.exit(0);
} }
@ -1102,16 +1049,6 @@ public class BaseMainActivity extends LoggableActivity implements OnTouchListene
.show(); .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 @Override
public void onBackPressed() { public void onBackPressed() {
// Prevent back // 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); ((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.rightOverride = val;
// this.secondaryButton.setBackgroundDrawable(this.rightOverride ? this.secondaryButtonColorBackground : this.secondaryButtonDefaultBackground); // this.secondaryButton.setBackgroundDrawable(this.rightOverride ? this.secondaryButtonColorBackground : this.secondaryButtonDefaultBackground);
} }

View File

@ -26,7 +26,6 @@ public class CustomControlsActivity extends BaseActivity
public boolean isModified = false; public boolean isModified = false;
private Gson gson;
private String selectedName = "new_control"; private String selectedName = "new_control";
@Override @Override
@ -36,8 +35,6 @@ public class CustomControlsActivity extends BaseActivity
mPref = PreferenceManager.getDefaultSharedPreferences(this); mPref = PreferenceManager.getDefaultSharedPreferences(this);
gson = new GsonBuilder().setPrettyPrinting().create();
ctrlLayout = (ControlLayout) findViewById(R.id.customctrl_controllayout); ctrlLayout = (ControlLayout) findViewById(R.id.customctrl_controllayout);
// Menu // Menu
@ -206,7 +203,7 @@ public class CustomControlsActivity extends BaseActivity
private void loadControl(String path) { private void loadControl(String path) {
try { try {
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class); mCtrl = Tools.GLOBAL_GSON.fromJson(Tools.read(path), CustomControls.class);
ctrlLayout.loadLayout(mCtrl); ctrlLayout.loadLayout(mCtrl);
selectedName = new File(path).getName(); selectedName = new File(path).getName();

View File

@ -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);
}
}
}

View File

@ -5,8 +5,10 @@ import android.view.*;
import android.view.View.*; import android.view.View.*;
import android.widget.*; import android.widget.*;
import net.kdt.pojavlaunch.customcontrols.*; 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, private Button upButton,
downButton, leftButton, downButton, leftButton,
rightButton, jumpButton, rightButton, jumpButton,
@ -21,7 +23,7 @@ public class MainActivity extends BaseMainActivity implements OnClickListener {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState, R.layout.main);
this.upButton = findButton(R.id.control_up); this.upButton = findButton(R.id.control_up);
this.downButton = findButton(R.id.control_down); 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;
}
} }

View File

@ -23,6 +23,9 @@ public class ControlData implements Cloneable
private static ControlData[] SPECIAL_BUTTONS; private static ControlData[] SPECIAL_BUTTONS;
private static String[] SPECIAL_BUTTON_NAME_ARRAY; private static String[] SPECIAL_BUTTON_NAME_ARRAY;
// Internal usage only
public boolean isHideable;
/** /**
* Both fields below are dynamic position data, auto updates * Both fields below are dynamic position data, auto updates
* X and Y position, unlike the original one which uses fixed * X and Y position, unlike the original one which uses fixed
@ -135,7 +138,13 @@ public class ControlData implements Cloneable
} }
public void update() { public void update() {
if (!isDynamicBtn) { if (keycode < 0) {
for (ControlData data : getSpecialButtons()) {
if (keycode == data.keycode) {
specialButtonListener = data.specialButtonListener;
}
}
} if (!isDynamicBtn) {
return; return;
} }

View File

@ -6,6 +6,7 @@ import android.view.*;
import com.google.gson.*; import com.google.gson.*;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import android.support.v7.app.*; import android.support.v7.app.*;
import java.util.*;
public class ControlLayout extends FrameLayout public class ControlLayout extends FrameLayout
{ {
@ -13,6 +14,7 @@ public class ControlLayout extends FrameLayout
private CustomControls mLayout; private CustomControls mLayout;
private CustomControlsActivity mActivity; private CustomControlsActivity mActivity;
private boolean mControlVisible = false; private boolean mControlVisible = false;
public ControlLayout(Context ctx) { public ControlLayout(Context ctx) {
super(ctx); super(ctx);
} }
@ -41,7 +43,8 @@ public class ControlLayout extends FrameLayout
public void loadLayout(CustomControls controlLayout) { public void loadLayout(CustomControls controlLayout) {
mLayout = controlLayout; mLayout = controlLayout;
removeAllViews(); 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); addControlView(button);
} }
@ -49,7 +52,7 @@ public class ControlLayout extends FrameLayout
} }
public void addControlButton(ControlData controlButton) { public void addControlButton(ControlData controlButton) {
mLayout.button.add(controlButton); mLayout.mControlDataList.add(controlButton);
addControlView(controlButton); addControlView(controlButton);
} }
@ -62,7 +65,7 @@ public class ControlLayout extends FrameLayout
} }
public void removeControlButton(ControlButton controlButton) { public void removeControlButton(ControlButton controlButton) {
mLayout.button.remove(controlButton.getProperties()); mLayout.mControlDataList.remove(controlButton.getProperties());
controlButton.setVisibility(View.GONE); controlButton.setVisibility(View.GONE);
removeView(controlButton); removeView(controlButton);
@ -84,7 +87,7 @@ public class ControlLayout extends FrameLayout
mControlVisible = !mControlVisible; mControlVisible = !mControlVisible;
for (int i = 0; i < getChildCount(); i++) { for (int i = 0; i < getChildCount(); i++) {
View view = getChildAt(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); ((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) { if (v instanceof ControlButton) {
ControlButton cv = ((ControlButton) v); ControlButton cv = ((ControlButton) v);
cv.setModifiable(z); cv.setModifiable(z);
// cv.setVisibility(cv.getProperties().hidden ? View.INVISIBLE : View.VISIBLE); if (!z) {
cv.setAlpha(cv.getProperties().hidden ? 0f : 1.0f);
}
} }
} }
} }

View File

@ -7,40 +7,49 @@ import org.lwjgl.glfw.*;
public class CustomControls public class CustomControls
{ {
public List<ControlData> button; public List<ControlData> mControlDataList;
public CustomControls() { public CustomControls() {
this(new ArrayList<ControlData>()); this(new ArrayList<ControlData>());
} }
public CustomControls(List<ControlData> button) { public CustomControls(List<ControlData> mControlDataList) {
this.button = button; this.mControlDataList = mControlDataList;
} }
// Generate default control // Generate default control
public CustomControls(Context ctx) { public CustomControls(Context ctx) {
this(); this();
this.button.add(ControlData.getSpecialButtons()[0].clone()); // Keyboard this.mControlDataList.add(ControlData.getSpecialButtons()[0].clone()); // Keyboard
this.button.add(ControlData.getSpecialButtons()[1].clone()); // GUI this.mControlDataList.add(ControlData.getSpecialButtons()[1].clone()); // GUI
this.button.add(ControlData.getSpecialButtons()[2].clone()); // Primary Mouse button this.mControlDataList.add(ControlData.getSpecialButtons()[2].clone()); // Primary Mouse mControlDataList
this.button.add(ControlData.getSpecialButtons()[3].clone()); // Secondary Mouse button this.mControlDataList.add(ControlData.getSpecialButtons()[3].clone()); // Secondary Mouse mControlDataList
this.button.add(ControlData.getSpecialButtons()[4].clone()); // Virtual mouse toggle 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.mControlDataList.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.mControlDataList.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.mControlDataList.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_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.mControlDataList.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.mControlDataList.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.mControlDataList.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_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.mControlDataList.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.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.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_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 { public void save(String path) throws Exception {
Tools.write(path, Tools.GLOBAL_GSON.toJson(this)); Tools.write(path, Tools.GLOBAL_GSON.toJson(this));
} }

View File

@ -229,7 +229,7 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
jvmArgs.add("-Xms128M"); jvmArgs.add("-Xms128M");
jvmArgs.add("-Xmx1G"); 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_LAUNCH_ADJACENT);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); mainIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

View 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>