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

@ -86,25 +86,27 @@ public class WndAlchemy extends Window {
h += desc.height() + 6; h += desc.height() + 6;
synchronized (inputs) {
for (int i = 0; i < inputs.length; i++) { for (int i = 0; i < inputs.length; i++) {
inputs[i] = new WndBlacksmith.ItemButton(){ inputs[i] = new WndBlacksmith.ItemButton() {
@Override @Override
protected void onClick() { protected void onClick() {
super.onClick(); super.onClick();
if (item != null){ if (item != null) {
if (!item.collect()){ if (!item.collect()) {
Dungeon.level.drop(item, Dungeon.hero.pos); Dungeon.level.drop(item, Dungeon.hero.pos);
} }
item = null; item = null;
slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING)); slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
} }
GameScene.selectItem( itemSelector, WndBag.Mode.ALCHEMY, Messages.get(WndAlchemy.class, "select") ); GameScene.selectItem(itemSelector, WndBag.Mode.ALCHEMY, Messages.get(WndAlchemy.class, "select"));
} }
}; };
inputs[i].setRect(10, h, BTN_SIZE, BTN_SIZE); inputs[i].setRect(10, h, BTN_SIZE, BTN_SIZE);
add(inputs[i]); add(inputs[i]);
h += BTN_SIZE + 2; h += BTN_SIZE + 2;
} }
}
btnCombine = new RedButton(""){ btnCombine = new RedButton(""){
Image arrow; Image arrow;
@ -211,10 +213,11 @@ 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) {
if (item != null && inputs[0] != null) {
for (int i = 0; i < inputs.length; i++) { for (int i = 0; i < inputs.length; i++) {
if (inputs[i].item == null){ if (inputs[i].item == null) {
if (item instanceof Dart){ if (item instanceof Dart) {
inputs[i].item(item.detachAll(Dungeon.hero.belongings.backpack)); inputs[i].item(item.detachAll(Dungeon.hero.belongings.backpack));
} else { } else {
inputs[i].item(item.detach(Dungeon.hero.belongings.backpack)); inputs[i].item(item.detach(Dungeon.hero.belongings.backpack));
@ -222,9 +225,10 @@ public class WndAlchemy extends Window {
break; break;
} }
} }
}
updateState(); updateState();
} }
}
}
}; };
private<T extends Item> ArrayList<T> filterInput(Class<? extends T> itemClass){ private<T extends Item> ArrayList<T> filterInput(Class<? extends T> itemClass){
@ -276,8 +280,9 @@ public class WndAlchemy extends Window {
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] != null && inputs[i].item != null) {
if (inputs[i].item.quantity() <= 0) { if (inputs[i].item.quantity() <= 0) {
inputs[i].slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING)); inputs[i].slot.item(new WndBag.Placeholder(ItemSpriteSheet.SOMETHING));
inputs[i].item = null; inputs[i].item = null;
@ -286,6 +291,7 @@ public class WndAlchemy extends Window {
} }
} }
} }
}
btnCombine.enable(false); btnCombine.enable(false);
} }