v0.7.4b: refactored input event handling structure

This commit is contained in:
Evan Debenham 2019-07-25 19:50:35 -04:00
parent 2a523f2ea2
commit 05d7f354dd
36 changed files with 502 additions and 506 deletions

View File

@ -24,97 +24,65 @@ package com.watabou.input;
import com.badlogic.gdx.InputAdapter;
import com.watabou.noosa.Game;
import java.util.ArrayList;
public class InputHandler extends InputAdapter {
// Accumulated touch events
protected ArrayList<Touchscreen.Touch> touchEvents = new ArrayList<>();
// Accumulated key events
protected ArrayList<Keys.Key> keyEvents = new ArrayList<>();
@Override
public boolean keyDown( int keyCode ) {
if (keyCode != Keys.BACK &&
keyCode != Keys.MENU) {
return false;
}
synchronized (keyEvents) {
keyEvents.add( new Keys.Key(keyCode, true) );
}
return true;
}
@Override
public boolean keyUp( int keyCode ) {
if (keyCode != Keys.BACK &&
keyCode != Keys.MENU) {
return false;
}
synchronized (keyEvents) {
keyEvents.add( new Keys.Key(keyCode, false) );
}
return true;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
synchronized (touchEvents) {
touchEvents.add(new Touchscreen.Touch(screenX, screenY, pointer, true));
}
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
synchronized (touchEvents) {
touchEvents.add(new Touchscreen.Touch(screenX, screenY, pointer, false));
}
return true;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
synchronized (touchEvents) {
touchEvents.add(new Touchscreen.Touch(screenX, screenY, pointer, true));
}
return true;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
public void processAllEvents(){
synchronized (touchEvents) {
Touchscreen.processTouchEvents( touchEvents );
touchEvents.clear();
}
synchronized (keyEvents) {
Keys.processKeyEvents( keyEvents );
keyEvents.clear();
}
PointerEvent.processPointerEvents();
KeyEvent.processKeyEvents();
}
// *********************
// *** Pointer Input ***
// *********************
@Override
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true));
return true;
}
@Override
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, false));
return true;
}
@Override
public synchronized boolean touchDragged(int screenX, int screenY, int pointer) {
screenX /= (Game.dispWidth / (float)Game.width);
screenY /= (Game.dispHeight / (float)Game.height);
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, true));
return true;
}
// *****************
// *** Key Input ***
// *****************
@Override
public synchronized boolean keyDown( int keyCode ) {
if (keyCode != KeyEvent.BACK && keyCode != KeyEvent.MENU) {
return false;
}
KeyEvent.addKeyEvent( new KeyEvent(keyCode, true) );
return true;
}
@Override
public synchronized boolean keyUp( int keyCode ) {
if (keyCode != KeyEvent.BACK && keyCode != KeyEvent.MENU) {
return false;
}
KeyEvent.addKeyEvent( new KeyEvent(keyCode, false) );
return true;
}
}

View File

