mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 08:05:34 -04:00
Refactor control button related files
This commit is contained in:
parent
16bdc35739
commit
cad3f63433
@ -16,8 +16,7 @@ import net.kdt.pojavlaunch.customcontrols.buttons.ControlSubButton;
|
|||||||
import net.kdt.pojavlaunch.customcontrols.handleview.HandleView;
|
import net.kdt.pojavlaunch.customcontrols.handleview.HandleView;
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
|
||||||
public class ControlLayout extends FrameLayout
|
public class ControlLayout extends FrameLayout {
|
||||||
{
|
|
||||||
protected CustomControls mLayout;
|
protected CustomControls mLayout;
|
||||||
private boolean mModifiable;
|
private boolean mModifiable;
|
||||||
private CustomControlsActivity mActivity;
|
private CustomControlsActivity mActivity;
|
||||||
|
@ -57,7 +57,7 @@ public class CustomControls {
|
|||||||
|
|
||||||
|
|
||||||
public void save(String path) throws IOException {
|
public void save(String path) throws IOException {
|
||||||
//Current version is the V2.4 so the version as to be marked as 4 !
|
//Current version is the V2.5 so the version as to be marked as 4 !
|
||||||
version = 4;
|
version = 4;
|
||||||
|
|
||||||
Tools.write(path, Tools.GLOBAL_GSON.toJson(this));
|
Tools.write(path, Tools.GLOBAL_GSON.toJson(this));
|
||||||
|
@ -29,19 +29,15 @@ import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
|
|||||||
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
|
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
|
||||||
|
|
||||||
@SuppressLint("ViewConstructor")
|
@SuppressLint("ViewConstructor")
|
||||||
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener
|
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener {
|
||||||
{
|
private final Paint mRectPaint = new Paint();
|
||||||
private final Paint mRectPaint = new Paint();;
|
|
||||||
|
|
||||||
protected GestureDetector mGestureDetector;
|
protected GestureDetector mGestureDetector;
|
||||||
protected ControlData mProperties;
|
protected ControlData mProperties;
|
||||||
protected SelectionEndHandleView mHandleView;
|
protected SelectionEndHandleView mHandleView;
|
||||||
|
|
||||||
protected boolean mModifiable = false;
|
protected boolean mModifiable = false;
|
||||||
protected boolean mCanTriggerLongClick = true;
|
protected boolean mCanTriggerLongClick = true;
|
||||||
|
protected boolean mIsToggled = false;
|
||||||
protected boolean isToggled = false;
|
protected boolean mIsPointerOutOfBounds = false;
|
||||||
protected boolean isPointerOutOfBounds = false;
|
|
||||||
|
|
||||||
public ControlButton(ControlLayout layout, ControlData properties) {
|
public ControlButton(ControlLayout layout, ControlData properties) {
|
||||||
super(layout.getContext());
|
super(layout.getContext());
|
||||||
@ -258,7 +254,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
if (isToggled || (!mProperties.isToggle && isActivated()))
|
if (mIsToggled || (!mProperties.isToggle && isActivated()))
|
||||||
canvas.drawRoundRect(0, 0, getWidth(), getHeight(), mProperties.cornerRadius, mProperties.cornerRadius, mRectPaint);
|
canvas.drawRoundRect(0, 0, getWidth(), getHeight(), mProperties.cornerRadius, mProperties.cornerRadius, mRectPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,26 +299,26 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
//If out of bounds
|
//If out of bounds
|
||||||
if(event.getX() < getLeft() || event.getX() > getRight() ||
|
if(event.getX() < getLeft() || event.getX() > getRight() ||
|
||||||
event.getY() < getTop() || event.getY() > getBottom()){
|
event.getY() < getTop() || event.getY() > getBottom()){
|
||||||
if(mProperties.isSwipeable && !isPointerOutOfBounds){
|
if(mProperties.isSwipeable && !mIsPointerOutOfBounds){
|
||||||
//Remove keys
|
//Remove keys
|
||||||
if(!triggerToggle()) {
|
if(!triggerToggle()) {
|
||||||
sendKeyPresses(false);
|
sendKeyPresses(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isPointerOutOfBounds = true;
|
mIsPointerOutOfBounds = true;
|
||||||
((ControlLayout) getParent()).onTouch(this, event);
|
((ControlLayout) getParent()).onTouch(this, event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Else if we now are in bounds
|
//Else if we now are in bounds
|
||||||
if(isPointerOutOfBounds) {
|
if(mIsPointerOutOfBounds) {
|
||||||
((ControlLayout) getParent()).onTouch(this, event);
|
((ControlLayout) getParent()).onTouch(this, event);
|
||||||
//RE-press the button
|
//RE-press the button
|
||||||
if(mProperties.isSwipeable && !mProperties.isToggle){
|
if(mProperties.isSwipeable && !mProperties.isToggle){
|
||||||
sendKeyPresses(true);
|
sendKeyPresses(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isPointerOutOfBounds = false;
|
mIsPointerOutOfBounds = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_DOWN: // 0
|
case MotionEvent.ACTION_DOWN: // 0
|
||||||
@ -339,8 +335,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
MinecraftGLView v = ((ControlLayout) this.getParent()).findViewById(R.id.main_game_render_view);
|
MinecraftGLView v = ((ControlLayout) this.getParent()).findViewById(R.id.main_game_render_view);
|
||||||
if (v != null) v.dispatchTouchEvent(event);
|
if (v != null) v.dispatchTouchEvent(event);
|
||||||
}
|
}
|
||||||
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(this, event);
|
if(mIsPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(this, event);
|
||||||
isPointerOutOfBounds = false;
|
mIsPointerOutOfBounds = false;
|
||||||
|
|
||||||
if(!triggerToggle()) {
|
if(!triggerToggle()) {
|
||||||
sendKeyPresses(false);
|
sendKeyPresses(false);
|
||||||
@ -500,9 +496,9 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
public boolean triggerToggle(){
|
public boolean triggerToggle(){
|
||||||
//returns true a the toggle system is triggered
|
//returns true a the toggle system is triggered
|
||||||
if(mProperties.isToggle){
|
if(mProperties.isToggle){
|
||||||
isToggled = !isToggled;
|
mIsToggled = !mIsToggled;
|
||||||
invalidate();
|
invalidate();
|
||||||
sendKeyPresses(isToggled);
|
sendKeyPresses(mIsToggled);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,7 +2,6 @@ package net.kdt.pojavlaunch.customcontrols.buttons;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.Tools;
|
import net.kdt.pojavlaunch.Tools;
|
||||||
@ -20,7 +19,7 @@ public class ControlDrawer extends ControlButton {
|
|||||||
|
|
||||||
public ArrayList<ControlSubButton> buttons;
|
public ArrayList<ControlSubButton> buttons;
|
||||||
public ControlDrawerData drawerData;
|
public ControlDrawerData drawerData;
|
||||||
public ControlLayout mLayout;
|
public ControlLayout layout;
|
||||||
public boolean areButtonsVisible;
|
public boolean areButtonsVisible;
|
||||||
|
|
||||||
|
|
||||||
@ -28,14 +27,14 @@ public class ControlDrawer extends ControlButton {
|
|||||||
super(layout, drawerData.properties);
|
super(layout, drawerData.properties);
|
||||||
|
|
||||||
buttons = new ArrayList<>(drawerData.buttonProperties.size());
|
buttons = new ArrayList<>(drawerData.buttonProperties.size());
|
||||||
mLayout = layout;
|
this.layout = layout;
|
||||||
this.drawerData = drawerData;
|
this.drawerData = drawerData;
|
||||||
areButtonsVisible = layout.getModifiable();
|
areButtonsVisible = layout.getModifiable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addButton(ControlData properties){
|
public void addButton(ControlData properties){
|
||||||
addButton(new ControlSubButton(mLayout, properties, this));
|
addButton(new ControlSubButton(layout, properties, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addButton(ControlSubButton button){
|
public void addButton(ControlSubButton button){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user