List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Dialog getContentTable
public Table getContentTable()
From source file:com.bladecoder.engine.ui.MenuScreen.java
License:Apache License
@Override public void show() { stage = new Stage(new ScreenViewport()); final Skin skin = ui.getSkin(); final World world = World.getInstance(); final MenuScreenStyle style = skin.get(MenuScreenStyle.class); final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font; float buttonWidth = f.getCapHeight() * 15f; // Image background = new Image(style.background); Drawable bg = style.background;/* w w w. j ava2 s . c om*/ if (bg == null && style.bgFile != null) { bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile)); bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear); bg = new TextureRegionDrawable(new TextureRegion(bgTexFile)); } final Table table = new Table(); table.setFillParent(true); table.center(); if (bg != null) table.setBackground(bg); table.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) if (world.getCurrentScene() != null) ui.setCurrentScreen(Screens.SCENE_SCREEN); return true; } }); table.defaults().pad(BUTTON_PADDING).width(buttonWidth); stage.setKeyboardFocus(table); if (style.showTitle) { Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin, style.titleStyle); title.setAlignment(Align.center); table.add(title).padBottom(DPIUtils.getMarginSize() * 2); table.row(); } if (world.savedGameExists() || world.getCurrentScene() != null) { TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle); continueGame.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (world.getCurrentScene() == null) try { world.load(); } catch (Exception e) { Gdx.app.exit(); } ui.setCurrentScreen(Screens.SCENE_SCREEN); } }); table.add(continueGame); } TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle); newGame.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (world.savedGameExists()) { Dialog d = new Dialog("", skin) { protected void result(Object object) { if (((Boolean) object).booleanValue()) { try { world.newGame(); } catch (Exception e) { Gdx.app.exit(); } ui.setCurrentScreen(Screens.SCENE_SCREEN); } } }; d.pad(DPIUtils.getMarginSize()); d.getButtonTable().padTop(DPIUtils.getMarginSize()); d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize()) .padRight(DPIUtils.getMarginSize()); Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog"); l.setWrap(true); l.setAlignment(Align.center); d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f); d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class)); d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class)); d.key(Keys.ENTER, true).key(Keys.ESCAPE, false); d.show(stage); } else { try { world.newGame(); } catch (Exception e) { Gdx.app.exit(); } ui.setCurrentScreen(Screens.SCENE_SCREEN); } } }); table.row(); table.add(newGame); TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle); loadGame.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN); } }); table.row(); table.add(loadGame); // if (world.getCurrentScene() != null) { // TextButton saveGame = new TextButton(I18N.getString("ui.save"), skin, style.textButtonStyle); // saveGame.addListener(new ClickListener() { // public void clicked(InputEvent event, float x, float y) { // ui.setCurrentScreen(Screens.SAVE_GAME_SCREEN); // } // }); // // table.row(); // table.add(saveGame); // } TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle); quit.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } }); table.row(); table.add(quit); table.pack(); stage.addActor(table); // BOTTOM-RIGHT BUTTON STACK credits = new Button(skin, "credits"); credits.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.CREDIT_SCREEN); } }); help = new Button(skin, "help"); help.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.HELP_SCREEN); } }); debug = new Button(skin, "debug"); debug.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { DebugScreen debugScr = new DebugScreen(); debugScr.setUI(ui); ui.setCurrentScreen(debugScr); } }); Table buttonStack = new Table(); buttonStack.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(), DPIUtils.getPrefButtonSize()); buttonStack.pad(DPIUtils.getMarginSize() * 2); if (EngineLogger.debugMode() && world.getCurrentScene() != null) { buttonStack.add(debug); buttonStack.row(); } buttonStack.add(help); buttonStack.row(); buttonStack.add(credits); buttonStack.bottom().right(); buttonStack.setFillParent(true); buttonStack.pack(); stage.addActor(buttonStack); Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin); version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize()); stage.addActor(version); debug.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { DebugScreen debugScr = new DebugScreen(); debugScr.setUI(ui); ui.setCurrentScreen(debugScr); } }); pointer = new Pointer(skin); stage.addActor(pointer); Gdx.input.setInputProcessor(stage); }
From source file:com.gdx.extension.screen.BaseScreen.java
License:Apache License
/** * Show a modal popup on top of all the screens children * /* w w w .ja va 2s .c o m*/ * @param title the title of the popup * @param message text you want to display in the popup */ public void showPopup(String title, String message) { final Dialog _dialog = new Dialog(title, skin); Label _message = new Label(message, skin); _message.setAlignment(Align.center); TextButton _okButton = new TextButton("Ok", skin); _okButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { _dialog.hide(); } }); _dialog.getContentTable().add(_message).minWidth(300f).pad(10f); _dialog.getButtonTable().add(_okButton).minWidth(100f).pad(10f); _dialog.setTitleAlignment(Align.center); _dialog.setMovable(false); _dialog.center(); _dialog.show(stage); }
From source file:com.ray3k.libraryinvaders.states.MenuState.java
License:Open Source License
private void showCharacterDialog() { Dialog dialog = new Dialog("", skin); Label label = new Label("Choose a character...", skin); dialog.getContentTable().add(label); dialog.getContentTable().row();// w ww . j av a2s . c om Table table = new Table(); ScrollPane scrollPane = new ScrollPane(table, skin); scrollPane.setFadeScrollBars(false); dialog.getContentTable().add(scrollPane).grow(); final ButtonGroup<ImageTextButton> buttons = new ButtonGroup<ImageTextButton>(); for (String name : getCore().getImagePacks().get(DATA_PATH + "/characters")) { Drawable drawable = new TextureRegionDrawable(getCore().getAtlas().findRegion(name)); Image image = new Image(drawable); ImageTextButton imageTextButton = new ImageTextButton(name, skin, "list"); imageTextButton.getImageCell().setActor(image); imageTextButton.getLabelCell().left().expandX(); table.add(imageTextButton).growX(); buttons.add(imageTextButton); table.row(); } dialog.getContentTable().row(); TextButton textButton = new TextButton("OK", skin); dialog.getContentTable().add(textButton); textButton.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/menu.wav", Sound.class).play(); ((GameState) getCore().getStateManager().getState("game")) .setSelectedCharacter(buttons.getChecked().getText().toString()); Gdx.input.setInputProcessor(null); Action changeStateAction = new Action() { @Override public boolean act(float delta) { getCore().getStateManager().loadState("game"); return true; } }; root.addAction(new SequenceAction(new DelayAction(.5f), changeStateAction)); } }); dialog.show(stage); dialog.setSize(600.0f, 500.0f); dialog.setPosition(stage.getWidth() / 2.0f, stage.getHeight() / 2.0f, Align.center); stage.setScrollFocus(scrollPane); }
From source file:com.ray3k.skincomposer.dialog.DialogColors.java
License:Open Source License
private void showColorPicker() { dialogFactory.showDialogColorPicker(new DialogColorPicker.ColorListener() { @Override// ww w .j a va 2 s.c om public void selected(Color color) { if (color != null) { final TextField field = new TextField("RGBA_" + (int) (color.r * 255) + "_" + (int) (color.g * 255) + "_" + (int) (color.b * 255) + "_" + (int) (color.a * 255), skin); final Dialog dialog = new Dialog("Color name...", skin, "bg") { @Override protected void result(Object object) { if ((Boolean) object == true) { newColor(field.getText(), color); } } }; dialog.getTitleTable().padLeft(5.0f); dialog.button("Ok", true).button("Cancel", false).key(Keys.ESCAPE, false); final TextButton button = (TextButton) dialog.getButtonTable().getCells().first().getActor(); button.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getButtonTable().pad(15.0f); field.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!button.isDisabled()) { String name = field.getText(); if (newColor(name, color)) { dialog.hide(); } } main.getStage().setKeyboardFocus(textField); } } }); field.addListener(main.getIbeamListener()); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.text("Please enter a name for the new color: "); dialog.getContentTable().row(); dialog.getContentTable().add(field).growX(); dialog.getContentTable().row(); dialog.text("Preview:"); dialog.getContentTable().row(); Table table = new Table(skin); table.setBackground("white"); table.setColor(color); dialog.getContentTable().add(table).minSize(50.0f); button.setDisabled(!ColorData.validate(field.getText())); field.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !ColorData.validate(field.getText()); if (!disable) { for (ColorData data : jsonData.getColors()) { if (data.getName().equals(field.getText())) { disable = true; break; } } } button.setDisabled(disable); } }); dialog.show(getStage()); getStage().setKeyboardFocus(field); field.selectAll(); field.setFocusTraversal(false); } } }); }
From source file:com.ray3k.skincomposer.dialog.DialogColors.java
License:Open Source License
private void renameDialog(ColorData color) { TextField textField = new TextField("", skin); TextButton okButton;/* ww w.j ava2 s. co m*/ Dialog dialog = new Dialog("Rename Color?", skin, "bg") { @Override protected void result(Object object) { if ((boolean) object) { renameColor(color, textField.getText()); } } @Override public Dialog show(Stage stage) { Dialog dialog = super.show(stage); main.getStage().setKeyboardFocus(textField); return dialog; } }; dialog.getTitleTable().padLeft(5.0f); float brightness = Utils.brightness(color.color); Color borderColor; if (brightness > .35f) { borderColor = Color.BLACK; } else { borderColor = Color.WHITE; } Table bg = new Table(skin); bg.setBackground("white"); bg.setColor(borderColor); dialog.getContentTable().add(bg); Label label = new Label(color.getName(), skin, "white"); label.setColor(color.color); bg.add(label).pad(10); dialog.getContentTable().row(); label = new Label("What do you want to rename the color to?", skin); dialog.getContentTable().add(label); dialog.getContentTable().row(); textField.setText(color.getName()); textField.selectAll(); textField.addListener(main.getIbeamListener()); dialog.getContentTable().add(textField); dialog.getCell(dialog.getContentTable()).pad(15.0f); dialog.button("OK", true); dialog.button("Cancel", false).key(Keys.ESCAPE, false); okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor(); okButton.setDisabled(true); okButton.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getButtonTable().padBottom(15.0f); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !ColorData.validate(textField.getText()); if (!disable) { for (ColorData data : jsonData.getColors()) { if (data.getName().equals(textField.getText())) { disable = true; break; } } } okButton.setDisabled(disable); } }); textField.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!okButton.isDisabled()) { renameColor(color, textField.getText()); dialog.hide(); } } } }); textField.setFocusTraversal(false); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
private void colorSwatchesDialog(DrawableData drawableData) { DialogColors dialog = new DialogColors(getSkin(), "dialog", null, true, dialogFactory, jsonData, projectData, atlasData, main, (ColorData colorData) -> { if (colorData != null) { final DrawableData tintedDrawable = new DrawableData(drawableData.file); tintedDrawable.tintName = colorData.getName(); //Fix background color for new, tinted drawable Color temp = Utils.averageEdgeColor(tintedDrawable.file, colorData.color); if (Utils.brightness(temp) > .5f) { tintedDrawable.bgColor = Color.BLACK; } else { tintedDrawable.bgColor = Color.WHITE; }//from w w w . j a v a 2 s. com final TextField textField = new TextField(drawableData.name, getSkin()); final TextButton button = new TextButton("OK", getSkin()); button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText())); button.addListener(main.getHandListener()); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { button.setDisabled(!DrawableData.validate(textField.getText()) || checkIfNameExists(textField.getText())); } }); textField.addListener(main.getIbeamListener()); Dialog approveDialog = new Dialog("TintedDrawable...", getSkin(), "bg") { @Override protected void result(Object object) { if (object instanceof Boolean && (boolean) object) { tintedDrawable.name = textField.getText(); atlasData.getDrawables().add(tintedDrawable); projectData.setChangesSaved(false); } } @Override public boolean remove() { gatherDrawables(); produceAtlas(); sortBySelectedMode(); getStage().setScrollFocus(scrollPane); return super.remove(); } }; approveDialog.addCaptureListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode2) { if (keycode2 == Input.Keys.ENTER) { if (!button.isDisabled()) { tintedDrawable.name = textField.getText(); atlasData.getDrawables().add(tintedDrawable); projectData.setChangesSaved(false); approveDialog.hide(); } } return false; } }); approveDialog.getTitleTable().padLeft(5.0f); approveDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); approveDialog.getButtonTable().padBottom(15.0f); approveDialog.text("What is the name of the new tinted drawable?"); Drawable drawable = drawablePairs.get(drawableData); Drawable preview = null; if (drawable instanceof SpriteDrawable) { preview = ((SpriteDrawable) drawable).tint(colorData.color); } else if (drawable instanceof NinePatchDrawable) { preview = ((NinePatchDrawable) drawable).tint(colorData.color); } if (preview != null) { approveDialog.getContentTable().row(); Table table = new Table(); table.setBackground(preview); approveDialog.getContentTable().add(table); } approveDialog.getContentTable().row(); approveDialog.getContentTable().add(textField).growX(); approveDialog.button(button, true); approveDialog.button("Cancel", false); approveDialog.getButtonTable().getCells().get(1).getActor() .addListener(main.getHandListener()); approveDialog.key(Input.Keys.ESCAPE, false); approveDialog.show(getStage()); getStage().setKeyboardFocus(textField); textField.selectAll(); textField.setFocusTraversal(false); } }); dialog.setFillParent(true); dialog.show(getStage()); dialog.populate(); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
private void renameDrawableDialog(DrawableData drawable) { TextField textField = new TextField("", getSkin()); Dialog dialog = new Dialog("Rename drawable?", getSkin(), "bg") { @Override/*from w w w. ja v a 2s.c o m*/ protected void result(Object object) { super.result(object); if (object instanceof Boolean && (boolean) object == true) { renameDrawable(drawable, textField.getText()); } getStage().setScrollFocus(scrollPane); } @Override public Dialog show(Stage stage) { Dialog dialog = super.show(stage); stage.setKeyboardFocus(textField); return dialog; } }; dialog.getTitleTable().padLeft(5.0f); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.getButtonTable().padBottom(15.0f); dialog.getContentTable().add(new Label("Please enter a new name for the drawable: ", getSkin())); dialog.button("OK", true); dialog.button("Cancel", false).key(Keys.ESCAPE, false); TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor(); okButton.setDisabled(true); okButton.addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.getContentTable().row(); textField.setText(drawable.name); textField.selectAll(); textField.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { boolean disable = !DrawableData.validate(textField.getText()); if (!disable) { for (DrawableData data : atlasData.getDrawables()) { if (data.name.equals(textField.getText())) { disable = true; break; } } } okButton.setDisabled(disable); } }); textField.setTextFieldListener(new TextField.TextFieldListener() { @Override public void keyTyped(TextField textField, char c) { if (c == '\n') { if (!okButton.isDisabled()) { renameDrawable(drawable, textField.getText()); dialog.hide(); } } } }); textField.addListener(main.getIbeamListener()); dialog.getContentTable().add(textField); textField.setFocusTraversal(false); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
/** * Shows a dialog to confirm deletion of all TintedDrawables based on the * provided drawable data. This is called when the delete button is pressed * on a drawable in the drawable list./*w w w . ja v a 2 s.co m*/ * @param drawable */ private void showConfirmDeleteDialog(DrawableData drawable) { Dialog dialog = new Dialog("Delete duplicates?", getSkin(), "bg") { @Override protected void result(Object object) { if ((boolean) object) { removeDuplicateDrawables(drawable.file); gatherDrawables(); sortBySelectedMode(); } } }; dialog.getTitleTable().padLeft(5.0f); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.getButtonTable().padBottom(15.0f); dialog.text( "Deleting this drawable will also delete one or more tinted drawables.\n" + "Delete duplicates?"); dialog.button("OK", true); dialog.button("Cancel", false); dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.key(Input.Keys.ENTER, true); dialog.key(Input.Keys.ESCAPE, false); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
/** * Show an setStatusBarError indicating a drawable that exceeds project specifications */// w ww . j av a 2 s.c om private void showDrawableError() { Dialog dialog = new Dialog("Error...", getSkin(), "bg"); dialog.getTitleTable().padLeft(5.0f); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.getButtonTable().padBottom(15.0f); Label label = new Label( "Error while adding new drawables.\nEnsure that image dimensions are\nless than maximums specified in project.\nRolling back changes...", getSkin()); label.setAlignment(Align.center); dialog.text(label); dialog.button("OK"); dialog.show(getStage()); }
From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java
License:Open Source License
/** * Shows a dialog to confirm removal of duplicate drawables that have the * same name without extension. This is called after selecting new drawables. * @param unhandledFiles//from ww w . ja v a2s . co m * @param backup * @param filesToProcess */ private void showRemoveDuplicatesDialog(Array<FileHandle> unhandledFiles, Array<DrawableData> backup, Array<FileHandle> filesToProcess) { Dialog dialog = new Dialog("Delete duplicates?", getSkin(), "bg") { @Override protected void result(Object object) { if ((boolean) object) { for (FileHandle fileHandle : unhandledFiles) { removeDuplicateDrawables(fileHandle); filesToProcess.add(fileHandle); } } finalizeDrawables(backup, filesToProcess); } }; dialog.getTitleTable().padLeft(5.0f); dialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f); dialog.getButtonTable().padBottom(15.0f); dialog.text("Adding this drawable will overwrite one or more drawables\n" + "Delete duplicates?"); dialog.button("OK", true); dialog.button("Cancel", false); dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener()); dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener()); dialog.key(Input.Keys.ENTER, true); dialog.key(Input.Keys.ESCAPE, false); dialog.show(getStage()); }