From eed06b618dcf78b8933d11de97df7e48a213c0b8 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 3 Jul 2016 17:39:36 -0400 Subject: [PATCH] v0.4.1: big changes to key functionality --- assets/hp_bar.png | Bin 2804 -> 2806 bytes assets/menu_button.png | Bin 0 -> 330 bytes assets/status_pane.png | Bin 1049 -> 941 bytes .../shatteredpixeldungeon/Assets.java | 1 + .../actors/hero/Belongings.java | 49 ++++---- .../actors/hero/Hero.java | 56 +++++---- .../items/keys/GoldenKey.java | 10 +- .../items/keys/IronKey.java | 26 ++--- .../shatteredpixeldungeon/items/keys/Key.java | 15 ++- .../items/keys/SkeletonKey.java | 8 ++ .../shatteredpixeldungeon/ui/StatusPane.java | 109 ++++++++++++++---- 11 files changed, 175 insertions(+), 99 deletions(-) create mode 100644 assets/menu_button.png diff --git a/assets/hp_bar.png b/assets/hp_bar.png index c1868b931b810cb589588479c5016cca1da58fe0..d35ea3fe85c87f11c3aa25dc1cc049908160c436 100644 GIT binary patch delta 118 zcmV-+0Ez$f74{XdZwd)M06+ja$j!J=lXwaqVBiM>1r<7tcR!H;002HoL_t(I%VXRh zVELb6cmPHi!*RoLqBXJHy7zThc|QHpC6Y96e<08qLhk5|O9p8KJ0$BzC Y00u7*_lMbVOaK4?07*qoM6N<$g4p{n2><{9 delta 116 zcmV-)0E_?j74#LbZwd+j0RI60puMM)lXwaqUf&A|2L=n_qY_F0002BmL_t(I%VXRh zVELb6hyuqA#~CR#gXPw}uS3%F>6b1sQo|gUx4#&Noad`4X35HNe6mbx zLKFKAk(^sgc*73#J0JZ2|8x0ui9hU2bHXy1MH`O%D4g-3*e-;TnNN61+2ha+FaQ7f z|HC)nR_}cl)dkWUwQj`mF`2pva0MUiGEOL1#qN}-W#Gm-gNr4wkztn&L&>b^MXZ-? R_5)qV;OXk;vd$@?2>_coZWRCk literal 0 HcmV?d00001 diff --git a/assets/status_pane.png b/assets/status_pane.png index 9bc121819370d9082dc2beb2342b8a75df13d706..c74a871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ato#Ms**yCO-Lwq=0000MOtM5 diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java index 8fa023f4c..0e9a56258 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java @@ -34,6 +34,7 @@ public class Assets { public static final String CHROME = "chrome.png"; public static final String ICONS = "icons.png"; public static final String STATUS = "status_pane.png"; + public static final String MENU = "menu_button.png"; public static final String HP_BAR = "hp_bar.png"; public static final String SHLD_BAR = "shield_bar.png"; public static final String XP_BAR = "exp_bar.png"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 931dc39d4..5355f0307 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -21,7 +21,6 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.hero; import com.shatteredpixel.shatteredpixeldungeon.Badges; -import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; @@ -49,6 +48,9 @@ public class Belongings implements Iterable { public Armor armor = null; public KindofMisc misc1 = null; public KindofMisc misc2 = null; + + public int[] ironKeys = new int[26]; + public int[] specialKeys = new int[26]; //golden or boss keys public Belongings( Hero owner ) { this.owner = owner; @@ -63,7 +65,10 @@ public class Belongings implements Iterable { private static final String WEAPON = "weapon"; private static final String ARMOR = "armor"; private static final String MISC1 = "misc1"; - private static final String MISC2 = "misc2"; + private static final String MISC2 = "misc2"; + + private static final String IRON_KEYS = "ironKeys"; + private static final String SPECIAL_KEYS = "specialKeys"; public void storeInBundle( Bundle bundle ) { @@ -73,13 +78,30 @@ public class Belongings implements Iterable { bundle.put( ARMOR, armor ); bundle.put( MISC1, misc1); bundle.put( MISC2, misc2); + + bundle.put( IRON_KEYS, ironKeys); + bundle.put( SPECIAL_KEYS, specialKeys); } public void restoreFromBundle( Bundle bundle ) { + + if (bundle.contains(IRON_KEYS)) ironKeys = bundle.getIntArray( IRON_KEYS ); + if (bundle.contains(SPECIAL_KEYS)) specialKeys = bundle.getIntArray( SPECIAL_KEYS ); backpack.clear(); backpack.restoreFromBundle( bundle ); + //removing keys, from pre-0.4.1 saves + for (Item item : backpack.items.toArray(new Item[0])){ + if (item instanceof Key){ + item.detachAll(backpack); + if (item instanceof IronKey) + ironKeys[((Key) item).depth] += item.quantity(); + else + specialKeys[((Key) item).depth] += item.quantity(); + } + } + if (bundle.get( WEAPON ) instanceof Wand){ //handles the case of an equipped wand from pre-0.3.0 Wand item = (Wand) bundle.get(WEAPON); @@ -123,29 +145,6 @@ public class Belongings implements Iterable { return null; } - @SuppressWarnings("unchecked") - public T getKey( Class kind, int depth ) { - - for (Item item : backpack) { - if (item.getClass() == kind && ((Key)item).depth == depth) { - return (T)item; - } - } - - return null; - } - - public void countIronKeys() { - - IronKey.curDepthQuantity = 0; - - for (Item item : backpack) { - if (item instanceof IronKey && ((IronKey)item).depth == Dungeon.depth) { - IronKey.curDepthQuantity += item.quantity(); - } - } - } - public void identify() { for (Item item : this) { item.identify(); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index f389853ad..7ce2ae054 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -65,10 +65,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.EtherealChains; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TalismanOfForesight; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourglass; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfMight; import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfStrength; @@ -638,7 +635,8 @@ public class Hero extends Char { if (item instanceof Dewdrop || item instanceof TimekeepersHourglass.sandBag - || item instanceof DriedRose.Petal) { + || item instanceof DriedRose.Petal + || item instanceof Key) { //Do Nothing } else { @@ -682,18 +680,14 @@ public class Hero extends Char { Heap heap = Dungeon.level.heaps.get( dst ); if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) { - - theKey = null; - if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST) { + if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST + && belongings.specialKeys[Dungeon.depth] < 1) { - theKey = belongings.getKey( GoldenKey.class, Dungeon.depth ); - - if (theKey == null) { GLog.w( Messages.get(this, "locked_chest") ); ready(); return false; - } + } switch (heap.type) { @@ -731,20 +725,22 @@ public class Hero extends Char { int doorCell = action.dst; if (Level.adjacent( pos, doorCell )) { - theKey = null; + boolean hasKey = false; int door = Dungeon.level.map[doorCell]; - if (door == Terrain.LOCKED_DOOR) { + if (door == Terrain.LOCKED_DOOR + && belongings.ironKeys[Dungeon.depth] > 0) { - theKey = belongings.getKey( IronKey.class, Dungeon.depth ); + hasKey = true; - } else if (door == Terrain.LOCKED_EXIT) { - - theKey = belongings.getKey( SkeletonKey.class, Dungeon.depth ); + } else if (door == Terrain.LOCKED_EXIT + && belongings.specialKeys[Dungeon.depth] > 0) { + + hasKey = true; } - if (theKey != null) { + if (hasKey) { spend( Key.TIME_TO_UNLOCK ); sprite.operate( doorCell ); @@ -1382,28 +1378,28 @@ public class Hero extends Char { public void onOperateComplete() { if (curAction instanceof HeroAction.Unlock) { - - if (theKey != null) { - theKey.detach( belongings.backpack ); - theKey = null; - } - + int doorCell = ((HeroAction.Unlock)curAction).dst; int door = Dungeon.level.map[doorCell]; + + if (door == Terrain.LOCKED_DOOR){ + belongings.ironKeys[Dungeon.depth]--; + Level.set( doorCell, Terrain.DOOR ); + } else { + belongings.specialKeys[Dungeon.depth]--; + Level.set( doorCell, Terrain.UNLOCKED_EXIT ); + } Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT ); GameScene.updateMap( doorCell ); } else if (curAction instanceof HeroAction.OpenChest) { - - if (theKey != null) { - theKey.detach( belongings.backpack ); - theKey = null; - } - + Heap heap = Dungeon.level.heaps.get( ((HeroAction.OpenChest)curAction).dst ); if (heap.type == Type.SKELETON || heap.type == Type.REMAINS) { Sample.INSTANCE.play( Assets.SND_BONES ); + } else if (heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST){ + belongings.specialKeys[Dungeon.depth]--; } heap.open( this ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java index 7fb038ed9..b53e76941 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java @@ -20,6 +20,8 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.keys; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; public class GoldenKey extends Key { @@ -27,7 +29,13 @@ public class GoldenKey extends Key { { image = ItemSpriteSheet.GOLDEN_KEY; } - + + @Override + public boolean doPickUp(Hero hero) { + Dungeon.hero.belongings.specialKeys[Dungeon.depth]++; + return super.doPickUp(hero); + } + public GoldenKey() { this( 0 ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java index 2473f331c..59c598bdc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java @@ -21,7 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.keys; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; public class IronKey extends Key { @@ -31,7 +31,13 @@ public class IronKey extends Key { { image = ItemSpriteSheet.IRON_KEY; } - + + @Override + public boolean doPickUp(Hero hero) { + Dungeon.hero.belongings.ironKeys[Dungeon.depth]++; + return super.doPickUp(hero); + } + public IronKey() { this( 0 ); } @@ -40,21 +46,5 @@ public class IronKey extends Key { super(); this.depth = depth; } - - @Override - public boolean collect( Bag bag ) { - boolean result = super.collect( bag ); - if (result && depth == Dungeon.depth && Dungeon.hero != null) { - Dungeon.hero.belongings.countIronKeys(); - } - return result; - } - - @Override - public void onDetach( ) { - if (depth == Dungeon.depth) { - Dungeon.hero.belongings.countIronKeys(); - } - } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java index 4e3c94956..2b46a33b7 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/Key.java @@ -20,10 +20,13 @@ */ 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.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; -public class Key extends Item { +public abstract class Key extends Item { public static final float TIME_TO_UNLOCK = 1f; @@ -38,7 +41,15 @@ public class Key extends Item { public boolean isSimilar( Item item ) { return item.getClass() == getClass() && ((Key)item).depth == depth; } - + + @Override + public boolean doPickUp(Hero hero) { + //TODO add a pickup animation to the journal + Sample.INSTANCE.play( Assets.SND_ITEM ); + hero.spendAndNext( TIME_TO_PICK_UP ); + return true; + } + private static final String DEPTH = "depth"; @Override diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java index 4c28d87cf..df817dfd7 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java @@ -20,6 +20,8 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.keys; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; @@ -38,6 +40,12 @@ public class SkeletonKey extends Key { super(); this.depth = depth; } + + @Override + public boolean doPickUp(Hero hero) { + Dungeon.hero.belongings.specialKeys[Dungeon.depth]++; + return super.doPickUp(hero); + } @Override public boolean isSimilar( Item item ) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java index 6d4c700e2..63bf56401 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -22,15 +22,14 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame; import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal; import com.watabou.input.Touchscreen.Touch; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; @@ -63,18 +62,18 @@ public class StatusPane extends Component { private BitmapText level; private BitmapText depth; - private BitmapText keys; private DangerIndicator danger; private BuffIndicator buffs; private Compass compass; + private JournalButton btnJournal; private MenuButton btnMenu; @Override protected void createChildren() { - bg = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 ); + bg = new NinePatch( Assets.STATUS, 85, 0, 45, 0 ); add( bg ); add( new TouchArea( 0, 1, 31, 31 ) { @@ -85,9 +84,12 @@ public class StatusPane extends Component { Camera.main.focusOn( sprite ); } GameScene.show( new WndHero() ); - }; + } } ); + btnJournal = new JournalButton(); + add( btnJournal ); + btnMenu = new MenuButton(); add( btnMenu ); @@ -129,11 +131,6 @@ public class StatusPane extends Component { depth.measure(); add( depth ); - Dungeon.hero.belongings.countIronKeys(); - keys = new BitmapText( PixelScene.pixelFont); - keys.hardlight( 0xCACFC2 ); - add( keys ); - danger = new DangerIndicator(); add( danger ); @@ -161,15 +158,15 @@ public class StatusPane extends Component { bossHP.setPos( 6 + (width - bossHP.width())/2, 20); - depth.x = width - 24 - depth.width() - 18; - depth.y = 6; - - keys.y = 6; + depth.x = width - 35.5f - depth.width() / 2f; + depth.y = 8f - depth.baseLine() / 2f; danger.setPos( width - danger.width(), 20 ); buffs.setPos( 31, 9 ); + btnJournal.setPos( width - 42, 1 ); + btnMenu.setPos( width - btnMenu.width(), 1 ); } @@ -215,14 +212,6 @@ public class StatusPane extends Component { PixelScene.align(level); } - int k = IronKey.curDepthQuantity; - if (k != lastKeys) { - lastKeys = k; - keys.text( Integer.toString( lastKeys ) ); - keys.measure(); - keys.x = width - 8 - keys.width() - 18; - } - int tier = Dungeon.hero.tier(); if (tier != lastTier) { lastTier = tier; @@ -230,6 +219,80 @@ public class StatusPane extends Component { } } + private static class JournalButton extends Button { + + private Image bg; + private Image icon; + + public JournalButton() { + super(); + + width = bg.width + 13; //includes the depth display to the left + height = bg.height + 4; + } + + @Override + protected void createChildren() { + super.createChildren(); + + bg = new Image( Assets.MENU, 2, 2, 13, 11 ); + add( bg ); + + icon = new Image( Assets.MENU, 32, 1, 10, 6); + add( icon ); + } + + @Override + protected void layout() { + super.layout(); + + bg.x = x + 13; + bg.y = y + 2; + + icon.x = bg.x + 2; + icon.y = bg.y + 3; + } + + @Override + public void update() { + super.update(); + + + for (int i = 1; i <= Dungeon.depth; i++){ + if (Dungeon.hero.belongings.ironKeys[i] > 0){ + + if (i == Dungeon.depth){ + icon.resetColor(); + } else { + icon.brightness(0); + icon.alpha(0.67f); + } + return; + } + } + + icon.brightness(0); + icon.alpha(0.33f); + } + + @Override + protected void onTouchDown() { + bg.brightness( 1.5f ); + Sample.INSTANCE.play( Assets.SND_CLICK ); + } + + @Override + protected void onTouchUp() { + bg.resetColor(); + } + + @Override + protected void onClick() { + GameScene.show( new WndJournal() ); + } + + } + private static class MenuButton extends Button { private Image image; @@ -245,7 +308,7 @@ public class StatusPane extends Component { protected void createChildren() { super.createChildren(); - image = new Image( Assets.STATUS, 114, 3, 12, 11 ); + image = new Image( Assets.MENU, 17, 2, 12, 11 ); add( image ); }