com.badlogic.gdx.scenes.scene2d.ui.Dialog Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.ui.Dialog. 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: 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 #2
Source File: ControllerMenuDialog.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    previousFocusedActor = null;
    previousEscapeActor = null;

    super.show(stage, action);

    if (stage instanceof ControllerMenuStage) {
        previousFocusedActor = ((ControllerMenuStage) stage).getFocusedActor();
        previousEscapeActor = ((ControllerMenuStage) stage).getEscapeActor();

        ((ControllerMenuStage) stage).setFocusedActor(getConfiguredDefaultActor());
        ((ControllerMenuStage) stage).setEscapeActor(getConfiguredEscapeActor());
    }

    return this;

}
 
Example #3
Source File: InstallationTable.java    From skin-composer with MIT License 6 votes vote down vote up
private void showQuitDialog() {
    pauseInstall = true;
    var dialog = new Dialog("", getSkin()) {
        @Override
        protected void result(Object object) {
            pauseInstall = false;
            if ((Boolean) object) {
                Core.transition(InstallationTable.this, new MenuTable(getSkin(), getStage()), 0.0f, .5f);
                continueInstall = false;
            }
        }
    };
    
    dialog.getContentTable().pad(10.0f);
    dialog.getButtonTable().pad(10.0f);
    dialog.text("Quit installation?");
    dialog.button("Quit", true).button("Install", false);
    dialog.key(Keys.ENTER, true).key(Keys.ESCAPE, false);
    dialog.show(getStage());
}
 
Example #4
Source File: Editor.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public void exit() {
	if (Ctx.project.isLoaded() && Ctx.project.isModified()) {
		new Dialog("Save Project", skin) {
			protected void result(Object object) {
				if (((Boolean) object).booleanValue()) {
					try {
						Ctx.project.saveProject();
					} catch (IOException e1) {
						String msg = "Something went wrong while saving the actor.\n\n"
								+ e1.getClass().getSimpleName() + " - " + e1.getMessage();
						Message.showMsgDialog(getStage(), "Error", msg);

						EditorLogger.printStackTrace(e1);
					}
				}

				((Main) Gdx.app).exitSaved();
			}
		}.text("Save changes to project?").button("Yes", true).button("No", false).key(Keys.ENTER, true)
				.key(Keys.ESCAPE, false).show(stage);

	} else {
		((Main) Gdx.app).exitSaved();
	}

}
 
Example #5
Source File: ProjectToolbar.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
private void saveProjectAndExecute(final Runnable task) {
	if (Ctx.project.isLoaded() && Ctx.project.isModified()) {
		new Dialog("Save Project", skin) {
			protected void result(Object object) {
				if (((Boolean) object).booleanValue()) {
					try {
						Ctx.project.saveProject();
					} catch (IOException e1) {
						String msg = "Something went wrong while saving the actor.\n\n"
								+ e1.getClass().getSimpleName() + " - " + e1.getMessage();
						Message.showMsgDialog(getStage(), "Error", msg);

						EditorLogger.printStackTrace(e1);
					}
				}

				task.run();
			}
		}.text("Save current project changes?").button("Yes", true).button("No", false).key(Keys.ENTER, true)
				.key(Keys.ESCAPE, false).show(getStage());
	} else {
		task.run();
	}
}
 
Example #6
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 #7
Source File: EditorUtils.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static void checkVersionAndLoadProject(final File projectToLoad, final Stage stage, Skin skin)
		throws FileNotFoundException, IOException {

	if (!Ctx.project.checkVersion(projectToLoad)) {
		new Dialog("Update Engine", skin) {
			protected void result(Object object) {
				if (((Boolean) object).booleanValue()) {
					try {
						Ctx.project.updateEngineVersion(projectToLoad);
					} catch (IOException e) {
						String msg = "Something went wrong while updating the engine.\n\n"
								+ e.getClass().getSimpleName() + " - " + e.getMessage();
						Message.showMsgDialog(getStage(), "Error", msg);

						EditorLogger.error(msg, e);
					}
				}

				loadProjectWithCustomClasses(projectToLoad, stage);
			}
		}.text("Your game uses an old (" + Ctx.project.getProjectBladeEngineVersion(projectToLoad)
				+ ") Engine version. Do you want to update the engine?").button("Yes", true).button("No", false)
				.key(Keys.ENTER, true).key(Keys.ESCAPE, false).show(stage);
	} else {
		loadProjectWithCustomClasses(projectToLoad, stage);
	}
}
 
Example #8
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 #9
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 #10
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 #11
Source File: DrawablePickerDialog.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog show(Stage stage) {

	refresh();

	Dialog d = super.show(stage);
	getStage().setScrollFocus(scrollPane);
	return d;
}
 
