mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
Adding custom controls cause broken?
This commit is contained in:
parent
0f76135da8
commit
4d008013ad
@ -140,10 +140,10 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
adapter.addAll(AndroidLWJGLKeycode.generateKeyName());
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||
spinnerKeycode.setAdapter(adapter);
|
||||
if (properties.lwjglKeycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.lwjglKeycode + 2);
|
||||
if (properties.keycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.keycode + 2);
|
||||
} else {
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.lwjglKeycode + 2));
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.keycode + 2));
|
||||
}
|
||||
spinnerKeycode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
||||
|
||||
@ -169,7 +169,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
if (editName.getText().toString().isEmpty()) {
|
||||
editName.setError(view.getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
properties.lwjglKeycode = AndroidLWJGLKeycode.getKeyIndex(spinnerKeycode.getSelectedItemPosition()) - 2;
|
||||
properties.keycode = AndroidLWJGLKeycode.getKeyIndex(spinnerKeycode.getSelectedItemPosition()) - 2;
|
||||
properties.name = editName.getText().toString();
|
||||
properties.hidden = checkHidden.isChecked();
|
||||
|
||||
|
@ -18,22 +18,25 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
{
|
||||
private DrawerLayout drawerLayout;
|
||||
private NavigationView navDrawer;
|
||||
|
||||
private ControlsLayout ctrlLayout;
|
||||
|
||||
private String selectedName = "";
|
||||
|
||||
private CustomControls mCtrl;
|
||||
|
||||
|
||||
private SharedPreferences mPref;
|
||||
|
||||
public boolean isModified = false;
|
||||
|
||||
private Gson gson;
|
||||
private String selectedName = "new_control";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.control_mapping);
|
||||
|
||||
|
||||
mPref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
|
||||
// Menu
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.customctrl_drawerlayout);
|
||||
|
||||
@ -49,6 +52,12 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
case R.id.menu_ctrl_add:
|
||||
ctrlLayout.addControlButton(new ControlButton("New", Keyboard.CHAR_NONE, 100, 100));
|
||||
break;
|
||||
case R.id.menu_ctrl_selectdefault:
|
||||
dialogSelectDefaultCtrl();
|
||||
break;
|
||||
case R.id.menu_ctrl_save:
|
||||
save(false);
|
||||
break;
|
||||
}
|
||||
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
@ -56,34 +65,87 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mCtrl = new CustomControls();
|
||||
generateDefaultControlMap();
|
||||
|
||||
String defaultControl = mPref.getString("defaultCtrl", "");
|
||||
if (defaultControl.isEmpty() || defaultControl.endsWith("/default.json")) {
|
||||
generateDefaultControlMap();
|
||||
try {
|
||||
doSaveCtrl("default");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
loadControl(defaultControl);
|
||||
}
|
||||
|
||||
ctrlLayout = (ControlsLayout) findViewById(R.id.customctrl_controllayout);
|
||||
ctrlLayout.setActivity(this);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
ctrlLayout.setModifiable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (!isModified) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
save(true);
|
||||
}
|
||||
|
||||
private void setDefaultControlJson(String path) {
|
||||
mPref.edit().putString("defaultCtrl", path).commit();
|
||||
}
|
||||
|
||||
private void dialogSelectDefaultCtrl() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.customctrl_selectdefault);
|
||||
builder.setPositiveButton(android.R.string.cancel, null);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
FileListView flv = new FileListView(this);
|
||||
flv.listFileAt(Tools.CTRLMAP_PATH);
|
||||
flv.setFileSelectedListener(new FileSelectedListener(){
|
||||
|
||||
@Override
|
||||
public void onFileSelected(File file, String path, String name) {
|
||||
if (name.endsWith(".json")) {
|
||||
setDefaultControlJson(path);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setView(flv);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private String doSaveCtrl(String name) throws Exception {
|
||||
String jsonPath = Tools.CTRLMAP_PATH + "/" + name + ".json";
|
||||
ctrlLayout.saveLayout(jsonPath);
|
||||
|
||||
return jsonPath;
|
||||
}
|
||||
|
||||
private void save(final boolean exit) {
|
||||
final EditText edit = new EditText(this);
|
||||
edit.setSingleLine();
|
||||
edit.setText(selectedName);
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.global_save);
|
||||
builder.setView(edit);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
builder.setNeutralButton("Exit without save", new AlertDialog.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface p1, int p2)
|
||||
{
|
||||
CustomControlsActivity.super.onBackPressed();
|
||||
}
|
||||
});
|
||||
if (exit) {
|
||||
builder.setNeutralButton("Exit without save", new AlertDialog.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface p1, int p2) {
|
||||
CustomControlsActivity.super.onBackPressed();
|
||||
}
|
||||
});
|
||||
}
|
||||
final AlertDialog dialog = builder.create();
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
|
||||
@ -99,11 +161,16 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
edit.setError(getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
try {
|
||||
Tools.write(Tools.CTRLMAP_PATH + "/" + edit.getText().toString() + ".json", gson.toJson(mCtrl));
|
||||
String jsonPath = doSaveCtrl(edit.getText().toString());
|
||||
|
||||
Toast.makeText(CustomControlsActivity.this, getString(R.string.global_save) + ": " + jsonPath, Toast.LENGTH_SHORT).show();
|
||||
|
||||
dialog.dismiss();
|
||||
CustomControlsActivity.super.onBackPressed();
|
||||
if (exit) {
|
||||
CustomControlsActivity.super.onBackPressed();
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(CustomControlsActivity.this, th);
|
||||
Tools.showError(CustomControlsActivity.this, th, exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,12 +178,12 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void actionLoad() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Select control json file");
|
||||
builder.setTitle(R.string.customctrl_title_selectctrl);
|
||||
builder.setPositiveButton(android.R.string.cancel, null);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
@ -127,32 +194,36 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
@Override
|
||||
public void onFileSelected(File file, String path, String name) {
|
||||
if (name.endsWith(".json")) {
|
||||
try {
|
||||
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
dialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
Tools.showError(CustomControlsActivity.this, e);
|
||||
}
|
||||
loadControl(path);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setView(flv);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private float dpToPx(float dp) {
|
||||
return Tools.dpToPx(this, dp);
|
||||
|
||||
private void loadControl(String path) {
|
||||
try {
|
||||
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
|
||||
selectedName = new File(path).getName();
|
||||
// Remove `.json`
|
||||
selectedName = selectedName.substring(0, selectedName.length() - 5);
|
||||
} catch (Exception e) {
|
||||
Tools.showError(CustomControlsActivity.this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void generateDefaultControlMap() {
|
||||
List<ControlButton> btn = mCtrl.button;
|
||||
btn.add(ControlButton.getSpecialButtons()[0]); // Keyboard
|
||||
btn.add(ControlButton.getSpecialButtons()[1]); // GUI
|
||||
btn.add(ControlButton.getSpecialButtons()[0].clone()); // Keyboard
|
||||
btn.add(ControlButton.getSpecialButtons()[1].clone()); // 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));
|
||||
btn.add(new ControlButton(this, R.string.control_listplayers, Keyboard.KEY_TAB, ControlButton.pixelOf2dp * 4 + ControlButton.pixelOf80dp * 3, ControlButton.pixelOf2dp, false));
|
||||
btn.add(new ControlButton(this, R.string.control_thirdperson, Keyboard.KEY_F5, ControlButton.pixelOf2dp, ControlButton.pixelOf30dp + ControlButton.pixelOf2dp, false));
|
||||
}
|
||||
}
|
||||
|
@ -978,6 +978,7 @@ public class MCLauncherActivity extends AppCompatActivity
|
||||
dialog = new ProgressDialog(MCLauncherActivity.this);
|
||||
dialog.setTitle("Installing OptiFine");
|
||||
dialog.setMessage("Preparing");
|
||||
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
dialog.setMax(5);
|
||||
dialog.setCancelable(false);
|
||||
dialog.show();
|
||||
|
@ -79,15 +79,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
private DisplayMetrics displayMetrics;
|
||||
public boolean hiddenTextIgnoreUpdate = true;
|
||||
public String hiddenTextContents = initText;
|
||||
private Button upButton,
|
||||
downButton, leftButton,
|
||||
rightButton, jumpButton,
|
||||
primaryButton, secondaryButton,
|
||||
debugButton, shiftButton,
|
||||
keyboardButton, inventoryButton,
|
||||
talkButton, thirdPersonButton,
|
||||
zoomButton, listPlayersButton,
|
||||
toggleControlButton;
|
||||
private ControlsLayout controlLayout;
|
||||
private LinearLayout touchPad;
|
||||
private ImageView mousePointer;
|
||||
//private EditText hiddenEditor;
|
||||
@ -114,7 +106,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
|
||||
private View.OnTouchListener glTouchListener;
|
||||
|
||||
private Button[] controlButtons;
|
||||
// private Button[] controlButtons;
|
||||
|
||||
/*
|
||||
private LinearLayout contentCanvas;
|
||||
@ -198,6 +190,12 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
System.out.println("WidthHeight: " + AndroidDisplay.windowWidth + ":" + AndroidDisplay.windowHeight);
|
||||
|
||||
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
|
||||
|
||||
glSurfaceView = (MinecraftGLView) findViewById(R.id.main_game_render_view);
|
||||
|
||||
controlLayout = findViewById(R.id.main_controllayout);
|
||||
controlLayout.loadLayout(getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE).getString("defaultCtrl", Tools.CTRLMAP_PATH + "/default.json"));
|
||||
controlLayout.setModifiable(false);
|
||||
|
||||
// Menu
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_options);
|
||||
@ -223,22 +221,8 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
@ -246,6 +230,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
inventoryButton, talkButton, thirdPersonButton,
|
||||
listPlayersButton
|
||||
};
|
||||
*/
|
||||
// this.overlayView = (ViewGroup) findViewById(R.id.main_control_overlay);
|
||||
|
||||
//this.hiddenEditor = findViewById(R.id.hiddenTextbox);
|
||||
@ -276,11 +261,6 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
|
||||
this.debugText = (TextView) findViewById(R.id.content_text_debug);
|
||||
|
||||
this.toggleControlButton.setOnClickListener(this);
|
||||
this.zoomButton.setVisibility(mVersionInfo.optifineLib == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
this.glSurfaceView = (MinecraftGLView) findViewById(R.id.main_game_render_view);
|
||||
|
||||
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener = new View.OnClickListener(){
|
||||
|
||||
@ -295,12 +275,12 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
MainActivity.this.onClick(toggleControlButton);
|
||||
// MainActivity.this.onClick(toggleControlButton);
|
||||
}
|
||||
};
|
||||
|
||||
// toggleGui(null);
|
||||
onClick(toggleControlButton);
|
||||
// onClick(toggleControlButton);
|
||||
this.drawerLayout.closeDrawers();
|
||||
|
||||
AndroidLWJGLKeycode.isBackspaceAfterChar = mVersionInfo.minimumLauncherVersion >= 18;
|
||||
@ -748,16 +728,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
|
||||
@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);
|
||||
}
|
||||
*/
|
||||
|
||||
case R.id.control_togglectrl: {
|
||||
for (Button button : controlButtons) {
|
||||
button.setVisibility(button.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
@ -765,6 +738,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
zoomButton.setVisibility((zoomButton.getVisibility() == View.GONE && mVersionInfo.optifineLib != null) ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean onTouch(View v, MotionEvent e) {
|
||||
@ -782,7 +756,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
switch (v.getId()) {
|
||||
case R.id.control_up: sendKeyPress(Keyboard.KEY_W, isDown); break;
|
||||
case R.id.control_left: sendKeyPress(Keyboard.KEY_A, isDown); break;
|
||||
@ -795,8 +769,8 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
sendMouseButton(1, isDown);
|
||||
} else {
|
||||
if (!isDown) {
|
||||
AndroidDisplay.putMouseEventWithCoords(/* right mouse */ (byte) 1, (byte) 0, AndroidDisplay.mouseX, AndroidDisplay.mouseY, 0, System.nanoTime());
|
||||
AndroidDisplay.putMouseEventWithCoords(/* right mouse */ (byte) 1, (byte) 1, AndroidDisplay.mouseX, AndroidDisplay.mouseY, 0, System.nanoTime());
|
||||
AndroidDisplay.putMouseEventWithCoords((byte) 1, (byte) 0, AndroidDisplay.mouseX, AndroidDisplay.mouseY, 0, System.nanoTime());
|
||||
AndroidDisplay.putMouseEventWithCoords((byte) 1, (byte) 1, AndroidDisplay.mouseX, AndroidDisplay.mouseY, 0, System.nanoTime());
|
||||
}
|
||||
setRightOverride(isDown);
|
||||
} break;
|
||||
@ -809,7 +783,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
case R.id.control_zoom: sendKeyPress(Keyboard.KEY_C, isDown); break;
|
||||
case R.id.control_listplayers: sendKeyPress(Keyboard.KEY_TAB, isDown); break;
|
||||
}
|
||||
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1222,20 +1196,20 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
// this.secondaryButton.setBackgroundDrawable(this.rightOverride ? this.secondaryButtonColorBackground : this.secondaryButtonDefaultBackground);
|
||||
}
|
||||
|
||||
public void sendKeyPress(int keyCode, boolean status) {
|
||||
public static void sendKeyPress(int keyCode, boolean status) {
|
||||
sendKeyPress(keyCode, '\u0000', status);
|
||||
}
|
||||
|
||||
public void sendKeyPress(int keyCode, char keyChar, boolean status) {
|
||||
public static void sendKeyPress(int keyCode, char keyChar, boolean status) {
|
||||
AndroidDisplay.setKey(keyCode, keyChar, status);
|
||||
}
|
||||
|
||||
public void sendKeyPress(char keyChar) {
|
||||
public static void sendKeyPress(char keyChar) {
|
||||
sendKeyPress(0, keyChar, true);
|
||||
sendKeyPress(0, keyChar, false);
|
||||
}
|
||||
|
||||
public void sendKeyPress(int keyCode) {
|
||||
public static void sendKeyPress(int keyCode) {
|
||||
sendKeyPress(keyCode, true);
|
||||
sendKeyPress(keyCode, false);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
package net.kdt.pojavlaunch.value.customcontrols;
|
||||
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import android.view.*;
|
||||
import java.util.*;
|
||||
@ -6,30 +7,30 @@ import android.content.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
public class ControlButton
|
||||
public class ControlButton implements Cloneable
|
||||
{
|
||||
public static int pixelOf2dp;
|
||||
public static int pixelOf30dp;
|
||||
public static int pixelOf50dp;
|
||||
public static int pixelOf80dp;
|
||||
|
||||
|
||||
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) {
|
||||
SPECIAL_BUTTONS = new ControlButton[]{
|
||||
new ControlButton("Keyboard", -1, pixelOf2dp * 3 + pixelOf80dp * 2, pixelOf2dp, pixelOf80dp, pixelOf30dp),
|
||||
new ControlButton("GUI", -2, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf2dp - pixelOf50dp)
|
||||
new ControlButton("GUI", -2, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf2dp - pixelOf50dp * 2)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return SPECIAL_BUTTONS;
|
||||
}
|
||||
|
||||
|
||||
public static String[] buildSpecialButtonArray() {
|
||||
if (SPECIAL_BUTTON_NAME_ARRAY == null) {
|
||||
List<String> nameList = new ArrayList<String>();
|
||||
@ -38,53 +39,58 @@ public class ControlButton
|
||||
}
|
||||
SPECIAL_BUTTON_NAME_ARRAY = nameList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
return SPECIAL_BUTTON_NAME_ARRAY;
|
||||
}
|
||||
|
||||
|
||||
public String name;
|
||||
public float x;
|
||||
public float y;
|
||||
public int width = pixelOf50dp;
|
||||
public int height = pixelOf50dp;
|
||||
public int lwjglKeycode;
|
||||
public int keycode;
|
||||
public int keyindex;
|
||||
public boolean hidden;
|
||||
public boolean holdCtrl;
|
||||
public boolean holdAlt;
|
||||
public boolean holdShift;
|
||||
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(String name, int keycode) {
|
||||
this(name, keycode, 0, 0);
|
||||
}
|
||||
|
||||
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 keycode, float x, float y) {
|
||||
this(name, keycode, x, y, pixelOf50dp, pixelOf50dp);
|
||||
}
|
||||
|
||||
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(android.content.Context ctx, int resId, int keycode, float x, float y, boolean isSquare) {
|
||||
this(ctx.getResources().getString(resId), keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y, int width, int height) {
|
||||
|
||||
public ControlButton(String name, int keycode, float x, float y, boolean isSquare) {
|
||||
this(name, keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int keycode, float x, float y, int width, int height) {
|
||||
this.name = name;
|
||||
this.lwjglKeycode = lwjglKeycode;
|
||||
this.keycode = keycode;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
public void execute(MainActivity act, boolean isDown) {
|
||||
act.sendKeyPress(lwjglKeycode, isDown);
|
||||
act.sendKeyPress(keycode, isDown);
|
||||
}
|
||||
|
||||
public ControlButton clone() {
|
||||
return new ControlButton(name, keycode, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (!mCanModify) {
|
||||
mCanTriggerLongClick = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -11,14 +11,15 @@ public class ControlsLayout extends FrameLayout
|
||||
{
|
||||
private boolean mCanModify;
|
||||
private CustomControls mLayout;
|
||||
private CustomControlsActivity mActivity;
|
||||
public ControlsLayout(Context ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
|
||||
public ControlsLayout(Context ctx, AttributeSet attrs) {
|
||||
super(ctx, attrs);
|
||||
}
|
||||
|
||||
|
||||
public void hideAllHandleViews() {
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View view = getChildAt(i);
|
||||
@ -27,43 +28,68 @@ public class ControlsLayout extends FrameLayout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadLayout(String jsonPath) {
|
||||
try {
|
||||
loadLayout(new Gson().fromJson(Tools.read(jsonPath), CustomControls.class));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLayout(CustomControls controlLayout) {
|
||||
mLayout = controlLayout;
|
||||
removeAllViews();
|
||||
for (ControlButton button : controlLayout.button) {
|
||||
addControlView(button);
|
||||
}
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
||||
public void addControlButton(ControlButton controlButton) {
|
||||
mLayout.button.add(controlButton);
|
||||
addControlView(controlButton);
|
||||
}
|
||||
|
||||
|
||||
private void addControlView(ControlButton controlButton) {
|
||||
final ControlView view = new ControlView(getContext(), controlButton);
|
||||
view.setModifiable(mCanModify);
|
||||
addView(view);
|
||||
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
|
||||
public void removeControlButton(ControlView controlButton) {
|
||||
mLayout.button.remove(controlButton.getProperties());
|
||||
controlButton.setVisibility(View.GONE);
|
||||
removeView(controlButton);
|
||||
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
|
||||
public void saveLayout(String path) throws Exception {
|
||||
Tools.write(path, new Gson().toJson(mLayout));
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
||||
public void setActivity(CustomControlsActivity activity) {
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
public void setModifiable(boolean z) {
|
||||
mCanModify = z;
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View v = getChildAt(i);
|
||||
if (v instanceof ControlView) {
|
||||
((ControlView) v).setModifiable(z);
|
||||
ControlView cv = ((ControlView) v);
|
||||
cv.setModifiable(z);
|
||||
cv.setVisibility(cv.getProperties().hidden ? View.INVISIBLE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setModified(boolean z) {
|
||||
if (mActivity != null) mActivity.isModified = z;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,6 @@
|
||||
android:fitsSystemWindows="true"
|
||||
app:menu="@menu/menu_customctrl"
|
||||
android:id="@+id/customctrl_navigation_view"/>
|
||||
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
||||
|
@ -22,11 +22,18 @@
|
||||
android:id="@+id/main_log_behind_GL"
|
||||
android:maxLines="100"/>
|
||||
|
||||
<net.kdt.pojavlaunch.MinecraftGLView
|
||||
android:id="@+id/main_game_render_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
<net.kdt.pojavlaunch.value.customcontrols.ControlsLayout
|
||||
android:id="@+id/main_controllayout"
|
||||
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"/>
|
||||
|
||||
</net.kdt.pojavlaunch.value.customcontrols.ControlsLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
@ -42,205 +49,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/control_debug"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginLeft="2.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:text="@string/control_debug"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginRight="2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/control_talk"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:layout_marginRight="2.0dip"
|
||||
android:text="@string/control_chat"
|
||||
android:layout_toRightOf="@id/control_debug"
|
||||
android:layout_alignParentTop="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/control_keyboard"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:layout_marginRight="2.0dip"
|
||||
android:text="@string/control_keyboard"
|
||||
android:layout_toRightOf="@id/control_talk"
|
||||
android:layout_alignParentTop="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/control_thirdperson"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginLeft="2.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:layout_marginRight="2.0dip"
|
||||
android:text="@string/control_thirdperson"
|
||||
android:layout_below="@id/control_debug"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
|
||||
<Button
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:layout_marginRight="2.0dip"
|
||||
android:text="@string/control_zoom"
|
||||
android:layout_below="@id/control_talk"
|
||||
android:layout_toRightOf="@id/control_thirdperson"
|
||||
android:id="@+id/control_zoom"/>
|
||||
|
||||
<Button
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30.0dip"
|
||||
android:layout_marginTop="2.0dip"
|
||||
android:layout_marginRight="2.0dip"
|
||||
android:text="@string/control_listplayers"
|
||||
android:layout_toRightOf="@id/control_keyboard"
|
||||
android:id="@+id/control_listplayers"/>
|
||||
|
||||
<Button
|
||||
android:textSize="32.0sp"
|
||||
android:id="@+id/control_down"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="68.0dip"
|
||||
android:layout_marginBottom="14.0dip"
|
||||
android:text="@string/control_down"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="32.0sp"
|
||||
android:id="@+id/control_up"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="68.0dip"
|
||||
android:layout_marginBottom="122.0dip"
|
||||
android:text="@string/control_up"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="32.0sp"
|
||||
android:id="@+id/control_left"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="14.0dip"
|
||||
android:layout_marginBottom="68.0dip"
|
||||
android:text="@string/control_left"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="32.0sp"
|
||||
android:id="@+id/control_right"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="122.0dip"
|
||||
android:layout_marginBottom="68.0dip"
|
||||
android:text="@string/control_right"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/control_jump"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginRight="68.0dip"
|
||||
android:layout_marginBottom="68.0dip"
|
||||
android:text="@string/control_jump"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="16.0sp"
|
||||
android:id="@+id/control_primary"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="14.0dip"
|
||||
android:layout_marginBottom="122.0dip"
|
||||
android:text="@string/control_primary"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="16.0sp"
|
||||
android:id="@+id/control_secondary"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="122.0dip"
|
||||
android:layout_marginBottom="122.0dip"
|
||||
android:text="@string/control_secondary"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="20.0sp"
|
||||
android:id="@+id/control_shift"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="68.0dip"
|
||||
android:layout_marginBottom="68.0dip"
|
||||
android:text="@string/control_shift"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:textSize="16.0sp"
|
||||
android:id="@+id/control_inventory"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50.0dip"
|
||||
android:layout_height="50.0dip"
|
||||
android:layout_marginLeft="122.0dip"
|
||||
android:layout_marginBottom="14.0dip"
|
||||
android:text="@string/control_inventory"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentBottom="true"/>
|
||||
|
||||
<Button
|
||||
android:layout_height="30dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/control_mouseoff"
|
||||
android:layout_below="@id/control_debug"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:onClick="toggleMouse"
|
||||
android:layout_alignParentTop="true"
|
||||
android:id="@+id/control_mouse_toggle"/>
|
||||
|
||||
<Button
|
||||
android:background="@drawable/control_button"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/control_toggle"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginLeft="14dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:id="@+id/control_togglecontrol"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -1,9 +1,17 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_add"
|
||||
android:title="@string/customctrl_addbutton"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_load"
|
||||
android:title="@string/global_load"/>
|
||||
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_add"
|
||||
android:title="@string/global_add"/>
|
||||
android:id="@+id/menu_ctrl_save"
|
||||
android:title="@string/global_save"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_selectdefault"
|
||||
android:title="@string/customctrl_selectdefault"/>
|
||||
</menu>
|
||||
|
@ -178,10 +178,13 @@
|
||||
|
||||
<string name="control_more3"></string>
|
||||
<string name="control_more4"></string>
|
||||
|
||||
<string name="customctrl_keyname">LWJGL Keycode</string>
|
||||
|
||||
<string name="customctrl_keyname">Keycode</string>
|
||||
<string name="customctrl_specialkey">Special Key</string>
|
||||
<string name="customctrl_hidden">Hidden</string>
|
||||
<string name="customctrl_addbutton">Add button</string>
|
||||
<string name="customctrl_title_selectctrl">Select default Control json</string>
|
||||
<string name="customctrl_selectdefault">Select default Control json</string>
|
||||
|
||||
<!-- Update part (unused now) -->
|
||||
<string name="update_console">Update console</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user