use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project Entitas-Java by Rubentxu.
the class GuiFactory method createTouchPad.
public Touchpad createTouchPad(float width, float height, InputEntity player) {
Touchpad touchpad = new Touchpad(10 * ScaleUtil.getSizeRatio(), skin);
touchpad.setPosition(25 * ScaleUtil.getSizeRatio(), 15);
touchpad.setWidth(width);
touchpad.setHeight(height);
PlayerInputController stateController = player.getPlayerInputController();
touchpad.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
System.out.println("PercentX " + ((Touchpad) actor).getKnobPercentX() + "PercentY " + ((Touchpad) actor).getKnobPercentY());
if (((Touchpad) actor).getKnobPercentX() == 0 || ((Touchpad) actor).getKnobPercentX() < 0.5 && ((Touchpad) actor).getKnobPercentX() > -0.5) {
// controller.rightReleased();
// controller.leftReleased();
player.replacePlayerInputController(false, false, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentX() > 0.5) {
// controller.rightPressed();
// controller.leftReleased();
player.replacePlayerInputController(false, true, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentX() < -0.5) {
// controller.leftPressed();
// controller.rightReleased();
player.replacePlayerInputController(true, false, stateController.jumpPressed);
}
if (((Touchpad) actor).getKnobPercentY() > 0.5) {
// controller.jumpPressed();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, true);
} else {
// controller.jumpReleased();
player.replacePlayerInputController(stateController.leftPressed, stateController.rightPressed, false);
}
}
});
return touchpad;
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.
the class FishMiniGame method dialog.
/**
* Displays the results dialog.
*/
public void dialog() {
message = formatString(answerField.getText());
Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
final Dialog dialog = new Dialog("Results", game.assets.skin);
final TextButton okButton = new TextButton("OK", game.assets.skin);
dialog.getButtonTable().bottom();
if (checkAnswer() == -1) {
Label label = new Label("Invalid answer. Please try again.", labelStyle);
label.setScale(.5f);
label.setWrap(true);
label.setAlignment(Align.center);
dialog.add(label).width(500).pad(50);
dialog.add(okButton).bottom();
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (okButton.isPressed()) {
dialog.hide();
canvas.setColor(drawColor);
}
}
});
dialog.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ENTER) {
dialog.hide();
return true;
}
return false;
}
});
} else {
Label label = new Label("Your answer was: " + message + ". " + "The correct answer was: " + answer + ". " + "You get " + checkAnswer() + " back!", labelStyle);
game.save.addScore(checkAnswer());
game.save.setLives(player.getLives());
label.setScale(.5f);
label.setWrap(true);
label.setAlignment(Align.center);
dialog.add(label).width(500).pad(50);
dialog.add(okButton).bottom();
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (okButton.isPressed()) {
dialog.cancel();
if ((game.save.getLevel() - 1) % 5 == 0) {
game.setScreen(new ContinueScreen(game, true));
} else {
game.setScreen(new MazeScreen(game, false));
}
}
}
});
dialog.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ENTER) {
if ((game.save.getLevel() - 1) % 5 == 0) {
game.setScreen(new ContinueScreen(game, true));
} else {
game.setScreen(new MazeScreen(game, false));
}
return true;
}
return false;
}
});
}
dialog.show(stage);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.
the class ContinueScreen method highScoreDialog.
/**
* Displays the high score dialog.
*/
public void highScoreDialog() {
Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
final Dialog dialog = new Dialog("High Score", game.assets.skin);
final TextButton okButton = new TextButton("OK", game.assets.skin);
dialog.getButtonTable().bottom();
Label label = new Label("Enter your name:", labelStyle);
label.setScale(.5f);
label.setWrap(true);
label.setAlignment(Align.center);
final TextField nameField = new TextField("", game.assets.skin);
dialog.add(label).width(500).pad(50);
dialog.add(nameField);
dialog.add(okButton).bottom();
nameField.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char key) {
name = formatString(nameField.getText());
if (!name.equals("")) {
if (key == (char) 13) {
displayHighScores(name);
}
}
}
});
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
name = formatString(nameField.getText());
if (!name.equals("")) {
if (okButton.isPressed()) {
dialog.hide();
displayHighScores(name);
}
}
}
});
dialog.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
name = formatString(nameField.getText());
if (!name.equals("")) {
if (keycode == Keys.ENTER) {
displayHighScores(name);
return true;
}
}
return false;
}
});
dialog.show(stage);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.
the class MazeScreen method setupPauseMenu.
/** Create the pause menu. */
private void setupPauseMenu() {
pauseMenu = new Stage(new ScreenViewport(), game.batch);
Table table = new Table();
table.setFillParent(true);
table.center();
pauseMenu.addActor(table);
TextButton resumeButton = new TextButton("Resume", game.assets.skin);
resumeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
paused = false;
}
});
table.add(resumeButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
table.row();
TextButton settingsButton = new TextButton("Settings", game.assets.skin);
final Screen sourceScreen = this;
settingsButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
game.settingsScreen.setSourceScreen(sourceScreen);
game.setScreen(game.settingsScreen);
}
});
table.add(settingsButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
table.row();
TextButton quitButton = new TextButton("Main Menu", game.assets.skin);
quitButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
game.setScreen(game.menuScreen);
}
});
table.add(quitButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project AmazingMaze by TheVirtualMachine.
the class StoryScreen method setupUI.
/** Helper method to setup the UI. */
private void setupUI() {
stage = new Stage(new ScreenViewport(), game.batch);
table = new Table();
table.top().center();
table.setFillParent(true);
stage.addActor(table);
header = new Label("Story", game.assets.skin, Assets.SERIF_HEADER_STYLE);
table.add(header).padTop(Gdx.graphics.getHeight() / 25f);
storyLabel = new Label(readStory(), game.assets.skin, Assets.STORY_STYLE);
storyLabel.setWrap(true);
table.row();
table.add(storyLabel).maxWidth(Gdx.graphics.getWidth()).prefWidth(Gdx.graphics.getWidth() / 1.125f).pad(Gdx.graphics.getHeight() / 25f);
continueButton = new TextButton("Continue...", game.assets.skin);
continueButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (continueButton.isPressed()) {
game.setScreen(new MazeScreen(game, false));
}
}
});
table.row();
table.add(continueButton).width(Gdx.graphics.getWidth() / 4f).pad(Gdx.graphics.getHeight() / 25f).expandY().bottom().fillY();
}
Aggregations