From 08a719ffe293ac5a31734283e579ccfee3400d9e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 14 Jan 2020 16:04:51 -0500 Subject: [PATCH] v0.8.0: fixes/tweaks: - damage numbers now appear where a sprite is arriving if it is moving - blob emitters can now have a defined bound within a cell - tweaked hero level exit/entrance behaviour - refactored game actions that are defined in GameAction.java --- .../java/com/watabou/input/GameAction.java | 2 -- .../java/com/watabou/input/KeyBindings.java | 30 ++++++++++++------- .../main/java/com/watabou/noosa/Scene.java | 8 ----- .../java/com/watabou/noosa/ui/Button.java | 3 +- .../shatteredpixeldungeon/SPDAction.java | 12 +++++--- .../actors/hero/Hero.java | 11 +++++-- .../effects/BlobEmitter.java | 7 +++-- .../scenes/GameScene.java | 7 ----- .../sprites/CharSprite.java | 6 ++-- .../shatteredpixeldungeon/ui/Window.java | 8 +---- .../shatteredpixeldungeon/windows/WndBag.java | 12 ++++++-- .../windows/WndKeyBindings.java | 6 ++-- 12 files changed, 58 insertions(+), 54 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/input/GameAction.java b/SPD-classes/src/main/java/com/watabou/input/GameAction.java index 6612ce630..2e979d4d3 100644 --- a/SPD-classes/src/main/java/com/watabou/input/GameAction.java +++ b/SPD-classes/src/main/java/com/watabou/input/GameAction.java @@ -52,9 +52,7 @@ public class GameAction { } public static final GameAction NONE = new GameAction( "none" ); - public static final GameAction BACK = new GameAction( "back" ); - public static final GameAction MENU = new GameAction( "menu" ); public static ArrayList allActions(){ return new ArrayList<>(ALL_ACTIONS); diff --git a/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java b/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java index b4f0e7d8c..c52838f77 100644 --- a/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java +++ b/SPD-classes/src/main/java/com/watabou/input/KeyBindings.java @@ -32,14 +32,6 @@ public class KeyBindings { private static LinkedHashMap bindings = new LinkedHashMap<>(); - public static void addKeyBinding(int keyCode, GameAction action){ - bindings.put(keyCode, action); - } - - public static void clearKeyBindings(){ - bindings.clear(); - } - public static LinkedHashMap getAllBindings(){ return new LinkedHashMap<>(bindings); } @@ -48,20 +40,32 @@ public class KeyBindings { bindings = new LinkedHashMap<>(newBindings); } + //these are special keybinding that are not user-configurable + private static LinkedHashMap hardBindings = new LinkedHashMap<>(); + + public static void addHardBinding(int keyCode, GameAction action){ + hardBindings.put(keyCode, action); + } + public static boolean acceptUnbound = false; public static boolean isKeyBound(int keyCode){ if (keyCode <= 0 || keyCode > 255){ return false; } - return acceptUnbound || bindings.containsKey( keyCode ); + return acceptUnbound || bindings.containsKey( keyCode ) || hardBindings.containsKey( keyCode ); } public static GameAction getActionForKey(KeyEvent event){ - return bindings.get( event.code ); + if (bindings.containsKey( event.code )){ + return bindings.get( event.code ); + } else if (hardBindings.containsKey( event.code )) { + return hardBindings.get( event.code ); + } + return GameAction.NONE; } - public static ArrayList getKeysForAction(GameAction action){ + public static ArrayList getBoundKeysForAction(GameAction action){ ArrayList result = new ArrayList<>(); for( int i : bindings.keySet()){ if (bindings.get(i) == action){ @@ -76,6 +80,10 @@ public class KeyBindings { return "None"; } else if (keyCode == Input.Keys.PLUS){ return "+"; + } else if (keyCode == Input.Keys.BACKSPACE) { + return "Backspace"; + } else if (keyCode == Input.Keys.FORWARD_DEL) { + return "Delete"; } else { return Input.Keys.toString(keyCode); } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java index bdccfff4b..c4cd14a6b 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java @@ -37,10 +37,6 @@ public class Scene extends Group { if (Game.instance != null && event.pressed) { if (KeyBindings.getActionForKey( event ) == GameAction.BACK){ onBackPressed(); - - } else if (KeyBindings.getActionForKey( event ) == GameAction.MENU){ - onMenuPressed(); - } } return false; @@ -79,9 +75,5 @@ public class Scene extends Group { protected void onBackPressed() { Game.instance.finish(); } - - protected void onMenuPressed() { - - } } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java b/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java index ea1a0cefa..cdbcaee2c 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/ui/Button.java @@ -66,8 +66,7 @@ public class Button extends Component { KeyEvent.addKeyListener( keyListener = new Signal.Listener() { @Override public boolean onSignal ( KeyEvent event ) { - if ( active && !event.pressed - && KeyBindings.getActionForKey( event ) == keyAction()){ + if ( active && event.pressed && KeyBindings.getActionForKey( event ) == keyAction()){ onClick(); return true; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java index 8107c972d..190355f36 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDAction.java @@ -38,9 +38,7 @@ public class SPDAction extends GameAction { //--New references to existing actions from GameAction public static final GameAction NONE = GameAction.NONE; - public static final GameAction BACK = GameAction.BACK; - public static final GameAction MENU = GameAction.MENU; //-- public static final GameAction HERO_INFO = new SPDAction("hero_info"); @@ -75,8 +73,8 @@ public class SPDAction extends GameAction { private static final LinkedHashMap defaultBindings = new LinkedHashMap<>(); static { - defaultBindings.put( Input.Keys.BACK, SPDAction.BACK ); - defaultBindings.put( Input.Keys.MENU, SPDAction.MENU ); + defaultBindings.put( Input.Keys.ESCAPE, SPDAction.BACK ); + defaultBindings.put( Input.Keys.BACKSPACE, SPDAction.BACK ); defaultBindings.put( Input.Keys.H, SPDAction.HERO_INFO ); defaultBindings.put( Input.Keys.J, SPDAction.JOURNAL ); @@ -120,6 +118,12 @@ public class SPDAction extends GameAction { return new LinkedHashMap<>(defaultBindings); } + //hard bindings for android devices + static { + KeyBindings.addHardBinding( Input.Keys.BACK, SPDAction.BACK ); + KeyBindings.addHardBinding( Input.Keys.MENU, SPDAction.INVENTORY ); + } + //we only save/loads keys which differ from the default configuration. private static final String BINDINGS_FILE = "keybinds.dat"; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index bb4ae86c6..9f7aac5fa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -846,8 +846,10 @@ public class Hero extends Char { private boolean actDescend( HeroAction.Descend action ) { int stairs = action.dst; - if (pos == stairs && (Dungeon.level.map[pos] == Terrain.EXIT - || Dungeon.level.map[pos] == Terrain.UNLOCKED_EXIT)) { + + //there can be multiple exit tiles, so descend on any of them + //TODO this is slightly brittle, it assumes there are no disjointed sets of exit tiles + if ((Dungeon.level.map[pos] == Terrain.EXIT || Dungeon.level.map[pos] == Terrain.UNLOCKED_EXIT)) { curAction = null; @@ -873,7 +875,10 @@ public class Hero extends Char { private boolean actAscend( HeroAction.Ascend action ) { int stairs = action.dst; - if (pos == stairs && Dungeon.level.map[pos] == Terrain.ENTRANCE) { + + //there can be multiple entrance tiles, so descend on any of them + //TODO this is slightly brittle, it assumes there are no disjointed sets of entrance tiles + if (Dungeon.level.map[pos] == Terrain.ENTRANCE) { if (Dungeon.depth == 1) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java index 2bce7699a..05b1ca395 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; import com.watabou.noosa.particles.Emitter; import com.watabou.utils.Random; +import com.watabou.utils.RectF; public class BlobEmitter extends Emitter { @@ -38,6 +39,8 @@ public class BlobEmitter extends Emitter { this.blob = blob; blob.use( this ); } + + public RectF bound = new RectF(0, 0, 1, 1); @Override protected void emit( int index ) { @@ -59,8 +62,8 @@ public class BlobEmitter extends Emitter { if (cell < Dungeon.level.heroFOV.length && (Dungeon.level.heroFOV[cell] || blob.alwaysVisible) && map[cell] > 0) { - float x = (i + Random.Float()) * size; - float y = (j + Random.Float()) * size; + float x = (i + Random.Float(bound.left, bound.right)) * size; + float y = (j + Random.Float(bound.top, bound.bottom)) * size; factory.emit(this, index, x, y); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 94e62f43d..7e3549f74 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -650,13 +650,6 @@ public class GameScene extends PixelScene { add( new WndGame() ); } } - - @Override - protected void onMenuPressed() { - if (Dungeon.hero.ready) { - selectItem( null, WndBag.Mode.ALL, null ); - } - } public void addCustomTile( CustomTilemap visual){ customTiles.add( visual.create() ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index a3c3c77a4..4c1b87395 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -180,10 +180,12 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip if (args.length > 0) { text = Messages.format( text, args ); } + float x = destinationCenter().x; + float y = destinationCenter().y - height()/2f; if (ch != null) { - FloatingText.show( x + width() * 0.5f, y, ch.pos, text, color ); + FloatingText.show( x, y, ch.pos, text, color ); } else { - FloatingText.show( x + width() * 0.5f, y, text, color ); + FloatingText.show( x, y, text, color ); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java index 224f91bd5..8ac53b344 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java @@ -160,10 +160,6 @@ public class Window extends Group implements Signal.Listener { if (event.pressed) { if (KeyBindings.getActionForKey( event ) == SPDAction.BACK){ onBackPressed(); - - } else if (KeyBindings.getActionForKey( event ) == SPDAction.MENU){ - onMenuPressed(); - } } @@ -175,7 +171,5 @@ public class Window extends Group implements Signal.Listener { public void onBackPressed() { hide(); } - - public void onMenuPressed() { - } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index 013a13218..eab369b99 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.SPDAction; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem; @@ -55,6 +56,8 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.ItemSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock; import com.watabou.gltextures.TextureCache; +import com.watabou.input.KeyBindings; +import com.watabou.input.KeyEvent; import com.watabou.noosa.BitmapText; import com.watabou.noosa.ColorBlock; import com.watabou.noosa.Game; @@ -244,11 +247,14 @@ public class WndBag extends WndTabbed { count++; } - + @Override - public void onMenuPressed() { - if (listener == null) { + public boolean onSignal(KeyEvent event) { + if (event.pressed && KeyBindings.getActionForKey( event ) == SPDAction.INVENTORY) { hide(); + return true; + } else { + return super.onSignal(event); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java index 0537281da..f0d2af8f5 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndKeyBindings.java @@ -99,8 +99,8 @@ public class WndKeyBindings extends Window { int y = 0; for (GameAction action : GameAction.allActions()){ - //start at 3. No bindings for NONE, BACK, and MENU atm - if (action.code() < 3) continue; + //start at 1. No bindings for NONE + if (action.code() < 1) continue; BindingItem item = new BindingItem(action); item.setRect(0, y, WIDTH, BindingItem.HEIGHT); @@ -192,7 +192,7 @@ public class WndKeyBindings extends Window { actionName.setHightlighting(false); add(actionName); - ArrayList keys = KeyBindings.getKeysForAction(action); + ArrayList keys = KeyBindings.getBoundKeysForAction(action); origKey1 = key1 = keys.isEmpty() ? 0 : keys.remove(0); origKey2 = key2 = keys.isEmpty() ? 0 : keys.remove(0);