A lot of bug fixes in custom controls

- Re-load control when unnecessary.
- Able to edit PRI and SEC while playing.
- Unable to move camera while holding a button.
- Probably more(?)
This commit is contained in:
khanhduytran0 2020-11-22 16:32:02 +07:00
parent f0a72d76d4
commit 3a30915a51
7 changed files with 56 additions and 66 deletions

View File

@ -24,7 +24,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 26 targetSdkVersion 26
versionCode 156236 versionCode 156236
versionName "3.3.0b_6408b_20201119" versionName "3.3.0b_6408b_20201122"
multiDexEnabled true //important multiDexEnabled true //important
} }

View File

@ -103,7 +103,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
String[] oldSpecialArr = ControlData.buildSpecialButtonArray(); String[] oldSpecialArr = ControlData.buildSpecialButtonArray();
final String[] specialArr = new String[oldSpecialArr.length]; final String[] specialArr = new String[oldSpecialArr.length];
for (int i = 0; i < specialArr.length; i++) { for (int i = 0; i < specialArr.length; i++) {
specialArr[i] = "SPECIAL_" + oldSpecialArr[i]; specialArr[i] = "SPECIAL_" + oldSpecialArr[specialArr.length - i - 1];
} }
adapter.addAll(specialArr); adapter.addAll(specialArr);
@ -111,7 +111,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
spinnerKeycode.setAdapter(adapter); spinnerKeycode.setAdapter(adapter);
if (properties.keycode < 0) { if (properties.keycode < 0) {
spinnerKeycode.setSelection(0 - properties.keycode); spinnerKeycode.setSelection(properties.keycode + specialArr.length);
} else { } else {
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.keycode) + specialArr.length); spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.keycode) + specialArr.length);
} }

View File

@ -20,12 +20,10 @@ public class CustomControlsActivity extends BaseActivity
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private NavigationView navDrawer; private NavigationView navDrawer;
private ControlLayout ctrlLayout; private ControlLayout ctrlLayout;
private CustomControls mCtrl;
private SharedPreferences mPref; private SharedPreferences mPref;
public boolean isModified = false; public boolean isModified = false;
private String selectedName = "new_control"; private String selectedName = "new_control";
@Override @Override
@ -66,14 +64,10 @@ public class CustomControlsActivity extends BaseActivity
} }
}); });
mCtrl = new CustomControls();
ctrlLayout.setActivity(this); ctrlLayout.setActivity(this);
ctrlLayout.setModifiable(true); ctrlLayout.setModifiable(true);
loadControl(LauncherPreferences.PREF_DEFAULTCTRL_PATH); loadControl(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
ctrlLayout.loadLayout(mCtrl);
} }
@Override @Override
@ -203,8 +197,7 @@ public class CustomControlsActivity extends BaseActivity
private void loadControl(String path) { private void loadControl(String path) {
try { try {
mCtrl = Tools.GLOBAL_GSON.fromJson(Tools.read(path), CustomControls.class); ctrlLayout.loadLayout(path);
ctrlLayout.loadLayout(mCtrl);
selectedName = new File(path).getName(); selectedName = new File(path).getName();
// Remove `.json` // Remove `.json`

View File

@ -7,9 +7,10 @@ import android.widget.*;
import net.kdt.pojavlaunch.customcontrols.*; import net.kdt.pojavlaunch.customcontrols.*;
import net.kdt.pojavlaunch.prefs.*; import net.kdt.pojavlaunch.prefs.*;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;
import java.io.*;
import com.google.gson.*;
public class CustomCtrlMainActivity extends BaseMainActivity { public class CustomCtrlMainActivity extends BaseMainActivity {
private CustomControls mControl;
private ControlLayout mControlLayout; private ControlLayout mControlLayout;
private View.OnClickListener mClickListener; private View.OnClickListener mClickListener;
@ -99,21 +100,15 @@ public class CustomCtrlMainActivity extends BaseMainActivity {
= mTouchListener; = mTouchListener;
mControlLayout = findViewById(R.id.main_control_layout); mControlLayout = findViewById(R.id.main_control_layout);
mControl = new CustomControls(); try {
mControlLayout.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
} catch (Throwable th) {
Tools.showError(this, th);
}
mControlLayout.setModifiable(false); mControlLayout.setModifiable(false);
loadControl(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
mControlLayout.loadLayout(mControl);
// toggleGui(null); // toggleGui(null);
mControlLayout.toggleControlVisible(); mControlLayout.toggleControlVisible();
} }
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

@ -106,8 +106,7 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
@Override @Override
public boolean onLongClick(View p1) { public boolean onLongClick(View p1) {
if (!mCanTriggerLongClick) return false; if (mCanTriggerLongClick) {
if (mHandleView.isShowing()) { if (mHandleView.isShowing()) {
mHandleView.hide(); mHandleView.hide();
} else { } else {
@ -116,7 +115,9 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
} }
mHandleView.show(); mHandleView.show();
} }
return true; }
return mCanTriggerLongClick;
} }
private float moveX, moveY; private float moveX, moveY;
@ -145,8 +146,6 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
return true; return true;
} }
return false;
} else { } else {
if (mGestureDetector.onTouchEvent(event)) { if (mGestureDetector.onTouchEvent(event)) {
mCanTriggerLongClick = true; mCanTriggerLongClick = true;
@ -173,10 +172,10 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
break; break;
} }
}
return false; return false;
} }
}
public void setModifiable(boolean z) { public void setModifiable(boolean z) {
mCanModify = z; mCanModify = z;

View File

@ -7,6 +7,7 @@ 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.*; import java.util.*;
import java.io.*;
public class ControlLayout extends FrameLayout public class ControlLayout extends FrameLayout
{ {
@ -32,17 +33,19 @@ public class ControlLayout extends FrameLayout
} }
} }
public void loadLayout(String jsonPath) { public void loadLayout(String jsonPath) throws IOException, JsonSyntaxException {
try {
loadLayout(Tools.GLOBAL_GSON.fromJson(Tools.read(jsonPath), CustomControls.class)); loadLayout(Tools.GLOBAL_GSON.fromJson(Tools.read(jsonPath), CustomControls.class));
} catch (Exception e) {
e.printStackTrace();
}
} }
public void loadLayout(CustomControls controlLayout) { public void loadLayout(CustomControls controlLayout) {
mLayout = controlLayout; mLayout = controlLayout;
removeAllViews();
for (int i = 0; i < getChildCount(); i++) {
if (getChildAt(i) instanceof ControlButton) {
removeViewAt(i);
}
}
for (ControlData button : controlLayout.mControlDataList) { for (ControlData button : controlLayout.mControlDataList) {
button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE; button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE;
addControlView(button); addControlView(button);

View File

@ -13,6 +13,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="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 <net.kdt.pojavlaunch.MinecraftGLView
android:id="@+id/main_game_render_view" android:id="@+id/main_game_render_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -33,11 +38,6 @@
</LinearLayout> </LinearLayout>
<net.kdt.pojavlaunch.customcontrols.ControlLayout
android:id="@+id/main_control_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</net.kdt.pojavlaunch.customcontrols.ControlLayout> </net.kdt.pojavlaunch.customcontrols.ControlLayout>
<LinearLayout <LinearLayout