use of com.badlogic.gdx.scenes.scene2d.ui.Dialog 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.ui.Dialog 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.ui.Dialog in project gdx-skineditor by cobolfoo.
the class SkinEditorGame method showNotice.
/**
* Display a dialog with a notice
*/
public void showNotice(String title, String message, Stage stage) {
Dialog dlg = new Dialog(title, skin);
dlg.pad(20);
dlg.getContentTable().add(message).pad(20);
dlg.button("OK", true);
dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlg.show(stage);
}
use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.
the class MenuBar method showExportDialog.
/*
* Show export dialog
*/
protected void showExportDialog() {
final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject());
final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin);
Dialog dlg = new Dialog("Export to Directory", game.skin) {
@Override
protected void result(Object object) {
if ((Boolean) object == true) {
if (textDirectory.getText().isEmpty() == true) {
game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage);
return;
}
FileHandle targetDirectory = new FileHandle(textDirectory.getText());
if (targetDirectory.exists() == false) {
game.showNotice("Warning", "Directory not found!", game.screenMain.stage);
return;
}
// Copy uiskin.* and *.fnt
FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject());
for (FileHandle file : projectFolder.list()) {
if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) {
Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ...");
FileHandle target = targetDirectory.child(file.name());
file.copyTo(target);
}
}
game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage);
}
}
};
dlg.pad(20);
Table table = dlg.getContentTable();
table.padTop(20);
table.add("Directory:");
table.add(textDirectory).width(320);
TextButton buttonChoose = new TextButton("...", game.skin);
buttonChoose.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
// Need to steal focus first with this hack (Thanks to Z-Man)
Frame frame = new Frame();
frame.setUndecorated(true);
frame.setOpacity(0);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.toFront();
frame.setVisible(false);
frame.dispose();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION) {
File f = chooser.getSelectedFile();
textDirectory.setText(f.getAbsolutePath());
// Store to file
prefs.putString("export_to_directory", f.getAbsolutePath());
prefs.flush();
}
}
});
table.add(buttonChoose);
table.row();
table.padBottom(20);
dlg.button("Export", true);
dlg.button("Cancel", false);
dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlg.show(getStage());
}
use of com.badlogic.gdx.scenes.scene2d.ui.Dialog in project gdx-skineditor by cobolfoo.
the class WelcomeScreen method showDeleteDialog.
/**
*
*/
private void showDeleteDialog() {
Dialog dlgStyle = new Dialog("Delete Project", game.skin) {
@Override
protected void result(Object object) {
if ((Boolean) object == false) {
return;
}
// We delete it
FileHandle projectFolder = Gdx.files.local("projects/" + (String) listProjects.getSelected());
projectFolder.deleteDirectory();
refreshProjects();
}
};
dlgStyle.pad(20);
dlgStyle.getContentTable().add("You are sure you want to delete this project?");
dlgStyle.button("OK", true);
dlgStyle.button("Cancel", false);
dlgStyle.key(com.badlogic.gdx.Input.Keys.ENTER, true);
dlgStyle.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
dlgStyle.show(stage);
}
Aggregations