mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 00:29:50 -04:00
Fix[controls]: A13 swipeable buttons
This commit is contained in:
parent
b55e513012
commit
b9ff3c177e
@ -307,30 +307,34 @@ public class ControlLayout extends FrameLayout {
|
|||||||
|
|
||||||
|
|
||||||
final HashMap<View, ControlInterface> mapTable = new HashMap<>();
|
final HashMap<View, ControlInterface> mapTable = new HashMap<>();
|
||||||
final int[] location = new int[2];
|
|
||||||
//While this is called onTouch, this should only be called from a ControlButton.
|
//While this is called onTouch, this should only be called from a ControlButton.
|
||||||
public void onTouch(View v, MotionEvent ev) {
|
public void onTouch(View v, MotionEvent ev) {
|
||||||
ControlInterface lastControlButton = mapTable.get(v);
|
ControlInterface lastControlButton = mapTable.get(v);
|
||||||
|
|
||||||
|
// Map location to screen coordinates
|
||||||
|
ev.offsetLocation(v.getX(), v.getY());
|
||||||
|
|
||||||
|
|
||||||
//Check if the action is cancelling, reset the lastControl button associated to the view
|
//Check if the action is cancelling, reset the lastControl button associated to the view
|
||||||
if(ev.getActionMasked() == MotionEvent.ACTION_UP
|
if (ev.getActionMasked() == MotionEvent.ACTION_UP
|
||||||
|| ev.getActionMasked() == MotionEvent.ACTION_CANCEL
|
|| ev.getActionMasked() == MotionEvent.ACTION_CANCEL
|
||||||
|| ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP){
|
|| ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
|
||||||
if(lastControlButton != null) lastControlButton.sendKeyPresses(false);
|
if (lastControlButton != null) lastControlButton.sendKeyPresses(false);
|
||||||
mapTable.put(v, null);
|
mapTable.put(v, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ev.getActionMasked() != MotionEvent.ACTION_MOVE) return;
|
if (ev.getActionMasked() != MotionEvent.ACTION_MOVE) return;
|
||||||
|
|
||||||
getLocationOnScreen(location);
|
|
||||||
|
|
||||||
//Optimization pass to avoid looking at all children again
|
//Optimization pass to avoid looking at all children again
|
||||||
if(lastControlButton != null){
|
if (lastControlButton != null) {
|
||||||
if( ev.getRawX() > lastControlButton.getControlView().getX() + location[0]
|
System.out.println("last control button check" + ev.getX() + "-" + ev.getY() + "-" + lastControlButton.getControlView().getX() + "-" + lastControlButton.getControlView().getY());
|
||||||
&& ev.getRawX() < lastControlButton.getControlView().getX() + lastControlButton.getControlView().getWidth() + location[0]
|
if (ev.getX() > lastControlButton.getControlView().getX()
|
||||||
&& ev.getRawY() > lastControlButton.getControlView().getY()
|
&& ev.getX() < lastControlButton.getControlView().getX() + lastControlButton.getControlView().getWidth()
|
||||||
&& ev.getRawY() < lastControlButton.getControlView().getY() + lastControlButton.getControlView().getHeight()){
|
&& ev.getY() > lastControlButton.getControlView().getY()
|
||||||
|
&& ev.getY() < lastControlButton.getControlView().getY() + lastControlButton.getControlView().getHeight()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,16 +344,16 @@ public class ControlLayout extends FrameLayout {
|
|||||||
mapTable.remove(v);
|
mapTable.remove(v);
|
||||||
|
|
||||||
// Update the state of all swipeable buttons
|
// Update the state of all swipeable buttons
|
||||||
for(ControlInterface button : getButtonChildren()){
|
for (ControlInterface button : getButtonChildren()) {
|
||||||
if(!button.getProperties().isSwipeable) continue;
|
if (!button.getProperties().isSwipeable) continue;
|
||||||
|
|
||||||
if( ev.getRawX() > button.getControlView().getX() + location[0]
|
if (ev.getX() > button.getControlView().getX()
|
||||||
&& ev.getRawX() - getGameSurface().getX() < button.getControlView().getX() + button.getControlView().getWidth() + location[0]
|
&& ev.getX() < button.getControlView().getX() + button.getControlView().getWidth()
|
||||||
&& ev.getRawY() > button.getControlView().getY()
|
&& ev.getY() > button.getControlView().getY()
|
||||||
&& ev.getRawY() < button.getControlView().getY() + button.getControlView().getHeight()){
|
&& ev.getY() < button.getControlView().getY() + button.getControlView().getHeight()) {
|
||||||
|
|
||||||
//Press the new key
|
//Press the new key
|
||||||
if(!button.equals(lastControlButton)){
|
if (!button.equals(lastControlButton)) {
|
||||||
button.sendKeyPresses(true);
|
button.sendKeyPresses(true);
|
||||||
mapTable.put(v, button);
|
mapTable.put(v, button);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user