v0.7.4b: refactored input event handling structure
This commit is contained in:
parent
2a523f2ea2
commit
05d7f354dd
|
@ -24,97 +24,65 @@ package com.watabou.input;
|
||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class InputHandler extends InputAdapter {
|
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(){
|
public void processAllEvents(){
|
||||||
synchronized (touchEvents) {
|
PointerEvent.processPointerEvents();
|
||||||
Touchscreen.processTouchEvents( touchEvents );
|
KeyEvent.processKeyEvents();
|
||||||
touchEvents.clear();
|
|
||||||
}
|
|
||||||
synchronized (keyEvents) {
|
|
||||||
Keys.processKeyEvents( keyEvents );
|
|
||||||
keyEvents.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *********************
|
||||||
|
// *** 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,28 +26,48 @@ import com.watabou.utils.Signal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
//TODO probably want to merge this into a central input processor class
|
public class KeyEvent {
|
||||||
public class Keys {
|
|
||||||
|
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 BACK = Input.Keys.BACK;
|
||||||
public static final int MENU = Input.Keys.MENU;
|
public static final int MENU = Input.Keys.MENU;
|
||||||
|
|
||||||
public static Signal<Key> event = new Signal<>( true );
|
|
||||||
|
|
||||||
public static void processKeyEvents( ArrayList<Key> events ){
|
private static Signal<KeyEvent> keySignal = new Signal<>( true );
|
||||||
for (Key k : events){
|
|
||||||
event.dispatch(k);
|
public static void addKeyListener( Signal.Listener<KeyEvent> listener ){
|
||||||
}
|
keySignal.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Key {
|
public static void removeKeyListener( Signal.Listener<KeyEvent> listener ){
|
||||||
|
keySignal.remove(listener);
|
||||||
public int code;
|
}
|
||||||
public boolean pressed;
|
|
||||||
|
public static void clearListeners(){
|
||||||
public Key( int code, boolean pressed ) {
|
keySignal.removeAll();
|
||||||
this.code = code;
|
}
|
||||||
this.pressed = pressed;
|
|
||||||
|
//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();
|
||||||
}
|
}
|
||||||
}
|
}
|
104
SPD-classes/src/main/java/com/watabou/input/PointerEvent.java
Normal file
104
SPD-classes/src/main/java/com/watabou/input/PointerEvent.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -36,7 +36,7 @@ import com.watabou.gltextures.TextureCache;
|
||||||
import com.watabou.glwrap.Blending;
|
import com.watabou.glwrap.Blending;
|
||||||
import com.watabou.glwrap.Vertexbuffer;
|
import com.watabou.glwrap.Vertexbuffer;
|
||||||
import com.watabou.input.InputHandler;
|
import com.watabou.input.InputHandler;
|
||||||
import com.watabou.input.Keys;
|
import com.watabou.input.KeyEvent;
|
||||||
import com.watabou.noosa.audio.Music;
|
import com.watabou.noosa.audio.Music;
|
||||||
import com.watabou.utils.SystemTime;
|
import com.watabou.utils.SystemTime;
|
||||||
|
|
||||||
|
@ -132,8 +132,8 @@ public class Game extends AndroidApplication implements ApplicationListener {
|
||||||
|
|
||||||
inputHandler = new InputHandler();
|
inputHandler = new InputHandler();
|
||||||
Gdx.input.setInputProcessor(inputHandler);
|
Gdx.input.setInputProcessor(inputHandler);
|
||||||
Gdx.input.setCatchKey(Keys.BACK, true);
|
Gdx.input.setCatchKey(KeyEvent.BACK, true);
|
||||||
Gdx.input.setCatchKey(Keys.MENU, true);
|
Gdx.input.setCatchKey(KeyEvent.MENU, true);
|
||||||
|
|
||||||
//FIXME this doesn't seem to work quite right. That might not be due to LibGDX though.
|
//FIXME this doesn't seem to work quite right. That might not be due to LibGDX though.
|
||||||
Music.setMuteListener();
|
Music.setMuteListener();
|
||||||
|
|
123
SPD-classes/src/main/java/com/watabou/noosa/PointerArea.java
Normal file
123
SPD-classes/src/main/java/com/watabou/noosa/PointerArea.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,34 +21,35 @@
|
||||||
|
|
||||||
package com.watabou.noosa;
|
package com.watabou.noosa;
|
||||||
|
|
||||||
import com.watabou.input.Keys;
|
import com.watabou.input.KeyEvent;
|
||||||
import com.watabou.utils.Signal;
|
import com.watabou.utils.Signal;
|
||||||
|
|
||||||
public class Scene extends Group {
|
public class Scene extends Group {
|
||||||
|
|
||||||
private Signal.Listener<Keys.Key> keyListener;
|
private Signal.Listener<KeyEvent> keyListener;
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
Keys.event.add( keyListener = new Signal.Listener<Keys.Key>() {
|
KeyEvent.addKeyListener( keyListener = new Signal.Listener<KeyEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSignal( Keys.Key key ) {
|
public boolean onSignal( KeyEvent event ) {
|
||||||
if (Game.instance != null && key.pressed) {
|
if (Game.instance != null && event.pressed) {
|
||||||
switch (key.code) {
|
switch (event.code) {
|
||||||
case Keys.BACK:
|
case KeyEvent.BACK:
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
break;
|
break;
|
||||||
case Keys.MENU:
|
case KeyEvent.MENU:
|
||||||
onMenuPressed();
|
onMenuPressed();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
Keys.event.remove( keyListener );
|
KeyEvent.removeKeyListener( keyListener );
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,15 +21,15 @@
|
||||||
|
|
||||||
package com.watabou.noosa.ui;
|
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.Game;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
|
|
||||||
public class Button extends Component {
|
public class Button extends Component {
|
||||||
|
|
||||||
public static float longClick = 1f;
|
public static float longClick = 1f;
|
||||||
|
|
||||||
protected TouchArea hotArea;
|
protected PointerArea hotArea;
|
||||||
|
|
||||||
protected boolean pressed;
|
protected boolean pressed;
|
||||||
protected float pressTime;
|
protected float pressTime;
|
||||||
|
@ -38,25 +38,25 @@ public class Button extends Component {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createChildren() {
|
protected void createChildren() {
|
||||||
hotArea = new TouchArea( 0, 0, 0, 0 ) {
|
hotArea = new PointerArea( 0, 0, 0, 0 ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown(Touch touch) {
|
protected void onPointerDown( PointerEvent event ) {
|
||||||
pressed = true;
|
pressed = true;
|
||||||
pressTime = 0;
|
pressTime = 0;
|
||||||
processed = false;
|
processed = false;
|
||||||
Button.this.onTouchDown();
|
Button.this.onPointerDown();
|
||||||
};
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp(Touch touch) {
|
protected void onPointerUp( PointerEvent event ) {
|
||||||
pressed = false;
|
pressed = false;
|
||||||
Button.this.onTouchUp();
|
Button.this.onPointerUp();
|
||||||
};
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
Button.this.onClick();
|
Button.this.onClick();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
add( hotArea );
|
add( hotArea );
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ public class Button extends Component {
|
||||||
|
|
||||||
hotArea.reset();
|
hotArea.reset();
|
||||||
processed = true;
|
processed = true;
|
||||||
onTouchUp();
|
onPointerUp();
|
||||||
|
|
||||||
Game.vibrate( 50 );
|
Game.vibrate( 50 );
|
||||||
}
|
}
|
||||||
|
@ -82,13 +82,12 @@ public class Button extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onTouchDown() {};
|
protected void onPointerDown() {}
|
||||||
protected void onTouchUp() {};
|
protected void onPointerUp() {}
|
||||||
protected void onClick() {};
|
protected void onClick() {}
|
||||||
|
|
||||||
protected boolean onLongClick() {
|
protected boolean onLongClick() {
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void layout() {
|
protected void layout() {
|
||||||
|
|
|
@ -25,9 +25,7 @@ import java.util.LinkedList;
|
||||||
|
|
||||||
public class Signal<T> {
|
public class Signal<T> {
|
||||||
|
|
||||||
private LinkedList<Listener<T>> listeners = new LinkedList<Signal.Listener<T>>();
|
private LinkedList<Listener<T>> listeners = new LinkedList<>();
|
||||||
|
|
||||||
private boolean canceled;
|
|
||||||
|
|
||||||
private boolean stackMode;
|
private boolean stackMode;
|
||||||
|
|
||||||
|
@ -70,13 +68,11 @@ public class Signal<T> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Listener<T>[] list = listeners.toArray( new Listener[0] );
|
Listener<T>[] list = listeners.toArray( new Listener[0] );
|
||||||
|
|
||||||
canceled = false;
|
|
||||||
for (Listener<T> listener : list) {
|
for (Listener<T> listener : list) {
|
||||||
|
|
||||||
if (listeners.contains(listener)) {
|
if (listeners.contains(listener)) {
|
||||||
listener.onSignal(t);
|
if (listener.onSignal(t)) {
|
||||||
if (canceled) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,11 +80,8 @@ public class Signal<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() {
|
public interface Listener<T> {
|
||||||
canceled = true;
|
//return true if the signal has been handled
|
||||||
}
|
boolean onSignal( T t );
|
||||||
|
|
||||||
public static interface Listener<T> {
|
|
||||||
public void onSignal( T t );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ import android.os.Build;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
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.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs;
|
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas;
|
||||||
|
|
|
@ -37,8 +37,6 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ExitRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ImpShopRoom;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.ImpShopRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
import com.watabou.noosa.Group;
|
import com.watabou.noosa.Group;
|
||||||
import com.watabou.utils.PathFinder;
|
|
||||||
import com.watabou.utils.Random;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
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.Camera;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.RenderedText;
|
import com.watabou.noosa.RenderedText;
|
||||||
import com.watabou.noosa.TouchArea;
|
|
||||||
import com.watabou.utils.DeviceCompat;
|
import com.watabou.utils.DeviceCompat;
|
||||||
|
|
||||||
public class AboutScene extends PixelScene {
|
public class AboutScene extends PixelScene {
|
||||||
|
@ -92,9 +92,9 @@ public class AboutScene extends PixelScene {
|
||||||
shpxlink.setPos((colWidth - shpxlink.width()) / 2, shpxtext.bottom() + 6);
|
shpxlink.setPos((colWidth - shpxlink.width()) / 2, shpxtext.bottom() + 6);
|
||||||
align(shpxlink);
|
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
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
DeviceCompat.openURI( "https://" + LNK_SHPX );
|
DeviceCompat.openURI( "https://" + LNK_SHPX );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -133,9 +133,9 @@ public class AboutScene extends PixelScene {
|
||||||
wataLink.setPos(wataOffset + (colWidth - wataLink.width()) / 2 , wataText.bottom() + 6);
|
wataLink.setPos(wataOffset + (colWidth - wataLink.width()) / 2 , wataText.bottom() + 6);
|
||||||
align(wataLink);
|
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
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
DeviceCompat.openURI( "https://" + LNK_WATA );
|
DeviceCompat.openURI( "https://" + LNK_WATA );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -499,12 +499,12 @@ public class AlchemyScene extends PixelScene {
|
||||||
|
|
||||||
slot = new ItemSlot() {
|
slot = new ItemSlot() {
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.2f );
|
bg.brightness( 1.2f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
};
|
};
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.resetColor();
|
bg.resetColor();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,13 +28,13 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
|
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.Camera;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.utils.GameMath;
|
import com.watabou.utils.GameMath;
|
||||||
import com.watabou.utils.PointF;
|
import com.watabou.utils.PointF;
|
||||||
|
|
||||||
public class CellSelector extends TouchArea {
|
public class CellSelector extends PointerArea {
|
||||||
|
|
||||||
public Listener listener = null;
|
public Listener listener = null;
|
||||||
|
|
||||||
|
@ -50,14 +50,14 @@ public class CellSelector extends TouchArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
|
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
|
||||||
} else {
|
} 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])){
|
for (Char mob : Dungeon.level.mobs.toArray(new Mob[0])){
|
||||||
if (mob.sprite != null && mob.sprite.overlapsPoint( p.x, p.y)){
|
if (mob.sprite != null && mob.sprite.overlapsPoint( p.x, p.y)){
|
||||||
select( mob.pos );
|
select( mob.pos );
|
||||||
|
@ -73,8 +73,8 @@ public class CellSelector extends TouchArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
select( ((DungeonTilemap)target).screenToTile(
|
select( ((DungeonTilemap)target).screenToTile(
|
||||||
(int)touch.current.x,
|
(int) event.current.x,
|
||||||
(int)touch.current.y,
|
(int) event.current.y,
|
||||||
true ) );
|
true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,47 +111,47 @@ public class CellSelector extends TouchArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean pinching = false;
|
private boolean pinching = false;
|
||||||
private Touch another;
|
private PointerEvent another;
|
||||||
private float startZoom;
|
private float startZoom;
|
||||||
private float startSpan;
|
private float startSpan;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown( Touch t ) {
|
protected void onPointerDown( PointerEvent event ) {
|
||||||
|
|
||||||
if (t != touch && another == null) {
|
if (event != curEvent && another == null) {
|
||||||
|
|
||||||
if (!touch.down) {
|
if (!curEvent.down) {
|
||||||
touch = t;
|
curEvent = event;
|
||||||
onTouchDown( t );
|
onPointerDown( event );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pinching = true;
|
pinching = true;
|
||||||
|
|
||||||
another = t;
|
another = event;
|
||||||
startSpan = PointF.distance( touch.current, another.current );
|
startSpan = PointF.distance( curEvent.current, another.current );
|
||||||
startZoom = camera.zoom;
|
startZoom = camera.zoom;
|
||||||
|
|
||||||
dragging = false;
|
dragging = false;
|
||||||
} else if (t != touch) {
|
} else if (event != curEvent) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp( Touch t ) {
|
protected void onPointerUp( PointerEvent event ) {
|
||||||
if (pinching && (t == touch || t == another)) {
|
if (pinching && (event == curEvent || event == another)) {
|
||||||
|
|
||||||
pinching = false;
|
pinching = false;
|
||||||
|
|
||||||
zoom(Math.round( camera.zoom ));
|
zoom(Math.round( camera.zoom ));
|
||||||
|
|
||||||
dragging = true;
|
dragging = true;
|
||||||
if (t == touch) {
|
if (event == curEvent) {
|
||||||
touch = another;
|
curEvent = another;
|
||||||
}
|
}
|
||||||
another = null;
|
another = null;
|
||||||
lastPos.set( touch.current );
|
lastPos.set( curEvent.current );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +159,13 @@ public class CellSelector extends TouchArea {
|
||||||
private PointF lastPos = new PointF();
|
private PointF lastPos = new PointF();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDrag( Touch t ) {
|
protected void onDrag( PointerEvent event ) {
|
||||||
|
|
||||||
camera.target = null;
|
camera.target = null;
|
||||||
|
|
||||||
if (pinching) {
|
if (pinching) {
|
||||||
|
|
||||||
float curSpan = PointF.distance( touch.current, another.current );
|
float curSpan = PointF.distance( curEvent.current, another.current );
|
||||||
float zoom = (startZoom * curSpan / startSpan);
|
float zoom = (startZoom * curSpan / startSpan);
|
||||||
camera.zoom( GameMath.gate(
|
camera.zoom( GameMath.gate(
|
||||||
PixelScene.minZoom,
|
PixelScene.minZoom,
|
||||||
|
@ -174,14 +174,14 @@ public class CellSelector extends TouchArea {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!dragging && PointF.distance( t.current, t.start ) > dragThreshold) {
|
if (!dragging && PointF.distance( event.current, event.start ) > dragThreshold) {
|
||||||
|
|
||||||
dragging = true;
|
dragging = true;
|
||||||
lastPos.set( t.current );
|
lastPos.set( event.current );
|
||||||
|
|
||||||
} else if (dragging) {
|
} else if (dragging) {
|
||||||
camera.scroll.offset( PointF.diff( lastPos, t.current ).invScale( camera.zoom ) );
|
camera.scroll.offset( PointF.diff( lastPos, event.current ).invScale( camera.zoom ) );
|
||||||
lastPos.set( t.current );
|
lastPos.set( event.current );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||||
import com.watabou.glwrap.Blending;
|
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;
|
||||||
import com.watabou.noosa.BitmapText.Font;
|
import com.watabou.noosa.BitmapText.Font;
|
||||||
import com.watabou.noosa.BitmapTextMultiline;
|
import com.watabou.noosa.BitmapTextMultiline;
|
||||||
|
@ -164,7 +164,7 @@ public class PixelScene extends Scene {
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
Touchscreen.event.removeAll();
|
PointerEvent.clearListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BitmapText.Font font;
|
public static BitmapText.Font font;
|
||||||
|
|
|
@ -41,7 +41,7 @@ import com.watabou.gltextures.SmartTexture;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
import com.watabou.glwrap.Matrix;
|
import com.watabou.glwrap.Matrix;
|
||||||
import com.watabou.glwrap.Quad;
|
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.Camera;
|
||||||
import com.watabou.noosa.ColorBlock;
|
import com.watabou.noosa.ColorBlock;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
@ -49,7 +49,7 @@ import com.watabou.noosa.Group;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.NoosaScript;
|
import com.watabou.noosa.NoosaScript;
|
||||||
import com.watabou.noosa.TextureFilm;
|
import com.watabou.noosa.TextureFilm;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.Visual;
|
import com.watabou.noosa.Visual;
|
||||||
import com.watabou.noosa.audio.Music;
|
import com.watabou.noosa.audio.Music;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
|
@ -199,8 +199,8 @@ public class SurfaceScene extends PixelScene {
|
||||||
window.add( a );
|
window.add( a );
|
||||||
window.add( pet );
|
window.add( pet );
|
||||||
|
|
||||||
window.add( new TouchArea( sky ) {
|
window.add( new PointerArea( sky ) {
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
pet.jump();
|
pet.jump();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -57,13 +57,13 @@ public class ExitButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
image.brightness( 1.5f );
|
image.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
image.resetColor();
|
image.resetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class GameLog extends Component implements Signal.Listener<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onSignal( String text ) {
|
public synchronized boolean onSignal( String text ) {
|
||||||
|
|
||||||
if (length != entries.size()){
|
if (length != entries.size()){
|
||||||
clear();
|
clear();
|
||||||
|
@ -126,6 +126,7 @@ public class GameLog extends Component implements Signal.Listener<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
layout();
|
layout();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -52,13 +52,13 @@ public class IconButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
if (icon != null) icon.brightness( 1.5f );
|
if (icon != null) icon.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
if (icon != null) icon.resetColor();
|
if (icon != null) icon.resetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,13 @@ public class LanguageButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
image.brightness( 1.5f );
|
image.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
image.resetColor();
|
image.resetColor();
|
||||||
updateIcon();
|
updateIcon();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,18 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
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.ColorBlock;
|
||||||
import com.watabou.noosa.NinePatch;
|
import com.watabou.noosa.NinePatch;
|
||||||
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.RenderedText;
|
import com.watabou.noosa.RenderedText;
|
||||||
import com.watabou.noosa.TouchArea;
|
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
import com.watabou.utils.GameMath;
|
import com.watabou.utils.GameMath;
|
||||||
import com.watabou.utils.PointF;
|
import com.watabou.utils.PointF;
|
||||||
|
|
||||||
public abstract class OptionSlider extends Component {
|
public abstract class OptionSlider extends Component {
|
||||||
|
|
||||||
private TouchArea touchArea;
|
private PointerArea pointerArea;
|
||||||
|
|
||||||
private RenderedText title;
|
private RenderedText title;
|
||||||
private RenderedText minTxt;
|
private RenderedText minTxt;
|
||||||
|
@ -102,32 +102,24 @@ public abstract class OptionSlider extends Component {
|
||||||
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
|
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
|
||||||
sliderNode.size(5, 9);
|
sliderNode.size(5, 9);
|
||||||
|
|
||||||
touchArea = new TouchArea(0, 0, 0, 0){
|
pointerArea = new PointerArea(0, 0, 0, 0){
|
||||||
boolean pressed = false;
|
boolean pressed = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown(Touchscreen.Touch touch) {
|
protected void onPointerDown( PointerEvent event ) {
|
||||||
pressed = true;
|
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.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2);
|
||||||
sliderNode.brightness(1.5f);
|
sliderNode.brightness(1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDrag(Touchscreen.Touch touch) {
|
protected void onPointerUp( PointerEvent event ) {
|
||||||
if (pressed) {
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onTouchUp(Touchscreen.Touch touch) {
|
|
||||||
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);
|
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
|
||||||
sliderNode.resetColor();
|
sliderNode.resetColor();
|
||||||
|
|
||||||
//sets the selected value
|
//sets the selected value
|
||||||
selectedVal = minVal + Math.round(sliderNode.x / tickDist);
|
selectedVal = minVal + Math.round(sliderNode.x / tickDist);
|
||||||
sliderNode.x = (int) (x + tickDist * (selectedVal - minVal));
|
sliderNode.x = (int) (x + tickDist * (selectedVal - minVal));
|
||||||
|
@ -135,8 +127,16 @@ public abstract class OptionSlider extends Component {
|
||||||
pressed = false;
|
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.x = (int)(x + tickDist*(selectedVal-minVal));
|
||||||
sliderNode.y = sliderBG.y-4;
|
sliderNode.y = sliderBG.y-4;
|
||||||
|
|
||||||
touchArea.x = x;
|
pointerArea.x = x;
|
||||||
touchArea.y = y;
|
pointerArea.y = y;
|
||||||
touchArea.width = width();
|
pointerArea.width = width();
|
||||||
touchArea.height = height();
|
pointerArea.height = height();
|
||||||
|
|
||||||
BG.size(width(), height());
|
BG.size(width(), height());
|
||||||
BG.x = x;
|
BG.x = x;
|
||||||
|
|
|
@ -50,13 +50,13 @@ public class PrefsButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
image.brightness( 1.5f );
|
image.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
image.resetColor();
|
image.resetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,11 +97,11 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
|
||||||
return QuickSlotButton.this.onLongClick();
|
return QuickSlotButton.this.onLongClick();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
icon.lightness( 0.7f );
|
icon.lightness( 0.7f );
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
icon.resetColor();
|
icon.resetColor();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
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.Camera;
|
||||||
import com.watabou.noosa.ColorBlock;
|
import com.watabou.noosa.ColorBlock;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
import com.watabou.utils.Point;
|
import com.watabou.utils.Point;
|
||||||
import com.watabou.utils.PointF;
|
import com.watabou.utils.PointF;
|
||||||
|
@ -35,7 +35,7 @@ public class ScrollPane extends Component {
|
||||||
protected static final int THUMB_COLOR = 0xFF7b8073;
|
protected static final int THUMB_COLOR = 0xFF7b8073;
|
||||||
protected static final float THUMB_ALPHA = 0.5f;
|
protected static final float THUMB_ALPHA = 0.5f;
|
||||||
|
|
||||||
protected TouchController controller;
|
protected PointerController controller;
|
||||||
protected Component content;
|
protected Component content;
|
||||||
protected ColorBlock thumb;
|
protected ColorBlock thumb;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class ScrollPane extends Component {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createChildren() {
|
protected void createChildren() {
|
||||||
controller = new TouchController();
|
controller = new PointerController();
|
||||||
add( controller );
|
add( controller );
|
||||||
|
|
||||||
thumb = new ColorBlock( 1, 1, THUMB_COLOR );
|
thumb = new ColorBlock( 1, 1, THUMB_COLOR );
|
||||||
|
@ -107,17 +107,17 @@ public class ScrollPane extends Component {
|
||||||
public void onClick( float x, float y ) {
|
public void onClick( float x, float y ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TouchController extends TouchArea {
|
public class PointerController extends PointerArea {
|
||||||
|
|
||||||
private float dragThreshold;
|
private float dragThreshold;
|
||||||
|
|
||||||
public TouchController() {
|
public PointerController() {
|
||||||
super( 0, 0, 0, 0 );
|
super( 0, 0, 0, 0 );
|
||||||
dragThreshold = PixelScene.defaultZoom * 8;
|
dragThreshold = PixelScene.defaultZoom * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp( Touch touch ) {
|
protected void onPointerUp( PointerEvent event ) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
|
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
@ -125,7 +125,7 @@ public class ScrollPane extends Component {
|
||||||
|
|
||||||
} else {
|
} 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 );
|
ScrollPane.this.onClick( p.x, p.y );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -135,12 +135,12 @@ public class ScrollPane extends Component {
|
||||||
private PointF lastPos = new PointF();
|
private PointF lastPos = new PointF();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDrag( Touch t ) {
|
protected void onDrag( PointerEvent event ) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
|
|
||||||
Camera c = content.camera;
|
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()) {
|
if (c.scroll.x + width > content.width()) {
|
||||||
c.scroll.x = content.width() - 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();
|
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;
|
dragging = true;
|
||||||
lastPos.set( t.current );
|
lastPos.set( event.current );
|
||||||
thumb.am = 1;
|
thumb.am = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
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.Image;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
|
|
||||||
public class SimpleButton extends Component {
|
public class SimpleButton extends Component {
|
||||||
|
@ -43,19 +43,19 @@ public class SimpleButton extends Component {
|
||||||
image = new Image();
|
image = new Image();
|
||||||
add( image );
|
add( image );
|
||||||
|
|
||||||
add( new TouchArea( image ) {
|
add( new PointerArea( image ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown(Touch touch) {
|
protected void onPointerDown( PointerEvent event ) {
|
||||||
image.brightness( 1.2f );
|
image.brightness( 1.2f );
|
||||||
};
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp(Touch touch) {
|
protected void onPointerUp( PointerEvent event ) {
|
||||||
image.brightness( 1.0f );
|
image.brightness( 1.0f );
|
||||||
};
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
SimpleButton.this.onClick();
|
SimpleButton.this.onClick();
|
||||||
};
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
|
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.BitmapText;
|
||||||
import com.watabou.noosa.Camera;
|
import com.watabou.noosa.Camera;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
import com.watabou.noosa.NinePatch;
|
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.audio.Sample;
|
||||||
import com.watabou.noosa.particles.Emitter;
|
import com.watabou.noosa.particles.Emitter;
|
||||||
import com.watabou.noosa.ui.Button;
|
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 );
|
bg = new NinePatch( Assets.STATUS, 0, 0, 128, 36, 85, 0, 45, 0 );
|
||||||
add( bg );
|
add( bg );
|
||||||
|
|
||||||
add( new TouchArea( 0, 1, 31, 31 ) {
|
add( new PointerArea( 0, 1, 31, 31 ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
Image sprite = Dungeon.hero.sprite;
|
Image sprite = Dungeon.hero.sprite;
|
||||||
if (!sprite.isVisible()) {
|
if (!sprite.isVisible()) {
|
||||||
Camera.main.focusOn( sprite );
|
Camera.main.focusOn( sprite );
|
||||||
|
@ -322,13 +322,13 @@ public class StatusPane extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.5f );
|
bg.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
if (keyIcon.keyCount() > 0) {
|
if (keyIcon.keyCount() > 0) {
|
||||||
bg.brightness(.8f - (Math.min(6, keyIcon.keyCount()) / 20f));
|
bg.brightness(.8f - (Math.min(6, keyIcon.keyCount()) / 20f));
|
||||||
} else {
|
} else {
|
||||||
|
@ -374,13 +374,13 @@ public class StatusPane extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
image.brightness( 1.5f );
|
image.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
image.resetColor();
|
image.resetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,13 @@ public class StyledButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.2f );
|
bg.brightness( 1.2f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.resetColor();
|
bg.resetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -324,12 +324,12 @@ public class Toolbar extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
base.brightness( 1.4f );
|
base.brightness( 1.4f );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
if (active) {
|
if (active) {
|
||||||
base.resetColor();
|
base.resetColor();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,24 +24,23 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
|
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.watabou.input.Keys;
|
import com.watabou.input.KeyEvent;
|
||||||
import com.watabou.input.Keys.Key;
|
import com.watabou.input.PointerEvent;
|
||||||
import com.watabou.input.Touchscreen.Touch;
|
|
||||||
import com.watabou.noosa.Camera;
|
import com.watabou.noosa.Camera;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.Group;
|
import com.watabou.noosa.Group;
|
||||||
import com.watabou.noosa.NinePatch;
|
import com.watabou.noosa.NinePatch;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.utils.Signal;
|
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 width;
|
||||||
protected int height;
|
protected int height;
|
||||||
|
|
||||||
protected int yOffset;
|
protected int yOffset;
|
||||||
|
|
||||||
protected TouchArea blocker;
|
protected PointerArea blocker;
|
||||||
protected ShadowBox shadow;
|
protected ShadowBox shadow;
|
||||||
protected NinePatch chrome;
|
protected NinePatch chrome;
|
||||||
|
|
||||||
|
@ -65,12 +64,12 @@ public class Window extends Group implements Signal.Listener<Key> {
|
||||||
|
|
||||||
this.yOffset = yOffset;
|
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
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
if (Window.this.parent != null && !Window.this.chrome.overlapsScreenPoint(
|
if (Window.this.parent != null && !Window.this.chrome.overlapsScreenPoint(
|
||||||
(int)touch.current.x,
|
(int) event.current.x,
|
||||||
(int)touch.current.y )) {
|
(int) event.current.y )) {
|
||||||
|
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
}
|
}
|
||||||
|
@ -112,7 +111,7 @@ public class Window extends Group implements Signal.Listener<Key> {
|
||||||
camera.y / camera.zoom,
|
camera.y / camera.zoom,
|
||||||
chrome.width(), chrome.height );
|
chrome.width(), chrome.height );
|
||||||
|
|
||||||
Keys.event.add( this );
|
KeyEvent.addKeyListener( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resize( int w, int h ) {
|
public void resize( int w, int h ) {
|
||||||
|
@ -151,23 +150,23 @@ public class Window extends Group implements Signal.Listener<Key> {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
Camera.remove( camera );
|
Camera.remove( camera );
|
||||||
Keys.event.remove( this );
|
KeyEvent.removeKeyListener( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSignal( Key key ) {
|
public boolean onSignal( KeyEvent event ) {
|
||||||
if (key.pressed) {
|
if (event.pressed) {
|
||||||
switch (key.code) {
|
switch (event.code) {
|
||||||
case Keys.BACK:
|
case KeyEvent.BACK:
|
||||||
onBackPressed();
|
onBackPressed();
|
||||||
break;
|
return true;
|
||||||
case Keys.MENU:
|
case KeyEvent.MENU:
|
||||||
onMenuPressed();
|
onMenuPressed();
|
||||||
break;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.event.cancel();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
|
@ -23,18 +23,18 @@ package com.shatteredpixel.shatteredpixeldungeon.ui.changelist;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage;
|
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.Image;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
|
|
||||||
public class ChangesWindow extends WndTitledMessage {
|
public class ChangesWindow extends WndTitledMessage {
|
||||||
|
|
||||||
public ChangesWindow(Image icon, String title, String message ) {
|
public ChangesWindow(Image icon, String title, String message ) {
|
||||||
super( icon, title, 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
|
@Override
|
||||||
protected void onClick( Touchscreen.Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -412,12 +412,12 @@ public class WndBag extends WndTabbed {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.5f );
|
bg.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
||||||
};
|
};
|
||||||
|
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.brightness( 1.0f );
|
bg.brightness( 1.0f );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,12 @@ public class WndBlacksmith extends Window {
|
||||||
|
|
||||||
slot = new ItemSlot() {
|
slot = new ItemSlot() {
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.2f );
|
bg.brightness( 1.2f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK );
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
||||||
};
|
};
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.resetColor();
|
bg.resetColor();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -348,12 +348,12 @@ public class WndRanking extends WndTabbed {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.5f );
|
bg.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
||||||
};
|
};
|
||||||
|
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.brightness( 1.0f );
|
bg.brightness( 1.0f );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -392,12 +392,12 @@ public class WndRanking extends WndTabbed {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onTouchDown() {
|
protected void onPointerDown() {
|
||||||
bg.brightness( 1.5f );
|
bg.brightness( 1.5f );
|
||||||
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
||||||
};
|
};
|
||||||
|
|
||||||
protected void onTouchUp() {
|
protected void onPointerUp() {
|
||||||
bg.brightness( 1.0f );
|
bg.brightness( 1.0f );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
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.Game;
|
||||||
import com.watabou.noosa.TouchArea;
|
import com.watabou.noosa.PointerArea;
|
||||||
import com.watabou.utils.SparseArray;
|
import com.watabou.utils.SparseArray;
|
||||||
|
|
||||||
public class WndStory extends Window {
|
public class WndStory extends Window {
|
||||||
|
@ -74,9 +74,9 @@ public class WndStory extends Window {
|
||||||
tf.setPos(MARGIN, 0);
|
tf.setPos(MARGIN, 0);
|
||||||
add( tf );
|
add( tf );
|
||||||
|
|
||||||
add( new TouchArea( chrome ) {
|
add( new PointerArea( chrome ) {
|
||||||
@Override
|
@Override
|
||||||
protected void onClick( Touch touch ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user