@ -26,28 +26,48 @@ import com.watabou.utils.Signal;
import java.util.ArrayList;
//TODO probably want to merge this into a central input processor class
public class Keys {
public class KeyEvent {
public int code;
public boolean pressed;
public KeyEvent( int code, boolean pressed ) {
this.code = code;
this.pressed = pressed;
}
// **********************
// *** Static members ***
// **********************
public static final int BACK = Input.Keys.BACK;
public static final int MENU = Input.Keys.MENU;
public static Signal<Key> event = new Signal<>( true );
public static void processKeyEvents( ArrayList<Key> events ){
for (Key k : events){
event.dispatch(k);
}
private static Signal<KeyEvent> keySignal = new Signal<>( true );
public static void addKeyListener( Signal.Listener<KeyEvent> listener ){
keySignal.add(listener);
}
public static class Key {
public int code;
public boolean pressed;
public Key( int code, boolean pressed ) {
this.code = code;
this.pressed = pressed;
public static void removeKeyListener( Signal.Listener<KeyEvent> listener ){
keySignal.remove(listener);
}
public static void clearListeners(){
keySignal.removeAll();
}
//Accumulated key events
private static ArrayList<KeyEvent> keyEvents = new ArrayList<>();
public static synchronized void addKeyEvent( KeyEvent event ){
keyEvents.add( event );
}
public static synchronized void processKeyEvents(){
for (KeyEvent k : keyEvents){
keySignal.dispatch(k);
}
keyEvents.clear();
}
}

View File

@ -0,0 +1,104 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.input;
import com.watabou.utils.PointF;
import com.watabou.utils.Signal;
import java.util.ArrayList;
import java.util.HashMap;
public class PointerEvent {
public PointF start;
public PointF current;
public int id;
public boolean down;
public PointerEvent( int x, int y, int id, boolean down){
start = current = new PointF(x, y);
this.id = id;
this.down = down;
}
public void update( PointerEvent other ){
this.current = other.current;
}
public void update( int x, int y ){
current.set( x, y );
}
public PointerEvent up() {
down = false;
return this;
}
// **********************
// *** Static members ***
// **********************
private static Signal<PointerEvent> pointerSignal = new Signal<>( true );
public static void addPointerListener( Signal.Listener<PointerEvent> listener ){
pointerSignal.add(listener);
}
public static void removePointerListener( Signal.Listener<PointerEvent> listener ){
pointerSignal.remove(listener);
}
public static void clearListeners(){
pointerSignal.removeAll();
}
// Accumulated pointer events
private static ArrayList<PointerEvent> pointerEvents = new ArrayList<>();
private static HashMap<Integer, PointerEvent> activePointers = new HashMap<>();
public static synchronized void addPointerEvent( PointerEvent event ){
pointerEvents.add( event );
}
public static synchronized void processPointerEvents(){
for (PointerEvent p : pointerEvents){
if (activePointers.containsKey(p.id)){
PointerEvent existing = activePointers.get(p.id);
existing.current = p.current;
if (existing.down == p.down){
pointerSignal.dispatch( null );
} else if (p.down) {
pointerSignal.dispatch( existing );
} else {
activePointers.remove(existing.id);
pointerSignal.dispatch(existing.up());
}
} else {
if (p.down) {
activePointers.put(p.id, p);
}
pointerSignal.dispatch(p);
}
}
pointerEvents.clear();
}
}

View File

@ -1,86 +0,0 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.input;
import com.watabou.utils.PointF;
import com.watabou.utils.Signal;
import java.util.ArrayList;
import java.util.HashMap;
//TODO integrate into a central input handler class
public class Touchscreen {
public static Signal<Touch> event = new Signal<>( true );
public static HashMap<Integer,Touch> pointers = new HashMap<>();
public static void processTouchEvents( ArrayList<Touch> events ) {
for (Touch t : events){
if (pointers.containsKey(t.id)){
Touch existing = pointers.get(t.id);
existing.current = t.current;
if (existing.down == t.down){
event.dispatch( null );
} else if (t.down) {
event.dispatch( existing );
} else {
pointers.remove(existing.id);
event.dispatch(existing.up());
}
} else {
if (t.down) {
pointers.put(t.id, t);
}
event.dispatch(t);
}
}
}
public static class Touch {
public PointF start;
public PointF current;
public int id;
public boolean down;
public Touch( int x, int y, int id, boolean down){
start = current = new PointF(x, y);
this.id = id;
this.down = down;
}
public void update( Touch other ){
this.current = other.current;
}
public void update( int x, int y ){
current.set( x, y );
}
public Touch up() {
down = false;
return this;
}
}
}

View File

@ -36,7 +36,7 @@ import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Blending;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.input.InputHandler;
import com.watabou.input.Keys;
import com.watabou.input.KeyEvent;
import com.watabou.noosa.audio.Music;
import com.watabou.utils.SystemTime;
@ -132,8 +132,8 @@ public class Game extends AndroidApplication implements ApplicationListener {
inputHandler = new InputHandler();
Gdx.input.setInputProcessor(inputHandler);
Gdx.input.setCatchKey(Keys.BACK, true);
Gdx.input.setCatchKey(Keys.MENU, true);
Gdx.input.setCatchKey(KeyEvent.BACK, true);
Gdx.input.setCatchKey(KeyEvent.MENU, true);
//FIXME this doesn't seem to work quite right. That might not be due to LibGDX though.
Music.setMuteListener();

View File

@ -0,0 +1,123 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.noosa;
import com.watabou.input.PointerEvent;
import com.watabou.utils.Signal;
public class PointerArea extends Visual implements Signal.Listener<PointerEvent> {
// Its target can be pointerarea itself
public Visual target;
protected PointerEvent curEvent = null;
//if true, this PointerArea will always block input, even when it is inactive
public boolean blockWhenInactive = false;
public PointerArea(Visual target ) {
super( 0, 0, 0, 0 );
this.target = target;
PointerEvent.addPointerListener( this );
}
public PointerArea(float x, float y, float width, float height ) {
super( x, y, width, height );
this.target = this;
visible = false;
PointerEvent.addPointerListener( this );
}
@Override
public boolean onSignal( PointerEvent event ) {
boolean hit = event != null && target.overlapsScreenPoint( (int)event.current.x, (int)event.current.y );
if (!isActive()) {
return (hit && blockWhenInactive);
}
if (hit) {
boolean returnValue = (event.down || event == curEvent);
if (event.down) {
if (curEvent == null) {
curEvent = event;
}
onPointerDown( event );
} else {
onPointerUp( event );
if (curEvent == event) {
curEvent = null;
onClick( event );
}
}
return returnValue;
} else {
if (event == null && curEvent != null) {
onDrag(curEvent);
}
else if (curEvent != null && !event.down) {
onPointerUp( event );
curEvent = null;
}
return false;
}
}
protected void onPointerDown( PointerEvent event ) {
}
protected void onPointerUp( PointerEvent event) {
}
protected void onClick( PointerEvent event ) {
}
protected void onDrag( PointerEvent event ) {
}
public void reset() {
curEvent = null;
}
@Override
public void destroy() {
PointerEvent.removePointerListener( this );
super.destroy();
}
}

View File

@ -21,34 +21,35 @@
package com.watabou.noosa;
import com.watabou.input.Keys;
import com.watabou.input.KeyEvent;
import com.watabou.utils.Signal;
public class Scene extends Group {
private Signal.Listener<Keys.Key> keyListener;
private Signal.Listener<KeyEvent> keyListener;
public void create() {
Keys.event.add( keyListener = new Signal.Listener<Keys.Key>() {
KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() {
@Override
public void onSignal( Keys.Key key ) {
if (Game.instance != null && key.pressed) {
switch (key.code) {
case Keys.BACK:
public boolean onSignal( KeyEvent event ) {
if (Game.instance != null && event.pressed) {
switch (event.code) {
case KeyEvent.BACK:
onBackPressed();
break;
case Keys.MENU:
case KeyEvent.MENU:
onMenuPressed();
break;
}
}
return false;
}
} );
}
@Override
public void destroy() {
Keys.event.remove( keyListener );
KeyEvent.removeKeyListener( keyListener );
super.destroy();
}

View File

@ -1,121 +0,0 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.noosa;
import com.watabou.input.Touchscreen;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.utils.Signal;
public class TouchArea extends Visual implements Signal.Listener<Touchscreen.Touch> {
// Its target can be toucharea itself
public Visual target;
protected Touchscreen.Touch touch = null;
//if true, this TouchArea will always block input, even when it is inactive
public boolean blockWhenInactive = false;
public TouchArea( Visual target ) {
super( 0, 0, 0, 0 );
this.target = target;
Touchscreen.event.add( this );
}
public TouchArea( float x, float y, float width, float height ) {
super( x, y, width, height );
this.target = this;
visible = false;
Touchscreen.event.add( this );
}
@Override
public void onSignal( Touch touch ) {
boolean hit = touch != null && target.overlapsScreenPoint( (int)touch.current.x, (int)touch.current.y );
if (!isActive()) {
if (hit && blockWhenInactive) Touchscreen.event.cancel();
return;
}
if (hit) {
if (touch.down || touch == this.touch) Touchscreen.event.cancel();
if (touch.down) {
if (this.touch == null) {
this.touch = touch;
}
onTouchDown( touch );
} else {
onTouchUp( touch );
if (this.touch == touch) {
this.touch = null;
onClick( touch );
}
}
} else {
if (touch == null && this.touch != null) {
onDrag( this.touch );
}
else if (this.touch != null && !touch.down) {
onTouchUp( touch );
this.touch = null;
}
}
}
protected void onTouchDown( Touch touch ) {
}
protected void onTouchUp( Touch touch ) {
}
protected void onClick( Touch touch ) {
}
protected void onDrag( Touch touch ) {
}
public void reset() {
touch = null;
}
@Override
public void destroy() {
Touchscreen.event.remove( this );
super.destroy();
}
}

View File

@ -21,15 +21,15 @@
package com.watabou.noosa.ui;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Game;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
public class Button extends Component {
public static float longClick = 1f;
protected TouchArea hotArea;
protected PointerArea hotArea;
protected boolean pressed;
protected float pressTime;
@ -38,25 +38,25 @@ public class Button extends Component {
@Override
protected void createChildren() {
hotArea = new TouchArea( 0, 0, 0, 0 ) {
hotArea = new PointerArea( 0, 0, 0, 0 ) {
@Override
protected void onTouchDown(Touch touch) {
protected void onPointerDown( PointerEvent event ) {
pressed = true;
pressTime = 0;
processed = false;
Button.this.onTouchDown();
};
Button.this.onPointerDown();
}
@Override
protected void onTouchUp(Touch touch) {
protected void onPointerUp( PointerEvent event ) {
pressed = false;
Button.this.onTouchUp();
};
Button.this.onPointerUp();
}
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
if (!processed) {
Button.this.onClick();
}
};
}
};
add( hotArea );
}
@ -74,7 +74,7 @@ public class Button extends Component {
hotArea.reset();
processed = true;
onTouchUp();
onPointerUp();
Game.vibrate( 50 );
}
@ -82,13 +82,12 @@ public class Button extends Component {
}
}
protected void onTouchDown() {};
protected void onTouchUp() {};
protected void onClick() {};
protected void onPointerDown() {}
protected void onPointerUp() {}
protected void onClick() {}
protected boolean onLongClick() {
return false;
};
}
@Override
protected void layout() {

View File

@ -25,9 +25,7 @@ import java.util.LinkedList;
public class Signal<T> {
private LinkedList<Listener<T>> listeners = new LinkedList<Signal.Listener<T>>();
private boolean canceled;
private LinkedList<Listener<T>> listeners = new LinkedList<>();
private boolean stackMode;
@ -70,13 +68,11 @@ public class Signal<T> {
@SuppressWarnings("unchecked")
Listener<T>[] list = listeners.toArray( new Listener[0] );
canceled = false;
for (Listener<T> listener : list) {
if (listeners.contains(listener)) {
listener.onSignal(t);
if (canceled) {
if (listener.onSignal(t)) {
return;
}
}
@ -84,11 +80,8 @@ public class Signal<T> {
}
}
public void cancel() {
canceled = true;
}
public static interface Listener<T> {
public void onSignal( T t );
public interface Listener<T> {
//return true if the signal has been handled
boolean onSignal( T t );
}
}

View File

@ -27,8 +27,6 @@ import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
import com.watabou.noosa.Game;

View File

@ -22,7 +22,6 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas;

View File

@ -37,8 +37,6 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ImpShopRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.noosa.Group;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
import java.util.ArrayList;

View File

@ -29,11 +29,11 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TouchArea;
import com.watabou.utils.DeviceCompat;
public class AboutScene extends PixelScene {
@ -92,9 +92,9 @@ public class AboutScene extends PixelScene {
shpxlink.setPos((colWidth - shpxlink.width()) / 2, shpxtext.bottom() + 6);
align(shpxlink);
TouchArea shpxhotArea = new TouchArea( shpxlink.left(), shpxlink.top(), shpxlink.width(), shpxlink.height() ) {
PointerArea shpxhotArea = new PointerArea( shpxlink.left(), shpxlink.top(), shpxlink.width(), shpxlink.height() ) {
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
DeviceCompat.openURI( "https://" + LNK_SHPX );
}
};
@ -133,9 +133,9 @@ public class AboutScene extends PixelScene {
wataLink.setPos(wataOffset + (colWidth - wataLink.width()) / 2 , wataText.bottom() + 6);
align(wataLink);
TouchArea hotArea = new TouchArea( wataLink.left(), wataLink.top(), wataLink.width(), wataLink.height() ) {
PointerArea hotArea = new PointerArea( wataLink.left(), wataLink.top(), wataLink.width(), wataLink.height() ) {
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
DeviceCompat.openURI( "https://" + LNK_WATA );
}
};

View File

@ -499,12 +499,12 @@ public class AlchemyScene extends PixelScene {
slot = new ItemSlot() {
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
};
@Override
protected void onTouchUp() {
protected void onPointerUp() {
bg.resetColor();
}
@Override

View File

@ -28,13 +28,13 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.utils.GameMath;
import com.watabou.utils.PointF;
public class CellSelector extends TouchArea {
public class CellSelector extends PointerArea {
public Listener listener = null;
@ -50,14 +50,14 @@ public class CellSelector extends TouchArea {
}
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
if (dragging) {
dragging = false;
} else {
PointF p = Camera.main.screenToCamera( (int)touch.current.x, (int)touch.current.y );
PointF p = Camera.main.screenToCamera( (int) event.current.x, (int) event.current.y );
for (Char mob : Dungeon.level.mobs.toArray(new Mob[0])){
if (mob.sprite != null && mob.sprite.overlapsPoint( p.x, p.y)){
select( mob.pos );
@ -73,8 +73,8 @@ public class CellSelector extends TouchArea {
}
select( ((DungeonTilemap)target).screenToTile(
(int)touch.current.x,
(int)touch.current.y,
(int) event.current.x,
(int) event.current.y,
true ) );
}
}
@ -111,47 +111,47 @@ public class CellSelector extends TouchArea {
}
private boolean pinching = false;
private Touch another;
private PointerEvent another;
private float startZoom;
private float startSpan;
@Override
protected void onTouchDown( Touch t ) {
protected void onPointerDown( PointerEvent event ) {
if (t != touch && another == null) {
if (event != curEvent && another == null) {
if (!touch.down) {
touch = t;
onTouchDown( t );
if (!curEvent.down) {
curEvent = event;
onPointerDown( event );
return;
}
pinching = true;
another = t;
startSpan = PointF.distance( touch.current, another.current );
another = event;
startSpan = PointF.distance( curEvent.current, another.current );
startZoom = camera.zoom;
dragging = false;
} else if (t != touch) {
} else if (event != curEvent) {
reset();
}
}
@Override
protected void onTouchUp( Touch t ) {
if (pinching && (t == touch || t == another)) {
protected void onPointerUp( PointerEvent event ) {
if (pinching && (event == curEvent || event == another)) {
pinching = false;
zoom(Math.round( camera.zoom ));
dragging = true;
if (t == touch) {
touch = another;
if (event == curEvent) {
curEvent = another;
}
another = null;
lastPos.set( touch.current );
lastPos.set( curEvent.current );
}
}
@ -159,13 +159,13 @@ public class CellSelector extends TouchArea {
private PointF lastPos = new PointF();
@Override
protected void onDrag( Touch t ) {
protected void onDrag( PointerEvent event ) {
camera.target = null;
if (pinching) {
float curSpan = PointF.distance( touch.current, another.current );
float curSpan = PointF.distance( curEvent.current, another.current );
float zoom = (startZoom * curSpan / startSpan);
camera.zoom( GameMath.gate(
PixelScene.minZoom,
@ -174,14 +174,14 @@ public class CellSelector extends TouchArea {
} else {
if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
if (!dragging && PointF.distance( event.current, event.start ) > dragThreshold) {
dragging = true;
lastPos.set( t.current );
lastPos.set( event.current );
} else if (dragging) {
camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
lastPos.set( t.current );
camera.scroll.offset( PointF.diff( lastPos, event.current ).invScale( camera.zoom ) );
lastPos.set( event.current );
}
}

View File

@ -28,7 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.glwrap.Blending;
import com.watabou.input.Touchscreen;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.BitmapText.Font;
import com.watabou.noosa.BitmapTextMultiline;
@ -164,7 +164,7 @@ public class PixelScene extends Scene {
@Override
public void destroy() {
super.destroy();
Touchscreen.event.removeAll();
PointerEvent.clearListeners();
}
public static BitmapText.Font font;

View File

@ -41,7 +41,7 @@ import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Matrix;
import com.watabou.glwrap.Quad;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
@ -49,7 +49,7 @@ import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Music;
import com.watabou.utils.Point;
@ -199,8 +199,8 @@ public class SurfaceScene extends PixelScene {
window.add( a );
window.add( pet );
window.add( new TouchArea( sky ) {
protected void onClick( Touch touch ) {
window.add( new PointerArea( sky ) {
protected void onClick( PointerEvent event ) {
pet.jump();
}
} );

View File

@ -57,13 +57,13 @@ public class ExitButton extends Button {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
image.resetColor();
}

View File

@ -61,7 +61,7 @@ public class GameLog extends Component implements Signal.Listener<String> {
}
@Override
public synchronized void onSignal( String text ) {
public synchronized boolean onSignal( String text ) {
if (length != entries.size()){
clear();
@ -126,6 +126,7 @@ public class GameLog extends Component implements Signal.Listener<String> {
}
layout();
return false;
}
@Override

View File

@ -52,13 +52,13 @@ public class IconButton extends Button {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
if (icon != null) icon.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
if (icon != null) icon.resetColor();
}

View File

@ -83,13 +83,13 @@ public class LanguageButton extends Button {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
image.resetColor();
updateIcon();
}

View File

@ -23,18 +23,18 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.Touchscreen;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.GameMath;
import com.watabou.utils.PointF;
public abstract class OptionSlider extends Component {
private TouchArea touchArea;
private PointerArea pointerArea;
private RenderedText title;
private RenderedText minTxt;
@ -102,32 +102,24 @@ public abstract class OptionSlider extends Component {
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
sliderNode.size(5, 9);
touchArea = new TouchArea(0, 0, 0, 0){
pointerArea = new PointerArea(0, 0, 0, 0){
boolean pressed = false;
@Override
protected void onTouchDown(Touchscreen.Touch touch) {
protected void onPointerDown( PointerEvent event ) {
pressed = true;
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
PointF p = camera().screenToCamera((int) event.current.x, (int) event.current.y);
sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2);
sliderNode.brightness(1.5f);
}
@Override
protected void onDrag(Touchscreen.Touch touch) {
protected void onPointerUp( PointerEvent event ) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
}
}
@Override
protected void onTouchUp(Touchscreen.Touch touch) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
PointF p = camera().screenToCamera((int) event.current.x, (int) event.current.y);
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
sliderNode.resetColor();
//sets the selected value
selectedVal = minVal + Math.round(sliderNode.x / tickDist);
sliderNode.x = (int) (x + tickDist * (selectedVal - minVal));
@ -135,8 +127,16 @@ public abstract class OptionSlider extends Component {
pressed = false;
}
}
@Override
protected void onDrag( PointerEvent event ) {
if (pressed) {
PointF p = camera().screenToCamera((int) event.current.x, (int) event.current.y);
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
}
}
};
add(touchArea);
add(pointerArea);
}
@ -162,10 +162,10 @@ public abstract class OptionSlider extends Component {
sliderNode.x = (int)(x + tickDist*(selectedVal-minVal));
sliderNode.y = sliderBG.y-4;
touchArea.x = x;
touchArea.y = y;
touchArea.width = width();
touchArea.height = height();
pointerArea.x = x;
pointerArea.y = y;
pointerArea.width = width();
pointerArea.height = height();
BG.size(width(), height());
BG.x = x;

View File

@ -50,13 +50,13 @@ public class PrefsButton extends Button {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
image.resetColor();
}

View File

@ -97,11 +97,11 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
return QuickSlotButton.this.onLongClick();
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
icon.lightness( 0.7f );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
icon.resetColor();
}
};

View File

@ -22,10 +22,10 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
@ -35,7 +35,7 @@ public class ScrollPane extends Component {
protected static final int THUMB_COLOR = 0xFF7b8073;
protected static final float THUMB_ALPHA = 0.5f;
protected TouchController controller;
protected PointerController controller;
protected Component content;
protected ColorBlock thumb;
@ -69,7 +69,7 @@ public class ScrollPane extends Component {
@Override
protected void createChildren() {
controller = new TouchController();
controller = new PointerController();
add( controller );
thumb = new ColorBlock( 1, 1, THUMB_COLOR );
@ -107,17 +107,17 @@ public class ScrollPane extends Component {
public void onClick( float x, float y ) {
}
public class TouchController extends TouchArea {
public class PointerController extends PointerArea {
private float dragThreshold;
public TouchController() {
public PointerController() {
super( 0, 0, 0, 0 );
dragThreshold = PixelScene.defaultZoom * 8;
}
@Override
protected void onTouchUp( Touch touch ) {
protected void onPointerUp( PointerEvent event ) {
if (dragging) {
dragging = false;
@ -125,7 +125,7 @@ public class ScrollPane extends Component {
} else {
PointF p = content.camera.screenToCamera( (int)touch.current.x, (int)touch.current.y );
PointF p = content.camera.screenToCamera( (int) event.current.x, (int) event.current.y );
ScrollPane.this.onClick( p.x, p.y );
}
@ -135,12 +135,12 @@ public class ScrollPane extends Component {
private PointF lastPos = new PointF();
@Override
protected void onDrag( Touch t ) {
protected void onDrag( PointerEvent event ) {
if (dragging) {
Camera c = content.camera;
c.scroll.offset( PointF.diff( lastPos, t.current ).invScale( c.zoom ) );
c.scroll.offset( PointF.diff( lastPos, event.current ).invScale( c.zoom ) );
if (c.scroll.x + width > content.width()) {
c.scroll.x = content.width() - width;
}
@ -156,12 +156,12 @@ public class ScrollPane extends Component {
thumb.y = y + height * c.scroll.y / content.height();
lastPos.set( t.current );
lastPos.set( event.current );
} else if (PointF.distance( t.current, t.start ) > dragThreshold) {
} else if (PointF.distance( event.current, event.start ) > dragThreshold) {
dragging = true;
lastPos.set( t.current );
lastPos.set( event.current );
thumb.am = 1;
}

View File

@ -21,9 +21,9 @@
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Image;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Component;
public class SimpleButton extends Component {
@ -43,19 +43,19 @@ public class SimpleButton extends Component {
image = new Image();
add( image );
add( new TouchArea( image ) {
add( new PointerArea( image ) {
@Override
protected void onTouchDown(Touch touch) {
protected void onPointerDown( PointerEvent event ) {
image.brightness( 1.2f );
};
}
@Override
protected void onTouchUp(Touch touch) {
protected void onPointerUp( PointerEvent event ) {
image.brightness( 1.0f );
};
}
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
SimpleButton.this.onClick();
};
}
} );
}

View File

@ -32,13 +32,13 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Button;
@ -82,9 +82,9 @@ public class StatusPane extends Component {
bg = new NinePatch( Assets.STATUS, 0, 0, 128, 36, 85, 0, 45, 0 );
add( bg );
add( new TouchArea( 0, 1, 31, 31 ) {
add( new PointerArea( 0, 1, 31, 31 ) {
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
Image sprite = Dungeon.hero.sprite;
if (!sprite.isVisible()) {
Camera.main.focusOn( sprite );
@ -322,13 +322,13 @@ public class StatusPane extends Component {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
if (keyIcon.keyCount() > 0) {
bg.brightness(.8f - (Math.min(6, keyIcon.keyCount()) / 20f));
} else {
@ -374,13 +374,13 @@ public class StatusPane extends Component {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
image.resetColor();
}

View File

@ -84,13 +84,13 @@ public class StyledButton extends Button {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
bg.resetColor();
}

View File

@ -324,12 +324,12 @@ public class Toolbar extends Component {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
base.brightness( 1.4f );
}
@Override
protected void onTouchUp() {
protected void onPointerUp() {
if (active) {
base.resetColor();
} else {

View File

@ -24,24 +24,23 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.Keys;
import com.watabou.input.Keys.Key;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.utils.Signal;
public class Window extends Group implements Signal.Listener<Key> {
public class Window extends Group implements Signal.Listener<KeyEvent> {
protected int width;
protected int height;
protected int yOffset;
protected TouchArea blocker;
protected PointerArea blocker;
protected ShadowBox shadow;
protected NinePatch chrome;
@ -65,12 +64,12 @@ public class Window extends Group implements Signal.Listener<Key> {
this.yOffset = yOffset;
blocker = new TouchArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) {
blocker = new PointerArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) {
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
if (Window.this.parent != null && !Window.this.chrome.overlapsScreenPoint(
(int)touch.current.x,
(int)touch.current.y )) {
(int) event.current.x,
(int) event.current.y )) {
onBackPressed();
}
@ -112,7 +111,7 @@ public class Window extends Group implements Signal.Listener<Key> {
camera.y / camera.zoom,
chrome.width(), chrome.height );
Keys.event.add( this );
KeyEvent.addKeyListener( this );
}
public void resize( int w, int h ) {
@ -151,23 +150,23 @@ public class Window extends Group implements Signal.Listener<Key> {
super.destroy();
Camera.remove( camera );
Keys.event.remove( this );
KeyEvent.removeKeyListener( this );
}
@Override
public void onSignal( Key key ) {
if (key.pressed) {
switch (key.code) {
case Keys.BACK:
onBackPressed();
break;
case Keys.MENU:
onMenuPressed();
break;
public boolean onSignal( KeyEvent event ) {
if (event.pressed) {
switch (event.code) {
case KeyEvent.BACK:
onBackPressed();
return true;
case KeyEvent.MENU:
onMenuPressed();
return true;
}
}
Keys.event.cancel();
return false;
}
public void onBackPressed() {

View File

@ -23,18 +23,18 @@ package com.shatteredpixel.shatteredpixeldungeon.ui.changelist;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage;
import com.watabou.input.Touchscreen;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Image;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
public class ChangesWindow extends WndTitledMessage {
public ChangesWindow(Image icon, String title, String message ) {
super( icon, title, message);
TouchArea blocker = new TouchArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) {
PointerArea blocker = new PointerArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) {
@Override
protected void onClick( Touchscreen.Touch touch ) {
protected void onClick( PointerEvent event ) {
hide();
}
};

View File

@ -412,12 +412,12 @@ public class WndBag extends WndTabbed {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
};
protected void onTouchUp() {
protected void onPointerUp() {
bg.brightness( 1.0f );
};

View File

@ -135,12 +135,12 @@ public class WndBlacksmith extends Window {
slot = new ItemSlot() {
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
};
@Override
protected void onTouchUp() {
protected void onPointerUp() {
bg.resetColor();
}
@Override

View File

@ -348,12 +348,12 @@ public class WndRanking extends WndTabbed {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
};
protected void onTouchUp() {
protected void onPointerUp() {
bg.brightness( 1.0f );
};
@ -392,12 +392,12 @@ public class WndRanking extends WndTabbed {
}
@Override
protected void onTouchDown() {
protected void onPointerDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
};
protected void onTouchUp() {
protected void onPointerUp() {
bg.brightness( 1.0f );
};

View File

@ -28,9 +28,9 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.input.Touchscreen.Touch;
import com.watabou.input.PointerEvent;
import com.watabou.noosa.Game;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.PointerArea;
import com.watabou.utils.SparseArray;
public class WndStory extends Window {
@ -74,9 +74,9 @@ public class WndStory extends Window {
tf.setPos(MARGIN, 0);
add( tf );
add( new TouchArea( chrome ) {
add( new PointerArea( chrome ) {
@Override
protected void onClick( Touch touch ) {
protected void onClick( PointerEvent event ) {
hide();
}
} );