mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -04:00
Add new ControlData properties and new constructors
This commit is contained in:
parent
eca6d9df47
commit
def161b40b
@ -1,5 +1,6 @@
|
|||||||
package net.kdt.pojavlaunch.customcontrols;
|
package net.kdt.pojavlaunch.customcontrols;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.kdt.pojavlaunch.*;
|
import net.kdt.pojavlaunch.*;
|
||||||
@ -9,12 +10,7 @@ import org.lwjgl.glfw.*;
|
|||||||
|
|
||||||
public class ControlData implements Cloneable
|
public class ControlData implements Cloneable
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
public static int pixelOf2dp = (int) Tools.dpToPx(2);
|
|
||||||
public static int pixelOf30dp = (int) Tools.dpToPx(30);
|
|
||||||
public static int pixelOf50dp = Tools.dpToPx(50);;
|
|
||||||
public static int pixelOf80dp;
|
|
||||||
*/
|
|
||||||
public static final int SPECIALBTN_KEYBOARD = -1;
|
public static final int SPECIALBTN_KEYBOARD = -1;
|
||||||
public static final int SPECIALBTN_TOGGLECTRL = -2;
|
public static final int SPECIALBTN_TOGGLECTRL = -2;
|
||||||
public static final int SPECIALBTN_MOUSEPRI = -3;
|
public static final int SPECIALBTN_MOUSEPRI = -3;
|
||||||
@ -38,20 +34,20 @@ public class ControlData implements Cloneable
|
|||||||
* bigger device or vice versa.
|
* bigger device or vice versa.
|
||||||
*/
|
*/
|
||||||
public String dynamicX, dynamicY;
|
public String dynamicX, dynamicY;
|
||||||
public boolean isDynamicBtn, isToggle, passThruEnabled, isRound;
|
public boolean isDynamicBtn, isToggle, passThruEnabled;
|
||||||
|
|
||||||
public static ControlData[] getSpecialButtons(){
|
public static ControlData[] getSpecialButtons(){
|
||||||
if (SPECIAL_BUTTONS == null) {
|
if (SPECIAL_BUTTONS == null) {
|
||||||
ControlData[] specialButtons = new ControlData[]{
|
ControlData[] specialButtons = new ControlData[]{
|
||||||
new ControlData("Keyboard", SPECIALBTN_KEYBOARD, "${margin} * 3 + ${width} * 2", "${margin}", false),
|
new ControlData("Keyboard", new int[]{SPECIALBTN_KEYBOARD}, "${margin} * 3 + ${width} * 2", "${margin}", false),
|
||||||
new ControlData("GUI", SPECIALBTN_TOGGLECTRL, "${margin}", "${bottom} - ${margin}"),
|
new ControlData("GUI", new int[]{SPECIALBTN_TOGGLECTRL}, "${margin}", "${bottom} - ${margin}"),
|
||||||
new ControlData("PRI", SPECIALBTN_MOUSEPRI, "${margin}", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
new ControlData("PRI", new int[]{SPECIALBTN_MOUSEPRI}, "${margin}", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
||||||
new ControlData("SEC", SPECIALBTN_MOUSESEC, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
new ControlData("SEC", new int[]{SPECIALBTN_MOUSESEC}, "${margin} * 3 + ${width} * 2", "${screen_height} - ${margin} * 3 - ${height} * 3"),
|
||||||
new ControlData("Mouse", SPECIALBTN_VIRTUALMOUSE, "${right}", "${margin}", false),
|
new ControlData("Mouse", new int[]{SPECIALBTN_VIRTUALMOUSE}, "${right}", "${margin}", false),
|
||||||
|
|
||||||
new ControlData("MID", SPECIALBTN_MOUSEMID, "${margin}", "${margin}"),
|
new ControlData("MID", new int[]{SPECIALBTN_MOUSEMID}, "${margin}", "${margin}"),
|
||||||
new ControlData("SCROLLUP", SPECIALBTN_SCROLLUP, "${margin}", "${margin}"),
|
new ControlData("SCROLLUP", new int[]{SPECIALBTN_SCROLLUP}, "${margin}", "${margin}"),
|
||||||
new ControlData("SCROLLDOWN", SPECIALBTN_SCROLLDOWN, "${margin}", "${margin}")
|
new ControlData("SCROLLDOWN", new int[]{SPECIALBTN_SCROLLDOWN}, "${margin}", "${margin}")
|
||||||
};
|
};
|
||||||
SPECIAL_BUTTONS = specialButtons;
|
SPECIAL_BUTTONS = specialButtons;
|
||||||
}
|
}
|
||||||
@ -76,8 +72,13 @@ public class ControlData implements Cloneable
|
|||||||
public float y;
|
public float y;
|
||||||
public float width;
|
public float width;
|
||||||
public float height;
|
public float height;
|
||||||
public int keycode;
|
public int[] keycodes; //Should store up to 4 keys
|
||||||
public int transparency;
|
public float opacity; //Alpha value from 0 to 1;
|
||||||
|
public int bgColor;
|
||||||
|
public int strokeColor;
|
||||||
|
public int strokeWidth;
|
||||||
|
public float cornerRadius;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean hidden;
|
public boolean hidden;
|
||||||
public boolean holdCtrl;
|
public boolean holdCtrl;
|
||||||
@ -86,63 +87,74 @@ public class ControlData implements Cloneable
|
|||||||
public Object specialButtonListener;
|
public Object specialButtonListener;
|
||||||
|
|
||||||
public ControlData() {
|
public ControlData() {
|
||||||
this("", LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN, 0, 0);
|
this("", new int[]{LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN}, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode) {
|
public ControlData(String name, int[] keycodes) {
|
||||||
this(name, keycode, 0, 0);
|
this(name, keycodes, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, float x, float y) {
|
public ControlData(String name, int[] keycodes, float x, float y) {
|
||||||
this(name, keycode, x, y, Tools.dpToPx(50), Tools.dpToPx(50));
|
this(name, keycodes, x, y, Tools.dpToPx(50), Tools.dpToPx(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(android.content.Context ctx, int resId, int keycode, float x, float y, boolean isSquare) {
|
public ControlData(android.content.Context ctx, int resId, int[] keycodes, float x, float y, boolean isSquare) {
|
||||||
this(ctx.getResources().getString(resId), keycode, x, y, isSquare);
|
this(ctx.getResources().getString(resId), keycodes, x, y, isSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, float x, float y, boolean isSquare) {
|
public ControlData(String name, int[] keycodes, float x, float y, boolean isSquare) {
|
||||||
this(name, keycode, x, y, isSquare ? Tools.dpToPx(50) : Tools.dpToPx(80), isSquare ? Tools.dpToPx(50) : Tools.dpToPx(30));
|
this(name, keycodes, x, y, isSquare ? Tools.dpToPx(50) : Tools.dpToPx(80), isSquare ? Tools.dpToPx(50) : Tools.dpToPx(30));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, float x, float y, float width, float height) {
|
public ControlData(String name, int[] keycodes, float x, float y, float width, float height) {
|
||||||
this(name, keycode, Float.toString(x), Float.toString(y), width, height, false);
|
this(name, keycodes, Float.toString(x), Float.toString(y), width, height, false);
|
||||||
this.isDynamicBtn = false;
|
this.isDynamicBtn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, String dynamicX, String dynamicY) {
|
public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY) {
|
||||||
this(name, keycode, dynamicX, dynamicY, Tools.dpToPx(50), Tools.dpToPx(50), false);
|
this(name, keycodes, dynamicX, dynamicY, Tools.dpToPx(50), Tools.dpToPx(50), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(android.content.Context ctx, int resId, int keycode, String dynamicX, String dynamicY, boolean isSquare) {
|
public ControlData(android.content.Context ctx, int resId, int[] keycodes, String dynamicX, String dynamicY, boolean isSquare) {
|
||||||
this(ctx.getResources().getString(resId), keycode, dynamicX, dynamicY, isSquare);
|
this(ctx.getResources().getString(resId), keycodes, dynamicX, dynamicY, isSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, String dynamicX, String dynamicY, boolean isSquare) {
|
public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, boolean isSquare) {
|
||||||
this(name, keycode, dynamicX, dynamicY, isSquare ? Tools.dpToPx(50) : Tools.dpToPx(80), isSquare ? Tools.dpToPx(50) : Tools.dpToPx(30), false);
|
this(name, keycodes, dynamicX, dynamicY, isSquare ? Tools.dpToPx(50) : Tools.dpToPx(80), isSquare ? Tools.dpToPx(50) : Tools.dpToPx(30), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, String dynamicX, String dynamicY, float width, float height, boolean isToggle) {
|
public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, float width, float height, boolean isToggle){
|
||||||
|
this(name, keycodes, dynamicX, dynamicY, width, height, isToggle, 1,0x4D000000, 0xFFFFFFFF,0,Tools.dpToPx(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControlData(String name, int[] keycodes, String dynamicX, String dynamicY, float width, float height, boolean isToggle, float opacity, int bgColor, int strokeColor, int strokeWidth, float cornerRadius) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.keycode = keycode;
|
this.keycodes = inflateKeycodeArray(keycodes);
|
||||||
this.dynamicX = dynamicX;
|
this.dynamicX = dynamicX;
|
||||||
this.dynamicY = dynamicY;
|
this.dynamicY = dynamicY;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.isDynamicBtn = true;
|
this.isDynamicBtn = true;
|
||||||
this.isToggle = isToggle;
|
this.isToggle = isToggle;
|
||||||
|
this.opacity = opacity;
|
||||||
|
this.bgColor = bgColor;
|
||||||
|
this.strokeColor = strokeColor;
|
||||||
|
this.strokeWidth = strokeWidth;
|
||||||
|
this.cornerRadius = cornerRadius;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(BaseMainActivity act, boolean isDown) {
|
public void execute(BaseMainActivity act, boolean isDown) {
|
||||||
act.sendKeyPress(keycode, 0, isDown);
|
for(int keycode : keycodes){
|
||||||
|
act.sendKeyPress(keycode, 0, isDown);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData clone() {
|
public ControlData clone() {
|
||||||
if (this instanceof ControlData) {
|
if (this instanceof ControlData) {
|
||||||
return new ControlData(name, keycode, ((ControlData) this).dynamicX, ((ControlData) this).dynamicY, width, height, isToggle);
|
return new ControlData(name, keycodes, ((ControlData) this).dynamicX, ((ControlData) this).dynamicY, width, height, isToggle, opacity, bgColor, strokeColor,strokeWidth, cornerRadius);
|
||||||
} else {
|
} else {
|
||||||
return new ControlData(name, keycode, x, y, width, height);
|
return new ControlData(name, keycodes, x, y, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,15 +179,20 @@ public class ControlData implements Cloneable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if (keycode < 0 && SPECIAL_BUTTONS != null) {
|
if(SPECIAL_BUTTONS != null){
|
||||||
for (ControlData data : getSpecialButtons()) {
|
for(int keycode : keycodes){
|
||||||
if (keycode == data.keycode) {
|
for (ControlData data : getSpecialButtons()) {
|
||||||
specialButtonListener = data.specialButtonListener;
|
if (keycode == data.keycodes[0]) {
|
||||||
|
specialButtonListener = data.specialButtonListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} if (dynamicX == null) {
|
}
|
||||||
|
|
||||||
|
if (dynamicX == null) {
|
||||||
dynamicX = Float.toString(x);
|
dynamicX = Float.toString(x);
|
||||||
} if (dynamicY == null) {
|
}
|
||||||
|
if (dynamicY == null) {
|
||||||
dynamicY = Float.toString(y);
|
dynamicY = Float.toString(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,4 +203,16 @@ public class ControlData implements Cloneable
|
|||||||
private static float calculate(String math) {
|
private static float calculate(String math) {
|
||||||
return (float) new ExpressionBuilder(math).build().evaluate();
|
return (float) new ExpressionBuilder(math).build().evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int[] inflateKeycodeArray(int[] keycodes){
|
||||||
|
int[] inflatedArray = new int[4];
|
||||||
|
int i;
|
||||||
|
for(i=0; i<keycodes.length; ++i){
|
||||||
|
inflatedArray[i] = keycodes[i];
|
||||||
|
}
|
||||||
|
for(;i<4;++i){
|
||||||
|
inflatedArray[i] = LWJGLGLFWKeycode.GLFW_KEY_UNKNOWN;
|
||||||
|
}
|
||||||
|
return inflatedArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user