From dc4d928da0ae410db64b390e6a0491bebb0d06ac Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 10 Jul 2017 05:20:31 -0400 Subject: [PATCH] v0.6.1: refactored keys, now stored in notes --- .../shatteredpixeldungeon/Dungeon.java | 5 +- .../actors/hero/Belongings.java | 47 ++-- .../actors/hero/Hero.java | 16 +- .../items/keys/GoldenKey.java | 8 - .../items/keys/IronKey.java | 8 - .../shatteredpixeldungeon/items/keys/Key.java | 2 + .../items/keys/SkeletonKey.java | 15 -- .../shatteredpixeldungeon/journal/Notes.java | 213 ++++++++++++++---- .../levels/traps/DistortionTrap.java | 8 +- .../messages/Messages.java | 1 + .../shatteredpixeldungeon/ui/StatusPane.java | 29 ++- .../windows/WndJournal.java | 48 +--- .../messages/journal/journal.properties | 20 +- 13 files changed, 245 insertions(+), 175 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index f5711f5ab..c08ba9e2c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -602,6 +602,8 @@ public class Dungeon { Badges.reset(); } + Notes.restoreFromBundle( bundle ); + hero = null; hero = (Hero)bundle.get( HERO ); @@ -609,10 +611,9 @@ public class Dungeon { depth = bundle.getInt( DEPTH ); Statistics.restoreFromBundle( bundle ); - Notes.restoreFromBundle( bundle ); Generator.restoreFromBundle( bundle ); - droppedItems = new SparseArray>(); + droppedItems = new SparseArray<>(); for (int i=2; i <= Statistics.deepestFloor + 1; i++) { ArrayList dropped = new ArrayList(); if (bundle.contains(Messages.format( DROPPED, i ))) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index 566c5ae47..2281ecdce 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -27,10 +27,13 @@ import com.shatteredpixel.shatteredpixeldungeon.items.KindOfWeapon; import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag; +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.scrolls.ScrollOfRemoveCurse; import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand; +import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Bundle; import com.watabou.utils.Random; @@ -49,9 +52,6 @@ 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; @@ -68,9 +68,6 @@ public class Belongings implements Iterable { private static final String MISC1 = "misc1"; 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 ) { backpack.storeInBundle( bundle ); @@ -79,29 +76,35 @@ 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 ); + //moving keys to Notes, for pre-0.6.1 saves + if (bundle.contains("ironKeys")) { + int[] ironKeys = bundle.getIntArray( "ironKeys" ); + for (int i = 0; i < ironKeys.length; i++){ + if (ironKeys[i] > 0){ + Notes.add((Key) new IronKey(i).quantity(ironKeys[i])); + } + } + } + + if (bundle.contains("specialKeys")) { + int[] specialKeys = bundle.getIntArray( "specialKeys" ); + for (int i = 0; i < specialKeys.length; i++){ + if (specialKeys[i] > 0){ + if (i % 5 == 0){ + Notes.add((Key) new GoldenKey(i).quantity(specialKeys[i])); + } else { + Notes.add((Key) new SkeletonKey(i).quantity(specialKeys[i])); + } + } + } + } 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(); - } - } weapon = (KindOfWeapon) bundle.get(WEAPON); if (weapon != null) { 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 a1972fcab..288fb6e31 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 @@ -68,7 +68,10 @@ import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.EtherealChains; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HornOfPlenty; 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; @@ -86,6 +89,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.Flail; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon; +import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.features.AlchemyPot; @@ -717,7 +721,7 @@ public class Hero extends Char { if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) { if ((heap.type == Type.LOCKED_CHEST || heap.type == Type.CRYSTAL_CHEST) - && belongings.specialKeys[Dungeon.depth] < 1) { + && Notes.keyCount(new GoldenKey(Dungeon.depth)) < 1) { GLog.w( Messages.get(this, "locked_chest") ); ready(); @@ -764,12 +768,12 @@ public class Hero extends Char { int door = Dungeon.level.map[doorCell]; if (door == Terrain.LOCKED_DOOR - && belongings.ironKeys[Dungeon.depth] > 0) { + && Notes.keyCount(new IronKey(Dungeon.depth)) > 0) { hasKey = true; } else if (door == Terrain.LOCKED_EXIT - && belongings.specialKeys[Dungeon.depth] > 0) { + && Notes.keyCount(new GoldenKey(Dungeon.depth)) > 0) { hasKey = true; @@ -1459,10 +1463,10 @@ public class Hero extends Char { int door = Dungeon.level.map[doorCell]; if (door == Terrain.LOCKED_DOOR){ - belongings.ironKeys[Dungeon.depth]--; + Notes.remove(new IronKey(Dungeon.depth)); Level.set( doorCell, Terrain.DOOR ); } else { - belongings.specialKeys[Dungeon.depth]--; + Notes.remove(new SkeletonKey(Dungeon.depth)); Level.set( doorCell, Terrain.UNLOCKED_EXIT ); } StatusPane.needsKeyUpdate = true; @@ -1476,7 +1480,7 @@ public class Hero extends Char { 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]--; + Notes.remove(new GoldenKey(Dungeon.depth)); } StatusPane.needsKeyUpdate = true; heap.open( this ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java index bedff41ec..bd7bd4647 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/GoldenKey.java @@ -21,8 +21,6 @@ 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 { @@ -31,12 +29,6 @@ public class GoldenKey extends Key { image = ItemSpriteSheet.GOLDEN_KEY; } - @Override - public boolean doPickUp(Hero hero) { - Dungeon.hero.belongings.specialKeys[depth] += quantity(); - return super.doPickUp(hero); - } - public GoldenKey() { this( 0 ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java index 83c3b7c7f..750da26aa 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/IronKey.java @@ -21,8 +21,6 @@ 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 IronKey extends Key { @@ -31,12 +29,6 @@ public class IronKey extends Key { image = ItemSpriteSheet.IRON_KEY; } - @Override - public boolean doPickUp(Hero hero) { - Dungeon.hero.belongings.ironKeys[depth] += quantity(); - return super.doPickUp(hero); - } - public IronKey() { this( 0 ); } 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 c4b82e93e..1053416ae 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 @@ -24,6 +24,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.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane; import com.watabou.noosa.audio.Sample; @@ -48,6 +49,7 @@ public abstract class Key extends Item { @Override public boolean doPickUp(Hero hero) { GameScene.pickUpJournal(this); + Notes.add(this); Sample.INSTANCE.play( Assets.SND_ITEM ); hero.spendAndNext( TIME_TO_PICK_UP ); StatusPane.needsKeyUpdate = true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java index 041cc6ac4..18ebeca60 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/keys/SkeletonKey.java @@ -21,16 +21,12 @@ 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; public class SkeletonKey extends Key { { image = ItemSpriteSheet.SKELETON_KEY; - stackable = false; } public SkeletonKey() { @@ -42,15 +38,4 @@ public class SkeletonKey extends Key { this.depth = depth; } - @Override - public boolean doPickUp(Hero hero) { - Dungeon.hero.belongings.specialKeys[depth]++; - return super.doPickUp(hero); - } - - @Override - public boolean isSimilar( Item item ) { - return false; - } - } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Notes.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Notes.java index 7975c8511..d9acb961b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Notes.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/journal/Notes.java @@ -22,14 +22,47 @@ package com.shatteredpixel.shatteredpixeldungeon.journal; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; import java.util.ArrayList; +import java.util.Collections; public class Notes { + + public static abstract class Record implements Comparable, Bundlable { + + protected int depth; + public int depth(){ + return depth; + } + + public abstract String desc(); + + @Override + public abstract boolean equals(Object obj); + + @Override + public int compareTo( Record another ) { + return another.depth() - depth(); + } + + private static final String DEPTH = "depth"; + + @Override + public void restoreFromBundle( Bundle bundle ) { + depth = bundle.getInt( DEPTH ); + } + + @Override + public void storeInBundle( Bundle bundle ) { + bundle.put( DEPTH, depth ); + } + } + public enum Landmark { WELL_OF_HEALTH, WELL_OF_AWARENESS, @@ -42,94 +75,178 @@ public class Notes { WANDMAKER, TROLL, IMP; - + public String desc() { return Messages.get(this, name()); } - }; + } - public static class Record implements Comparable, Bundlable { + public static class LandmarkRecord extends Record { - //compatibility with pre-0.6.1 saves - private static final String FEATURE = "feature"; + protected Landmark landmark; - private static final String LANDMARK = "landmark"; + public LandmarkRecord() {} - private static final String DEPTH = "depth"; - - public Landmark landmark; - - public int depth; - - public Record() { - } - - public Record(Landmark landmark, int depth ) { + public LandmarkRecord(Landmark landmark, int depth ) { this.landmark = landmark; this.depth = depth; } - + @Override - public int compareTo( Record another ) { - return another.depth - depth; + public String desc() { + return landmark.desc(); } - + @Override - public void restoreFromBundle( Bundle bundle ) { - if (bundle.contains(FEATURE)) { - landmark = Landmark.valueOf(bundle.getString(FEATURE)); - } else { - landmark = Landmark.valueOf(bundle.getString(LANDMARK)); - } - depth = bundle.getInt( DEPTH ); + public boolean equals(Object obj) { + return (obj instanceof LandmarkRecord) + && landmark == ((LandmarkRecord) obj).landmark + && depth() == ((LandmarkRecord) obj).depth(); } - + + private static final String LANDMARK = "landmark"; + @Override - public void storeInBundle( Bundle bundle ) { + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + landmark = Landmark.valueOf(bundle.getString(LANDMARK)); + } + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); bundle.put( LANDMARK, landmark.toString() ); - bundle.put( DEPTH, depth ); } } - public static ArrayList records; + public static class KeyRecord extends Record { + + protected Key key; + + public KeyRecord() {} + + public KeyRecord( Key key ){ + this.key = key; + } + + @Override + public int depth() { + return key.depth; + } + + @Override + public String desc() { + return key.toString(); + } + + public Class type(){ + return key.getClass(); + } + + public int quantity(){ + return key.quantity(); + } + + public void quantity(int num){ + key.quantity(num); + } + + @Override + public boolean equals(Object obj) { + return (obj instanceof KeyRecord) + && key.isSimilar(((KeyRecord) obj).key); + } + + private static final String KEY = "key"; + + @Override + public void restoreFromBundle(Bundle bundle) { + super.restoreFromBundle(bundle); + key = (Key) bundle.get(KEY); + } + + @Override + public void storeInBundle(Bundle bundle) { + super.storeInBundle(bundle); + bundle.put( KEY, key ); + } + } + + private static ArrayList records; public static void reset() { records = new ArrayList<>(); } - private static final String JOURNAL = "journal"; + private static final String RECORDS = "records"; public static void storeInBundle( Bundle bundle ) { - bundle.put( JOURNAL, records ); + bundle.put( RECORDS, records ); } public static void restoreFromBundle( Bundle bundle ) { records = new ArrayList<>(); - for (Bundlable rec : bundle.getCollection( JOURNAL ) ) { + for (Bundlable rec : bundle.getCollection( RECORDS ) ) { records.add( (Record) rec ); } } public static void add( Landmark landmark ) { - int size = records.size(); - for (int i=0; i < size; i++) { - Record rec = records.get( i ); - if (rec.landmark == landmark && rec.depth == Dungeon.depth) { - return; - } + LandmarkRecord l = new LandmarkRecord( landmark, Dungeon.depth ); + if (!records.contains(l)) { + records.add(new LandmarkRecord(landmark, Dungeon.depth)); + Collections.sort(records); } - - records.add( new Record(landmark, Dungeon.depth ) ); } public static void remove( Landmark landmark ) { - int size = records.size(); - for (int i=0; i < size; i++) { - Record rec = records.get( i ); - if (rec.landmark == landmark && rec.depth == Dungeon.depth) { - records.remove( i ); - return; + records.remove( new LandmarkRecord(landmark, Dungeon.depth) ); + } + + public static void add( Key key ){ + KeyRecord k = new KeyRecord(key); + if (!records.contains(k)){ + records.add(k); + Collections.sort(records); + } else { + k = (KeyRecord) records.get(records.indexOf(k)); + k.quantity(k.quantity() + key.quantity()); + } + } + + public static void remove( Key key ){ + KeyRecord k = new KeyRecord( key ); + if (records.contains(k)){ + k = (KeyRecord) records.get(records.indexOf(k)); + k.quantity(k.quantity() - key.quantity()); + if (k.quantity() <= 0){ + records.remove(k); } } } + + public static int keyCount( Key key ){ + KeyRecord k = new KeyRecord( key ); + if (records.contains(k)){ + k = (KeyRecord) records.get(records.indexOf(k)); + return k.quantity(); + } else { + return 0; + } + } + + public static ArrayList getRecords(){ + return getRecords(Record.class); + } + + public static ArrayList getRecords( Class recordType ){ + ArrayList filtered = new ArrayList<>(); + for (Record rec : records){ + if (recordType.isInstance(rec)){ + filtered.add((T)rec); + } + } + return filtered; + } + } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java index fc9ea7085..9b5637e61 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DistortionTrap.java @@ -25,6 +25,10 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.LloydsBeacon; +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.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene; import com.watabou.noosa.Game; @@ -39,8 +43,8 @@ public class DistortionTrap extends Trap{ public void activate() { InterlevelScene.returnDepth = Dungeon.depth; Belongings belongings = Dungeon.hero.belongings; - belongings.ironKeys[Dungeon.depth] = 0; - belongings.specialKeys[Dungeon.depth] = 0; + Notes.remove((Key) new IronKey(Dungeon.depth).quantity(99)); + Notes.remove((Key) new GoldenKey(Dungeon.depth).quantity(99)); for (Item i : belongings){ if (i instanceof LloydsBeacon && ((LloydsBeacon) i).returnDepth == Dungeon.depth) ((LloydsBeacon) i).returnDepth = -1; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java index f62466682..89c2956c8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java @@ -62,6 +62,7 @@ public class Messages { private static String[] prop_files = new String[]{ "com.shatteredpixel.shatteredpixeldungeon.messages.actors.actors", "com.shatteredpixel.shatteredpixeldungeon.messages.items.items", + "com.shatteredpixel.shatteredpixeldungeon.messages.journal.journal", "com.shatteredpixel.shatteredpixeldungeon.messages.levels.levels", "com.shatteredpixel.shatteredpixeldungeon.messages.plants.plants", "com.shatteredpixel.shatteredpixeldungeon.messages.scenes.scenes", 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 27e98f76a..a1a12a37f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java @@ -25,6 +25,8 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; +import com.shatteredpixel.shatteredpixeldungeon.journal.Notes; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite; @@ -272,30 +274,23 @@ public class StatusPane extends Component { public void updateKeyDisplay() { needsKeyUpdate = false; - - boolean foundKeys = false; + boolean blackKey = false; boolean specialKey = false; int ironKeys = 0; - for (int i = 1; i <= Math.min(Dungeon.depth, 25); i++) { - if (Dungeon.hero.belongings.ironKeys[i] > 0 || Dungeon.hero.belongings.specialKeys[i] > 0) { - foundKeys = true; - - if (i < Dungeon.depth){ - blackKey = true; - + for (Notes.KeyRecord rec : Notes.getRecords(Notes.KeyRecord.class)){ + if (rec.depth() < Dungeon.depth){ + blackKey = true; + } else if (rec.depth() == Dungeon.depth){ + if (rec.type().equals(IronKey.class)) { + ironKeys += rec.quantity(); } else { - if (Dungeon.hero.belongings.specialKeys[i] > 0){ - specialKey = true; - } - ironKeys = Dungeon.hero.belongings.ironKeys[i]; + specialKey = true; } } } - if (!foundKeys){ - icon.frame(31, 0, 11, 7); - } else { + if (blackKey || specialKey || ironKeys > 0){ int left = 46, top = 0, width = 0, height = 7; if (blackKey){ left = 43; @@ -308,6 +303,8 @@ public class StatusPane extends Component { width += ironKeys*3; width = Math.min( width, 9); icon.frame(left, top, width, height); + } else { + icon.frame(31, 0, 11, 7); } layout(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java index 3d341a1fd..b9dacaa05 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndJournal.java @@ -24,9 +24,6 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.items.Item; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; -import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey; import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion; import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll; @@ -199,47 +196,22 @@ public class WndJournal extends WndTabbed { private void updateList(){ Component content = list.content(); - Collections.sort( Notes.records ); - float pos = 0; //Keys - for (int i = Dungeon.hero.belongings.ironKeys.length-1; i > 0; i--){ - if (Dungeon.hero.belongings.specialKeys[i] > 0){ - String text; - if (i % 5 == 0) - text = Messages.capitalize(Messages.get(SkeletonKey.class, "name")); - else - text = Messages.capitalize(Messages.get(GoldenKey.class, "name")); - - if (Dungeon.hero.belongings.specialKeys[i] > 1){ - text += " x" + Dungeon.hero.belongings.specialKeys[i]; - } - ListItem item = new ListItem( Icons.get(Icons.DEPTH), Messages.titleCase(text), i ); - item.setRect( 0, pos, width(), ITEM_HEIGHT ); - content.add( item ); - - pos += item.height(); - } - if (Dungeon.hero.belongings.ironKeys[i] > 0){ - String text = Messages.titleCase(Messages.get(IronKey.class, "name")); - - if (Dungeon.hero.belongings.ironKeys[i] > 1){ - text += " x" + Dungeon.hero.belongings.ironKeys[i]; - } - - ListItem item = new ListItem( Icons.get(Icons.DEPTH), text, i ); - item.setRect( 0, pos, width(), ITEM_HEIGHT ); - content.add( item ); - - pos += item.height(); - } + for(Notes.Record rec : Notes.getRecords(Notes.KeyRecord.class)){ + ListItem item = new ListItem( Icons.get(Icons.DEPTH), + Messages.titleCase(rec.desc()), rec.depth() ); + item.setRect( 0, pos, width(), ITEM_HEIGHT ); + content.add( item ); + pos += item.height(); } - //Notes entries - for (Notes.Record rec : Notes.records) { - ListItem item = new ListItem( Icons.get(Icons.DEPTH), rec.landmark.desc(), rec.depth ); + //Landmarks + for (Notes.Record rec : Notes.getRecords(Notes.LandmarkRecord.class)) { + ListItem item = new ListItem( Icons.get(Icons.DEPTH), + Messages.titleCase(rec.desc()), rec.depth() ); item.setRect( 0, pos, width(), ITEM_HEIGHT ); content.add( item ); diff --git a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties index 1801d564e..b8898065c 100644 --- a/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties +++ b/core/src/main/resources/com/shatteredpixel/shatteredpixeldungeon/messages/journal/journal.properties @@ -1,10 +1,10 @@ -notes$landmark.well_of_health=Well of Health -notes$landmark.well_of_awareness=Well of Awareness -notes$landmark.well_of_transmutation=Well of Transmutation -notes$landmark.alchemy=Alchemy pot -notes$landmark.garden=Garden -notes$landmark.statue=Animated statue -notes$landmark.ghost=Sad ghost -notes$landmark.wandmaker=Old wandmaker -notes$landmark.troll=Troll blacksmith -notes$landmark.imp=Ambitious imp \ No newline at end of file +journal.notes$landmark.well_of_health=well of health +journal.notes$landmark.well_of_awareness=well of awareness +journal.notes$landmark.well_of_transmutation=well of transmutation +journal.notes$landmark.alchemy=alchemy pot +journal.notes$landmark.garden=garden +journal.notes$landmark.statue=animated statue +journal.notes$landmark.ghost=sad ghost +journal.notes$landmark.wandmaker=old wandmaker +journal.notes$landmark.troll=troll blacksmith +journal.notes$landmark.imp=ambitious imp \ No newline at end of file