mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 14:16:58 -04:00
Partial mapping default controls to custom controls
This commit is contained in:
parent
325835ddaa
commit
186b89c12e
@ -10,7 +10,9 @@ import android.widget.*;
|
||||
import com.google.gson.*;
|
||||
import com.kdt.filerapi.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
import org.lwjgl.input.*;
|
||||
|
||||
public class CustomControlsActivity extends AppCompatActivity
|
||||
{
|
||||
@ -45,15 +47,7 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
actionLoad();
|
||||
break;
|
||||
case R.id.menu_ctrl_add:
|
||||
ControlButton ctrlBtn = new ControlButton();
|
||||
ctrlBtn.name = "New";
|
||||
ctrlBtn.x = 100;
|
||||
ctrlBtn.y = 100;
|
||||
ctrlLayout.addControlButton(ctrlBtn);
|
||||
break;
|
||||
case R.id.menu_ctrl_edit: // openLogOutput();
|
||||
break;
|
||||
case R.id.menu_ctrl_remove: // toggleDebug();
|
||||
ctrlLayout.addControlButton(new ControlButton("New", Keyboard.CHAR_NONE, 100, 100));
|
||||
break;
|
||||
}
|
||||
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
|
||||
@ -64,14 +58,8 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
});
|
||||
|
||||
mCtrl = new CustomControls();
|
||||
/*
|
||||
ControlButton ctrlEx = new ControlButton();
|
||||
ctrlEx.name = "Test";
|
||||
ctrlEx.x = 100;
|
||||
ctrlEx.y = 100;
|
||||
generateDefaultControlMap();
|
||||
|
||||
mCtrl.button.add(ctrlEx);
|
||||
*/
|
||||
ctrlLayout = (ControlsLayout) findViewById(R.id.customctrl_controllayout);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
ctrlLayout.setCanMove(true);
|
||||
@ -152,4 +140,19 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
dialog.setView(flv);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private float dpToPx(float dp) {
|
||||
return Tools.dpToPx(this, dp);
|
||||
}
|
||||
|
||||
private void generateDefaultControlMap() {
|
||||
List<ControlButton> btn = mCtrl.button;
|
||||
btn.add(ControlButton.getSpecialButtons()[0]); // Keyboard
|
||||
btn.add(ControlButton.getSpecialButtons()[1]); // GUI
|
||||
// btn.add(ControlButton.getSpecialButtons()[2]); // Toggle mouse
|
||||
btn.add(new ControlButton(this, R.string.control_debug, Keyboard.KEY_F3, ControlButton.pixelOf2dp, ControlButton.pixelOf2dp, false));
|
||||
btn.add(new ControlButton(this, R.string.control_chat, Keyboard.KEY_T, ControlButton.pixelOf2dp * 2 + ControlButton.pixelOf80dp, ControlButton.pixelOf2dp, false));
|
||||
btn.add(new ControlButton(this, R.string.control_listplayers, Keyboard.KEY_TAB, ControlButton.pixelOf2dp * 3 + ControlButton.pixelOf80dp * 2, ControlButton.pixelOf2dp, false));
|
||||
btn.add(new ControlButton(this, R.string.control_thirdperson, Keyboard.KEY_F5, ControlButton.pixelOf2dp, ControlButton.pixelOf2dp, false));
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||
versions.add(fVer.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
versions.add(getStr(com.android.internal.R.string.dlg_error_title) + ":");
|
||||
versions.add(getStr(R.string.global_error) + ":");
|
||||
versions.add(e.getMessage());
|
||||
|
||||
} finally {
|
||||
|
@ -1166,7 +1166,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
public void dialogForceClose()
|
||||
{
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getResources().getString(R.string.mcn_exit_confirm, getResources().getString(com.android.internal.R.string.force_close)))
|
||||
.setMessage(R.string.mcn_exit_confirm)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
|
||||
|
||||
|
@ -24,7 +24,10 @@ public class PojavApplication extends Application
|
||||
|
||||
LauncherPreferences.loadPreferences(this);
|
||||
|
||||
ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2);
|
||||
ControlButton.pixelOf30dp = (int) Tools.dpToPx(this, 30);
|
||||
ControlButton.pixelOf50dp = (int) Tools.dpToPx(this, 50);
|
||||
ControlButton.pixelOf80dp = (int) Tools.dpToPx(this, 80);
|
||||
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
|
||||
specialButtons[0].name = getString(R.string.control_keyboard);
|
||||
specialButtons[1].name = getString(R.string.control_toggle);
|
||||
|
@ -34,7 +34,7 @@ public class PojavLoginActivity extends MineActivity
|
||||
// private boolean isPermGranted = false;
|
||||
|
||||
private SharedPreferences firstLaunchPrefs;
|
||||
private String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
||||
// private String PREF_IS_DONOTSHOWAGAIN_WARN = "isWarnDoNotShowAgain";
|
||||
private String PREF_IS_INSTALLED_LIBRARIES = "isLibrariesExtracted";
|
||||
|
||||
private boolean isInitCalled = false;
|
||||
@ -553,7 +553,7 @@ public class PojavLoginActivity extends MineActivity
|
||||
{
|
||||
// TODO: Implement this method
|
||||
if(result[0].equals("ERROR")){
|
||||
Tools.dialogOnUiThread(PojavLoginActivity.this, getResources().getString(com.android.internal.R.string.dlg_error_title), strArrToString(result));
|
||||
Tools.dialogOnUiThread(PojavLoginActivity.this, getResources().getString(R.string.global_error), strArrToString(result));
|
||||
} else{
|
||||
MCProfile.Builder builder = new MCProfile.Builder();
|
||||
builder.setAccessToken(result[1]);
|
||||
|
@ -182,7 +182,7 @@ public final class Tools
|
||||
{
|
||||
final String errMsg = showMore ? Log.getStackTraceString(e): e.getMessage();
|
||||
new AlertDialog.Builder((Context) ctx)
|
||||
.setTitle(com.android.internal.R.string.dlg_error_title)
|
||||
.setTitle(R.string.global_error)
|
||||
.setMessage(errMsg)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
|
||||
|
||||
|
@ -3,28 +3,27 @@ import net.kdt.pojavlaunch.*;
|
||||
import android.view.*;
|
||||
import java.util.*;
|
||||
import android.content.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
public class ControlButton
|
||||
{
|
||||
public static int pixelOf2dp;
|
||||
public static int pixelOf30dp;
|
||||
public static int pixelOf50dp;
|
||||
public static int pixelOf80dp;
|
||||
|
||||
public static int SPECIALBTN_KEYBOARD = 0;
|
||||
public static int SPECIALBTN_TOGGLECTRL = 1;
|
||||
public static final int SPECIALBTN_KEYBOARD = 0;
|
||||
public static final int SPECIALBTN_TOGGLECTRL = 1;
|
||||
|
||||
private static ControlButton[] SPECIAL_BUTTONS;
|
||||
private static String[] SPECIAL_BUTTON_NAME_ARRAY;
|
||||
|
||||
public static ControlButton[] getSpecialButtons(){
|
||||
if (SPECIAL_BUTTONS == null) {
|
||||
ControlButton keyboardBtn = new ControlButton();
|
||||
keyboardBtn.lwjglKeycode = -1;
|
||||
|
||||
ControlButton toggleCtrlBtn = new ControlButton();
|
||||
toggleCtrlBtn.lwjglKeycode = -2;
|
||||
|
||||
SPECIAL_BUTTONS = new ControlButton[]{
|
||||
keyboardBtn,
|
||||
toggleCtrlBtn
|
||||
new ControlButton("Keyboard", -1, pixelOf2dp * 3 + pixelOf80dp * 2, pixelOf2dp, pixelOf80dp, pixelOf30dp),
|
||||
new ControlButton("GUI", -2, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf2dp - pixelOf50dp)
|
||||
};
|
||||
}
|
||||
|
||||
@ -43,7 +42,6 @@ public class ControlButton
|
||||
return SPECIAL_BUTTON_NAME_ARRAY;
|
||||
}
|
||||
|
||||
// Concept...
|
||||
public String name;
|
||||
public float x;
|
||||
public float y;
|
||||
@ -57,6 +55,35 @@ public class ControlButton
|
||||
public View.OnClickListener specialButtonListener;
|
||||
// public boolean hold
|
||||
|
||||
public ControlButton() {
|
||||
this("", Keyboard.CHAR_NONE, 0, 0);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode) {
|
||||
this(name, lwjglKeycode, 0, 0);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y) {
|
||||
this(name, lwjglKeycode, x, y, pixelOf50dp, pixelOf50dp);
|
||||
}
|
||||
|
||||
public ControlButton(android.content.Context ctx, int resId, int lwjglKeycode, float x, float y, boolean isSquare) {
|
||||
this(ctx.getResources().getString(resId), lwjglKeycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y, boolean isSquare) {
|
||||
this(name, lwjglKeycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y, int width, int height) {
|
||||
this.name = name;
|
||||
this.lwjglKeycode = lwjglKeycode;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void execute(MainActivity act, boolean isDown) {
|
||||
act.sendKeyPress(lwjglKeycode, isDown);
|
||||
}
|
||||
|
@ -26,25 +26,19 @@ public class ControlsLayout extends FrameLayout
|
||||
alert.setView(R.layout.control_setting);
|
||||
alert.setPositiveButton(android.R.string.ok, null);
|
||||
alert.setNegativeButton(android.R.string.cancel, null);
|
||||
alert.setNeutralButton(com.android.internal.R.string.delete, new DialogInterface.OnClickListener(){
|
||||
String deleteText = "Delete";
|
||||
try {
|
||||
// Try to get non-public delete text, which translated to multiple languages.
|
||||
deleteText = getResources().getString((int) com.android.internal.R.string.class.getDeclaredField("deleteText").get(null));
|
||||
} catch (Throwable unused) {
|
||||
}
|
||||
|
||||
alert.setNeutralButton(deleteText, new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface p1, int p2)
|
||||
{
|
||||
ControlButton.getSpecialButtons();
|
||||
|
||||
AlertDialog.Builder alert2 = new AlertDialog.Builder(getContext());
|
||||
alert2.setCancelable(false);
|
||||
alert2.setTitle(R.string.customctrl_specialkey);
|
||||
alert2.setItems(ControlButton.buildSpecialButtonArray(), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dInterface, int position) {
|
||||
view.setProperties(ControlButton.getSpecialButtons()[position], false);
|
||||
}
|
||||
});
|
||||
alert2.setPositiveButton(android.R.string.cancel, null);
|
||||
alert2.show();
|
||||
removeControlButton(view);
|
||||
}
|
||||
});
|
||||
final AlertDialog dialog = alert.create();
|
||||
@ -63,22 +57,26 @@ public class ControlsLayout extends FrameLayout
|
||||
final Spinner spinnerKeycode = dialog.findViewById(R.id.controlsetting_spinner_lwjglkeycode);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item);
|
||||
|
||||
String[] specialArr = ControlButton.buildSpecialButtonArray();
|
||||
String[] oldSpecialArr = ControlButton.buildSpecialButtonArray();
|
||||
String[] specialArr = new String[oldSpecialArr.length];
|
||||
for (int i = 0; i < specialArr.length; i++) {
|
||||
specialArr[i] = "SPECIAL_" + specialArr[i];
|
||||
specialArr[i] = "SPECIAL_" + oldSpecialArr[i];
|
||||
}
|
||||
|
||||
adapter.addAll(specialArr);
|
||||
adapter.addAll(AndroidLWJGLKeycode.generateKeyName());
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||
spinnerKeycode.setAdapter(adapter);
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.lwjglKeycode) + 2);
|
||||
if (properties.lwjglKeycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.lwjglKeycode + 2);
|
||||
} else {
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.lwjglKeycode + 2));
|
||||
}
|
||||
spinnerKeycode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
|
||||
normalBtnLayout.setVisibility(id < 2 ? View.GONE : View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,7 +116,17 @@ public class ControlsLayout extends FrameLayout
|
||||
mLayout = controlLayout;
|
||||
removeAllViews();
|
||||
for (ControlButton button : controlLayout.button) {
|
||||
final ControlView view = new ControlView(getContext(), button);
|
||||
addControlView(button);
|
||||
}
|
||||
}
|
||||
|
||||
public void addControlButton(ControlButton controlButton) {
|
||||
mLayout.button.add(controlButton);
|
||||
addControlView(controlButton);
|
||||
}
|
||||
|
||||
private void addControlView(ControlButton controlButton) {
|
||||
final ControlView view = new ControlView(getContext(), controlButton);
|
||||
view.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
@ -127,29 +135,12 @@ public class ControlsLayout extends FrameLayout
|
||||
}
|
||||
});
|
||||
view.setCanMove(mCanMove);
|
||||
view.setLayoutParams(new LayoutParams((int) Tools.dpToPx(getContext(), 50), (int) Tools.dpToPx(getContext(), 50)));
|
||||
addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public void addControlButton(ControlButton controlButton) {
|
||||
mLayout.button.add(controlButton);
|
||||
|
||||
final ControlView view = new ControlView(getContext(), controlButton);
|
||||
view.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View p1) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
|
||||
alert.setTitle(getResources().getString(R.string.global_edit) + " " + view.getText());
|
||||
// alert.setView(edit);
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
view.setCanMove(mCanMove);
|
||||
addView(view);
|
||||
|
||||
// loadLayout(controlLayout);
|
||||
public void removeControlButton(ControlView controlButton) {
|
||||
mLayout.button.remove(controlButton.getProperties());
|
||||
removeView(controlButton);
|
||||
}
|
||||
|
||||
public void saveLayout(String path) throws Exception {
|
||||
|
@ -17,7 +17,7 @@
|
||||
<TextView
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="An unofficial Minecraft Java Launcher in your pocket!"/>
|
||||
android:text="@string/app_motd"/>
|
||||
|
||||
<ProgressBar
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -6,12 +6,4 @@
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_add"
|
||||
android:title="@string/global_add"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_edit"
|
||||
android:title="@string/global_edit"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_remove"
|
||||
android:title="@string/global_remove"/>
|
||||
</menu>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item
|
||||
android:id="@+id/nav_forceclose"
|
||||
android:title="@*android:string/force_close" />
|
||||
android:title="@string/control_forceclose" />
|
||||
<item
|
||||
android:id="@+id/nav_viewlog"
|
||||
android:title="@string/control_viewout" />
|
||||
|
@ -3,6 +3,7 @@
|
||||
<!-- App name part -->
|
||||
<string name="app_name">PojavLauncher (Minecraft: Java Edition for Android)</string>
|
||||
<string name="app_short_name">PojavLauncher</string>
|
||||
<string name="app_motd">Launch Minecraft: Java Edition in your device!</string>
|
||||
|
||||
<!-- Action bar part -->
|
||||
<string name="actionbar_help">HELP</string>
|
||||
@ -111,6 +112,7 @@
|
||||
<!-- Global strings -->
|
||||
<string name="global_add">Add</string>
|
||||
<string name="global_edit">Edit</string>
|
||||
<string name="global_error">Error</string>
|
||||
<string name="global_load">Load</string>
|
||||
<string name="global_name">Name</string>
|
||||
<string name="global_remove">Remove</string>
|
||||
@ -145,7 +147,7 @@
|
||||
<string name="mcn_exit_call">Exit</string>
|
||||
<string name="mcn_exit_crash">Game Crash detected! Click OK to exit.</string>
|
||||
<string name="mcn_exit_errcrash">Unable to locate crash!</string>
|
||||
<string name="mcn_exit_confirm">Are you sure want to %s ?</string>
|
||||
<string name="mcn_exit_confirm">Are you sure want to force close?</string>
|
||||
|
||||
<!-- MainActivity: Control buttons -->
|
||||
<string name="controls">Controls</string>
|
||||
@ -169,6 +171,7 @@
|
||||
<string name="control_mouseon">Mouse: on </string>
|
||||
|
||||
<!-- MainActivity: Menu advanced controls -->
|
||||
<string name="control_forceclose">Force close</string>
|
||||
<string name="control_viewout">Log output</string>
|
||||
<string name="control_adebug">PointerCapture Debug</string>
|
||||
<string name="control_customkey">Send custom keycode</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user