Java Code Examples for com.badlogic.gdx.scenes.scene2d.ui.Dialog#button()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Dialog#button() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HudRenderer.java    From xibalba with MIT License 6 votes vote down vote up
private void setupDeathDialog() {
  deathDialog = new Dialog("", Main.skin) {
    public void result(Object obj) {
      if (obj.equals(true)) {
        Main.playScreen.dispose();
        main.setScreen(new MainMenuScreen(main));
      } else {
        Gdx.app.exit();
      }
    }
  };

  deathDialog.button("[DARK_GRAY][[[CYAN] ENTER [DARK_GRAY]][WHITE] Return to Main Menu", true);
  deathDialog.key(Input.Keys.ENTER, true);
  deathDialog.button("[DARK_GRAY][[[CYAN] Q [DARK_GRAY]][WHITE] Quit", false);
  deathDialog.key(Input.Keys.Q, false);
  deathDialog.pad(10);
}
 
Example 2
Source File: UsersList.java    From Cardshifter with Apache License 2.0 6 votes vote down vote up
public void inviteSelected(String[] availableMods, Stage stage, final CardshifterClient client) {
    if (selected == null) {
        return;
    }

    Dialog dialog = new Dialog("Invite " + selected.getName(), skin) {
        @Override
        protected void result(Object object) {
        	if (object != null) {
                client.send(new StartGameRequest(selected.getId(), (String) object));
                callback.callback((String) object);
        	}
        }
    };
    dialog.text("Which mod do you want to play?");
    for (String mod : availableMods) {
        dialog.button(mod, mod);
    }
    dialog.button("Cancel");
    dialog.show(stage);
}
 
Example 3
Source File: Scene2dUtils.java    From gdx-soundboard with MIT License 5 votes vote down vote up
public static Dialog showAlert(String title, String text, Skin skin, Stage stage){
    Dialog dialog = new Dialog(title, skin);
    dialog.text(text);
    dialog.button("Ok");
    dialog.show(stage);

    return dialog;
}
 
Example 4
Source File: OptionsPane.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
protected void showDeleteDialog() {

	// Check if it used by other style prior to delete it
	// FIXME: TODO

	Dialog dlgStyle = new Dialog("Delete Style", game.skin) {

		@Override
		protected void result(Object object) {
			if ((Boolean) object == false) {
				return;
			}

			// Now we really add it!
			game.skinProject.remove((String) listStyles.getSelected(), currentStyle.getClass());
			refresh();
			game.screenMain.saveToSkin();
			game.screenMain.panePreview.refresh();

		}

	};

	dlgStyle.pad(20);
	dlgStyle.getContentTable().add("You are sure you want to delete this style?");
	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(getStage());

}
 
Example 5
Source File: WelcomeScreen.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
private void showNewProjectDialog() {

	final TextField textProject = new TextField("", game.skin);
	Dialog dlg = new Dialog("New Project", game.skin) {

		@Override
		protected void result(Object object) {
			if ((Boolean) object == false) {
				return;
			}

			String projectName = textProject.getText();
			projectName = projectName.replace(".", "_");
			projectName = projectName.replace("/", "_");
			projectName = projectName.replace("\\", "_");
			projectName = projectName.replace("-", "_");
			if (projectName.isEmpty() == true)
				return;

			createProject(projectName);

		}

	};

	dlg.pad(20);
	dlg.getContentTable().add("Project Name:");
	dlg.getContentTable().add(textProject).pad(20);
	dlg.button("OK", true);
	dlg.button("Cancel", false);
	dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
	dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
	dlg.setWidth(480);
	dlg.show(stage);
	stage.setKeyboardFocus(textProject);
}
 
Example 6
Source File: WelcomeScreen.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
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);
	
}
 
Example 7
Source File: SkinEditorGame.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: LoadSaveScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void clicked(InputEvent event, float x, float y) {
	final Actor listenerActor = event.getListenerActor();

	Dialog d = new Dialog("", ui.getSkin()) {
		@Override
		protected void result(Object object) {
			if (((Boolean) object).booleanValue()) {
				final World world = ui.getWorld();
				final String filename = listenerActor.getName() + WorldSerialization.GAMESTATE_EXT;

				try {
					world.removeGameState(filename);

					listenerActor.getParent().getParent().getParent()
							.removeActor(listenerActor.getParent().getParent());

				} catch (IOException e) {
					EngineLogger.error(e.getMessage());
				}
			}
		}
	};

	d.pad(DPIUtils.getMarginSize());
	d.getButtonTable().padTop(DPIUtils.getMarginSize());
	d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize()).padRight(DPIUtils.getMarginSize());

	Label l = new Label(ui.getWorld().getI18N().getString("ui.remove"), ui.getSkin(), "ui-dialog");
	l.setWrap(true);
	l.setAlignment(Align.center);

	d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f);

	d.button(ui.getWorld().getI18N().getString("ui.yes"), true,
			ui.getSkin().get("ui-dialog", TextButtonStyle.class));
	d.button(ui.getWorld().getI18N().getString("ui.no"), false,
			ui.getSkin().get("ui-dialog", TextButtonStyle.class));
	d.key(Keys.ENTER, true).key(Keys.ESCAPE, false);

	d.show(stage);
}
 
Example 9
Source File: MenuBar.java    From gdx-skineditor with Apache License 2.0 4 votes vote down vote up
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());
	
}
 
Example 10
Source File: OptionsPane.java    From gdx-skineditor with Apache License 2.0 4 votes vote down vote up
/**
 * 
 */
protected void createNewStyle() {

	final TextField textStyleName = new TextField("", game.skin);
	Dialog dlgStyle = new Dialog("New Style", game.skin) {

		@Override
		protected void result(Object object) {
			if ((Boolean) object == false) {
				return;
			}

			String styleName = textStyleName.getText();
			if (styleName.length() == 0) {

				game.showNotice("Warning", "No style name entered!", game.screenMain.stage);
				return;
			}

			// Check if the style name is already in use
			if (listItems.contains(styleName, false)) {
				game.showNotice("Warning", "Style name already in use!", game.screenMain.stage);
				return;
			}
			
			
			try {
				game.skinProject.add(styleName,  currentStyle.getClass().newInstance());
			} catch(Exception e) {
				e.printStackTrace();
			}
			//game.skinProject.add(text, game.skin.get("default", currentStyle.getClass()), currentStyle.getClass());
			game.screenMain.saveToSkin();
			refresh();

			game.screenMain.panePreview.refresh();

		}

	};

	dlgStyle.pad(20);
	dlgStyle.getContentTable().add("Style Name:");
	dlgStyle.getContentTable().add(textStyleName).pad(20);
	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(getStage());
	getStage().setKeyboardFocus(textStyleName);

}