mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 23:59:21 -04:00
Clean up code.
This commit is contained in:
parent
6493daaf66
commit
bc4e6e7c16
@ -250,8 +250,8 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
|
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
float y = event.getY();
|
float y = event.getY();
|
||||||
float mouseX = mousePointer.getTranslationX();
|
float mouseX = mousePointer.getX();
|
||||||
float mouseY = mousePointer.getTranslationY();
|
float mouseY = mousePointer.getY();
|
||||||
|
|
||||||
if (gestureDetector.onTouchEvent(event)) {
|
if (gestureDetector.onTouchEvent(event)) {
|
||||||
mouse_x = (mouseX * scaleFactor);
|
mouse_x = (mouseX * scaleFactor);
|
||||||
@ -797,13 +797,13 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void placeMouseAdd(float x, float y) {
|
public void placeMouseAdd(float x, float y) {
|
||||||
this.mousePointer.setTranslationX(mousePointer.getTranslationX() + x);
|
this.mousePointer.setX(mousePointer.getX() + x);
|
||||||
this.mousePointer.setTranslationY(mousePointer.getTranslationY() + y);
|
this.mousePointer.setY(mousePointer.getY() + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeMouseAt(float x, float y) {
|
public void placeMouseAt(float x, float y) {
|
||||||
this.mousePointer.setTranslationX(x);
|
this.mousePointer.setX(x);
|
||||||
this.mousePointer.setTranslationY(y);
|
this.mousePointer.setY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleMouse(View view) {
|
public void toggleMouse(View view) {
|
||||||
|
@ -108,8 +108,8 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
prevX = x;
|
prevX = x;
|
||||||
prevY = y;
|
prevY = y;
|
||||||
}
|
}
|
||||||
float mouseX = mousePointer.getTranslationX();
|
float mouseX = mousePointer.getX();
|
||||||
float mouseY = mousePointer.getTranslationY();
|
float mouseY = mousePointer.getY();
|
||||||
|
|
||||||
if (gestureDetector.onTouchEvent(event)) {
|
if (gestureDetector.onTouchEvent(event)) {
|
||||||
|
|
||||||
@ -250,13 +250,13 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void placeMouseAdd(float x, float y) {
|
public void placeMouseAdd(float x, float y) {
|
||||||
this.mousePointer.setTranslationX(mousePointer.getTranslationX() + x);
|
this.mousePointer.setX(mousePointer.getX() + x);
|
||||||
this.mousePointer.setTranslationY(mousePointer.getTranslationY() + y);
|
this.mousePointer.setY(mousePointer.getY() + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void placeMouseAt(float x, float y) {
|
public void placeMouseAt(float x, float y) {
|
||||||
this.mousePointer.setTranslationX(x);
|
this.mousePointer.setX(x);
|
||||||
this.mousePointer.setTranslationY(y);
|
this.mousePointer.setY(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendScaledMousePosition(float x, float y){
|
void sendScaledMousePosition(float x, float y){
|
||||||
|
@ -98,8 +98,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
setText(properties.name);
|
setText(properties.name);
|
||||||
|
|
||||||
if (changePos) {
|
if (changePos) {
|
||||||
setTranslationX(moveX = properties.x);
|
setX(properties.x);
|
||||||
setTranslationY(moveY = properties.y);
|
setY(properties.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (properties.specialButtonListener == null) {
|
if (properties.specialButtonListener == null) {
|
||||||
@ -172,8 +172,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
|
|
||||||
// Re-calculate position
|
// Re-calculate position
|
||||||
mProperties.update();
|
mProperties.update();
|
||||||
setTranslationX(mProperties.x);
|
setX(mProperties.x);
|
||||||
setTranslationY(mProperties.y);
|
setY(mProperties.y);
|
||||||
|
|
||||||
setModified(true);
|
setModified(true);
|
||||||
}
|
}
|
||||||
@ -184,8 +184,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationX(float x) {
|
public void setX(float x) {
|
||||||
super.setTranslationX(x);
|
super.setX(x);
|
||||||
|
|
||||||
if (!mProperties.isDynamicBtn) {
|
if (!mProperties.isDynamicBtn) {
|
||||||
mProperties.x = x;
|
mProperties.x = x;
|
||||||
@ -195,8 +195,8 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationY(float y) {
|
public void setY(float y) {
|
||||||
super.setTranslationY(y);
|
super.setY(y);
|
||||||
|
|
||||||
if (!mProperties.isDynamicBtn) {
|
if (!mProperties.isDynamicBtn) {
|
||||||
mProperties.y = y;
|
mProperties.y = y;
|
||||||
@ -238,24 +238,20 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
return mCanTriggerLongClick;
|
return mCanTriggerLongClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float moveX, moveY;
|
|
||||||
protected float downX, downY;
|
protected float downX, downY;
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
System.out.println("IS BEING TOUCHED");
|
|
||||||
if(!mModifiable){
|
if(!mModifiable){
|
||||||
mCanTriggerLongClick = false;
|
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:
|
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 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()){
|
||||||
@ -290,6 +286,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
sendKeyPresses(event, true);
|
sendKeyPresses(event, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP: // 1
|
case MotionEvent.ACTION_UP: // 1
|
||||||
case MotionEvent.ACTION_CANCEL: // 3
|
case MotionEvent.ACTION_CANCEL: // 3
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||||
@ -306,8 +303,9 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
//If the button can be modified/moved
|
||||||
if (mGestureDetector.onTouchEvent(event)) {
|
if (mGestureDetector.onTouchEvent(event)) {
|
||||||
mCanTriggerLongClick = true;
|
mCanTriggerLongClick = true;
|
||||||
onLongClick(this);
|
onLongClick(this);
|
||||||
@ -317,22 +315,19 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
|
|||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
mCanTriggerLongClick = true;
|
mCanTriggerLongClick = true;
|
||||||
downX = event.getX();
|
downX = event.getRawX() - getX();
|
||||||
downY = event.getY();
|
downY = event.getRawY() - getY();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
mCanTriggerLongClick = false;
|
mCanTriggerLongClick = false;
|
||||||
moveX += event.getX() - downX;
|
|
||||||
moveY += event.getY() - downY;
|
|
||||||
|
|
||||||
if (!mProperties.isDynamicBtn) {
|
if (!mProperties.isDynamicBtn) {
|
||||||
setTranslationX(moveX);
|
setX(event.getRawX() - downX);
|
||||||
setTranslationY(moveY);
|
setY(event.getRawY() - downY);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -78,23 +78,23 @@ public class ControlDrawer extends ControlButton {
|
|||||||
for(int i=0; i < buttons.size(); ++i){
|
for(int i=0; i < buttons.size(); ++i){
|
||||||
switch (drawerData.orientation){
|
switch (drawerData.orientation){
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
buttons.get(i).setTranslationX(drawerData.properties.x + (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
|
buttons.get(i).setX(drawerData.properties.x + (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
|
||||||
buttons.get(i).setTranslationY(drawerData.properties.y);
|
buttons.get(i).setY(drawerData.properties.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LEFT:
|
case LEFT:
|
||||||
buttons.get(i).setTranslationX(drawerData.properties.x - (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
|
buttons.get(i).setX(drawerData.properties.x - (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) );
|
||||||
buttons.get(i).setTranslationY(drawerData.properties.y);
|
buttons.get(i).setY(drawerData.properties.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UP:
|
case UP:
|
||||||
buttons.get(i).setTranslationY(drawerData.properties.y - (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
|
buttons.get(i).setY(drawerData.properties.y - (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
|
||||||
buttons.get(i).setTranslationX(drawerData.properties.x);
|
buttons.get(i).setX(drawerData.properties.x);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOWN:
|
case DOWN:
|
||||||
buttons.get(i).setTranslationY(drawerData.properties.y + (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
|
buttons.get(i).setY(drawerData.properties.y + (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1) );
|
||||||
buttons.get(i).setTranslationX(drawerData.properties.x);
|
buttons.get(i).setX(drawerData.properties.x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buttons.get(i).updateProperties();
|
buttons.get(i).updateProperties();
|
||||||
@ -146,14 +146,14 @@ public class ControlDrawer extends ControlButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationX(float x) {
|
public void setX(float x) {
|
||||||
super.setTranslationX(x);
|
super.setX(x);
|
||||||
alignButtons();
|
alignButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationY(float y) {
|
public void setY(float y) {
|
||||||
super.setTranslationY(y);
|
super.setY(y);
|
||||||
alignButtons();
|
alignButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,8 +298,8 @@ public class Gamepad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void placePointerView(int x, int y){
|
private void placePointerView(int x, int y){
|
||||||
pointerView.setTranslationX(x-32);
|
pointerView.setX(x-32);
|
||||||
pointerView.setTranslationY(y-32);
|
pointerView.setY(y-32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user