Refactor control button related files

This commit is contained in:
SerpentSpirale 2022-02-26 18:36:21 +01:00 committed by ArtDev
parent 16bdc35739
commit cad3f63433
4 changed files with 18 additions and 24 deletions

View File

@ -16,8 +16,7 @@ import net.kdt.pojavlaunch.customcontrols.buttons.ControlSubButton;
import net.kdt.pojavlaunch.customcontrols.handleview.HandleView;
import net.kdt.pojavlaunch.prefs.*;
public class ControlLayout extends FrameLayout
{
public class ControlLayout extends FrameLayout {
protected CustomControls mLayout;
private boolean mModifiable;
private CustomControlsActivity mActivity;

View File

@ -57,7 +57,7 @@ public class CustomControls {
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;
Tools.write(path, Tools.GLOBAL_GSON.toJson(this));

View File

@ -29,19 +29,15 @@ import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;
@SuppressLint("ViewConstructor")
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener
{
private final Paint mRectPaint = new Paint();;
public class ControlButton extends androidx.appcompat.widget.AppCompatButton implements OnLongClickListener {
private final Paint mRectPaint = new Paint();
protected GestureDetector mGestureDetector;
protected ControlData mProperties;
protected SelectionEndHandleView mHandleView;
protected boolean mModifiable = false;
protected boolean mCanTriggerLongClick = true;
protected boolean isToggled = false;
protected boolean isPointerOutOfBounds = false;
protected boolean mIsToggled = false;
protected boolean mIsPointerOutOfBounds = false;
public ControlButton(ControlLayout layout, ControlData properties) {
super(layout.getContext());
@ -258,7 +254,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
@Override
protected void onDraw(Canvas 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);
}
@ -303,26 +299,26 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
//If out of bounds
if(event.getX() < getLeft() || event.getX() > getRight() ||
event.getY() < getTop() || event.getY() > getBottom()){
if(mProperties.isSwipeable && !isPointerOutOfBounds){
if(mProperties.isSwipeable && !mIsPointerOutOfBounds){
//Remove keys
if(!triggerToggle()) {
sendKeyPresses(false);
}
}
isPointerOutOfBounds = true;
mIsPointerOutOfBounds = true;
((ControlLayout) getParent()).onTouch(this, event);
break;
}
//Else if we now are in bounds
if(isPointerOutOfBounds) {
if(mIsPointerOutOfBounds) {
((ControlLayout) getParent()).onTouch(this, event);
//RE-press the button
if(mProperties.isSwipeable && !mProperties.isToggle){
sendKeyPresses(true);
}
}
isPointerOutOfBounds = false;
mIsPointerOutOfBounds = false;
break;
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);
if (v != null) v.dispatchTouchEvent(event);
}
if(isPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(this, event);
isPointerOutOfBounds = false;
if(mIsPointerOutOfBounds) ((ControlLayout) getParent()).onTouch(this, event);
mIsPointerOutOfBounds = false;
if(!triggerToggle()) {
sendKeyPresses(false);
@ -500,9 +496,9 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
public boolean triggerToggle(){
//returns true a the toggle system is triggered
if(mProperties.isToggle){
isToggled = !isToggled;
mIsToggled = !mIsToggled;
invalidate();
sendKeyPresses(isToggled);
sendKeyPresses(mIsToggled);
return true;
}
return false;

View File

@ -2,7 +2,6 @@ package net.kdt.pojavlaunch.customcontrols.buttons;
import android.annotation.SuppressLint;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import net.kdt.pojavlaunch.Tools;
@ -20,7 +19,7 @@ public class ControlDrawer extends ControlButton {
public ArrayList<ControlSubButton> buttons;
public ControlDrawerData drawerData;
public ControlLayout mLayout;
public ControlLayout layout;
public boolean areButtonsVisible;
@ -28,14 +27,14 @@ public class ControlDrawer extends ControlButton {
super(layout, drawerData.properties);
buttons = new ArrayList<>(drawerData.buttonProperties.size());
mLayout = layout;
this.layout = layout;
this.drawerData = drawerData;
areButtonsVisible = layout.getModifiable();
}
public void addButton(ControlData properties){
addButton(new ControlSubButton(mLayout, properties, this));
addButton(new ControlSubButton(layout, properties, this));
}
public void addButton(ControlSubButton button){