v0.2.3e: added backend support for multiple quickslots (needs testing!)
This commit is contained in:
parent
72cbc3440f
commit
e53c6b678f
|
@ -158,9 +158,6 @@ public class Dungeon {
|
||||||
public static Hero hero;
|
public static Hero hero;
|
||||||
public static Level level;
|
public static Level level;
|
||||||
|
|
||||||
// Either Item or Class<? extends Item>
|
|
||||||
public static Object quickslot;
|
|
||||||
|
|
||||||
public static int depth;
|
public static int depth;
|
||||||
public static int gold;
|
public static int gold;
|
||||||
// Reason of death
|
// Reason of death
|
||||||
|
@ -512,10 +509,6 @@ public class Dungeon {
|
||||||
Journal.storeInBundle( bundle );
|
Journal.storeInBundle( bundle );
|
||||||
Generator.storeInBundle( bundle );
|
Generator.storeInBundle( bundle );
|
||||||
|
|
||||||
if (quickslot instanceof Class) {
|
|
||||||
bundle.put( QUICKSLOT, ((Class<?>)quickslot).getName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
Scroll.save( bundle );
|
Scroll.save( bundle );
|
||||||
Potion.save( bundle );
|
Potion.save( bundle );
|
||||||
Wand.save( bundle );
|
Wand.save( bundle );
|
||||||
|
@ -642,16 +635,6 @@ public class Dungeon {
|
||||||
Badges.reset();
|
Badges.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
String qsClass = bundle.getString( QUICKSLOT );
|
|
||||||
if (qsClass != null) {
|
|
||||||
try {
|
|
||||||
quickslot = Class.forName( qsClass );
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
quickslot = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
hero = null;
|
hero = null;
|
||||||
hero = (Hero)bundle.get( HERO );
|
hero = (Hero)bundle.get( HERO );
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ 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;
|
||||||
|
@ -69,6 +71,8 @@ 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 ) {
|
||||||
|
@ -92,6 +96,8 @@ 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")
|
||||||
|
|
|
@ -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 (Dungeon.quickslot == wand) {
|
if (belongings.quickslot.contains(wand)) {
|
||||||
QuickSlot.refresh();
|
QuickSlot.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,9 +136,10 @@ public enum HeroClass {
|
||||||
hero.STR = hero.STR + 1;
|
hero.STR = hero.STR + 1;
|
||||||
|
|
||||||
(hero.belongings.weapon = new ShortSword()).identify();
|
(hero.belongings.weapon = new ShortSword()).identify();
|
||||||
new Dart( 8 ).identify().collect();
|
Dart darts = new Dart( 8 );
|
||||||
|
darts.identify().collect();
|
||||||
|
|
||||||
Dungeon.quickslot = Dart.class;
|
hero.belongings.quickslot.setSlot(0, darts);
|
||||||
|
|
||||||
new PotionOfStrength().setKnown();
|
new PotionOfStrength().setKnown();
|
||||||
}
|
}
|
||||||
|
@ -149,7 +150,7 @@ public enum HeroClass {
|
||||||
WandOfMagicMissile wand = new WandOfMagicMissile();
|
WandOfMagicMissile wand = new WandOfMagicMissile();
|
||||||
wand.identify().collect();
|
wand.identify().collect();
|
||||||
|
|
||||||
Dungeon.quickslot = wand;
|
hero.belongings.quickslot.setSlot(0, wand);
|
||||||
|
|
||||||
new ScrollOfIdentify().setKnown();
|
new ScrollOfIdentify().setKnown();
|
||||||
}
|
}
|
||||||
|
@ -161,10 +162,11 @@ public enum HeroClass {
|
||||||
(hero.belongings.misc1 = cloak).identify();
|
(hero.belongings.misc1 = cloak).identify();
|
||||||
hero.belongings.misc1.activate( hero );
|
hero.belongings.misc1.activate( hero );
|
||||||
|
|
||||||
new Dart( 8 ).identify().collect();
|
Dart darts = new Dart( 8 );
|
||||||
|
darts.identify().collect();
|
||||||
|
|
||||||
|
hero.belongings.quickslot.setSlot(0, cloak);
|
||||||
Dungeon.quickslot = cloak;
|
hero.belongings.quickslot.setSlot(1, darts);
|
||||||
|
|
||||||
new ScrollOfMagicMapping().setKnown();
|
new ScrollOfMagicMapping().setKnown();
|
||||||
}
|
}
|
||||||
|
@ -177,7 +179,7 @@ public enum HeroClass {
|
||||||
Boomerang boomerang = new Boomerang();
|
Boomerang boomerang = new Boomerang();
|
||||||
boomerang.identify().collect();
|
boomerang.identify().collect();
|
||||||
|
|
||||||
Dungeon.quickslot = boomerang;
|
hero.belongings.quickslot.setSlot(0, boomerang);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String title() {
|
public String title() {
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.shatteredpixel.shatteredpixeldungeon.actors.hero;
|
||||||
|
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
|
import com.watabou.utils.Bundlable;
|
||||||
|
import com.watabou.utils.Bundle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by debenhame on 16/01/2015.
|
||||||
|
*/
|
||||||
|
public class QuickSlot {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slots contain objects which are also in a player's inventory.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
private ArrayList<Item> slots = new ArrayList<Item>();
|
||||||
|
|
||||||
|
public void setSlot(int slot, Item item){
|
||||||
|
slots.set(slot, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item getItem(int slot){
|
||||||
|
return slots.get(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: this will currently only get the first occurance of an item, even if it's in multiple slots
|
||||||
|
//perhaps do not allow duplicate items in quickslots.
|
||||||
|
public int getSlot(Item item) {
|
||||||
|
return slots.indexOf(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isPlaceholder(int slot){
|
||||||
|
return slots.get(slot) != null && slots.get(slot).quantity() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearSlot(int slot){
|
||||||
|
setSlot(slot, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearItem(Item item){
|
||||||
|
for (int i = 0; i < slots.size(); i++)
|
||||||
|
if (slots.get(i) == item)
|
||||||
|
clearSlot(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(){
|
||||||
|
slots = new ArrayList<Item>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(Item item){
|
||||||
|
return slots.contains(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceSimilar(Item item){
|
||||||
|
for (int i = 0; i < slots.size(); i++)
|
||||||
|
if (item.isSimilar(slots.get(i)))
|
||||||
|
setSlot( i , item );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void convertToPlaceholder(Item item){
|
||||||
|
Item placeholder = Item.virtual(item.getClass());
|
||||||
|
|
||||||
|
if (placeholder != null && slots.contains(item))
|
||||||
|
for (int i = 0; i < slots.size(); i++)
|
||||||
|
if (slots.get(i) == item)
|
||||||
|
setSlot( i , placeholder );
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String PLACEHOLDERS = "placeholders";
|
||||||
|
private final String PLACEMENTS = "placements";
|
||||||
|
|
||||||
|
public void storePlaceholders(Bundle bundle){
|
||||||
|
ArrayList<Item> placeholders = new ArrayList<Item>(slots.size());
|
||||||
|
boolean[] placements = new boolean[slots.size()];
|
||||||
|
|
||||||
|
for (int i = 0; i < slots.size(); i++)
|
||||||
|
if (isPlaceholder(i)) {
|
||||||
|
placeholders.add(slots.get(i));
|
||||||
|
placements[i] = true;
|
||||||
|
}
|
||||||
|
bundle.put( PLACEHOLDERS, placeholders );
|
||||||
|
bundle.put( PLACEMENTS, placements );
|
||||||
|
}
|
||||||
|
|
||||||
|
//placements array is used as order is preserved while bundling, but exact index is not, so if we
|
||||||
|
//bundle both the placeholders (which preserves their order) an an array telling us where the placeholders are,
|
||||||
|
//we can reconstruct them perfectly.
|
||||||
|
|
||||||
|
public void restorePlaceholders(Bundle bundle){
|
||||||
|
Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
|
||||||
|
boolean[] placements = bundle.getBooleanArray( PLACEMENTS );
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (Bundlable item : placeholders){
|
||||||
|
while (placements[i] == false) i++;
|
||||||
|
setSlot( i, (Item)item );
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -178,6 +178,7 @@ public class Item implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
items.add( this );
|
items.add( this );
|
||||||
|
Dungeon.hero.belongings.quickslot.replaceSimilar(this);
|
||||||
QuickSlot.refresh();
|
QuickSlot.refresh();
|
||||||
Collections.sort( items, itemComparator );
|
Collections.sort( items, itemComparator );
|
||||||
return true;
|
return true;
|
||||||
|
@ -203,6 +204,10 @@ public class Item implements Bundlable {
|
||||||
} else
|
} else
|
||||||
if (quantity == 1) {
|
if (quantity == 1) {
|
||||||
|
|
||||||
|
if (stackable == true){
|
||||||
|
Dungeon.hero.belongings.quickslot.convertToPlaceholder(this);
|
||||||
|
}
|
||||||
|
|
||||||
return detachAll( container );
|
return detachAll( container );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,6 +237,7 @@ public class Item implements Bundlable {
|
||||||
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();
|
QuickSlot.refresh();
|
||||||
return this;
|
return this;
|
||||||
} else if (item instanceof Bag) {
|
} else if (item instanceof Bag) {
|
||||||
|
@ -390,7 +396,7 @@ public class Item implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuickslot() {
|
public void updateQuickslot() {
|
||||||
if ((stackable && Dungeon.quickslot == getClass()) || Dungeon.quickslot == this) {
|
if (Dungeon.hero.belongings.quickslot.contains( this )) {
|
||||||
QuickSlot.refresh();
|
QuickSlot.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,7 +406,8 @@ public class Item implements Bundlable {
|
||||||
private static final String LEVEL_KNOWN = "levelKnown";
|
private static final String LEVEL_KNOWN = "levelKnown";
|
||||||
private static final String CURSED = "cursed";
|
private static final String CURSED = "cursed";
|
||||||
private static final String CURSED_KNOWN = "cursedKnown";
|
private static final String CURSED_KNOWN = "cursedKnown";
|
||||||
private static final String QUICKSLOT = "quickslot";
|
private static final String OLDSLOT = "quickslot";
|
||||||
|
private static final String QUICKSLOT = "quickslotpos";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeInBundle( Bundle bundle ) {
|
public void storeInBundle( Bundle bundle ) {
|
||||||
|
@ -409,8 +416,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 (this == Dungeon.quickslot) {
|
if (Dungeon.hero.belongings.quickslot.contains(this)) {
|
||||||
bundle.put( QUICKSLOT, true );
|
bundle.put( QUICKSLOT, Dungeon.hero.belongings.quickslot.getSlot(this) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,8 +436,11 @@ public class Item implements Bundlable {
|
||||||
|
|
||||||
cursed = bundle.getBoolean( CURSED );
|
cursed = bundle.getBoolean( CURSED );
|
||||||
|
|
||||||
if (bundle.getBoolean( QUICKSLOT )) {
|
//support for pre-0.2.3 saves and rankings
|
||||||
Dungeon.quickslot = this;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||||
|
|
||||||
|
//TODO: add proper multi-quickslot functionality.
|
||||||
public class QuickSlot extends Button implements WndBag.Listener {
|
public class QuickSlot extends Button implements WndBag.Listener {
|
||||||
|
|
||||||
private static final String TXT_SELECT_ITEM = "Select an item for the quickslot";
|
private static final String TXT_SELECT_ITEM = "Select an item for the quickslot";
|
||||||
|
@ -126,20 +127,7 @@ public class QuickSlot extends Button implements WndBag.Listener {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Item select() {
|
private static Item select() {
|
||||||
if (Dungeon.quickslot instanceof Item) {
|
return Dungeon.hero.belongings.quickslot.getItem(0);
|
||||||
|
|
||||||
return (Item)Dungeon.quickslot;
|
|
||||||
|
|
||||||
} else if (Dungeon.quickslot != null) {
|
|
||||||
|
|
||||||
Item item = Dungeon.hero.belongings.getItem( (Class<? extends Item>)Dungeon.quickslot );
|
|
||||||
return item != null ? item : Item.virtual( (Class<? extends Item>)Dungeon.quickslot );
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item getItem(){
|
public static Item getItem(){
|
||||||
|
@ -150,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.quickslot = item.stackable ? item.getClass() : item;
|
Dungeon.hero.belongings.quickslot.setSlot( 0 , item );
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.quickslot = (item instanceof EquipableItem && !item.stackable) ? item : item.getClass();
|
Dungeon.hero.belongings.quickslot.setSlot( 0 , item );
|
||||||
QuickSlot.refresh();
|
QuickSlot.refresh();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -247,16 +247,9 @@ public class WndRanking extends WndTabbed {
|
||||||
addItem( stuff.misc2);
|
addItem( stuff.misc2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Dungeon.quickslot instanceof Item &&
|
//TODO: add proper visual support for mutli-quickslots
|
||||||
Dungeon.hero.belongings.backpack.contains( (Item)Dungeon.quickslot )) {
|
if (stuff.quickslot.getItem(0) != null){
|
||||||
|
addItem( stuff.quickslot.getItem(0) );
|
||||||
addItem( (Item)Dungeon.quickslot );
|
|
||||||
} else if (Dungeon.quickslot instanceof Class){
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Item item = Dungeon.hero.belongings.getItem( (Class<? extends Item>)Dungeon.quickslot );
|
|
||||||
if (item != null) {
|
|
||||||
addItem( item );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user