v0.6.3a: fixed various rare crashes with the alchemy window

This commit is contained in:
Evan Debenham 2018-02-19 13:50:31 -05:00
parent 6d53f238bc
commit 8d09f897a5

View File

@ -85,25 +85,27 @@ public class WndAlchemy extends Window {
add(desc); add(desc);
h += desc.height() + 6; h += desc.height() + 6;
for (int i = 0; i < inputs.length; i++) { synchronized (inputs) {
inputs[i] = new WndBlacksmith.ItemButton(){ for (int i = 0; i < inputs.length; i++) {
@Override inputs[i] = new WndBlacksmith.ItemButton() {
protected void onClick() { @Override
super.onClick(); protected void onClick() {
if (item != null){ super.onClick();
if (!item.collect()){ if (item != null) {
Dungeon.level.drop(item, Dungeon.hero.pos); if (!item.collect()) {
Dungeon.level.drop(item, Dungeon.hero.pos);
}
item = null;
slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
} }
item = null; GameScene.selectItem(itemSelector, WndBag.Mode.ALCHEMY, Messages.get(WndAlchemy.class, "select"));
slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
} }
GameScene.selectItem( itemSelector, WndBag.Mode.ALCHEMY, Messages.get(WndAlchemy.class, "select") ); };
} inputs[i].setRect(10, h, BTN_SIZE, BTN_SIZE);
}; add(inputs[i]);
inputs[i].setRect(10, h, BTN_SIZE, BTN_SIZE); h += BTN_SIZE + 2;
add(inputs[i]); }
h += BTN_SIZE + 2;
} }
btnCombine = new RedButton(""){ btnCombine = new RedButton(""){
@ -211,19 +213,21 @@ public class WndAlchemy extends Window {
protected WndBag.Listener itemSelector = new WndBag.Listener() { protected WndBag.Listener itemSelector = new WndBag.Listener() {
@Override @Override
public void onSelect( Item item ) { public void onSelect( Item item ) {
if (item != null) { synchronized (inputs) {
for (int i = 0; i < inputs.length; i++) { if (item != null && inputs[0] != null) {
if (inputs[i].item == null){ for (int i = 0; i < inputs.length; i++) {
if (item instanceof Dart){ if (inputs[i].item == null) {
inputs[i].item(item.detachAll(Dungeon.hero.belongings.backpack)); if (item instanceof Dart) {
} else { inputs[i].item(item.detachAll(Dungeon.hero.belongings.backpack));
inputs[i].item(item.detach(Dungeon.hero.belongings.backpack)); } else {
inputs[i].item(item.detach(Dungeon.hero.belongings.backpack));
}
break;
} }
break;
} }
updateState();
} }
} }
updateState();
} }
}; };
@ -275,14 +279,16 @@ public class WndAlchemy extends Window {
if (!result.collect()){ if (!result.collect()){
Dungeon.level.drop(result, Dungeon.hero.pos); Dungeon.level.drop(result, Dungeon.hero.pos);
} }
for (int i = 0; i < inputs.length; i++){ synchronized (inputs) {
if (inputs[i].item != null) { for (int i = 0; i < inputs.length; i++) {
if (inputs[i].item.quantity() <= 0) { if (inputs[i] != null && inputs[i].item != null) {
inputs[i].slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING)); if (inputs[i].item.quantity() <= 0) {
inputs[i].item = null; inputs[i].slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
} else { inputs[i].item = null;
inputs[i].slot.item(inputs[i].item); } else {
inputs[i].slot.item(inputs[i].item);
}
} }
} }
} }