From 697c81455188e38f166325d0d67d1ae4d9edeba7 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 31 Aug 2017 02:49:10 -0400 Subject: [PATCH] v0.6.2: improved visuals for picked up items --- .../shatteredpixeldungeon/items/Gold.java | 2 +- .../shatteredpixeldungeon/items/Item.java | 2 +- .../items/journal/DocumentPage.java | 2 +- .../shatteredpixeldungeon/items/keys/Key.java | 2 +- .../scenes/GameScene.java | 8 +-- .../shatteredpixeldungeon/ui/StatusPane.java | 8 +-- .../shatteredpixeldungeon/ui/Toolbar.java | 52 ++++++++++--------- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Gold.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Gold.java index 583576acf..f3981c3b0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Gold.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Gold.java @@ -69,7 +69,7 @@ public class Gold extends Item { if (thievery != null) thievery.collect(quantity); - GameScene.pickUp( this ); + GameScene.pickUp( this, hero.pos ); hero.sprite.showStatus( CharSprite.NEUTRAL, TXT_VALUE, quantity ); hero.spendAndNext( TIME_TO_PICK_UP ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index a669146a2..239b9ff3a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -104,7 +104,7 @@ public class Item implements Bundlable { public boolean doPickUp( Hero hero ) { if (collect( hero.belongings.backpack )) { - GameScene.pickUp( this ); + GameScene.pickUp( this, hero.pos ); Sample.INSTANCE.play( Assets.SND_ITEM ); hero.spendAndNext( TIME_TO_PICK_UP ); return true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/journal/DocumentPage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/journal/DocumentPage.java index b7e1a7c6e..480b06943 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/journal/DocumentPage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/journal/DocumentPage.java @@ -51,7 +51,7 @@ public abstract class DocumentPage extends Item { @Override public final boolean doPickUp(Hero hero) { - GameScene.pickUpJournal(this); + GameScene.pickUpJournal(this, hero.pos); GameScene.flashJournal(); WndJournal.last_index = 0; document().addPage(page); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java index 028e9a430..17ddc57e0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java @@ -49,7 +49,7 @@ public abstract class Key extends Item { @Override public boolean doPickUp(Hero hero) { - GameScene.pickUpJournal(this); + GameScene.pickUpJournal(this, hero.pos); WndJournal.last_index = 1; Notes.add(this); Sample.INSTANCE.play( Assets.SND_ITEM ); 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 994b5cb81..11cd01d23 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -729,12 +729,12 @@ public class GameScene extends PixelScene { return scene != null ? (FloatingText)scene.statuses.recycle( FloatingText.class ) : null; } - public static void pickUp( Item item ) { - if (scene != null) scene.toolbar.pickup( item ); + public static void pickUp( Item item, int pos ) { + if (scene != null) scene.toolbar.pickup( item, pos ); } - public static void pickUpJournal( Item item ) { - if (scene != null) scene.pane.pickup( item ); + public static void pickUpJournal( Item item, int pos ) { + if (scene != null) scene.pane.pickup( item, pos ); } public static void flashJournal(){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 131d9f74a..e3888d4bb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -221,11 +221,11 @@ public class StatusPane extends Component { } } - public void pickup( Item item ) { + public void pickup( Item item, int cell) { pickedUp.reset( item, - btnJournal.icon.x + btnJournal.icon.width()/2f, - btnJournal.icon.y + btnJournal.icon.height()/2f, - true ); + cell, + btnJournal.icon.x + btnJournal.icon.width()/2f, + btnJournal.icon.y + btnJournal.icon.height()/2f); } public void flash(){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index cec9ea897..b97b77bfa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -29,14 +29,17 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; -import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap; +import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal; +import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Gizmo; import com.watabou.noosa.Image; import com.watabou.noosa.ui.Button; import com.watabou.noosa.ui.Component; +import com.watabou.utils.Point; +import com.watabou.utils.PointF; public class Toolbar extends Component { @@ -265,11 +268,11 @@ public class Toolbar extends Component { } } - public void pickup( Item item ) { + public void pickup( Item item, int cell ) { pickedUp.reset( item, + cell, btnInventory.centerX(), - btnInventory.centerY(), - false ); + btnInventory.centerY()); } private static CellSelector.Listener informer = new CellSelector.Listener() { @@ -380,14 +383,12 @@ public class Toolbar extends Component { public static class PickedUpItem extends ItemSprite { - private static final float DISTANCE = DungeonTilemap.SIZE; - private static final float DURATION = 0.2f; + private static final float DURATION = 0.5f; - private float dstX; - private float dstY; + private float startScale; + private float startX, startY; + private float endX, endY; private float left; - - private boolean rising = false; public PickedUpItem() { super(); @@ -399,23 +400,26 @@ public class Toolbar extends Component { false; } - public void reset( Item item, float dstX, float dstY, boolean rising ) { + public void reset( Item item, int cell, float endX, float endY ) { view( item ); active = visible = true; - - this.rising = rising; - this.dstX = dstX - ItemSprite.SIZE / 2; - this.dstY = dstY - ItemSprite.SIZE / 2; + PointF tile = DungeonTerrainTilemap.raisedTileCenterToWorld(cell); + Point screen = Camera.main.cameraToScreen(tile.x, tile.y); + PointF start = camera().screenToCamera(screen.x, screen.y); + + x = this.startX = start.x - ItemSprite.SIZE / 2; + y = this.startY = start.y - ItemSprite.SIZE / 2; + + this.endX = endX - ItemSprite.SIZE / 2; + this.endY = endY - ItemSprite.SIZE / 2; left = DURATION; - x = this.dstX - DISTANCE; - if (rising) y = this.dstY + DISTANCE; - else y = this.dstY - DISTANCE; - alpha( 1 ); + scale.set( startScale = Camera.main.zoom / camera().zoom ); + } @Override @@ -431,12 +435,10 @@ public class Toolbar extends Component { } else { float p = left / DURATION; - scale.set( (float)Math.sqrt( p ) ); - float offset = DISTANCE * p; - - x = dstX - offset; - if (rising) y = dstY + offset; - else y = dstY - offset; + scale.set( startScale * (float)Math.sqrt( p ) ); + + x = startX*p + endX*(1-p); + y = startY*p + endY*(1-p); } } }