mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-09 15:28:18 +07:00
Improved in-game input auto-focus and keyboard handling
This commit is contained in:
@ -30,6 +30,7 @@ import com.badlogic.gdx.utils.IntMap;
|
|||||||
import com.badlogic.gdx.utils.Scaling;
|
import com.badlogic.gdx.utils.Scaling;
|
||||||
import com.badlogic.gdx.utils.Timer;
|
import com.badlogic.gdx.utils.Timer;
|
||||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||||
|
import com.riiablo.Client;
|
||||||
import com.riiablo.Keys;
|
import com.riiablo.Keys;
|
||||||
import com.riiablo.Riiablo;
|
import com.riiablo.Riiablo;
|
||||||
import com.riiablo.codec.DC6;
|
import com.riiablo.codec.DC6;
|
||||||
@ -125,6 +126,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
|||||||
DCWrapper enteringImage;
|
DCWrapper enteringImage;
|
||||||
|
|
||||||
public TextArea input;
|
public TextArea input;
|
||||||
|
Client.ScreenBoundsListener screenBoundsListener;
|
||||||
TextArea output;
|
TextArea output;
|
||||||
|
|
||||||
//Char character;
|
//Char character;
|
||||||
@ -169,22 +171,27 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
|||||||
background.setTopHeight(padding);
|
background.setTopHeight(padding);
|
||||||
background.setRightWidth(padding);
|
background.setRightWidth(padding);
|
||||||
background.setBottomHeight(padding);
|
background.setBottomHeight(padding);
|
||||||
}}) {{
|
}}) {
|
||||||
|
{
|
||||||
writeEnters = false;
|
writeEnters = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
if (!visible) input.setText("");
|
if (!visible) input.setText("");
|
||||||
|
else {
|
||||||
|
stage.setKeyboardFocus(this);
|
||||||
|
Gdx.input.setOnscreenKeyboardVisible(true);
|
||||||
|
}
|
||||||
super.setVisible(visible);
|
super.setVisible(visible);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
input.setDebug(true);
|
//input.setDebug(true);
|
||||||
input.setSize(stage.getWidth() * 0.75f, Riiablo.fonts.fontformal12.getLineHeight() * 3);
|
input.setSize(stage.getWidth() * 0.75f, Riiablo.fonts.fontformal12.getLineHeight() * 3);
|
||||||
input.setPosition(stage.getWidth() / 2 - input.getWidth() / 2, 100);
|
input.setPosition(stage.getWidth() / 2 - input.getWidth() / 2, 100);
|
||||||
input.setAlignment(Align.topLeft);
|
input.setAlignment(Align.topLeft);
|
||||||
input.setVisible(false);
|
input.setVisible(false);
|
||||||
input.setTouchable(Touchable.disabled);
|
if (Gdx.app.getType() != Application.ApplicationType.Android) input.setTouchable(Touchable.disabled);
|
||||||
|
|
||||||
output = new TextArea("", new TextArea.TextFieldStyle() {{
|
output = new TextArea("", new TextArea.TextFieldStyle() {{
|
||||||
this.font = Riiablo.fonts.fontformal12;
|
this.font = Riiablo.fonts.fontformal12;
|
||||||
@ -624,6 +631,18 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
|||||||
Keys.Enter.addStateListener(mappedKeyStateListener);
|
Keys.Enter.addStateListener(mappedKeyStateListener);
|
||||||
Riiablo.input.addProcessor(stage);
|
Riiablo.input.addProcessor(stage);
|
||||||
Riiablo.input.addProcessor(inputProcessorTest);
|
Riiablo.input.addProcessor(inputProcessorTest);
|
||||||
|
Riiablo.client.addScreenBoundsListener(screenBoundsListener = new Client.ScreenBoundsListener() {
|
||||||
|
final float THRESHOLD = 150;
|
||||||
|
float prevY = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreenBounds(float x, float y, float width, float height) {
|
||||||
|
if (y < THRESHOLD && prevY >= THRESHOLD) input.setVisible(false);
|
||||||
|
input.setPosition(stage.getWidth() / 2, y + 100, Align.bottom | Align.center);
|
||||||
|
prevY = y;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
screenBoundsListener.updateScreenBounds(0, 0, 0, 0);
|
||||||
|
|
||||||
if (socket != null && socket.isConnected()) {
|
if (socket != null && socket.isConnected()) {
|
||||||
Gdx.app.log(TAG, "connecting to " + socket.getRemoteAddress() + "...");
|
Gdx.app.log(TAG, "connecting to " + socket.getRemoteAddress() + "...");
|
||||||
@ -669,6 +688,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
|||||||
Keys.Enter.removeStateListener(mappedKeyStateListener);
|
Keys.Enter.removeStateListener(mappedKeyStateListener);
|
||||||
Riiablo.input.removeProcessor(stage);
|
Riiablo.input.removeProcessor(stage);
|
||||||
Riiablo.input.removeProcessor(inputProcessorTest);
|
Riiablo.input.removeProcessor(inputProcessorTest);
|
||||||
|
Riiablo.client.removeScreenBoundsListener(screenBoundsListener);
|
||||||
|
|
||||||
//updateTask.cancel();
|
//updateTask.cancel();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user