Clean up code.

This commit is contained in:
SerpentSpirale 2021-07-01 14:50:37 +02:00
parent 6493daaf66
commit bc4e6e7c16
5 changed files with 64 additions and 69 deletions

View File

@ -250,8 +250,8 @@ public class BaseMainActivity extends LoggableActivity {
float x = event.getX();
float y = event.getY();
float mouseX = mousePointer.getTranslationX();
float mouseY = mousePointer.getTranslationY();
float mouseX = mousePointer.getX();
float mouseY = mousePointer.getY();
if (gestureDetector.onTouchEvent(event)) {
mouse_x = (mouseX * scaleFactor);
@ -797,13 +797,13 @@ public class BaseMainActivity extends LoggableActivity {
}
public void placeMouseAdd(float x, float y) {
this.mousePointer.setTranslationX(mousePointer.getTranslationX() + x);
this.mousePointer.setTranslationY(mousePointer.getTranslationY() + y);
this.mousePointer.setX(mousePointer.getX() + x);
this.mousePointer.setY(mousePointer.getY() + y);
}
public void placeMouseAt(float x, float y) {
this.mousePointer.setTranslationX(x);
this.mousePointer.setTranslationY(y);
this.mousePointer.setX(x);
this.mousePointer.setY(y);
}
public void toggleMouse(View view) {

View File

@ -108,8 +108,8 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
prevX = x;
prevY = y;
}
float mouseX = mousePointer.getTranslationX();
float mouseY = mousePointer.getTranslationY();
float mouseX = mousePointer.getX();
float mouseY = mousePointer.getY();
if (gestureDetector.onTouchEvent(event)) {
@ -250,13 +250,13 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
}
public void placeMouseAdd(float x, float y) {
this.mousePointer.setTranslationX(mousePointer.getTranslationX() + x);
this.mousePointer.setTranslationY(mousePointer.getTranslationY() + y);
this.mousePointer.setX(mousePointer.getX() + x);
this.mousePointer.setY(mousePointer.getY() + y);
}
public void placeMouseAt(float x, float y) {
this.mousePointer.setTranslationX(x);
this.mousePointer.setTranslationY(y);
this.mousePointer.setX(x);
this.mousePointer.setY(y);
}
void sendScaledMousePosition(float x, float y){

View File

@ -98,8 +98,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
setText(properties.name);
if (changePos) {
setTranslationX(moveX = properties.x);
setTranslationY(moveY = properties.y);
setX(properties.x);
setY(properties.y);
}
if (properties.specialButtonListener == null) {
@ -172,8 +172,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
// Re-calculate position
mProperties.update();
setTranslationX(mProperties.x);
setTranslationY(mProperties.y);
setX(mProperties.x);
setY(mProperties.y);
setModified(true);
}
@ -184,8 +184,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
}
@Override
public void setTranslationX(float x) {
super.setTranslationX(x);
public void setX(float x) {
super.setX(x);
if (!mProperties.isDynamicBtn) {
mProperties.x = x;
@ -195,8 +195,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
}
@Override
public void setTranslationY(float y) {
super.setTranslationY(y);
public void setY(float y) {
super.setY(y);
if (!mProperties.isDynamicBtn) {
mProperties.y = y;
@ -238,27 +238,23 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
return mCanTriggerLongClick;
}
protected float moveX, moveY;
protected float downX, downY;
@Override
public boolean onTouchEvent(MotionEvent event) {
System.out.println("IS BEING TOUCHED");
if (!mModifiable) {
if(!mModifiable){
mCanTriggerLongClick = false;
if (event.getAction() == MotionEvent.ACTION_MOVE && CallbackBridge.isGrabbing() && mProperties.passThruEnabled) {
MinecraftGLView v = ((ControlLayout) this.getParent()).findViewById(R.id.main_game_render_view);
if (v != null) {
v.dispatchTouchEvent(event);
return true;
}
}
switch (event.getActionMasked()) {
switch (event.getActionMasked()){
case MotionEvent.ACTION_MOVE:
//Send the event to be taken as a mouse action
if(mProperties.passThruEnabled && CallbackBridge.isGrabbing()){
MinecraftGLView v = ((ControlLayout) this.getParent()).findViewById(R.id.main_game_render_view);
if (v != null) v.dispatchTouchEvent(event);
}
//If out of bounds
if(event.getX() < getLeft() || event.getX() > getRight() ||
event.getY() < getTop() || event.getY() > getBottom()){
event.getY() < getTop() || event.getY() > getBottom()){
if(mProperties.isSwipeable && !isPointerOutOfBounds){
//Remove keys
if(!triggerToggle(event)) {
@ -290,6 +286,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
sendKeyPresses(event, true);
}
break;
case MotionEvent.ACTION_UP: // 1
case MotionEvent.ACTION_CANCEL: // 3
case MotionEvent.ACTION_POINTER_UP: // 6
@ -306,32 +303,30 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
return false;
}
return true;
}
} else {
if (mGestureDetector.onTouchEvent(event)) {
//If the button can be modified/moved
if (mGestureDetector.onTouchEvent(event)) {
mCanTriggerLongClick = true;
onLongClick(this);
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
mCanTriggerLongClick = true;
onLongClick(this);
}
downX = event.getRawX() - getX();
downY = event.getRawY() - getY();
break;
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_DOWN:
mCanTriggerLongClick = true;
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
mCanTriggerLongClick = false;
case MotionEvent.ACTION_MOVE:
mCanTriggerLongClick = false;
moveX += event.getX() - downX;
moveY += event.getY() - downY;
if (!mProperties.isDynamicBtn) {
setTranslationX(moveX);
setTranslationY(moveY);
}
break;
}
if (!mProperties.isDynamicBtn) {
setX(event.getRawX() - downX);
setY(event.getRawY() - downY);
}
break;
}
return super.onTouchEvent(event);

View File

@ -78,23 +78,23 @@ public class ControlDrawer extends ControlButton {
for(int i=0; i < buttons.size(); ++i){
switch (drawerData.orientation){
case RIGHT:
buttons.get(i).setTranslationX(drawerData.properties.x + (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setTranslationY(drawerData.properties.y);
buttons.get(i).setX(drawerData.properties.x + (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setY(drawerData.properties.y);
break;
case LEFT:
buttons.get(i).setTranslationX(drawerData.properties.x - (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setTranslationY(drawerData.properties.y);
buttons.get(i).setX(drawerData.properties.x - (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setY(drawerData.properties.y);
break;
case UP:
buttons.get(i).setTranslationY(drawerData.properties.y - (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setTranslationX(drawerData.properties.x);
buttons.get(i).setY(drawerData.properties.y - (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setX(drawerData.properties.x);
break;
case DOWN:
buttons.get(i).setTranslationY(drawerData.properties.y + (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setTranslationX(drawerData.properties.x);
buttons.get(i).setY(drawerData.properties.y + (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
buttons.get(i).setX(drawerData.properties.x);
break;
}
buttons.get(i).updateProperties();
@ -146,14 +146,14 @@ public class ControlDrawer extends ControlButton {
}
@Override
public void setTranslationX(float x) {
super.setTranslationX(x);
public void setX(float x) {
super.setX(x);
alignButtons();
}
@Override
public void setTranslationY(float y) {
super.setTranslationY(y);
public void setY(float y) {
super.setY(y);
alignButtons();
}

View File

@ -298,8 +298,8 @@ public class Gamepad {
}
private void placePointerView(int x, int y){
pointerView.setTranslationX(x-32);
pointerView.setTranslationY(y-32);
pointerView.setX(x-32);
pointerView.setY(y-32);
}