v0.8.2: improved misc equip swapping window

This commit is contained in:
Evan Debenham 2020-08-05 12:19:24 -04:00
parent 1325f3317e
commit 3bc61ac40c
2 changed files with 37 additions and 11 deletions

View File

@ -51,35 +51,56 @@ public abstract class KindofMisc extends EquipableItem {
if (equipFull) { if (equipFull) {
final KindofMisc m1; final KindofMisc[] miscs = new KindofMisc[3];
final KindofMisc m2; miscs[0] = hero.belongings.artifact;
if (this instanceof Artifact){ miscs[1] = hero.belongings.misc;
m1 = hero.belongings.artifact; miscs[2] = hero.belongings.ring;
m2 = hero.belongings.misc;
} else { final boolean[] enabled = new boolean[3];
m1 = hero.belongings.misc; enabled[0] = miscs[0] != null;
m2 = hero.belongings.ring; enabled[1] = miscs[1] != null;
enabled[2] = miscs[2] != null;
//force swapping with the same type of item if 2x of that type is already present
if (this instanceof Ring && hero.belongings.misc instanceof Ring){
enabled[0] = false; //disable artifact
} else if (this instanceof Artifact && hero.belongings.misc instanceof Artifact){
enabled[2] = false; //disable ring
} }
GameScene.show( GameScene.show(
new WndOptions(Messages.get(KindofMisc.class, "unequip_title"), new WndOptions(Messages.get(KindofMisc.class, "unequip_title"),
Messages.get(KindofMisc.class, "unequip_message"), Messages.get(KindofMisc.class, "unequip_message"),
Messages.titleCase(m1.toString()), miscs[0] == null ? "---" : Messages.titleCase(miscs[0].toString()),
Messages.titleCase(m2.toString())) { miscs[1] == null ? "---" : Messages.titleCase(miscs[1].toString()),
miscs[2] == null ? "---" : Messages.titleCase(miscs[2].toString())) {
@Override @Override
protected void onSelect(int index) { protected void onSelect(int index) {
KindofMisc equipped = (index == 0 ? m1 : m2); KindofMisc equipped = miscs[index];
int slot = Dungeon.quickslot.getSlot(KindofMisc.this); int slot = Dungeon.quickslot.getSlot(KindofMisc.this);
detach(hero.belongings.backpack); detach(hero.belongings.backpack);
if (equipped.doUnequip(hero, true, false)) { if (equipped.doUnequip(hero, true, false)) {
//swap out equip in misc slot if needed
if (index == 0 && KindofMisc.this instanceof Ring){
hero.belongings.artifact = (Artifact)hero.belongings.misc;
hero.belongings.misc = null;
} else if (index == 2 && KindofMisc.this instanceof Artifact){
hero.belongings.ring = (Ring) hero.belongings.misc;
hero.belongings.misc = null;
}
doEquip(hero); doEquip(hero);
} else { } else {
collect(); collect();
} }
if (slot != -1) Dungeon.quickslot.setSlot(slot, KindofMisc.this); if (slot != -1) Dungeon.quickslot.setSlot(slot, KindofMisc.this);
} }
@Override
protected boolean enabled(int index) {
return enabled[index];
}
}); });
return false; return false;

View File

@ -61,6 +61,7 @@ public class WndOptions extends Window {
onSelect( index ); onSelect( index );
} }
}; };
btn.enable(enabled(i));
btn.setRect( MARGIN, pos, width - MARGIN * 2, BUTTON_HEIGHT ); btn.setRect( MARGIN, pos, width - MARGIN * 2, BUTTON_HEIGHT );
add( btn ); add( btn );
@ -69,6 +70,10 @@ public class WndOptions extends Window {
resize( width, (int)pos ); resize( width, (int)pos );
} }
protected boolean enabled( int index ){
return true;
}
protected void onSelect( int index ) {} protected void onSelect( int index ) {}
} }