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();
}
use of com.badlogic.gdx.scenes.scene2d.utils.ChangeListener in project libgdx by libgdx.
the class Dialog method initialize.
private void initialize() {
setModal(true);
defaults().space(6);
add(contentTable = new Table(skin)).expand().fill();
row();
add(buttonTable = new Table(skin)).fillX();
contentTable.defaults().space(6);
buttonTable.defaults().space(6);
buttonTable.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
if (!values.containsKey(actor))
return;
while (actor.getParent() != buttonTable) actor = actor.getParent();
result(values.get(actor));
if (!cancelHide)
hide();
cancelHide = false;
}
});
focusListener = new FocusListener() {
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused)
focusChanged(event);
}
public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused)
focusChanged(event);
}
private void focusChanged(FocusEvent event) {
Stage stage = getStage();
if (isModal && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == Dialog.this) {
// Dialog is top most actor.
Actor newFocusedActor = event.getRelatedActor();
if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus)))
event.cancel();
}
}
};
}
Aggregations