From 5d3f5dc4b60557f77dc3d5e89b9445c0be96e5b5 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Mon, 11 Feb 2019 01:44:39 -0800 Subject: [PATCH] Fixed chat box behavior GameScreen now ignores hotkeys while chat box is open Esc closes chat box Closing chat box will now set text to empty string Chat output TextArea will no longer block touch events (i.e., inventory management) --- core/src/gdx/diablo/screen/GameScreen.java | 55 ++++++---------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/core/src/gdx/diablo/screen/GameScreen.java b/core/src/gdx/diablo/screen/GameScreen.java index 784a5420..2c93e3d4 100644 --- a/core/src/gdx/diablo/screen/GameScreen.java +++ b/core/src/gdx/diablo/screen/GameScreen.java @@ -16,6 +16,7 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.net.Socket; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.Touchable; import com.badlogic.gdx.scenes.scene2d.ui.Touchpad; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; @@ -128,48 +129,15 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable background.setTopHeight(padding); background.setRightWidth(padding); background.setBottomHeight(padding); - }}) { - //boolean newlyVisible = false; - - { + }}) {{ writeEnters = false; - //setTextFieldFilter(new TextFieldFilter() { - // @Override - // public boolean acceptChar(TextField textField, char c) { - // return c != ENTER_ANDROID && c != ENTER_DESKTOP; - // } - //}); - /*setTextFieldListener(new TextFieldListener() { - @Override - public void keyTyped(TextField textField, char c) { - if (c == ENTER_ANDROID || c == ENTER_DESKTOP) { - //if (newlyVisible) { - // newlyVisible = false; - // return; - //} - - String text = input.getText(); - if (!text.isEmpty()) { - Gdx.app.debug(TAG, text); - Message message = new Message(player.stats.getName(), text); - out.println(Packets.build(message)); - input.setText(""); - } - - input.setVisible(false); - } - } - });*/ } - //@Override - //public void setVisible(boolean visible) { - //if (visible && !isVisible()) { - // newlyVisible = true; - //} - - // super.setVisible(visible); - //} + @Override + public void setVisible(boolean visible) { + if (!visible) input.setText(""); + super.setVisible(visible); + } }; input.setDebug(true); input.setSize(Diablo.VIRTUAL_WIDTH * 0.75f, Diablo.fonts.fontformal12.getLineHeight() * 3); @@ -188,6 +156,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable output.setAlignment(Align.topLeft); output.setDisabled(true); output.setVisible(true); + output.setTouchable(Touchable.disabled); escapePanel = new EscapePanel(); @@ -270,11 +239,17 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable mappedKeyStateListener = new MappedKeyStateAdapter() { @Override public void onPressed(MappedKey key, int keycode) { + if (input.isVisible() && (key != Keys.Enter && key != Keys.Esc)) { + return; + } + if (key == Keys.Esc) { if (escapePanel.isVisible()) { escapePanel.setVisible(false); + } else if (input.isVisible()) { + input.setVisible(false); } else if (inventoryPanel.isVisible() - || characterPanel.isVisible()) { + || characterPanel.isVisible()) { inventoryPanel.setVisible(false); characterPanel.setVisible(false); } else {