From 80a4ef2b9b8cdc71a01f32e6eee7f031c55e63b9 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 20 Jul 2016 01:19:18 -0400 Subject: [PATCH] v0.4.1: added a visual effect for adding items to the journal --- .../shatteredpixeldungeon/items/keys/Key.java | 3 ++- .../scenes/GameScene.java | 18 ++++++++++----- .../shatteredpixeldungeon/ui/StatusPane.java | 12 ++++++++++ .../shatteredpixeldungeon/ui/Toolbar.java | 22 +++++++++++++------ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java index 2b46a33b7..ce1a3e315 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java @@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.keys; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; @@ -44,7 +45,7 @@ public abstract class Key extends Item { @Override public boolean doPickUp(Hero hero) { - //TODO add a pickup animation to the journal + GameScene.pickUpJournal(this); Sample.INSTANCE.play( Assets.SND_ITEM ); hero.spendAndNext( TIME_TO_PICK_UP ); return true; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 4c5bff7cf..23cf1fcb1 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -109,6 +109,8 @@ public class GameScene extends PixelScene { private DungeonTilemap tiles; private FogOfWar fog; private HeroSprite hero; + + private StatusPane pane; private GameLog log; @@ -248,11 +250,11 @@ public class GameScene extends PixelScene { add( new HealthIndicator() ); add( cellSelector = new CellSelector( tiles ) ); - - StatusPane sb = new StatusPane(); - sb.camera = uiCamera; - sb.setSize( uiCamera.width, 0 ); - add( sb ); + + pane = new StatusPane(); + pane.camera = uiCamera; + pane.setSize( uiCamera.width, 0 ); + add( pane ); toolbar = new Toolbar(); toolbar.camera = uiCamera; @@ -284,7 +286,7 @@ public class GameScene extends PixelScene { busy = new BusyIndicator(); busy.camera = uiCamera; busy.x = 1; - busy.y = sb.bottom() + 1; + busy.y = pane.bottom() + 1; add( busy ); switch (InterlevelScene.mode) { @@ -656,6 +658,10 @@ public class GameScene extends PixelScene { scene.toolbar.pickup( item ); } + public static void pickUpJournal( Item item ) { + scene.pane.pickup( item ); + } + public static void resetMap() { if (scene != null) { scene.tiles.map(Dungeon.level.map, Level.WIDTH ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 8181d9c32..0b5187cba 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -24,6 +24,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle; +import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; @@ -69,6 +70,8 @@ public class StatusPane extends Component { private JournalButton btnJournal; private MenuButton btnMenu; + private Toolbar.PickedUpItem pickedUp; + @Override protected void createChildren() { @@ -135,6 +138,8 @@ public class StatusPane extends Component { buffs = new BuffIndicator( Dungeon.hero ); add( buffs ); + + add( pickedUp = new Toolbar.PickedUpItem()); } @Override @@ -218,6 +223,13 @@ public class StatusPane extends Component { } } + public void pickup( Item item ) { + pickedUp.reset( item, + btnJournal.icon.x + btnJournal.icon.width()/2f, + btnJournal.icon.y + btnJournal.icon.height()/2f, + true ); + } + private static class JournalButton extends Button { private Image bg; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java index 9b0da96b2..5aa806bcc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java @@ -267,7 +267,8 @@ public class Toolbar extends Component { public void pickup( Item item ) { pickedUp.reset( item, btnInventory.centerX(), - btnInventory.centerY() ); + btnInventory.centerY(), + false ); } private static CellSelector.Listener informer = new CellSelector.Listener() { @@ -376,7 +377,7 @@ public class Toolbar extends Component { } } - private static class PickedUpItem extends ItemSprite { + public static class PickedUpItem extends ItemSprite { private static final float DISTANCE = DungeonTilemap.SIZE; private static final float DURATION = 0.2f; @@ -384,6 +385,8 @@ public class Toolbar extends Component { private float dstX; private float dstY; private float left; + + private boolean rising = false; public PickedUpItem() { super(); @@ -395,19 +398,22 @@ public class Toolbar extends Component { false; } - public void reset( Item item, float dstX, float dstY ) { + public void reset( Item item, float dstX, float dstY, boolean rising ) { view( item ); active = visible = true; + + this.rising = rising; this.dstX = dstX - ItemSprite.SIZE / 2; this.dstY = dstY - ItemSprite.SIZE / 2; left = DURATION; - x = this.dstX - DISTANCE; - y = this.dstY - DISTANCE; + x = this.dstX - DISTANCE; + if (rising) y = this.dstY + DISTANCE; + else y = this.dstY - DISTANCE; alpha( 1 ); } @@ -426,8 +432,10 @@ public class Toolbar extends Component { float p = left / DURATION; scale.set( (float)Math.sqrt( p ) ); float offset = DISTANCE * p; - x = dstX - offset; - y = dstY - offset; + + x = dstX - offset; + if (rising) y = dstY + offset; + else y = dstY - offset; } } }