diff --git a/assets/hp_bar.png b/assets/hp_bar.png index c1868b931..d35ea3fe8 100644 Binary files a/assets/hp_bar.png and b/assets/hp_bar.png differ diff --git a/assets/menu_button.png b/assets/menu_button.png new file mode 100644 index 000000000..dd2478af1 Binary files /dev/null and b/assets/menu_button.png differ diff --git a/assets/status_pane.png b/assets/status_pane.png index 9bc121819..c74a87199 100644 Binary files a/assets/status_pane.png and b/assets/status_pane.png differ 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 ); }