v0.2.3e: tonnes of fixes relating to WIP multi-quickslot implementation

This commit is contained in:
Evan Debenham 2015-01-20 00:56:36 -05:00
parent e53c6b678f
commit 6e3c2223cd
13 changed files with 66 additions and 36 deletions

View File

@ -158,6 +158,8 @@ public class Dungeon {
public static Hero hero; public static Hero hero;
public static Level level; public static Level level;
public static QuickSlot quickslot = new QuickSlot();
public static int depth; public static int depth;
public static int gold; public static int gold;
// Reason of death // Reason of death
@ -190,6 +192,8 @@ public class Dungeon {
Statistics.reset(); Statistics.reset();
Journal.reset(); Journal.reset();
quickslot.reset();
depth = 0; depth = 0;
gold = 0; gold = 0;
@ -481,6 +485,8 @@ public class Dungeon {
bundle.put( GOLD, gold ); bundle.put( GOLD, gold );
bundle.put( DEPTH, depth ); bundle.put( DEPTH, depth );
quickslot.storePlaceholders( bundle );
bundle.put( DV, dewVial ); bundle.put( DV, dewVial );
bundle.put( WT, transmutation ); bundle.put( WT, transmutation );
@ -571,6 +577,9 @@ public class Dungeon {
Generator.reset(); Generator.reset();
quickslot.reset();
quickslot.restorePlaceholders( bundle );
Dungeon.challenges = bundle.getInt( CHALLENGES ); Dungeon.challenges = bundle.getInt( CHALLENGES );
Dungeon.level = null; Dungeon.level = null;
@ -625,10 +634,10 @@ public class Dungeon {
Imp.Quest.reset(); Imp.Quest.reset();
} }
Room.restoreRoomsFromBundle( bundle ); Room.restoreRoomsFromBundle(bundle);
} }
Bundle badges = bundle.getBundle( BADGES ); Bundle badges = bundle.getBundle(BADGES);
if (!badges.isNull()) { if (!badges.isNull()) {
Badges.loadLocal( badges ); Badges.loadLocal( badges );
} else { } else {

View File

@ -1,4 +1,4 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.hero; package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.watabou.utils.Bundlable; import com.watabou.utils.Bundlable;
@ -18,9 +18,11 @@ public class QuickSlot {
* The one exception to this is when quantity is 0, which can * 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. * 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<Item> slots = new ArrayList<Item>(); private ArrayList<Item> slots = new ArrayList<Item>();
public void setSlot(int slot, Item item){ public void setSlot(int slot, Item item){
slots.ensureCapacity(slot+1);
slots.set(slot, item); slots.set(slot, item);
} }
@ -48,8 +50,12 @@ public class QuickSlot {
clearSlot(i); clearSlot(i);
} }
public void clear(){ public void reset(){
slots = new ArrayList<Item>(); slots = new ArrayList<Item>();
slots.add(null);
slots.add(null);
slots.add(null);
slots.add(null);
} }
public boolean contains(Item item){ public boolean contains(Item item){
@ -58,7 +64,7 @@ public class QuickSlot {
public void replaceSimilar(Item item){ public void replaceSimilar(Item item){
for (int i = 0; i < slots.size(); i++) 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 ); setSlot( i , item );
} }

View File

@ -41,8 +41,6 @@ public class Belongings implements Iterable<Item> {
public Bag backpack; public Bag backpack;
public QuickSlot quickslot;
public KindOfWeapon weapon = null; public KindOfWeapon weapon = null;
public Armor armor = null; public Armor armor = null;
public KindofMisc misc1 = null; public KindofMisc misc1 = null;
@ -71,8 +69,6 @@ public class Belongings implements Iterable<Item> {
bundle.put( ARMOR, armor ); bundle.put( ARMOR, armor );
bundle.put( MISC1, misc1); bundle.put( MISC1, misc1);
bundle.put( MISC2, misc2); bundle.put( MISC2, misc2);
quickslot.storePlaceholders( bundle );
} }
public void restoreFromBundle( Bundle bundle ) { public void restoreFromBundle( Bundle bundle ) {
@ -96,8 +92,6 @@ public class Belongings implements Iterable<Item> {
if (misc2 != null) { if (misc2 != null) {
misc2.activate( owner ); misc2.activate( owner );
} }
quickslot.restorePlaceholders(bundle);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -878,7 +878,7 @@ public class Hero extends Char {
if (wand.curCharges < wand.maxCharges && damage > 0) { if (wand.curCharges < wand.maxCharges && damage > 0) {
wand.curCharges++; wand.curCharges++;
if (belongings.quickslot.contains(wand)) { if (Dungeon.quickslot.contains(wand)) {
QuickSlot.refresh(); QuickSlot.refresh();
} }

View File

@ -139,7 +139,7 @@ public enum HeroClass {
Dart darts = new Dart( 8 ); Dart darts = new Dart( 8 );
darts.identify().collect(); darts.identify().collect();
hero.belongings.quickslot.setSlot(0, darts); Dungeon.quickslot.setSlot(0, darts);
new PotionOfStrength().setKnown(); new PotionOfStrength().setKnown();
} }
@ -150,7 +150,7 @@ public enum HeroClass {
WandOfMagicMissile wand = new WandOfMagicMissile(); WandOfMagicMissile wand = new WandOfMagicMissile();
wand.identify().collect(); wand.identify().collect();
hero.belongings.quickslot.setSlot(0, wand); Dungeon.quickslot.setSlot(0, wand);
new ScrollOfIdentify().setKnown(); new ScrollOfIdentify().setKnown();
} }
@ -165,8 +165,8 @@ public enum HeroClass {
Dart darts = new Dart( 8 ); Dart darts = new Dart( 8 );
darts.identify().collect(); darts.identify().collect();
hero.belongings.quickslot.setSlot(0, cloak); Dungeon.quickslot.setSlot(0, cloak);
hero.belongings.quickslot.setSlot(1, darts); Dungeon.quickslot.setSlot(1, darts);
new ScrollOfMagicMapping().setKnown(); new ScrollOfMagicMapping().setKnown();
} }
@ -179,7 +179,7 @@ public enum HeroClass {
Boomerang boomerang = new Boomerang(); Boomerang boomerang = new Boomerang();
boomerang.identify().collect(); boomerang.identify().collect();
hero.belongings.quickslot.setSlot(0, boomerang); Dungeon.quickslot.setSlot(0, boomerang);
} }
public String title() { public String title() {

View File

@ -178,7 +178,7 @@ public class Item implements Bundlable {
} }
items.add( this ); items.add( this );
Dungeon.hero.belongings.quickslot.replaceSimilar(this); Dungeon.quickslot.replaceSimilar(this);
QuickSlot.refresh(); QuickSlot.refresh();
Collections.sort( items, itemComparator ); Collections.sort( items, itemComparator );
return true; return true;
@ -205,7 +205,7 @@ public class Item implements Bundlable {
if (quantity == 1) { if (quantity == 1) {
if (stackable == true){ if (stackable == true){
Dungeon.hero.belongings.quickslot.convertToPlaceholder(this); Dungeon.quickslot.convertToPlaceholder(this);
} }
return detachAll( container ); return detachAll( container );
@ -233,12 +233,13 @@ public class Item implements Bundlable {
} }
public final Item detachAll( Bag container ) { public final Item detachAll( Bag container ) {
Dungeon.quickslot.clearItem( this );
QuickSlot.refresh();
for (Item item : container.items) { for (Item item : container.items) {
if (item == this) { if (item == this) {
container.items.remove( this ); container.items.remove( this );
item.onDetach( ); item.onDetach( );
Dungeon.hero.belongings.quickslot.clearItem( this );
QuickSlot.refresh();
return this; return this;
} else if (item instanceof Bag) { } else if (item instanceof Bag) {
Bag bag = (Bag)item; Bag bag = (Bag)item;
@ -396,7 +397,7 @@ public class Item implements Bundlable {
} }
public void updateQuickslot() { public void updateQuickslot() {
if (Dungeon.hero.belongings.quickslot.contains( this )) { if (Dungeon.quickslot.contains( this )) {
QuickSlot.refresh(); QuickSlot.refresh();
} }
} }
@ -416,8 +417,8 @@ public class Item implements Bundlable {
bundle.put( LEVEL_KNOWN, levelKnown ); bundle.put( LEVEL_KNOWN, levelKnown );
bundle.put( CURSED, cursed ); bundle.put( CURSED, cursed );
bundle.put( CURSED_KNOWN, cursedKnown ); bundle.put( CURSED_KNOWN, cursedKnown );
if (Dungeon.hero.belongings.quickslot.contains(this)) { if (Dungeon.quickslot.contains(this)) {
bundle.put( QUICKSLOT, Dungeon.hero.belongings.quickslot.getSlot(this) ); bundle.put( QUICKSLOT, Dungeon.quickslot.getSlot(this) );
} }
} }
@ -436,11 +437,14 @@ public class Item implements Bundlable {
cursed = bundle.getBoolean( CURSED ); cursed = bundle.getBoolean( CURSED );
//support for pre-0.2.3 saves and rankings //only want to populate slot on first load.
if (bundle.contains( OLDSLOT )) { if (Dungeon.hero == null) {
Dungeon.hero.belongings.quickslot.setSlot( 0 , this); //support for pre-0.2.3 saves and rankings
} else if (bundle.contains( QUICKSLOT )) { if (bundle.contains(OLDSLOT)) {
Dungeon.hero.belongings.quickslot.setSlot( bundle.getInt( QUICKSLOT ), this); Dungeon.quickslot.setSlot(0, this);
} else if (bundle.contains(QUICKSLOT)) {
Dungeon.quickslot.setSlot(bundle.getInt(QUICKSLOT), this);
}
} }
} }

View File

@ -19,6 +19,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items;
import java.util.ArrayList; import java.util.ArrayList;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlot;
@ -49,8 +50,12 @@ public class KindOfWeapon extends EquipableItem {
@Override @Override
public boolean doEquip( Hero hero ) { public boolean doEquip( Hero hero ) {
int slot = Dungeon.quickslot.getSlot( this );
detachAll( hero.belongings.backpack ); detachAll( hero.belongings.backpack );
if (slot != -1) Dungeon.quickslot.setSlot( slot, this );
if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) { if (hero.belongings.weapon == null || hero.belongings.weapon.doUnequip( hero, true )) {
hero.belongings.weapon = this; hero.belongings.weapon = this;

View File

@ -86,8 +86,12 @@ public class Armor extends EquipableItem {
@Override @Override
public boolean doEquip( Hero hero ) { public boolean doEquip( Hero hero ) {
int slot = Dungeon.quickslot.getSlot( this );
detach( hero.belongings.backpack ); detach( hero.belongings.backpack );
if (slot != -1) Dungeon.quickslot.setSlot( slot, this );
if (hero.belongings.armor == null || hero.belongings.armor.doUnequip( hero, true, false )) { if (hero.belongings.armor == null || hero.belongings.armor.doUnequip( hero, true, false )) {
hero.belongings.armor = this; hero.belongings.armor = this;

View File

@ -80,8 +80,12 @@ public class Artifact extends KindofMisc {
hero.belongings.misc2 = this; hero.belongings.misc2 = this;
} }
int slot = Dungeon.quickslot.getSlot( this );
detach( hero.belongings.backpack ); detach( hero.belongings.backpack );
if (slot != -1) Dungeon.quickslot.setSlot( slot, this );
activate( hero ); activate( hero );
cursedKnown = true; cursedKnown = true;

View File

@ -124,8 +124,12 @@ public class Ring extends KindofMisc {
hero.belongings.misc2 = this; hero.belongings.misc2 = this;
} }
int slot = Dungeon.quickslot.getSlot( this );
detach( hero.belongings.backpack ); detach( hero.belongings.backpack );
if (slot != -1) Dungeon.quickslot.setSlot( slot, this );
activate( hero ); activate( hero );
cursedKnown = true; cursedKnown = true;

View File

@ -127,7 +127,7 @@ public class QuickSlot extends Button implements WndBag.Listener {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Item select() { private static Item select() {
return Dungeon.hero.belongings.quickslot.getItem(0); return Dungeon.quickslot.getItem(0);
} }
public static Item getItem(){ public static Item getItem(){
@ -138,7 +138,7 @@ public class QuickSlot extends Button implements WndBag.Listener {
@Override @Override
public void onSelect( Item item ) { public void onSelect( Item item ) {
if (item != null) { if (item != null) {
Dungeon.hero.belongings.quickslot.setSlot( 0 , item ); Dungeon.quickslot.setSlot( 0 , item );
refresh(); refresh();
} }
} }

View File

@ -395,7 +395,7 @@ public class WndBag extends WndTabbed {
protected boolean onLongClick() { protected boolean onLongClick() {
if (listener == null && item.defaultAction != null) { if (listener == null && item.defaultAction != null) {
hide(); hide();
Dungeon.hero.belongings.quickslot.setSlot( 0 , item ); Dungeon.quickslot.setSlot( 0 , item );
QuickSlot.refresh(); QuickSlot.refresh();
return true; return true;
} else { } else {

View File

@ -248,8 +248,8 @@ public class WndRanking extends WndTabbed {
} }
//TODO: add proper visual support for mutli-quickslots //TODO: add proper visual support for mutli-quickslots
if (stuff.quickslot.getItem(0) != null){ if (Dungeon.quickslot.getItem(0) != null){
addItem( stuff.quickslot.getItem(0) ); addItem( Dungeon.quickslot.getItem(0) );
} }
} }