From 6e3c2223cd767ab8301e418473da312f5a4b16c4 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 20 Jan 2015 00:56:36 -0500 Subject: [PATCH] v0.2.3e: tonnes of fixes relating to WIP multi-quickslot implementation --- .../shatteredpixeldungeon/Dungeon.java | 13 +++++++-- .../{actors/hero => }/QuickSlot.java | 12 ++++++-- .../actors/hero/Belongings.java | 6 ---- .../actors/hero/Hero.java | 2 +- .../actors/hero/HeroClass.java | 10 +++---- .../shatteredpixeldungeon/items/Item.java | 28 +++++++++++-------- .../items/KindOfWeapon.java | 7 ++++- .../items/armor/Armor.java | 4 +++ .../items/artifacts/Artifact.java | 4 +++ .../items/rings/Ring.java | 6 +++- .../shatteredpixeldungeon/ui/QuickSlot.java | 4 +-- .../shatteredpixeldungeon/windows/WndBag.java | 2 +- .../windows/WndRanking.java | 4 +-- 13 files changed, 66 insertions(+), 36 deletions(-) rename src/com/shatteredpixel/shatteredpixeldungeon/{actors/hero => }/QuickSlot.java (89%) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index d7541da81..9e057794b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -157,6 +157,8 @@ public class Dungeon { public static Hero hero; public static Level level; + + public static QuickSlot quickslot = new QuickSlot(); public static int depth; public static int gold; @@ -189,6 +191,8 @@ public class Dungeon { Statistics.reset(); Journal.reset(); + + quickslot.reset(); depth = 0; gold = 0; @@ -481,6 +485,8 @@ public class Dungeon { bundle.put( GOLD, gold ); bundle.put( DEPTH, depth ); + quickslot.storePlaceholders( bundle ); + bundle.put( DV, dewVial ); bundle.put( WT, transmutation ); @@ -571,6 +577,9 @@ public class Dungeon { Generator.reset(); + quickslot.reset(); + quickslot.restorePlaceholders( bundle ); + Dungeon.challenges = bundle.getInt( CHALLENGES ); Dungeon.level = null; @@ -625,10 +634,10 @@ public class Dungeon { Imp.Quest.reset(); } - Room.restoreRoomsFromBundle( bundle ); + Room.restoreRoomsFromBundle(bundle); } - Bundle badges = bundle.getBundle( BADGES ); + Bundle badges = bundle.getBundle(BADGES); if (!badges.isNull()) { Badges.loadLocal( badges ); } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/QuickSlot.java b/src/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java similarity index 89% rename from src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/QuickSlot.java rename to src/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java index 4cbb0c203..738a9d590 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/QuickSlot.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java @@ -1,4 +1,4 @@ -package com.shatteredpixel.shatteredpixeldungeon.actors.hero; +package com.shatteredpixel.shatteredpixeldungeon; import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.watabou.utils.Bundlable; @@ -18,9 +18,11 @@ public class QuickSlot { * The one exception to this is when quantity is 0, which can * happen for a stackable item that has been 'used up', these are refered to a placeholders. */ + //TODO: seriously reconsider using an arraylist here, may make much more sense to just use an array. private ArrayList slots = new ArrayList(); public void setSlot(int slot, Item item){ + slots.ensureCapacity(slot+1); slots.set(slot, item); } @@ -48,8 +50,12 @@ public class QuickSlot { clearSlot(i); } - public void clear(){ + public void reset(){ slots = new ArrayList(); + slots.add(null); + slots.add(null); + slots.add(null); + slots.add(null); } public boolean contains(Item item){ @@ -58,7 +64,7 @@ public class QuickSlot { public void replaceSimilar(Item item){ for (int i = 0; i < slots.size(); i++) - if (item.isSimilar(slots.get(i))) + if (slots.get(i) != null && item.isSimilar(slots.get(i))) setSlot( i , item ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java index fe822f5f0..97662f066 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Belongings.java @@ -41,8 +41,6 @@ public class Belongings implements Iterable { public Bag backpack; - public QuickSlot quickslot; - public KindOfWeapon weapon = null; public Armor armor = null; public KindofMisc misc1 = null; @@ -71,8 +69,6 @@ public class Belongings implements Iterable { bundle.put( ARMOR, armor ); bundle.put( MISC1, misc1); bundle.put( MISC2, misc2); - - quickslot.storePlaceholders( bundle ); } public void restoreFromBundle( Bundle bundle ) { @@ -96,8 +92,6 @@ public class Belongings implements Iterable { if (misc2 != null) { misc2.activate( owner ); } - - quickslot.restorePlaceholders(bundle); } @SuppressWarnings("unchecked") diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 145a4a902..ef3623f4f 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -878,7 +878,7 @@ public class Hero extends Char { if (wand.curCharges < wand.maxCharges && damage > 0) { wand.curCharges++; - if (belongings.quickslot.contains(wand)) { + if (Dungeon.quickslot.contains(wand)) { QuickSlot.refresh(); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroClass.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroClass.java index b332e11fe..bca4c56eb 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroClass.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/HeroClass.java @@ -139,7 +139,7 @@ public enum HeroClass { Dart darts = new Dart( 8 ); darts.identify().collect(); - hero.belongings.quickslot.setSlot(0, darts); + Dungeon.quickslot.setSlot(0, darts); new PotionOfStrength().setKnown(); } @@ -150,7 +150,7 @@ public enum HeroClass { WandOfMagicMissile wand = new WandOfMagicMissile(); wand.identify().collect(); - hero.belongings.quickslot.setSlot(0, wand); + Dungeon.quickslot.setSlot(0, wand); new ScrollOfIdentify().setKnown(); } @@ -165,8 +165,8 @@ public enum HeroClass { Dart darts = new Dart( 8 ); darts.identify().collect(); - hero.belongings.quickslot.setSlot(0, cloak); - hero.belongings.quickslot.setSlot(1, darts); + Dungeon.quickslot.setSlot(0, cloak); + Dungeon.quickslot.setSlot(1, darts); new ScrollOfMagicMapping().setKnown(); } @@ -179,7 +179,7 @@ public enum HeroClass { Boomerang boomerang = new Boomerang(); boomerang.identify().collect(); - hero.belongings.quickslot.setSlot(0, boomerang); + Dungeon.quickslot.setSlot(0, boomerang); } public String title() { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java index 75734de02..549d1dcd0 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Item.java @@ -178,7 +178,7 @@ public class Item implements Bundlable { } items.add( this ); - Dungeon.hero.belongings.quickslot.replaceSimilar(this); + Dungeon.quickslot.replaceSimilar(this); QuickSlot.refresh(); Collections.sort( items, itemComparator ); return true; @@ -205,7 +205,7 @@ public class Item implements Bundlable { if (quantity == 1) { if (stackable == true){ - Dungeon.hero.belongings.quickslot.convertToPlaceholder(this); + Dungeon.quickslot.convertToPlaceholder(this); } return detachAll( container ); @@ -233,12 +233,13 @@ public class Item implements Bundlable { } public final Item detachAll( Bag container ) { + Dungeon.quickslot.clearItem( this ); + QuickSlot.refresh(); + for (Item item : container.items) { if (item == this) { container.items.remove( this ); item.onDetach( ); - Dungeon.hero.belongings.quickslot.clearItem( this ); - QuickSlot.refresh(); return this; } else if (item instanceof Bag) { Bag bag = (Bag)item; @@ -396,7 +397,7 @@ public class Item implements Bundlable { } public void updateQuickslot() { - if (Dungeon.hero.belongings.quickslot.contains( this )) { + if (Dungeon.quickslot.contains( this )) { QuickSlot.refresh(); } } @@ -416,8 +417,8 @@ public class Item implements Bundlable { bundle.put( LEVEL_KNOWN, levelKnown ); bundle.put( CURSED, cursed ); bundle.put( CURSED_KNOWN, cursedKnown ); - if (Dungeon.hero.belongings.quickslot.contains(this)) { - bundle.put( QUICKSLOT, Dungeon.hero.belongings.quickslot.getSlot(this) ); + if (Dungeon.quickslot.contains(this)) { + bundle.put( QUICKSLOT, Dungeon.quickslot.getSlot(this) ); } } @@ -436,11 +437,14 @@ public class Item implements Bundlable { cursed = bundle.getBoolean( CURSED ); - //support for pre-0.2.3 saves and rankings - if (bundle.contains( OLDSLOT )) { - Dungeon.hero.belongings.quickslot.setSlot( 0 , this); - } else if (bundle.contains( QUICKSLOT )) { - Dungeon.hero.belongings.quickslot.setSlot( bundle.getInt( QUICKSLOT ), this); + //only want to populate slot on first load. + if (Dungeon.hero == null) { + //support for pre-0.2.3 saves and rankings + if (bundle.contains(OLDSLOT)) { + Dungeon.quickslot.setSlot(0, this); + } else if (bundle.contains(QUICKSLOT)) { + Dungeon.quickslot.setSlot(bundle.getInt(QUICKSLOT), this); + } } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java index 8230be7f5..70ce7d80a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/KindOfWeapon.java @@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items; import java.util.ArrayList; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot; @@ -48,8 +49,12 @@ public class KindOfWeapon extends EquipableItem { @Override public boolean doEquip( Hero hero ) { - + + int slot = Dungeon.quickslot.getSlot( this ); + detachAll( hero.belongings.backpack ); + + if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java index eed619794..4151cc559 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/armor/Armor.java @@ -85,8 +85,12 @@ public class Armor extends EquipableItem { @Override public boolean doEquip( Hero hero ) { + + int slot = Dungeon.quickslot.getSlot( this ); detach( hero.belongings.backpack ); + + if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); if (hero.belongings.armor == null || hero.belongings.armor.doUnequip( hero, true, false )) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java index f87eb4956..c33b90dbf 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java @@ -80,8 +80,12 @@ public class Artifact extends KindofMisc { hero.belongings.misc2 = this; } + int slot = Dungeon.quickslot.getSlot( this ); + detach( hero.belongings.backpack ); + if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); + activate( hero ); cursedKnown = true; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java index 5ca12dfd1..1f302390d 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/Ring.java @@ -123,8 +123,12 @@ public class Ring extends KindofMisc { } else { hero.belongings.misc2 = this; } - + + int slot = Dungeon.quickslot.getSlot( this ); + detach( hero.belongings.backpack ); + + if (slot != -1) Dungeon.quickslot.setSlot( slot, this ); activate( hero ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlot.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlot.java index 058a7537c..b87909302 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlot.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlot.java @@ -127,7 +127,7 @@ public class QuickSlot extends Button implements WndBag.Listener { @SuppressWarnings("unchecked") private static Item select() { - return Dungeon.hero.belongings.quickslot.getItem(0); + return Dungeon.quickslot.getItem(0); } public static Item getItem(){ @@ -138,7 +138,7 @@ public class QuickSlot extends Button implements WndBag.Listener { @Override public void onSelect( Item item ) { if (item != null) { - Dungeon.hero.belongings.quickslot.setSlot( 0 , item ); + Dungeon.quickslot.setSlot( 0 , item ); refresh(); } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java index 9f47146ff..c61ded0ce 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndBag.java @@ -395,7 +395,7 @@ public class WndBag extends WndTabbed { protected boolean onLongClick() { if (listener == null && item.defaultAction != null) { hide(); - Dungeon.hero.belongings.quickslot.setSlot( 0 , item ); + Dungeon.quickslot.setSlot( 0 , item ); QuickSlot.refresh(); return true; } else { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndRanking.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndRanking.java index 6987ad5a2..38ab8fa1f 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndRanking.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndRanking.java @@ -248,8 +248,8 @@ public class WndRanking extends WndTabbed { } //TODO: add proper visual support for mutli-quickslots - if (stuff.quickslot.getItem(0) != null){ - addItem( stuff.quickslot.getItem(0) ); + if (Dungeon.quickslot.getItem(0) != null){ + addItem( Dungeon.quickslot.getItem(0) ); } }