v0.9.4: completely refactored item selection in WndBag

This commit is contained in:
Evan Debenham 2021-07-15 13:19:08 -04:00
parent 3c3e22d486
commit e9e32835a7
32 changed files with 518 additions and 270 deletions

View File

@ -55,21 +55,23 @@ public class Belongings implements Iterable<Item> {
//used when thrown weapons temporary occupy the weapon slot
public KindOfWeapon stashedWeapon = null;
public static class Backpack extends Bag {
public int capacity(){
int cap = super.capacity();
for (Item item : items){
if (item instanceof Bag){
cap++;
}
}
return cap;
}
}
public Belongings( Hero owner ) {
this.owner = owner;
backpack = new Bag() {
public int capacity(){
int cap = super.capacity();
for (Item item : items){
if (item instanceof Bag){
cap++;
}
}
return cap;
}
};
backpack = new Backpack();
backpack.owner = owner;
}

View File

@ -104,18 +104,24 @@ public class Shopkeeper extends NPC {
}
public static WndBag sell() {
return GameScene.selectItem( itemSelector, WndBag.Mode.FOR_SALE, Messages.get(Shopkeeper.class, "sell"));
return GameScene.selectItem( itemSelector );
}
public static boolean willBuyItem( Item item ){
if (item.value() <= 0) return false;
if (item.unique && !item.stackable) return false;
if (item instanceof Armor && ((Armor) item).checkSeal() != null) return false;
if (item.isEquipped(Dungeon.hero) && item.cursed) return false;
return true;
}
private static WndBag.Listener itemSelector = new WndBag.Listener() {
private static WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(Shopkeeper.class, "sell");
}
@Override
public boolean itemSelectable(Item item) {
if (item.value() <= 0) return false;
if (item.unique && !item.stackable) return false;
if (item instanceof Armor && ((Armor) item).checkSeal() != null) return false;
if (item.isEquipped(Dungeon.hero) && item.cursed) return false;
return true;
}
@Override
public void onSelect( Item item ) {
if (item != null) {

View File

@ -24,9 +24,11 @@ package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.ShieldBuff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
@ -90,7 +92,7 @@ public class BrokenSeal extends Item {
if (action.equals(AC_AFFIX)){
curItem = this;
GameScene.selectItem(armorSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt"));
GameScene.selectItem(armorSelector);
} else if (action.equals(AC_INFO)) {
GameScene.show(new WndUseItem(null, this));
}
@ -102,7 +104,23 @@ public class BrokenSeal extends Item {
return level() == 0;
}
protected static WndBag.Listener armorSelector = new WndBag.Listener() {
protected static WndBag.ItemSelector armorSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(BrokenSeal.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Armor;
}
@Override
public void onSelect( Item item ) {
BrokenSeal seal = (BrokenSeal) curItem;

View File

@ -22,10 +22,13 @@
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Enchanting;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.PurpleParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
@ -66,7 +69,7 @@ public class Stylus extends Item {
if (action.equals(AC_INSCRIBE)) {
curUser = hero;
GameScene.selectItem( itemSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt") );
GameScene.selectItem( itemSelector );
}
}
@ -111,7 +114,23 @@ public class Stylus extends Item {
return 30 * quantity;
}
private final WndBag.Listener itemSelector = new WndBag.Listener() {
private final WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(Stylus.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Armor;
}
@Override
public void onSelect( Item item ) {
if (item != null) {

View File

@ -31,7 +31,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.AlchemyScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.Game;
import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
@ -53,8 +52,6 @@ public class AlchemistsToolkit extends Artifact {
public static final String AC_BREW = "BREW";
protected WndBag.Mode mode = WndBag.Mode.POTION;
private boolean alchemyReady = false;
@Override

View File

@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Corruption;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Wraith;
@ -43,6 +44,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.glyphs.AntiMagic;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.glyphs.Brimstone;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEnergy;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRetribution;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfPsionicBlast;
@ -846,7 +848,23 @@ public class DriedRose extends Artifact {
}
rose.weapon = null;
} else {
GameScene.selectItem(new WndBag.Listener() {
GameScene.selectItem(new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(WndGhostHero.class, "weapon_prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof MeleeWeapon;
}
@Override
public void onSelect(Item item) {
if (!(item instanceof MeleeWeapon)) {
@ -874,7 +892,7 @@ public class DriedRose extends Artifact {
}
}
}, WndBag.Mode.WEAPON, Messages.get(WndGhostHero.class, "weapon_prompt"));
});
}
}
};
@ -896,7 +914,23 @@ public class DriedRose extends Artifact {
}
rose.armor = null;
} else {
GameScene.selectItem(new WndBag.Listener() {
GameScene.selectItem(new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(WndGhostHero.class, "armor_prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Armor;
}
@Override
public void onSelect(Item item) {
if (!(item instanceof Armor)) {
@ -924,7 +958,7 @@ public class DriedRose extends Artifact {
}
}
}, WndBag.Mode.ARMOR, Messages.get(WndGhostHero.class, "armor_prompt"));
});
}
}
};

View File

@ -28,10 +28,12 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEnergy;
@ -65,8 +67,6 @@ public class HornOfPlenty extends Artifact {
public static final String AC_EAT = "EAT";
public static final String AC_STORE = "STORE";
protected WndBag.Mode mode = WndBag.Mode.FOOD;
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
@ -133,7 +133,7 @@ public class HornOfPlenty extends Artifact {
} else if (action.equals(AC_STORE)){
GameScene.selectItem(itemSelector, mode, Messages.get(this, "prompt"));
GameScene.selectItem(itemSelector);
}
}
@ -272,7 +272,23 @@ public class HornOfPlenty extends Artifact {
}
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
protected static WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(HornOfPlenty.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Food;
}
@Override
public void onSelect( Item item ) {
if (item != null && item instanceof Food) {

View File

@ -30,6 +30,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.EarthParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEnergy;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Earthroot;
@ -60,8 +62,6 @@ public class SandalsOfNature extends Artifact {
public static final String AC_FEED = "FEED";
public static final String AC_ROOT = "ROOT";
protected WndBag.Mode mode = WndBag.Mode.SEED;
public ArrayList<Class> seeds = new ArrayList<>();
@Override
@ -80,7 +80,7 @@ public class SandalsOfNature extends Artifact {
if (action.equals(AC_FEED)){
GameScene.selectItem(itemSelector, mode, Messages.get(this, "prompt"));
GameScene.selectItem(itemSelector);
} else if (action.equals(AC_ROOT) && level() > 0){
@ -146,12 +146,8 @@ public class SandalsOfNature extends Artifact {
return super.upgrade();
}
public static boolean canUseSeed(Item item){
if (item instanceof Plant.Seed){
return !(curItem instanceof SandalsOfNature) ||
!((SandalsOfNature) curItem).seeds.contains(item.getClass());
}
return false;
public boolean canUseSeed(Item item){
return item instanceof Plant.Seed && !seeds.contains(item.getClass());
}
@ -190,7 +186,23 @@ public class SandalsOfNature extends Artifact {
}
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(SandalsOfNature.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return VelvetPouch.class;
}
@Override
public boolean itemSelectable(Item item) {
return canUseSeed(item);
}
@Override
public void onSelect( Item item ) {
if (item != null && item instanceof Plant.Seed) {

View File

@ -31,6 +31,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfEnergy;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfIdentify;
@ -75,8 +77,6 @@ public class UnstableSpellbook extends Artifact {
private final ArrayList<Class> scrolls = new ArrayList<>();
protected WndBag.Mode mode = WndBag.Mode.SCROLL;
public UnstableSpellbook() {
super();
@ -173,7 +173,7 @@ public class UnstableSpellbook extends Artifact {
}
} else if (action.equals( AC_ADD )) {
GameScene.selectItem(itemSelector, mode, Messages.get(this, "prompt"));
GameScene.selectItem(itemSelector);
}
}
@ -239,17 +239,6 @@ public class UnstableSpellbook extends Artifact {
return super.upgrade();
}
public static boolean canUseScroll( Item item ){
if (item instanceof Scroll){
if (!(curItem instanceof UnstableSpellbook)){
return true;
} else {
return item.isIdentified() && ((UnstableSpellbook) curItem).scrolls.contains(item.getClass());
}
}
return false;
}
@Override
public String desc() {
String desc = super.desc();
@ -317,7 +306,23 @@ public class UnstableSpellbook extends Artifact {
}
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(UnstableSpellbook.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return ScrollHolder.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Scroll && !scrolls.contains(item.getClass());
}
@Override
public void onSelect(Item item) {
if (item != null && item instanceof Scroll && item.isIdentified()){

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
@ -32,9 +33,8 @@ import com.watabou.noosa.audio.Sample;
public abstract class InventoryScroll extends Scroll {
protected String inventoryTitle = Messages.get(this, "inv_title");
protected WndBag.Mode mode = WndBag.Mode.ALL;
protected static boolean identifiedByUse = false;
@Override
public void doRead() {
@ -45,7 +45,7 @@ public abstract class InventoryScroll extends Scroll {
identifiedByUse = false;
}
GameScene.selectItem( itemSelector, mode, inventoryTitle );
GameScene.selectItem( itemSelector );
}
private void confirmCancelation() {
@ -62,18 +62,43 @@ public abstract class InventoryScroll extends Scroll {
identifiedByUse = false;
break;
case 1:
GameScene.selectItem( itemSelector, mode, inventoryTitle );
GameScene.selectItem( itemSelector );
break;
}
}
public void onBackPressed() {}
} );
}
private String inventoryTitle(){
return Messages.get(this, "inv_title");
}
protected Class<?extends Bag> preferredBag = null;
protected boolean usableOnItem( Item item ){
return true;
}
protected abstract void onItemSelected( Item item );
protected static boolean identifiedByUse = false;
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return inventoryTitle();
}
@Override
public Class<? extends Bag> preferredBag() {
return preferredBag;
}
@Override
public boolean itemSelectable(Item item) {
return usableOnItem(item);
}
@Override
public void onSelect( Item item ) {

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.effects.Identification;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
@ -33,11 +34,15 @@ public class ScrollOfIdentify extends InventoryScroll {
{
icon = ItemSpriteSheet.Icons.SCROLL_IDENTIFY;
mode = WndBag.Mode.UNIDENTIFED;
bones = true;
}
@Override
protected boolean usableOnItem(Item item) {
return !item.isIdentified();
}
@Override
protected void onItemSelected( Item item ) {

View File

@ -23,6 +23,7 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Degrade;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
@ -34,15 +35,33 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class ScrollOfRemoveCurse extends InventoryScroll {
{
icon = ItemSpriteSheet.Icons.SCROLL_REMCURSE;
mode = WndBag.Mode.UNCURSABLE;
preferredBag = Belongings.Backpack.class;
}
@Override
protected boolean usableOnItem(Item item) {
return uncursable(item);
}
public static boolean uncursable( Item item ){
if (item.isEquipped(Dungeon.hero) && Dungeon.hero.buff(Degrade.class) != null) {
return true;
} if ((item instanceof EquipableItem || item instanceof Wand) && ((!item.isIdentified() && !item.cursedKnown) || item.cursed)){
return true;
} else if (item instanceof Weapon){
return ((Weapon)item).hasCurseEnchant();
} else if (item instanceof Armor){
return ((Armor)item).hasCurseGlyph();
} else {
return false;
}
}
@Override
protected void onItemSelected(Item item) {
new Flare( 6, 32 ).show( curUser.sprite, 2f ) ;
@ -97,20 +116,6 @@ public class ScrollOfRemoveCurse extends InventoryScroll {
return procced;
}
public static boolean uncursable( Item item ){
if (item.isEquipped(Dungeon.hero) && Dungeon.hero.buff(Degrade.class) != null) {
return true;
} if ((item instanceof EquipableItem || item instanceof Wand) && ((!item.isIdentified() && !item.cursedKnown) || item.cursed)){
return true;
} else if (item instanceof Weapon){
return ((Weapon)item).hasCurseEnchant();
} else if (item instanceof Armor){
return ((Armor)item).hasCurseGlyph();
} else {
return false;
}
}
@Override
public int value() {
return isKnown() ? 30 * quantity : super.value();

View File

@ -48,7 +48,6 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.utils.Random;
import com.watabou.utils.Reflection;
@ -56,12 +55,12 @@ public class ScrollOfTransmutation extends InventoryScroll {
{
icon = ItemSpriteSheet.Icons.SCROLL_TRANSMUTE;
mode = WndBag.Mode.TRANMSUTABLE;
bones = true;
}
public static boolean canTransmute(Item item){
@Override
protected boolean usableOnItem(Item item) {
return item instanceof MeleeWeapon ||
(item instanceof MissileWeapon && !(item instanceof Dart)) ||
(item instanceof Potion && !(item instanceof Elixir || item instanceof Brew || item instanceof AlchemicalCatalyst)) ||

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Degrade;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
@ -37,17 +38,21 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class ScrollOfUpgrade extends InventoryScroll {
{
icon = ItemSpriteSheet.Icons.SCROLL_UPGRADE;
mode = WndBag.Mode.UPGRADEABLE;
preferredBag = Belongings.Backpack.class;
unique = true;
}
@Override
protected boolean usableOnItem(Item item) {
return item.isUpgradable();
}
@Override
protected void onItemSelected( Item item ) {

View File

@ -23,12 +23,16 @@ package com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.Enchanting;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
@ -50,10 +54,30 @@ public class ScrollOfEnchantment extends ExoticScroll {
public void doRead() {
identify();
GameScene.selectItem( itemSelector, WndBag.Mode.ENCHANTABLE, Messages.get(this, "inv_title"));
GameScene.selectItem( itemSelector );
}
public static boolean enchantable( Item item ){
return (item instanceof MeleeWeapon || item instanceof SpiritBow || item instanceof Armor);
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(ScrollOfEnchantment.class, "inv_title");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return enchantable(item);
}
@Override
public void onSelect(final Item item) {

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.quest.MetalShard;
@ -34,17 +35,21 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.audio.Sample;
public class CurseInfusion extends InventorySpell {
{
image = ItemSpriteSheet.CURSE_INFUSE;
mode = WndBag.Mode.CURSABLE;
}
@Override
protected boolean usableOnItem(Item item) {
return ((item instanceof EquipableItem && !(item instanceof MissileWeapon)) || item instanceof Wand);
}
@Override
protected void onItemSelected(Item item) {

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
@ -32,18 +33,41 @@ import com.watabou.noosa.audio.Sample;
public abstract class InventorySpell extends Spell {
protected String inventoryTitle = Messages.get(this, "inv_title");
protected WndBag.Mode mode = WndBag.Mode.ALL;
@Override
protected void onCast(Hero hero) {
curItem = detach( hero.belongings.backpack );
GameScene.selectItem( itemSelector, mode, inventoryTitle );
GameScene.selectItem( itemSelector );
}
private String inventoryTitle(){
return Messages.get(this, "inv_title");
}
protected Class<?extends Bag> preferredBag = null;
protected boolean usableOnItem( Item item ){
return true;
}
protected abstract void onItemSelected( Item item );
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return inventoryTitle();
}
@Override
public Class<? extends Bag> preferredBag() {
return preferredBag;
}
@Override
public boolean itemSelectable(Item item) {
return usableOnItem(item);
}
@Override
public void onSelect( Item item ) {

View File

@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Degrade;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade;
@ -34,17 +33,20 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class MagicalInfusion extends InventorySpell {
{
mode = WndBag.Mode.UPGRADEABLE;
image = ItemSpriteSheet.MAGIC_INFUSE;
unique = true;
}
@Override
protected boolean usableOnItem(Item item) {
return item.isUpgradable();
}
@Override
protected void onItemSelected( Item item ) {

View File

@ -28,7 +28,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.MerchantsBeacon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import java.util.ArrayList;
@ -36,9 +35,8 @@ public class MagicalPorter extends InventorySpell {
{
image = ItemSpriteSheet.MAGIC_PORTER;
mode = WndBag.Mode.NOT_EQUIPPED;
}
@Override
protected void onCast(Hero hero) {
if (Dungeon.depth >= 25){
@ -47,7 +45,12 @@ public class MagicalPorter extends InventorySpell {
super.onCast(hero);
}
}
@Override
protected boolean usableOnItem(Item item) {
return !item.isEquipped(Dungeon.hero);
}
@Override
protected void onItemSelected(Item item) {

View File

@ -39,16 +39,22 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.utils.Reflection;
public class Recycle extends InventorySpell {
{
image = ItemSpriteSheet.RECYCLE;
mode = WndBag.Mode.RECYCLABLE;
}
@Override
protected boolean usableOnItem(Item item) {
return (item instanceof Potion && !(item instanceof Elixir || item instanceof Brew)) ||
item instanceof Scroll ||
item instanceof Plant.Seed ||
item instanceof Runestone;
}
@Override
protected void onItemSelected(Item item) {
Item result;
@ -79,13 +85,6 @@ public class Recycle extends InventorySpell {
curUser.sprite.emitter().start(Speck.factory(Speck.CHANGE), 0.2f, 10);
}
public static boolean isRecyclable(Item item){
return (item instanceof Potion && !(item instanceof Elixir || item instanceof Brew)) ||
item instanceof Scroll ||
item instanceof Plant.Seed ||
item instanceof Runestone;
}
@Override
public int value() {
//prices of ingredients, divided by output quantity

View File

@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
@ -34,9 +35,6 @@ import java.util.ArrayList;
public abstract class InventoryStone extends Runestone {
protected String inventoryTitle = Messages.get(this, "inv_title");
protected WndBag.Mode mode = WndBag.Mode.ALL;
{
defaultAction = AC_USE;
}
@ -61,7 +59,7 @@ public abstract class InventoryStone extends Runestone {
@Override
protected void activate(int cell) {
GameScene.selectItem( itemSelector, mode, inventoryTitle );
GameScene.selectItem( itemSelector );
}
protected void useAnimation() {
@ -72,10 +70,36 @@ public abstract class InventoryStone extends Runestone {
Sample.INSTANCE.play( Assets.Sounds.READ );
Invisibility.dispel();
}
private String inventoryTitle(){
return Messages.get(this, "inv_title");
}
protected Class<?extends Bag> preferredBag = null;
protected boolean usableOnItem( Item item ){
return true;
}
protected abstract void onItemSelected( Item item );
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return inventoryTitle();
}
@Override
public Class<? extends Bag> preferredBag() {
return preferredBag;
}
@Override
public boolean itemSelectable(Item item) {
return usableOnItem(item);
}
@Override
public void onSelect( Item item ) {

View File

@ -21,9 +21,11 @@
package com.shatteredpixel.shatteredpixeldungeon.items.stones;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfUpgrade;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@ -33,15 +35,19 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class StoneOfAugmentation extends InventoryStone {
{
mode = WndBag.Mode.ENCHANTABLE;
preferredBag = Belongings.Backpack.class;
image = ItemSpriteSheet.STONE_AUGMENTATION;
}
@Override
protected boolean usableOnItem(Item item) {
return ScrollOfEnchantment.enchantable(item);
}
@Override
protected void onItemSelected(Item item) {

View File

@ -21,24 +21,30 @@
package com.shatteredpixel.shatteredpixeldungeon.items.stones;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.effects.Enchanting;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class StoneOfEnchantment extends InventoryStone {
{
mode = WndBag.Mode.ENCHANTABLE;
preferredBag = Belongings.Backpack.class;
image = ItemSpriteSheet.STONE_ENCHANT;
unique = true;
}
@Override
protected boolean usableOnItem(Item item) {
return ScrollOfEnchantment.enchantable(item);
}
@Override
protected void onItemSelected(Item item) {

View File

@ -40,7 +40,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.IconTitle;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.Image;
import com.watabou.utils.Reflection;
@ -48,13 +47,12 @@ import java.util.ArrayList;
public class StoneOfIntuition extends InventoryStone {
{
mode = WndBag.Mode.INTUITIONABLE;
image = ItemSpriteSheet.STONE_INTUITION;
}
public static boolean isIntuitionable( Item item ){
@Override
protected boolean usableOnItem(Item item) {
if (item instanceof Ring){
return !((Ring) item).isKnown();
} else if (item instanceof Potion){

View File

@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRecharging;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfCorrosion;
@ -123,7 +124,7 @@ public class MagesStaff extends MeleeWeapon {
if (action.equals(AC_IMBUE)) {
curUser = hero;
GameScene.selectItem(itemSelector, WndBag.Mode.WAND, Messages.get(this, "prompt"));
GameScene.selectItem(itemSelector);
} else if (action.equals(AC_ZAP)){
@ -367,7 +368,23 @@ public class MagesStaff extends MeleeWeapon {
return super.enchant(ench);
}
private final WndBag.Listener itemSelector = new WndBag.Listener() {
private final WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(MagesStaff.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return MagicalHolster.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Wand;
}
@Override
public void onSelect( final Item item ) {
if (item != null) {

View File

@ -27,6 +27,8 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.Crossbow;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@ -67,7 +69,7 @@ public class Dart extends MissileWeapon {
public void execute(Hero hero, String action) {
super.execute(hero, action);
if (action.equals(AC_TIP)){
GameScene.selectItem(itemSelector, WndBag.Mode.SEED, Messages.get(this, "prompt"));
GameScene.selectItem(itemSelector);
}
}
@ -166,8 +168,23 @@ public class Dart extends MissileWeapon {
return super.value()/2; //half normal value
}
private final WndBag.Listener itemSelector = new WndBag.Listener() {
private final WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(Dart.class, "prompt");
}
@Override
public Class<?extends Bag> preferredBag(){
return VelvetPouch.class;
}
@Override
public boolean itemSelectable(Item item) {
return item instanceof Plant.Seed;
}
@Override
public void onSelect(final Item item) {

View File

@ -155,7 +155,7 @@ public class AlchemyScene extends PixelScene {
slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
updateState();
}
AlchemyScene.this.addToFront(WndBag.lastBag( itemSelector, WndBag.Mode.ALCHEMY, Messages.get(AlchemyScene.class, "select")));
AlchemyScene.this.addToFront(WndBag.getBag( itemSelector ));
}
@Override
@ -319,7 +319,18 @@ public class AlchemyScene extends PixelScene {
Game.switchScene(GameScene.class);
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(AlchemyScene.class, "select");
}
@Override
public boolean itemSelectable(Item item) {
return Recipe.usableInRecipe(item);
}
@Override
public void onSelect( Item item ) {
synchronized (inputs) {

View File

@ -47,10 +47,6 @@ import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Honeypot;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
import com.shatteredpixel.shatteredpixeldungeon.journal.Journal;
@ -92,7 +88,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag.Mode;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoCell;
@ -1057,20 +1052,11 @@ public class GameScene extends PixelScene {
}
}
public static WndBag selectItem( WndBag.Listener listener, WndBag.Mode mode, String title ) {
public static WndBag selectItem( WndBag.ItemSelector listener ) {
cancelCellSelector();
WndBag wnd =
mode == Mode.SEED ?
WndBag.getBag( VelvetPouch.class, listener, mode, title ) :
mode == Mode.SCROLL ?
WndBag.getBag( ScrollHolder.class, listener, mode, title ) :
mode == Mode.POTION ?
WndBag.getBag( PotionBandolier.class, listener, mode, title ) :
mode == Mode.WAND ?
WndBag.getBag( MagicalHolster.class, listener, mode, title ) :
WndBag.lastBag( listener, mode, title );
WndBag wnd = WndBag.getBag( listener );
if (scene != null) scene.addToFront( wnd );
return wnd;

View File

@ -37,7 +37,7 @@ import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.PathFinder;
public class QuickSlotButton extends Button implements WndBag.Listener {
public class QuickSlotButton extends Button {
private static QuickSlotButton[] instance = new QuickSlotButton[4];
private int slotNum;
@ -166,26 +166,39 @@ public class QuickSlotButton extends Button implements WndBag.Listener {
@Override
protected void onClick() {
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") );
GameScene.selectItem( itemSelector );
}
@Override
protected boolean onLongClick() {
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") );
GameScene.selectItem( itemSelector );
return true;
}
private WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(QuickSlotButton.class, "select_item");
}
@Override
public boolean itemSelectable(Item item) {
return item.defaultAction != null;
}
@Override
public void onSelect(Item item) {
if (item != null) {
Dungeon.quickslot.setSlot( slotNum , item );
refresh();
}
}
};
private static Item select(int slotNum){
return Dungeon.quickslot.getItem( slotNum );
}
@Override
public void onSelect( Item item ) {
if (item != null) {
Dungeon.quickslot.setSlot( slotNum , item );
refresh();
}
}
public void item( Item item ) {
slot.item( item );

View File

@ -143,7 +143,7 @@ public class Toolbar extends Component {
@Override
protected void onClick() {
GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null));
GameScene.show(new WndBag(Dungeon.hero.belongings.backpack));
}
@Override

View File

@ -26,29 +26,15 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDAction;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Shopkeeper;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.Recipe;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.SandalsOfNature;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.UnstableSpellbook;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfRemoveCurse;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTransmutation;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.Recycle;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfIntuition;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
@ -71,31 +57,6 @@ public class WndBag extends WndTabbed {
//only one bag window can appear at a time
public static Window INSTANCE;
//FIXME this is getting cumbersome, there should be a better way to manage this
public static enum Mode {
ALL,
UNIDENTIFED,
UNCURSABLE,
CURSABLE,
UPGRADEABLE,
QUICKSLOT,
FOR_SALE,
WEAPON,
ARMOR,
ENCHANTABLE,
WAND,
SEED,
FOOD,
POTION,
SCROLL,
INTUITIONABLE,
EQUIPMENT,
TRANMSUTABLE,
ALCHEMY,
RECYCLABLE,
NOT_EQUIPPED
}
protected static final int COLS_P = 5;
protected static final int COLS_L = 5;
@ -110,9 +71,7 @@ public class WndBag extends WndTabbed {
protected static final int TITLE_HEIGHT = 14;
private Listener listener;
private WndBag.Mode mode;
private String title;
private ItemSelector selector;
private int nCols;
private int nRows;
@ -124,10 +83,13 @@ public class WndBag extends WndTabbed {
protected int col;
protected int row;
private static Mode lastMode;
private static Bag lastBag;
public WndBag( Bag bag, Listener listener, Mode mode, String title ) {
public WndBag( Bag bag ) {
this(bag, null);
}
public WndBag( Bag bag, ItemSelector selector ) {
super();
@ -136,11 +98,8 @@ public class WndBag extends WndTabbed {
}
INSTANCE = this;
this.listener = listener;
this.mode = mode;
this.title = title;
this.selector = selector;
lastMode = mode;
lastBag = bag;
slotWidth = PixelScene.landscape() ? SLOT_WIDTH_L : SLOT_WIDTH_P;
@ -189,25 +148,29 @@ public class WndBag extends WndTabbed {
layoutTabs();
}
public static WndBag lastBag( Listener listener, Mode mode, String title ) {
public static WndBag lastBag( ItemSelector selector ) {
if (mode == lastMode && lastBag != null &&
Dungeon.hero.belongings.backpack.contains( lastBag )) {
if (lastBag != null && Dungeon.hero.belongings.backpack.contains( lastBag )) {
return new WndBag( lastBag, listener, mode, title );
return new WndBag( lastBag, selector );
} else {
return new WndBag( Dungeon.hero.belongings.backpack, listener, mode, title );
return new WndBag( Dungeon.hero.belongings.backpack, selector );
}
}
public static WndBag getBag( Class<? extends Bag> bagClass, Listener listener, Mode mode, String title ) {
Bag bag = Dungeon.hero.belongings.getItem( bagClass );
return bag != null ?
new WndBag( bag, listener, mode, title ) :
lastBag( listener, mode, title );
public static WndBag getBag( ItemSelector selector ) {
if (selector.preferredBag() == Belongings.Backpack.class){
return new WndBag( Dungeon.hero.belongings.backpack, selector );
} else if (selector.preferredBag() != null){
Bag bag = Dungeon.hero.belongings.getItem( selector.preferredBag() );
if (bag != null) return new WndBag( bag, selector );
}
return lastBag( selector );
}
protected void placeTitle( Bag bag, int width ){
@ -225,7 +188,8 @@ public class WndBag extends WndTabbed {
amt.y = (TITLE_HEIGHT - amt.baseLine())/2f - 1;
PixelScene.align(amt);
add(amt);
String title = selector != null ? selector.textPrompt() : null;
RenderedTextBlock txtTitle = PixelScene.renderTextBlock(
title != null ? Messages.titleCase(title) : Messages.titleCase( bag.name() ), 8 );
txtTitle.hardlight( TITLE_COLOR );
@ -297,8 +261,8 @@ public class WndBag extends WndTabbed {
@Override
public void onBackPressed() {
if (listener != null) {
listener.onSelect( null );
if (selector != null) {
selector.onSelect( null );
}
super.onBackPressed();
}
@ -306,7 +270,7 @@ public class WndBag extends WndTabbed {
@Override
protected void onClick( Tab tab ) {
hide();
Game.scene().addToFront(new WndBag(((BagTab) tab).bag, listener, mode, title));
Game.scene().addToFront(new WndBag(((BagTab) tab).bag, selector));
}
@Override
@ -429,30 +393,8 @@ public class WndBag extends WndTabbed {
if (item.name() == null) {
enable( false );
} else {
enable(
mode == Mode.FOR_SALE && Shopkeeper.willBuyItem(item) ||
mode == Mode.UPGRADEABLE && item.isUpgradable() ||
mode == Mode.UNIDENTIFED && !item.isIdentified() ||
mode == Mode.UNCURSABLE && ScrollOfRemoveCurse.uncursable(item) ||
mode == Mode.CURSABLE && ((item instanceof EquipableItem && !(item instanceof MissileWeapon)) || item instanceof Wand) ||
mode == Mode.QUICKSLOT && (item.defaultAction != null) ||
mode == Mode.WEAPON && (item instanceof MeleeWeapon) ||
mode == Mode.ARMOR && (item instanceof Armor) ||
mode == Mode.ENCHANTABLE && (item instanceof MeleeWeapon || item instanceof SpiritBow || item instanceof Armor) ||
mode == Mode.WAND && (item instanceof Wand) ||
mode == Mode.SEED && SandalsOfNature.canUseSeed(item) ||
mode == Mode.FOOD && (item instanceof Food) ||
mode == Mode.POTION && (item instanceof Potion) ||
mode == Mode.SCROLL && UnstableSpellbook.canUseScroll(item) ||
mode == Mode.INTUITIONABLE && StoneOfIntuition.isIntuitionable(item) ||
mode == Mode.EQUIPMENT && (item instanceof EquipableItem || item instanceof Wand) ||
mode == Mode.ALCHEMY && Recipe.usableInRecipe(item) ||
mode == Mode.TRANMSUTABLE && ScrollOfTransmutation.canTransmute(item) ||
mode == Mode.NOT_EQUIPPED && !item.isEquipped(Dungeon.hero) ||
mode == Mode.RECYCLABLE && Recycle.isRecyclable(item) ||
mode == Mode.ALL
);
} else if (selector != null) {
enable(selector.itemSelectable(item));
}
} else {
bg.color( NORMAL );
@ -475,10 +417,10 @@ public class WndBag extends WndTabbed {
hide();
} else if (listener != null) {
} else if (selector != null) {
hide();
listener.onSelect( item );
selector.onSelect( item );
} else {
@ -489,12 +431,12 @@ public class WndBag extends WndTabbed {
@Override
protected boolean onLongClick() {
if (listener == null && item.defaultAction != null) {
if (selector == null && item.defaultAction != null) {
hide();
Dungeon.quickslot.setSlot( 0 , item );
QuickSlotButton.refresh();
return true;
} else if (listener != null) {
} else if (selector != null) {
Game.scene().addToFront(new WndInfoItem(item));
return true;
} else {
@ -502,8 +444,13 @@ public class WndBag extends WndTabbed {
}
}
}
public interface Listener {
void onSelect( Item item );
public abstract static class ItemSelector {
public abstract String textPrompt();
public Class<?extends Bag> preferredBag(){
return null; //defaults to last bag opened
}
public abstract boolean itemSelectable( Item item );
public abstract void onSelect( Item item );
}
}

View File

@ -23,9 +23,11 @@ package com.shatteredpixel.shatteredpixeldungeon.windows;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
@ -69,7 +71,7 @@ public class WndBlacksmith extends Window {
@Override
protected void onClick() {
btnPressed = btnItem1;
GameScene.selectItem( itemSelector, WndBag.Mode.UPGRADEABLE, Messages.get(WndBlacksmith.class, "select") );
GameScene.selectItem( itemSelector );
}
};
btnItem1.setRect( (WIDTH - BTN_GAP) / 2 - BTN_SIZE, message.top() + message.height() + BTN_GAP, BTN_SIZE, BTN_SIZE );
@ -79,7 +81,7 @@ public class WndBlacksmith extends Window {
@Override
protected void onClick() {
btnPressed = btnItem2;
GameScene.selectItem( itemSelector, WndBag.Mode.UPGRADEABLE, Messages.get(WndBlacksmith.class, "select") );
GameScene.selectItem( itemSelector );
}
};
btnItem2.setRect( btnItem1.right() + BTN_GAP, btnItem1.top(), BTN_SIZE, BTN_SIZE );
@ -100,7 +102,23 @@ public class WndBlacksmith extends Window {
resize( WIDTH, (int)btnReforge.bottom() );
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
protected WndBag.ItemSelector itemSelector = new WndBag.ItemSelector() {
@Override
public String textPrompt() {
return Messages.get(WndBlacksmith.class, "select");
}
@Override
public Class<?extends Bag> preferredBag(){
return Belongings.Backpack.class;
}
@Override
public boolean itemSelectable(Item item) {
return item.isUpgradable();
}
@Override
public void onSelect( Item item ) {
if (item != null && btnPressed.parent != null) {