Example #12
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 #13
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 #14
Source File: FileChooser.java    From gdx-soundboard with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    final Table content = getContentTable();
    content.add(fileListLabel).top().left().expandX().fillX().row();
    content.add(new ScrollPane(fileList, skin)).size(300, 150).fill().expand().row();

    if (fileNameEnabled) {
        content.add(fileNameLabel).fillX().expandX().row();
        content.add(fileNameInput).fillX().expandX().row();
        stage.setKeyboardFocus(fileNameInput);
    }

    if (newFolderEnabled) {
        content.add(newFolderButton).fillX().expandX().row();
    }
    
    if(directoryBrowsingEnabled){
        fileList.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                final FileListItem selected = fileList.getSelected();
                if (selected.file.isDirectory()) {
                    changeDirectory(selected.file);
                }
            }
        });
    }

    this.stage = stage;
    changeDirectory(baseDir);
    return super.show(stage, action);
}
 
Example #15
Source File: Message.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static void showMsgDialog(final Stage stage, final String title, final String msg) {

		Timer.post(new Task() {

			@Override
			public void run() {
				Message.hideMsg();
				
				new Dialog(title, skin).text(msg).button("Close", true).key(Keys.ENTER, true).key(Keys.ESCAPE, false)
						.show(stage);
			}
		});
	}
 
Example #16
Source File: DialogCustomStyle.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage) {
    Dialog dialog = super.show(stage);
    
    stage.setKeyboardFocus(nameField);
    nameField.selectAll();
    
    return dialog;
}
 
Example #17
Source File: DialogLoading.java    From skin-composer with MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage) {
    Dialog dialog = super.show(stage);
    RunnableAction runnableAction = new RunnableAction();
    runnableAction.setRunnable(() -> {
        if (Utils.isMac()) {
            if (runnable != null) {
                runnable.run();
            }
            hide();
        } else {
            Thread thread = new Thread(() -> {
                if (runnable != null) {
                    runnable.run();
                }
                Gdx.app.postRunnable(() -> {
                    hide();
                });
            });
            thread.start();
        }
    });
    Action action = new SequenceAction(new DelayAction(.5f), runnableAction);
    addAction(action);
    
    return dialog;
}
 
Example #18
Source File: InventoryUI.java    From Unlucky with MIT License 5 votes vote down vote up
/**
 * Handles consuming potions
 */
private void consume() {
    new Dialog("Consume", rm.dialogSkin) {
        {
            Label l = new Label("Heal for " +
                (currentItem.hp < 0 ? (int) ((-currentItem.hp / 100f) * player.getMaxHp()) : currentItem.hp)
                + " HP\nusing this potion?", rm.dialogSkin);
            if (currentItem.exp > 0) {
                l.setText("Gain " + (int) ((currentItem.exp / 100f) * player.getMaxExp()) + " EXP\nfrom this potion?");
            }
            l.setFontScale(0.5f);
            l.setAlignment(Align.center);
            text(l);
            getButtonTable().defaults().width(40);
            getButtonTable().defaults().height(15);
            button("Yes", "yes");
            button("No", "no");
        }

        @Override
        protected void result(Object object) {
            if (!game.player.settings.muteSfx) rm.buttonclick2.play(game.player.settings.sfxVolume);
            if (object.equals("yes")) {
                if (currentItem.hp < 0) player.percentagePotion(-currentItem.hp);
                else if (currentItem.exp > 0) player.addExp((int) ((currentItem.exp / 100f) * player.getMaxExp()));
                else player.potion(currentItem.hp);
                player.inventory.items[currentItem.index].actor.remove();
                player.inventory.removeItem(currentItem.index);
                unselectItem();
                updateText();
                if (inMenu) game.save.save();
            }
        }

    }.show(stage).getTitleLabel().setAlignment(Align.center);
}
 
Example #19
Source File: InventoryUI.java    From Unlucky with MIT License 5 votes vote down vote up
/**
 * Dialog event after dragging an enchant scroll onto an equip
 * @param item bonus to be put on item
 * @param scroll enchant scroll
 */
private void applyEnchantBonus(final Item item, final Item scroll) {
    new Dialog("Enchant scroll", rm.dialogSkin) {
        {
            Label l = new Label("Use enchant scroll on\n" + item.labelName + "?", rm.dialogSkin);
            l.setFontScale(0.5f);
            l.setAlignment(Align.center);
            text(l);
            getButtonTable().defaults().width(40);
            getButtonTable().defaults().height(15);
            button("Yes", "yes");
            button("No", "no");
        }
        @Override
        protected void result(Object object) {
            if (!game.player.settings.muteSfx) rm.buttonclick2.play(game.player.settings.sfxVolume);
            if (object.equals("yes")) {
                item.bonusEnchantChance = scroll.eChance;
                scroll.actor.remove();
                player.inventory.removeItem(scroll.index);
                if (inMenu) game.save.save();
            }
            else {
                player.inventory.addItemAtIndex(scroll, scroll.index);
            }
        }
    }.show(stage).getTitleLabel().setAlignment(Align.center);
}
 
Example #20
Source File: NewFileDialog.java    From gdx-soundboard with MIT License 4 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    super.show(stage, action);
    stage.setKeyboardFocus(fileName);
    return this;
}
 
Example #21
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 #22
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);

}
 
Example #23
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);
}