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

@ -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 {

View File

@ -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<Item> slots = new ArrayList<Item>();
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<Item>();
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 );
}

View File

@ -41,8 +41,6 @@ public class Belongings implements Iterable<Item> {
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<Item> {
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<Item> {
if (misc2 != null) {
misc2.activate( owner );
}
quickslot.restorePlaceholders(bundle);
}
@SuppressWarnings("unchecked")

View File

@ -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();
}

View File

@ -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() {

View File

@ -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);
}
}
}

View File

@ -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 )) {

View File

@ -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 )) {

View File

@ -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;

View File

@ -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 );

View File

@ -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();
}
}

View File

@ -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 {

View File

@ -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) );
}
}