v1.2.0: fixed keypresses not cancelling inventory pane selection

This commit is contained in:
Evan Debenham 2022-02-14 14:25:38 -05:00
parent 2f17a264ea
commit 83c83e7b25

View File

@ -40,6 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndUseItem;
import com.watabou.gltextures.TextureCache; import com.watabou.gltextures.TextureCache;
import com.watabou.input.KeyEvent;
import com.watabou.input.PointerEvent; import com.watabou.input.PointerEvent;
import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapText;
import com.watabou.noosa.ColorBlock; import com.watabou.noosa.ColorBlock;
@ -50,6 +51,7 @@ import com.watabou.noosa.PointerArea;
import com.watabou.noosa.ui.Component; import com.watabou.noosa.ui.Component;
import com.watabou.utils.Point; import com.watabou.utils.Point;
import com.watabou.utils.PointF; import com.watabou.utils.PointF;
import com.watabou.utils.Signal;
import java.util.ArrayList; import java.util.ArrayList;
@ -61,6 +63,8 @@ public class InventoryPane extends Component {
//used to prevent clicks through the BG normally, or to cancel selectors if they're enabled //used to prevent clicks through the BG normally, or to cancel selectors if they're enabled
private PointerArea blocker; private PointerArea blocker;
private Signal.Listener keyBlocker;
private static InventoryPane instance; private static InventoryPane instance;
private ArrayList<InventorySlot> equipped; private ArrayList<InventorySlot> equipped;
@ -129,6 +133,18 @@ public class InventoryPane extends Component {
blocker.target = bg; //targets bg when there is no selector, otherwise targets itself blocker.target = bg; //targets bg when there is no selector, otherwise targets itself
add (blocker); add (blocker);
keyBlocker = new Signal.Listener<KeyEvent>(){
@Override
public boolean onSignal(KeyEvent keyEvent) {
if (keyEvent.pressed && isSelecting()){
selector = null;
updateInventory();
return true;
}
return false;
}
};
equipped = new ArrayList<>(); equipped = new ArrayList<>();
for (int i = 0; i < 5; i++){ for (int i = 0; i < 5; i++){
InventorySlot btn = new InventoryPaneSlot(null); InventorySlot btn = new InventoryPaneSlot(null);
@ -243,8 +259,10 @@ public class InventoryPane extends Component {
public void updateInventory(){ public void updateInventory(){
if (selector == null){ if (selector == null){
blocker.target = bg; blocker.target = bg;
KeyEvent.removeKeyListener(keyBlocker);
} else { } else {
blocker.target = blocker; blocker.target = blocker;
KeyEvent.addKeyListener(keyBlocker);
} }
Belongings stuff = Dungeon.hero.belongings; Belongings stuff = Dungeon.hero.belongings;