From 6319e6c6978833666d96c79cd54dbc736909aa3d Mon Sep 17 00:00:00 2001 From: RedHatter <_c_@mail.com> Date: Tue, 5 Aug 2014 14:52:52 -0700 Subject: [PATCH 1/5] Alternative Navigation with joystick. --- assets/joystick.png | Bin 0 -> 606 bytes src/com/watabou/pixeldungeon/Assets.java | 1 + .../watabou/pixeldungeon/PixelDungeon.java | 11 ++ src/com/watabou/pixeldungeon/Preferences.java | 1 + .../pixeldungeon/scenes/GameScene.java | 14 +- src/com/watabou/pixeldungeon/ui/Joystick.java | 125 ++++++++++++++++++ .../pixeldungeon/windows/WndSettings.java | 18 ++- 7 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 assets/joystick.png create mode 100644 src/com/watabou/pixeldungeon/ui/Joystick.java diff --git a/assets/joystick.png b/assets/joystick.png new file mode 100644 index 0000000000000000000000000000000000000000..338f95983646a9178080dcc2399efeb136f556c2 GIT binary patch literal 606 zcmV-k0-^nhP)j4Y>)u(0N@G0J%GEe0l;V1 z-T@c@{{XmEizI#RhUAXq7q{!Hn{(r{?Snp(JSP0&UyQ4c!8G z5co}l6P0C&BuS8_>DAygO_3xC%CejregesId;sH+ky4(W-xg(AMk%E))Jl;2n1iAV znXw~nm9=&fYBTT;ko;bPR#kN|v{xT$3-Isjz2|=wa;t+m*URbGq9~}88q(l3GR9CT zwRCyBfaK%c$V$TBB#({9pefS left()+(width()/3) && p.x < right()-(width()/3) + && p.y < bottom()-(height()/3) && p.y > top()+(height()/3)) + pressed = true; + else { + pressed = false; + current = p; + } + } + } + + protected void onTouchDown( Touch touch ) { + onDrag (touch); + } + + protected void onTouchUp( Touch touch ) { + pressed = false; + draging = false; + current = null; + bg.x = x; + bg.y = y; + } + + }; + add( hotArea ); + } + + @Override + public void update() { + super.update(); + + hotArea.active = visible; + + if (current != null) + step (current); + + if (pressed) { + if ((pressTime += Game.elapsed) >= longClick) { + pressed = false; + draging = true; + Game.vibrate( 50 ); + } + } + } + + protected boolean onLongClick() { + return false; + }; + + @Override + protected void layout() { + hotArea.x = x; + hotArea.y = y; + hotArea.width = width; + hotArea.height = height; + + bg.x = x; + bg.y = y; + } + + private void step (PointF p) { + if (p.x > left()+(width()/3) && p.x < right()-(width()/3)) { + if (p.y < top()+(height()/3)) { + bg.x = x; + bg.y = y-1; + GameScene.handleCell (Dungeon.hero.pos-Level.WIDTH); + } else if (p.y > bottom()-(height()/3)) { + bg.x = x; + bg.y = y+1; + GameScene.handleCell (Dungeon.hero.pos+Level.WIDTH); + } + } else if (p.y < bottom()-(height()/3) && p.y > top()+(height()/3)) { + if (p.x < left()+(width()/3)) { + bg.y = y; + bg.x = x-1; + GameScene.handleCell (Dungeon.hero.pos-1); + } else if (p.x > right()-(width()/3)) { + bg.y = y; + bg.x = x+1; + GameScene.handleCell (Dungeon.hero.pos+1); + } + } + } +} \ No newline at end of file diff --git a/src/com/watabou/pixeldungeon/windows/WndSettings.java b/src/com/watabou/pixeldungeon/windows/WndSettings.java index f1a3b0b24f..9b194445cd 100644 --- a/src/com/watabou/pixeldungeon/windows/WndSettings.java +++ b/src/com/watabou/pixeldungeon/windows/WndSettings.java @@ -40,6 +40,8 @@ public class WndSettings extends Window { private static final String TXT_BRIGHTNESS = "Brightness"; + private static final String TXT_JOYSTICK = "Joystick"; + private static final String TXT_SWITCH_PORT = "Switch to portrait"; private static final String TXT_SWITCH_LAND = "Switch to landscape"; @@ -119,6 +121,18 @@ protected void onClick() { btnSound.setRect( 0, btnMusic.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnSound.checked( PixelDungeon.soundFx() ); add( btnSound ); + + CheckBox btnJoystick = new CheckBox( TXT_JOYSTICK ) { + @Override + protected void onClick() { + super.onClick(); + PixelDungeon.joystick( checked() ); + Sample.INSTANCE.play( Assets.SND_CLICK ); + } + }; + btnJoystick.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnJoystick.checked( PixelDungeon.joystick() ); + add( btnJoystick ); if (!inGame) { @@ -128,7 +142,7 @@ protected void onClick() { PixelDungeon.landscape( !PixelDungeon.landscape() ); } }; - btnOrientation.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnOrientation.setRect( 0, btnJoystick.bottom() + GAP, WIDTH, BTN_HEIGHT ); add( btnOrientation ); resize( WIDTH, (int)btnOrientation.bottom() ); @@ -142,7 +156,7 @@ protected void onClick() { PixelDungeon.brightness( checked() ); } }; - btnBrightness.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnBrightness.setRect( 0, btnJoystick.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnBrightness.checked( PixelDungeon.brightness() ); add( btnBrightness ); From e0ce5aaa4c84c635127fdfd59c45f034ec63b124 Mon Sep 17 00:00:00 2001 From: RedHatter <_c_@mail.com> Date: Tue, 5 Aug 2014 17:40:48 -0700 Subject: [PATCH 2/5] Extended log window. --- src/com/watabou/pixeldungeon/ui/GameLog.java | 42 +++++++++++++-- .../watabou/pixeldungeon/windows/WndLog.java | 53 +++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/com/watabou/pixeldungeon/windows/WndLog.java diff --git a/src/com/watabou/pixeldungeon/ui/GameLog.java b/src/com/watabou/pixeldungeon/ui/GameLog.java index 188a84b146..002b7420ee 100644 --- a/src/com/watabou/pixeldungeon/ui/GameLog.java +++ b/src/com/watabou/pixeldungeon/ui/GameLog.java @@ -18,13 +18,21 @@ package com.watabou.pixeldungeon.ui; import java.util.regex.Pattern; +import java.util.List; +import java.util.ArrayList; import com.watabou.noosa.BitmapTextMultiline; import com.watabou.noosa.ui.Component; +import com.watabou.noosa.Gizmo; +import com.watabou.input.Touchscreen.Touch; +import com.watabou.noosa.TouchArea; +import com.watabou.pixeldungeon.windows.WndLog; import com.watabou.pixeldungeon.scenes.PixelScene; import com.watabou.pixeldungeon.sprites.CharSprite; import com.watabou.pixeldungeon.utils.GLog; import com.watabou.pixeldungeon.utils.Utils; +import com.watabou.pixeldungeon.scenes.GameScene; + import com.watabou.utils.Signal; public class GameLog extends Component implements Signal.Listener { @@ -34,7 +42,10 @@ public class GameLog extends Component implements Signal.Listener { private static final Pattern PUNCTUATION = Pattern.compile( ".*[.,;?! ]$" ); private BitmapTextMultiline lastEntry; + private List entries = new ArrayList (); private int lastColor; + private WndLog window; + private TouchArea hotArea; public GameLog() { super(); @@ -47,6 +58,16 @@ public void newLine() { lastEntry = null; } + @Override + protected void createChildren() { + hotArea = new TouchArea( 0, 0, 0, 0 ) { + protected void onTouchUp( Touch touch ) { + GameScene.show( new WndLog (entries) ); + } + }; + add( hotArea ); + } + @Override public void onSignal( String text ) { @@ -84,12 +105,12 @@ public void onSignal( String text ) { lastEntry.measure(); lastEntry.hardlight( color ); lastColor = color; + entries.add ( lastEntry ); add( lastEntry ); - } if (length > MAX_MESSAGES) { - remove( members.get( 0 ) ); + remove( entries.get(entries.size()-MAX_MESSAGES) ); } layout(); @@ -97,13 +118,26 @@ public void onSignal( String text ) { @Override protected void layout() { - float pos = y; + float pos = bottom(); for (int i=length-1; i >= 0; i--) { - BitmapTextMultiline entry = (BitmapTextMultiline)members.get( i ); + Gizmo item = members.get( i ); + if (item == hotArea) + continue; + + BitmapTextMultiline entry = (BitmapTextMultiline)item; entry.x = x; entry.y = pos - entry.height(); pos -= entry.height(); } + + height = bottom ()-pos; + y = pos; + + hotArea.active = visible; + hotArea.x = x; + hotArea.y = y; + hotArea.width = width; + hotArea.height = height; } @Override diff --git a/src/com/watabou/pixeldungeon/windows/WndLog.java b/src/com/watabou/pixeldungeon/windows/WndLog.java new file mode 100644 index 0000000000..9814be78b7 --- /dev/null +++ b/src/com/watabou/pixeldungeon/windows/WndLog.java @@ -0,0 +1,53 @@ +package com.watabou.pixeldungeon.windows; + +import java.util.List; + +import com.watabou.noosa.BitmapTextMultiline; +import com.watabou.noosa.BitmapText; +import com.watabou.noosa.ui.Component; +import com.watabou.pixeldungeon.scenes.PixelScene; +import com.watabou.pixeldungeon.ui.ScrollPane; +import com.watabou.pixeldungeon.ui.Window; + +public class WndLog extends Window { + + private static final int WIDTH = 112; + private static final int HEIGHT = 160; + + private static final String TXT_TITLE = "Log"; + + private BitmapText txtTitle; + + public WndLog(List entries) { + + super(); + resize( WIDTH, HEIGHT ); + + txtTitle = PixelScene.createText( TXT_TITLE, 9 ); + txtTitle.hardlight( Window.TITLE_COLOR ); + txtTitle.measure(); + txtTitle.x = PixelScene.align( PixelScene.uiCamera, (WIDTH - txtTitle.width()) / 2 ); + add( txtTitle ); + + float pos = txtTitle.height(); + Component content = new Component(); + for (int i = entries.size()-1; i >= 0; i--) { + BitmapTextMultiline entry = entries.get( i ); + BitmapTextMultiline text = PixelScene.createMultiline( entry.text(), 6 ); + text.maxWidth = entry.maxWidth; + text.measure(); + text.hardlight( entry.rm, entry.gm, entry.bm ); + content.add (text); + text.x = 0; + text.y = pos; + pos += entry.height(); + } + + content.setSize ( WIDTH, pos ); + + ScrollPane list = new ScrollPane( content ); + add( list ); + + list.setRect( 0, txtTitle.height(), WIDTH, HEIGHT - txtTitle.height() ); + } +} From 37155ee654b9e18fc15e7fc3d4fbe76d78bd02f4 Mon Sep 17 00:00:00 2001 From: RedHatter <_c_@mail.com> Date: Wed, 6 Aug 2014 00:45:43 -0700 Subject: [PATCH 3/5] Explore tool travels to closest unvisited area. --- assets/toolbar.png | Bin 3796 -> 3771 bytes src/com/watabou/pixeldungeon/ui/Toolbar.java | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/assets/toolbar.png b/assets/toolbar.png index 89fe80800d1772073b19f0dbefa00675b3285611..07131536dbfb083b0b7422fe56d4b401139b8a4d 100644 GIT binary patch delta 1136 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 bg8SD1DQDc9gj69K00000NkvXXu0mjfjra>B diff --git a/src/com/watabou/pixeldungeon/ui/Toolbar.java b/src/com/watabou/pixeldungeon/ui/Toolbar.java index 0f317cef7b..63efd3c3c3 100644 --- a/src/com/watabou/pixeldungeon/ui/Toolbar.java +++ b/src/com/watabou/pixeldungeon/ui/Toolbar.java @@ -17,6 +17,7 @@ */ package com.watabou.pixeldungeon.ui; +import com.watabou.utils.PathFinder; import com.watabou.noosa.Game; import com.watabou.noosa.Gizmo; import com.watabou.noosa.Image; @@ -30,6 +31,7 @@ import com.watabou.pixeldungeon.items.Heap; import com.watabou.pixeldungeon.items.Item; import com.watabou.pixeldungeon.levels.Level; +import com.watabou.pixeldungeon.levels.Terrain; import com.watabou.pixeldungeon.plants.Plant; import com.watabou.pixeldungeon.scenes.CellSelector; import com.watabou.pixeldungeon.scenes.GameScene; @@ -49,6 +51,7 @@ public class Toolbar extends Component { private Tool btnWait; private Tool btnSearch; private Tool btnInfo; + private Tool btnExplore; private Tool btnResume; private Tool btnInventory; private Tool btnQuick; @@ -91,6 +94,54 @@ protected void onClick() { } } ); + add( btnExplore = new Tool( 127, 7, 21, 24 ) { + @Override + protected void onClick() { + Level level = Dungeon.level; + int cell = -1; + int dst = -1; + for (int i = 0; i < Level.LENGTH; i++) { + int type = Terrain.flags[level.map[i]]; + if (!level.visited[i] + && (type == Terrain.LOCKED_DOOR || (type & Terrain.PASSABLE) != 0 || (type & Terrain.AVOID) != 0)) { + for (int n : Level.NEIGHBOURS8) { + if (i+n < 0 || i+n >= Level.LENGTH) + continue; + + if (level.visited[i+n] && (Terrain.flags[level.map[i+n]] & Terrain.PASSABLE) != 0) { + int size = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ).size(); + if (size < dst || dst == -1) { + cell = i+n; + dst = size; + } + } + } + } + } + + if (cell == -1) { + for (int i = 0; i < Level.LENGTH; i++) { + if (!level.visited[i] && (Terrain.flags[level.map[i]] & Terrain.PASSABLE) != 0) { + for (int n : Level.NEIGHBOURS8) { + if (i+n < 0 || i+n >= Level.LENGTH) + continue; + + if (level.visited[i+n] && level.map[i+n] == Terrain.LOCKED_DOOR) { + int size = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ).size(); + if (size < dst || dst == -1) { + cell = i+n; + dst = size; + } + } + } + } + } + } + + GameScene.handleCell( cell ); + } + } ); + add( btnResume = new Tool( 61, 7, 21, 24 ) { @Override protected void onClick() { @@ -131,6 +182,7 @@ protected void layout() { btnWait.setPos( x, y ); btnSearch.setPos( btnWait.right(), y ); btnInfo.setPos( btnSearch.right(), y ); + btnExplore.setPos( btnInfo.right(), y ); btnResume.setPos( btnInfo.right(), y ); btnQuick.setPos( width - btnQuick.width(), y ); btnInventory.setPos( btnQuick.left() - btnInventory.width(), y ); @@ -151,6 +203,7 @@ public void update() { } btnResume.visible = Dungeon.hero.lastAction != null; + btnExplore.visible = !btnResume.visible; if (!Dungeon.hero.isAlive()) { btnInventory.enable( true ); From 714578935ba0c544d7348d7763af8d041a3bba74 Mon Sep 17 00:00:00 2001 From: RedHatter <_c_@mail.com> Date: Wed, 6 Aug 2014 14:15:03 -0700 Subject: [PATCH 4/5] Explore tool bug fix and refactoring. --- src/com/watabou/pixeldungeon/ui/Toolbar.java | 72 +++++++++++++------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/src/com/watabou/pixeldungeon/ui/Toolbar.java b/src/com/watabou/pixeldungeon/ui/Toolbar.java index 63efd3c3c3..1a003a1592 100644 --- a/src/com/watabou/pixeldungeon/ui/Toolbar.java +++ b/src/com/watabou/pixeldungeon/ui/Toolbar.java @@ -98,47 +98,69 @@ protected void onClick() { @Override protected void onClick() { Level level = Dungeon.level; - int cell = -1; - int dst = -1; + int[] cells = {-1, -1, -1}; + int[] dst = {-1, -1, -1}; for (int i = 0; i < Level.LENGTH; i++) { + if (level.visited[i]) + continue; + int type = Terrain.flags[level.map[i]]; - if (!level.visited[i] - && (type == Terrain.LOCKED_DOOR || (type & Terrain.PASSABLE) != 0 || (type & Terrain.AVOID) != 0)) { + if (type == Terrain.LOCKED_DOOR || (type & Terrain.PASSABLE) != 0) { for (int n : Level.NEIGHBOURS8) { - if (i+n < 0 || i+n >= Level.LENGTH) + if (i+n < 0 || i+n >= Level.LENGTH || !level.visited[i+n]) continue; - if (level.visited[i+n] && (Terrain.flags[level.map[i+n]] & Terrain.PASSABLE) != 0) { - int size = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ).size(); - if (size < dst || dst == -1) { - cell = i+n; - dst = size; + if ((Terrain.flags[level.map[i+n]] & Terrain.PASSABLE) != 0) { + PathFinder.Path p = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ); + if (p == null) + continue; + + int size = p.size(); + + if (size < dst[0] || dst[0] == -1) { + cells[0] = i+n; + dst[0] = size; + } + } else if (level.map[i+n] == Terrain.LOCKED_DOOR) { + PathFinder.Path p = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ); + if (p == null) + continue; + + int size = p.size(); + + if (size < dst[1] || dst[1] == -1) { + cells[1] = i+n; + dst[1] = size; } } } - } - } - - if (cell == -1) { - for (int i = 0; i < Level.LENGTH; i++) { - if (!level.visited[i] && (Terrain.flags[level.map[i]] & Terrain.PASSABLE) != 0) { + } else if ((type & Terrain.AVOID) != 0) { for (int n : Level.NEIGHBOURS8) { - if (i+n < 0 || i+n >= Level.LENGTH) + if (i+n < 0 || i+n >= Level.LENGTH + || !(level.visited[i+n] && (Terrain.flags[level.map[i+n]] & Terrain.PASSABLE) != 0)) continue; - if (level.visited[i+n] && level.map[i+n] == Terrain.LOCKED_DOOR) { - int size = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ).size(); - if (size < dst || dst == -1) { - cell = i+n; - dst = size; - } + PathFinder.Path p = PathFinder.find( Dungeon.hero.pos, i+n, level.passable ); + if (p == null) + continue; + + int size = p.size(); + + if (size < dst[2] || dst[2] == -1) { + cells[2] = i+n; + dst[2] = size; } } } } - } - GameScene.handleCell( cell ); + for (int cell : cells) { + if (cell == -1) + continue; + + GameScene.handleCell( cell ); + break; + } } } ); From 68148261a82b56709b0b41c77687c6b0605cae7b Mon Sep 17 00:00:00 2001 From: RedHatter <_c_@mail.com> Date: Wed, 6 Aug 2014 21:20:48 -0700 Subject: [PATCH 5/5] Continuous goto. --- .../watabou/pixeldungeon/PixelDungeon.java | 8 ++ src/com/watabou/pixeldungeon/Preferences.java | 1 + .../pixeldungeon/scenes/CellSelector.java | 82 +++++++++++++++++++ .../pixeldungeon/windows/WndSettings.java | 17 +++- 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/com/watabou/pixeldungeon/PixelDungeon.java b/src/com/watabou/pixeldungeon/PixelDungeon.java index 10feb32ee3..c7f61db7e4 100644 --- a/src/com/watabou/pixeldungeon/PixelDungeon.java +++ b/src/com/watabou/pixeldungeon/PixelDungeon.java @@ -206,6 +206,14 @@ public static void joystick( boolean value ) { public static boolean joystick () { return Preferences.INSTANCE.getBoolean( Preferences.KEY_JOYSTICK, true ); } + + public static void continuous( boolean value ) { + Preferences.INSTANCE.put( Preferences.KEY_CONTINUOUS, value ); + } + + public static boolean continuous () { + return Preferences.INSTANCE.getBoolean( Preferences.KEY_CONTINUOUS, true ); + } /* * <--- Preferences diff --git a/src/com/watabou/pixeldungeon/Preferences.java b/src/com/watabou/pixeldungeon/Preferences.java index 8aa6a9d81d..74b959a2af 100644 --- a/src/com/watabou/pixeldungeon/Preferences.java +++ b/src/com/watabou/pixeldungeon/Preferences.java @@ -35,6 +35,7 @@ enum Preferences { public static final String KEY_INTRO = "intro"; public static final String KEY_BRIGHTNESS = "brightness"; public static final String KEY_JOYSTICK = "joystick"; + public static final String KEY_CONTINUOUS = "continuous"; private SharedPreferences prefs; diff --git a/src/com/watabou/pixeldungeon/scenes/CellSelector.java b/src/com/watabou/pixeldungeon/scenes/CellSelector.java index dbfd1d6d27..1d3398238d 100644 --- a/src/com/watabou/pixeldungeon/scenes/CellSelector.java +++ b/src/com/watabou/pixeldungeon/scenes/CellSelector.java @@ -19,10 +19,14 @@ import com.watabou.input.Touchscreen.Touch; import com.watabou.noosa.TouchArea; +import com.watabou.noosa.Game; +import com.watabou.pixeldungeon.Dungeon; import com.watabou.pixeldungeon.DungeonTilemap; import com.watabou.pixeldungeon.PixelDungeon; +import com.watabou.pixeldungeon.levels.Level; import com.watabou.utils.GameMath; import com.watabou.utils.PointF; +import com.watabou.utils.Point; public class CellSelector extends TouchArea { @@ -31,6 +35,11 @@ public class CellSelector extends TouchArea { public boolean enabled; private float dragThreshold; + + private boolean pressed; + private float pressTime; + private boolean continuous; + private float continuousThreshold = 0.2f; public CellSelector( DungeonTilemap map ) { super( map ); @@ -73,6 +82,7 @@ public void select( int cell ) { @Override protected void onTouchDown( Touch t ) { + continuous = false; if (t != touch && another == null) { @@ -89,11 +99,80 @@ protected void onTouchDown( Touch t ) { startZoom = camera.zoom; dragging = false; + } else { + pressed = true; + } + } + + @Override + public void update () { + if (!pressed || dragging || pinching) + return; + + if (!(pressTime >= continuousThreshold)) { + pressTime += Game.elapsed; + return; + } + + continuous = PixelDungeon.continuous(); + if (!continuous) + return; + + float size = DungeonTilemap.SIZE*camera.zoom; + PointF p = Dungeon.hero.sprite.worldToCamera( Dungeon.hero.pos ); + Point hero = camera.cameraToScreen (p.x, p.y); + hero.x += size/2; + hero.y += size/2; + float x = Math.abs( touch.current.x - hero.x ); + float y = Math.abs( touch.current.y - hero.y ); + float x2 = 0, y2 = 0; + if (Math.abs(x) > Math.abs(y)) { + x2 += size; + y2 += (y*(x2/x)); + } else { + y2 += size; + x2 += (x*(y2/y)); } + + if (touch.current.x < hero.x) + x2 *= -1; + + if (touch.current.y < hero.y) + y2 *= -1; + + int cell = ((DungeonTilemap)target).screenToTile( hero.x + (int)x2, hero.y + (int)y2 ); + if (!Dungeon.level.passable[cell]) { + int[] neighbours = {Dungeon.hero.pos+1, + Dungeon.hero.pos+1+Level.WIDTH, + Dungeon.hero.pos+Level.WIDTH, + Dungeon.hero.pos-1+Level.WIDTH, + Dungeon.hero.pos-1, + Dungeon.hero.pos-1-Level.WIDTH, + Dungeon.hero.pos-Level.WIDTH, + Dungeon.hero.pos+1-Level.WIDTH}; + + for (int i = 0; i < 8; i++) { + if (neighbours[i] != cell) + continue; + + int next = (i+1 >= 8) ? 0 : i+1; + int prv = (i-1 < 0) ? 7 : i-1; + + if (Dungeon.level.passable[neighbours[next]]) + cell = neighbours[next]; + + if (Dungeon.level.passable[neighbours[prv]]) + cell = neighbours[prv]; + } + } + + select( cell ); } @Override protected void onTouchUp( Touch t ) { + pressed = false; + pressTime = 0; if (pinching && (t == touch || t == another)) { pinching = false; @@ -117,6 +196,9 @@ protected void onTouchUp( Touch t ) { @Override protected void onDrag( Touch t ) { + if (continuous) + return; + camera.target = null; if (pinching) { diff --git a/src/com/watabou/pixeldungeon/windows/WndSettings.java b/src/com/watabou/pixeldungeon/windows/WndSettings.java index 9b194445cd..fa9f32085b 100644 --- a/src/com/watabou/pixeldungeon/windows/WndSettings.java +++ b/src/com/watabou/pixeldungeon/windows/WndSettings.java @@ -41,6 +41,7 @@ public class WndSettings extends Window { private static final String TXT_BRIGHTNESS = "Brightness"; private static final String TXT_JOYSTICK = "Joystick"; + private static final String TXT_CONTINUOUS = "Continuous goto"; private static final String TXT_SWITCH_PORT = "Switch to portrait"; private static final String TXT_SWITCH_LAND = "Switch to landscape"; @@ -133,6 +134,18 @@ protected void onClick() { btnJoystick.setRect( 0, btnSound.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnJoystick.checked( PixelDungeon.joystick() ); add( btnJoystick ); + + CheckBox btnContinuous = new CheckBox( TXT_CONTINUOUS ) { + @Override + protected void onClick() { + super.onClick(); + PixelDungeon.continuous( checked() ); + Sample.INSTANCE.play( Assets.SND_CLICK ); + } + }; + btnContinuous.setRect( 0, btnJoystick.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnContinuous.checked( PixelDungeon.continuous() ); + add( btnContinuous ); if (!inGame) { @@ -142,7 +155,7 @@ protected void onClick() { PixelDungeon.landscape( !PixelDungeon.landscape() ); } }; - btnOrientation.setRect( 0, btnJoystick.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnOrientation.setRect( 0, btnContinuous.bottom() + GAP, WIDTH, BTN_HEIGHT ); add( btnOrientation ); resize( WIDTH, (int)btnOrientation.bottom() ); @@ -156,7 +169,7 @@ protected void onClick() { PixelDungeon.brightness( checked() ); } }; - btnBrightness.setRect( 0, btnJoystick.bottom() + GAP, WIDTH, BTN_HEIGHT ); + btnBrightness.setRect( 0, btnContinuous.bottom() + GAP, WIDTH, BTN_HEIGHT ); btnBrightness.checked( PixelDungeon.brightness() ); add( btnBrightness );