mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-20 09:37:07 -04:00
- Migrate from clone to recopy constructors
- Support for cloning Drawers
This commit is contained in:
@@ -12,8 +12,7 @@ import org.lwjgl.glfw.*;
|
||||
|
||||
import static net.kdt.pojavlaunch.LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN;
|
||||
|
||||
public class ControlData implements Cloneable
|
||||
{
|
||||
public class ControlData {
|
||||
|
||||
public static final int SPECIALBTN_KEYBOARD = -1;
|
||||
public static final int SPECIALBTN_TOGGLECTRL = -2;
|
||||
@@ -141,6 +140,24 @@ public class ControlData implements Cloneable
|
||||
this.strokeWidth = strokeWidth;
|
||||
this.cornerRadius = cornerRadius;
|
||||
}
|
||||
|
||||
//Deep copy constructor
|
||||
public ControlData(ControlData controlData){
|
||||
this(
|
||||
controlData.name,
|
||||
controlData.keycodes,
|
||||
controlData.dynamicX,
|
||||
controlData.dynamicY,
|
||||
controlData.width,
|
||||
controlData.height,
|
||||
controlData.isToggle,
|
||||
controlData.opacity,
|
||||
controlData.bgColor,
|
||||
controlData.strokeColor,
|
||||
controlData.strokeWidth,
|
||||
controlData.cornerRadius
|
||||
);
|
||||
}
|
||||
|
||||
public void execute(boolean isDown) {
|
||||
for(int keycode : keycodes){
|
||||
@@ -148,10 +165,6 @@ public class ControlData implements Cloneable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ControlData clone() {
|
||||
return new ControlData(name, keycodes, dynamicX, dynamicY, width, height, isToggle, opacity, bgColor, strokeColor,strokeWidth, cornerRadius);
|
||||
}
|
||||
|
||||
public float insertDynamicPos(String dynamicPos) {
|
||||
// Values in the map below may be always changed
|
||||
|
||||
@@ -9,6 +9,8 @@ import static net.kdt.pojavlaunch.customcontrols.ControlDrawerData.Orientation.L
|
||||
import static net.kdt.pojavlaunch.customcontrols.ControlDrawerData.Orientation.RIGHT;
|
||||
import static net.kdt.pojavlaunch.customcontrols.ControlDrawerData.Orientation.UP;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class ControlDrawerData {
|
||||
|
||||
public ArrayList<ControlData> buttonProperties;
|
||||
@@ -73,4 +75,13 @@ public class ControlDrawerData {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public ControlDrawerData(ControlDrawerData drawerData){
|
||||
buttonProperties = new ArrayList<>(drawerData.buttonProperties.size());
|
||||
for(ControlData controlData : drawerData.buttonProperties){
|
||||
buttonProperties.add(new ControlData(controlData));
|
||||
}
|
||||
properties = new ControlData(drawerData.properties);
|
||||
orientation = drawerData.orientation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,10 +76,7 @@ public class ControlLayout extends FrameLayout
|
||||
if(mModifiable) drawer.areButtonsVisible = true;
|
||||
|
||||
|
||||
//CONTROL SUB BUTTON
|
||||
for (ControlData subButton : drawerData.buttonProperties) {
|
||||
addSubView(drawer, subButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mLayout.scaledAt = LauncherPreferences.PREF_BUTTONSIZE;
|
||||
@@ -126,6 +123,10 @@ public class ControlLayout extends FrameLayout
|
||||
view.setFocusableInTouchMode(false);
|
||||
}
|
||||
addView(view);
|
||||
//CONTROL SUB BUTTON
|
||||
for (ControlData subButton : view.getDrawerData().buttonProperties) {
|
||||
addSubView(view, subButton);
|
||||
}
|
||||
|
||||
setModified(true);
|
||||
return view;
|
||||
|
||||
@@ -27,11 +27,11 @@ public class CustomControls {
|
||||
// Generate default control
|
||||
public CustomControls(Context ctx) {
|
||||
this();
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[0].clone()); // Keyboard
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[1].clone()); // GUI
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[2].clone()); // Primary Mouse mControlDataList
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[3].clone()); // Secondary Mouse mControlDataList
|
||||
this.mControlDataList.add(ControlData.getSpecialButtons()[4].clone()); // Virtual mouse toggle
|
||||
this.mControlDataList.add(new ControlData(ControlData.getSpecialButtons()[0])); // Keyboard
|
||||
this.mControlDataList.add(new ControlData(ControlData.getSpecialButtons()[1])); // GUI
|
||||
this.mControlDataList.add(new ControlData(ControlData.getSpecialButtons()[2])); // Primary Mouse mControlDataList
|
||||
this.mControlDataList.add(new ControlData(ControlData.getSpecialButtons()[3])); // Secondary Mouse mControlDataList
|
||||
this.mControlDataList.add(new ControlData(ControlData.getSpecialButtons()[4])); // Virtual mouse toggle
|
||||
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_debug, new int[]{LWJGLGLFWKeycode.GLFW_KEY_F3}, "${margin}", "${margin}", false));
|
||||
this.mControlDataList.add(new ControlData(ctx, R.string.control_chat, new int[]{LWJGLGLFWKeycode.GLFW_KEY_T}, "${margin} * 2 + ${width}", "${margin}", false));
|
||||
@@ -53,17 +53,7 @@ public class CustomControls {
|
||||
//The default controls are conform to the V2
|
||||
version = 3;
|
||||
}
|
||||
|
||||
public ControlData findControlData(int keycode) {
|
||||
for (ControlData data : mControlDataList) {
|
||||
for(int dataKeycode : data.keycodes){
|
||||
if (dataKeycode == keycode) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void save(String path) throws IOException {
|
||||
//Current version is the V2.3 so the version as to be marked as 3 !
|
||||
|
||||
@@ -140,10 +140,18 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
alertBuilder.setNegativeButton(android.R.string.cancel, null);
|
||||
alertBuilder.show();
|
||||
}else if(view == mCloneTextView) {
|
||||
ControlData cloneData = editedButton.getProperties().clone();
|
||||
cloneData.dynamicX = "0.5 * ${screen_width}";
|
||||
cloneData.dynamicY = "0.5 * ${screen_height}";
|
||||
((ControlLayout) mHandleView.mView.getParent()).addControlButton(cloneData);
|
||||
if(editedButton instanceof ControlDrawer){
|
||||
ControlDrawerData cloneData = new ControlDrawerData(((ControlDrawer)editedButton).getDrawerData());
|
||||
cloneData.properties.dynamicX = "0.5 * ${screen_width}";
|
||||
cloneData.properties.dynamicY = "0.5 * ${screen_height}";
|
||||
((ControlLayout) mHandleView.mView.getParent()).addDrawer(cloneData);
|
||||
}else{
|
||||
ControlData cloneData = new ControlData(editedButton.getProperties());
|
||||
cloneData.dynamicX = "0.5 * ${screen_width}";
|
||||
cloneData.dynamicY = "0.5 * ${screen_height}";
|
||||
((ControlLayout) mHandleView.mView.getParent()).addControlButton(cloneData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hide();
|
||||
|
||||
@@ -60,7 +60,7 @@ public class EditControlDrawerPopup extends EditControlButtonPopup{
|
||||
|
||||
builder.setNeutralButton(v.getResources().getString(R.string.customctrl_addsubbutton), (dialogInterface, i) -> {
|
||||
ControlLayout layout = (ControlLayout) drawer.getParent();
|
||||
ControlData controlData = drawerData.properties.clone();
|
||||
ControlData controlData = new ControlData(drawerData.properties);
|
||||
controlData.name = "new";
|
||||
layout.addSubButton(drawer, controlData);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user