mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-18 16:46:58 -04:00
Imported Custom controls from v3
This commit is contained in:
@@ -28,7 +28,7 @@ public class GLTextureView
|
||||
View.OnLayoutChangeListener {
|
||||
|
||||
private final static String TAG = "GLTextureView";
|
||||
private final static boolean LOG_ALL = false;
|
||||
private final static boolean LOG_ALL = true;
|
||||
private final static boolean LOG_ATTACH_DETACH = LOG_ALL;
|
||||
private final static boolean LOG_THREADS = LOG_ALL;
|
||||
private final static boolean LOG_PAUSE_RESUME = LOG_ALL;
|
||||
|
||||
@@ -13,6 +13,9 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import android.support.v7.preference.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
|
||||
public class CustomControlsActivity extends AppCompatActivity
|
||||
{
|
||||
@@ -33,10 +36,12 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.control_mapping);
|
||||
|
||||
mPref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||
mPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
ctrlLayout = (ControlsLayout) findViewById(R.id.customctrl_controllayout);
|
||||
|
||||
// Menu
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.customctrl_drawerlayout);
|
||||
|
||||
@@ -67,22 +72,13 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
});
|
||||
|
||||
mCtrl = new CustomControls();
|
||||
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);
|
||||
|
||||
loadControl(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
|
||||
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +92,14 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
private void setDefaultControlJson(String path) {
|
||||
mPref.edit().putString("defaultCtrl", path).commit();
|
||||
try {
|
||||
// Load before save to make sure control is not error
|
||||
ctrlLayout.loadLayout(new Gson().fromJson(Tools.read(path), CustomControls.class));
|
||||
LauncherPreferences.DEFAULT_PREF.edit().putString("defaultCtrl", path).commit();
|
||||
LauncherPreferences.PREF_DEFAULTCTRL_PATH = path;
|
||||
} catch (Throwable th) {
|
||||
Tools.showError(this, th);
|
||||
}
|
||||
}
|
||||
|
||||
private void dialogSelectDefaultCtrl() {
|
||||
@@ -215,15 +218,4 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
Tools.showError(CustomControlsActivity.this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDefaultControlMap() {
|
||||
List<ControlButton> btn = mCtrl.button;
|
||||
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 * 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
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.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
|
||||
controlLayout.setModifiable(false);
|
||||
|
||||
// Menu
|
||||
@@ -601,7 +601,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
}
|
||||
});
|
||||
glSurfaceView.setOnTouchListener(glTouchListener);
|
||||
glSurfaceView.setRenderer(new GLTextureView.Renderer() {
|
||||
glSurfaceView.setRenderer(new MinecraftGLView.Renderer() {
|
||||
@Override
|
||||
public void onSurfaceDestroyed(GL10 gl) {
|
||||
Log.d(Tools.APP_NAME, "Surface destroyed.");
|
||||
|
||||
@@ -6,6 +6,8 @@ import android.content.pm.PackageManager.*;
|
||||
import android.content.pm.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
import android.support.v7.preference.*;
|
||||
import java.io.*;
|
||||
|
||||
public class PojavApplication extends Application
|
||||
{
|
||||
@@ -22,6 +24,7 @@ public class PojavApplication extends Application
|
||||
Tools.usingVerCode = thisApp.versionCode;
|
||||
Tools.datapath = getDir("files", MODE_PRIVATE).getParent();
|
||||
|
||||
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
LauncherPreferences.loadPreferences(this);
|
||||
|
||||
ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2);
|
||||
@@ -31,6 +34,12 @@ public class PojavApplication extends Application
|
||||
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
|
||||
specialButtons[0].name = getString(R.string.control_keyboard);
|
||||
specialButtons[1].name = getString(R.string.control_toggle);
|
||||
specialButtons[2].name = getString(R.string.control_primary);
|
||||
specialButtons[3].name = getString(R.string.control_secondary);
|
||||
|
||||
new File(Tools.CTRLMAP_PATH).mkdirs();
|
||||
new CustomControls(this).save(Tools.CTRLDEF_FILE);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public final class Tools
|
||||
public static String MAIN_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/games/minecraft";
|
||||
public static String ASSETS_PATH = MAIN_PATH + "/assets";
|
||||
public static String CTRLMAP_PATH = MAIN_PATH + "/controlmap";
|
||||
public static String CTRLDEF_FILE = MAIN_PATH + "/controlmap/default.json";
|
||||
|
||||
public static int usingVerCode = 1;
|
||||
public static String usingVerName = "2.4.2";
|
||||
@@ -74,12 +75,6 @@ public final class Tools
|
||||
return versnDir + "/" + version + "/" + version + ".jar";
|
||||
}
|
||||
|
||||
// May useless
|
||||
public static boolean isOptifineInstalled(String version)
|
||||
{
|
||||
return new File(versnDir + "/" + version + "/optifine.jar").exists();
|
||||
}
|
||||
|
||||
private static boolean isClientFirst = false;
|
||||
public static String generate(String version) throws IOException
|
||||
{
|
||||
@@ -155,13 +150,6 @@ public final class Tools
|
||||
showError(ctx, e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static void extractLibraries(Activity ctx) throws Exception
|
||||
{
|
||||
extractAssetFolder(ctx, "libraries", worksDir);
|
||||
}
|
||||
*/
|
||||
|
||||
public static void showError(Context ctx, Throwable e)
|
||||
{
|
||||
|
||||
@@ -2,9 +2,11 @@ package net.kdt.pojavlaunch.prefs;
|
||||
|
||||
import android.content.*;
|
||||
import com.pojavdx.dex.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
|
||||
public class LauncherPreferences
|
||||
{
|
||||
public static SharedPreferences DEFAULT_PREF;
|
||||
public static boolean PREF_VERTYPE_RELEASE = true;
|
||||
public static boolean PREF_VERTYPE_SNAPSHOT = false;
|
||||
public static boolean PREF_VERTYPE_OLDALPHA = false;
|
||||
@@ -13,20 +15,21 @@ public class LauncherPreferences
|
||||
public static boolean PREF_FORGETOF = false;
|
||||
public static float PREF_BUTTONSIZE = 1.0f;
|
||||
public static int PREF_LONGPRESS_TRIGGER = 500;
|
||||
public static String PREF_DEFAULTCTRL_PATH = Tools.CTRLDEF_FILE;
|
||||
|
||||
public static void loadPreferences(Context ctx) {
|
||||
SharedPreferences mainPreference = ctx.getSharedPreferences(ctx.getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||
int maxDxPref = mainPreference.getInt("maxDxRefs", 0xFFF);
|
||||
int maxDxPref = DEFAULT_PREF.getInt("maxDxRefs", 0xFFF);
|
||||
DexFormat.MAX_MEMBER_IDX = maxDxPref;
|
||||
DexFormat.MAX_TYPE_IDX = maxDxPref;
|
||||
|
||||
PREF_BUTTONSIZE = mainPreference.getFloat("controlSize", 1f);
|
||||
PREF_FREEFORM = mainPreference.getBoolean("freeform", false);
|
||||
PREF_FORGETOF = mainPreference.getBoolean("forgetOptifinePath", false);
|
||||
PREF_VERTYPE_RELEASE = mainPreference.getBoolean("vertype_release", true);
|
||||
PREF_VERTYPE_SNAPSHOT = mainPreference.getBoolean("vertype_snapshot", false);
|
||||
PREF_VERTYPE_OLDALPHA = mainPreference.getBoolean("vertype_oldalpha", false);
|
||||
PREF_VERTYPE_OLDBETA = mainPreference.getBoolean("vertype_oldbeta", false);
|
||||
PREF_LONGPRESS_TRIGGER = mainPreference.getInt("timeLongPressTrigger", 500);
|
||||
PREF_BUTTONSIZE = DEFAULT_PREF.getFloat("controlSize", 1f);
|
||||
PREF_FREEFORM = DEFAULT_PREF.getBoolean("freeform", false);
|
||||
PREF_FORGETOF = DEFAULT_PREF.getBoolean("forgetOptifinePath", false);
|
||||
PREF_VERTYPE_RELEASE = DEFAULT_PREF.getBoolean("vertype_release", true);
|
||||
PREF_VERTYPE_SNAPSHOT = DEFAULT_PREF.getBoolean("vertype_snapshot", false);
|
||||
PREF_VERTYPE_OLDALPHA = DEFAULT_PREF.getBoolean("vertype_oldalpha", false);
|
||||
PREF_VERTYPE_OLDBETA = DEFAULT_PREF.getBoolean("vertype_oldbeta", false);
|
||||
PREF_LONGPRESS_TRIGGER = DEFAULT_PREF.getInt("timeLongPressTrigger", 500);
|
||||
PREF_DEFAULTCTRL_PATH = DEFAULT_PREF.getString("defaultCtrl", Tools.CTRLDEF_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +14,21 @@ public class ControlButton implements Cloneable
|
||||
public static int pixelOf50dp;
|
||||
public static int pixelOf80dp;
|
||||
|
||||
public static final int SPECIALBTN_KEYBOARD = 0;
|
||||
public static final int SPECIALBTN_TOGGLECTRL = 1;
|
||||
|
||||
public static final int SPECIALBTN_KEYBOARD = -1;
|
||||
public static final int SPECIALBTN_TOGGLECTRL = -2;
|
||||
public static final int SPECIALBTN_MOUSEPRI = -3;
|
||||
public static final int SPECIALBTN_MOUSESEC = -4;
|
||||
|
||||
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 * 2)
|
||||
new ControlButton("Keyboard", SPECIALBTN_KEYBOARD, pixelOf2dp * 3 + pixelOf80dp * 2, pixelOf2dp, pixelOf80dp, pixelOf30dp),
|
||||
new ControlButton("GUI", SPECIALBTN_TOGGLECTRL, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 2 + pixelOf2dp * 4),
|
||||
new ControlButton("PRI", SPECIALBTN_MOUSEPRI, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2),
|
||||
new ControlButton("SEC", SPECIALBTN_MOUSESEC, pixelOf2dp * 3 + pixelOf50dp * 2, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,7 +74,7 @@ public class ControlButton implements Cloneable
|
||||
}
|
||||
|
||||
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);
|
||||
this(ctx.getResources().getString(resId), keycode, x, y, isSquare);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int keycode, float x, float y, boolean isSquare) {
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ControlsLayout extends FrameLayout
|
||||
}
|
||||
|
||||
public void saveLayout(String path) throws Exception {
|
||||
Tools.write(path, new Gson().toJson(mLayout));
|
||||
mLayout.save(path);
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,47 @@
|
||||
package net.kdt.pojavlaunch.value.customcontrols;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import com.google.gson.*;
|
||||
import android.content.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.AndroidDisplay;
|
||||
|
||||
public class CustomControls
|
||||
{
|
||||
public List<ControlButton> button = new ArrayList<ControlButton>();
|
||||
public List<ControlButton> button;
|
||||
public CustomControls() {
|
||||
this(new ArrayList<ControlButton>());
|
||||
}
|
||||
|
||||
public CustomControls(List<ControlButton> button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
// Generate default control
|
||||
public CustomControls(Context ctx) {
|
||||
this();
|
||||
this.button.add(ControlButton.getSpecialButtons()[0].clone()); // Keyboard
|
||||
this.button.add(ControlButton.getSpecialButtons()[1].clone()); // GUI
|
||||
this.button.add(ControlButton.getSpecialButtons()[2].clone()); // Primary Mouse button
|
||||
this.button.add(ControlButton.getSpecialButtons()[3].clone()); // Secondary Mouse button
|
||||
|
||||
this.button.add(new ControlButton(ctx, R.string.control_debug, Keyboard.KEY_F3, ControlButton.pixelOf2dp, ControlButton.pixelOf2dp, false));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_chat, Keyboard.KEY_T, ControlButton.pixelOf2dp * 2 + ControlButton.pixelOf80dp, ControlButton.pixelOf2dp, false));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_listplayers, Keyboard.KEY_TAB, ControlButton.pixelOf2dp * 4 + ControlButton.pixelOf80dp * 3, ControlButton.pixelOf2dp, false));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_thirdperson, Keyboard.KEY_F5, ControlButton.pixelOf2dp, ControlButton.pixelOf30dp + ControlButton.pixelOf2dp, false));
|
||||
|
||||
this.button.add(new ControlButton(ctx, R.string.control_up, Keyboard.KEY_W, ControlButton.pixelOf2dp * 2 + ControlButton.pixelOf50dp, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp * 3 - ControlButton.pixelOf50dp * 3, true));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_left, Keyboard.KEY_A, ControlButton.pixelOf2dp, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp * 2 - ControlButton.pixelOf50dp * 2, true));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_down, Keyboard.KEY_S, ControlButton.pixelOf2dp * 2 + ControlButton.pixelOf50dp, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp - ControlButton.pixelOf50dp, true));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_right, Keyboard.KEY_D, ControlButton.pixelOf2dp * 3 + ControlButton.pixelOf50dp * 2, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp * 2 - ControlButton.pixelOf50dp * 2, true));
|
||||
|
||||
this.button.add(new ControlButton(ctx, R.string.control_inventory, Keyboard.KEY_E, ControlButton.pixelOf2dp * 3 + ControlButton.pixelOf50dp * 2, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp - ControlButton.pixelOf50dp, true));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_shift, Keyboard.KEY_LSHIFT, ControlButton.pixelOf2dp * 2 + ControlButton.pixelOf50dp, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp * 2 - ControlButton.pixelOf50dp * 2, true));
|
||||
this.button.add(new ControlButton(ctx, R.string.control_jump, Keyboard.KEY_SPACE, AndroidDisplay.windowWidth - ControlButton.pixelOf2dp * 3 - ControlButton.pixelOf50dp * 2, AndroidDisplay.windowHeight - ControlButton.pixelOf2dp * 2 - ControlButton.pixelOf50dp * 2, true));
|
||||
|
||||
}
|
||||
|
||||
public void save(String path) throws Exception {
|
||||
Tools.write(path, new Gson().toJson(this));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user