List of usage examples for com.badlogic.gdx.scenes.scene2d.ui TextButton getLabel
public Label getLabel()
From source file:com.bladecoder.engine.ui.DialogUI.java
License:Apache License
public void show() { ArrayList<DialogOption> options = World.getInstance().getCurrentDialog().getVisibleOptions(); if (options.size() == 0) return;// www . j av a 2 s. c om else if (options.size() == 1) { // If only has one option, // autoselect it select(0); return; } panel.clear(); setVisible(true); for (DialogOption o : options) { String str = o.getText(); if (str.charAt(0) == I18N.PREFIX) str = I18N.getString(str.substring(1)); TextButton ob = new TextButton(str, style.textButtonStyle); ob.setUserObject(o); panel.row(); panel.add(ob); ob.getLabel().setWrap(true); ob.getLabel().setAlignment(Align.left); ob.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { DialogOption o = (DialogOption) event.getListenerActor().getUserObject(); ArrayList<DialogOption> options = World.getInstance().getCurrentDialog().getVisibleOptions(); for (int i = 0; i < options.size(); i++) { if (options.get(i) == o) { select(i); break; } } } }); } panel.pack(); setWidth(getStage().getWidth()); setHeight(Math.min(panel.getHeight(), getStage().getHeight() / 2)); }
From source file:com.exovum.test.animation.AnimatorMenuScreen.java
License:Creative Commons License
public AnimatorMenuScreen(final Game game) { this.batch = new SpriteBatch(); this.game = game; screen = this; menuBackground = new Texture(Gdx.files.internal("beach-ocean-sea-bg/transparent-png/full_background.png")); menuMusic = Gdx.audio.newMusic(Gdx.files.internal("Carpe Diem.mp3")); stage = new Stage(new FitViewport(800, 480)); Gdx.input.setInputProcessor(stage);/* w ww.jav a 2s . com*/ // Setup the UI skin. Pass the TextureAtlas too so it can find the default settings. TextureAtlas skinAtlas = new TextureAtlas(Gdx.files.internal("uiskin.atlas")); skin = new Skin(Gdx.files.internal("uiskin.json"), skinAtlas); mainTable = new Table(skin); //mainTable.defaults().expand().fill().padBottom(4f).padTop(4f); mainTable.setFillParent(true); // Add the title of the game at the top of the MenuScreen titleTable = new Table(skin); final Label titleLabel = new Label("Kordan Jirby", skin, "title"); titleLabel.setColor(Color.FIREBRICK); //titleLabel.setStyle(new Label.LabelStyle(titleFont, Color.FIREBRICK)); titleLabel.setAlignment(Align.center, Align.center); titleLabel.setPosition(stage.getWidth() / 2, stage.getHeight()); //titleLabel.setFontScale(2.0f); titleTable.defaults().expand().fill().padBottom(4f).padTop(4f); titleTable.add(titleLabel); titleTable.padBottom(10f); // Bottom/Base Table: left-child holds buttonTable for menu buttons, // right-child holds some text info ie instructions or credits baseTable = new Table(skin); baseTable.defaults().expand().fill().padBottom(10f).padTop(10f); // Add the buttons for the user to press: play, help, credits, exit TextButton playButton = new TextButton("Play Game", skin, "small-font"); TextButton helpButton = new TextButton("Instructions", skin, "small-font"); TextButton creditsButton = new TextButton("Credits", skin, "small-font"); TextButton exitButton = new TextButton("Exit", skin, "small-font"); Table buttonTable = new Table(skin); // Add the button table as the left-child to baseTable baseTable.add(buttonTable); //menuTable.setBackground("console2"); // Set the color of the BACKGROUND on the buttons Color buttonColor = Color.SKY; Gdx.app.log("AnimatorMenuScreen", "Color RGB SKY: " + Color.SKY.toString()); playButton.setColor(buttonColor); helpButton.setColor(buttonColor); creditsButton.setColor(buttonColor); exitButton.setColor(buttonColor); // Set the color of the TEXT on the buttons //buttonColor = new Color(0.845f, 0.845f, 0.845f, 1); buttonColor = new Color(0.91f, 0.91f, 0.91f, 1); playButton.getLabel().setColor(buttonColor); helpButton.getLabel().setColor(buttonColor); creditsButton.getLabel().setColor(buttonColor); exitButton.getLabel().setColor(buttonColor); buttonTable.defaults().expand().fill().padBottom(8f).padTop(2f); buttonTable.add(playButton).width(180f).height(60f).row(); buttonTable.add(helpButton).width(180f).height(60f).row(); buttonTable.add(creditsButton).width(180f).height(60f).row(); buttonTable.add(exitButton).width(180f).height(60f); buttonTable.padTop(30f).padBottom(30f); buttonTable.left(); /* Temporary removal of infoTable It was not easy for me to add hidden/new text and for the layouts to update correctly. Changing plan to create a new Screen for Credits (and instructions too). */ infoTable = new Table(skin); // = new Label("", skin, "small-font"); infoTable.setVisible(false); infoTable.defaults().expand().fill().padBottom(8f).padTop(2f); //baseTable.add(infoTable); // Add title table at the top of mainTable mainTable.add(titleTable).row(); // Add baseTable containing buttonTable to the next row of mainTable //mainTable.add(buttonTable); mainTable.add(baseTable); // Add mainTable to the stage stage.addActor(mainTable); // Event Listeners for the menu buttons playButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("AnimatorMenuScreen", "Pressed playButton"); //game.setScreen(new AnimatorGameScreen(game, screen)); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorGameScreen(game, screen)); } }); helpButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("AnimatorMenuScreen", "Pressed helpButton"); //game.setScreen(new InstructionsScreen(game, screen)); ((Game) Gdx.app.getApplicationListener()).setScreen(new InstructionsScreen(game, screen)); } }); creditsButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("AnimatorMenuScreen", "Pressed creditsButton"); //game.setScreen(new CreditsScreen(game, screen)); ((Game) Gdx.app.getApplicationListener()).setScreen(new CreditsScreen(game, screen)); /* * Attempt at adding text next to the buttons. * Status: Unsuccessful. Updating the layout once adding the credits text * does not update as easily as I hoped. * Changing plan to use different Screens for Credits & Instructions. // If the table is visible and already showing credits, then 'minimize' infoTable if(infoTable.isVisible() && infoTable.getName() != null && infoTable.getName().equals("Credits")) { Gdx.app.log("AnimatorMenuScreen", "Hide the credits menu"); infoTable.setVisible(false); infoTable.clearChildren(); } else { Gdx.app.log("AnimatorMenuScreen", "Display the credits text"); // Otherwise, make the infoTable visible and set text to the credits infoTable.setVisible(true); infoTable.clearChildren(); //infoTable.center(); Label musicLabel = new Label("Music\n" + "Pixel Peeker Polka - slower Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0 License\n" + "http://creativecommons.org/licenses/by/3.0/", skin, "small-font"); musicLabel.setColor(Color.BLACK); //infoTable.addActor(musicLabel); infoTable.addActor(musicLabel); infoTable.padLeft(20f); //musicLabel.setPosition(stage.getWidth() / 2 + 50, stage.getHeight() / 2 + 100, Align.right); infoTable.defaults().expand().fill().padBottom(8f).padTop(2f); musicLabel.setWidth(200f); //musicLabel.setWrap(true); musicLabel.setAlignment(Align.center); //musicLabel.setFillParent(true); // "Invalidates this actor's layout, causing layout() to happen next time // validate() is called infoTable.invalidate(); baseTable.invalidate(); infoTable.center(); //infoTable.setFillParent(true); //titleTable.add(musicLabel); } infoTable.setName("Credits"); */ } }); exitButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("AnimatorMenuScreen", "Pressed exitButton - exiting application"); Gdx.app.exit(); } }); }
From source file:com.exovum.test.animation.CreditsScreen.java
License:Creative Commons License
public CreditsScreen(final Game game, Screen parentScreen) { this.batch = new SpriteBatch(); this.game = game; this.parent = parentScreen; Gdx.app.log("CreditsScreen", "Creating CreditsScreen"); menuBackground = new Texture(Gdx.files.internal("beach-ocean-sea-bg/transparent-png/full_background.png")); stage = new Stage(new FitViewport(800, 480)); Gdx.input.setInputProcessor(stage);//from w w w . j av a 2 s. c o m skin = new Skin(Gdx.files.internal("uiskin.json")); mainTable = new Table(skin); //mainTable.defaults().expand().fill().padBottom(4f).padTop(4f); mainTable.setFillParent(true); baseTable = new Table(skin); baseTable.defaults().expand().fill().padBottom(10f).padTop(10f); Label myHeader = new Label("General", skin, "small-font"); myHeader.setColor(Color.FIREBRICK); myHeader.setAlignment(Align.center); Label myCredits = new Label("Programming and Development\n" + "Caleb Stevenson", skin, "small-font"); myCredits.setColor(Color.BLACK); myCredits.setAlignment(Align.center); Label musicHeader = new Label("Music", skin, "small-font"); musicHeader.setColor(Color.FIREBRICK); musicHeader.setAlignment(Align.center); Label musicCredits = new Label("\"Capre Diem\", \"Hidden Past\", \"Pixel Peeker Polka - slower\"\n" + "Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0\n" + "http://creativecommons.org/licenses/by/3.0/", skin, "small-font"); musicCredits.setColor(Color.BLACK); musicCredits.setAlignment(Align.center); Label artHeader = new Label("Artwork", skin, "small-font"); artHeader.setColor(Color.FIREBRICK); artHeader.setAlignment(Align.center); Label artCredits = new Label("Background and Tree Sprites\n" + "http://bevouliin.com\nopengameart.org", skin, "small-font"); artCredits.setColor(Color.BLACK); artCredits.setAlignment(Align.center); TextButton exitButton = new TextButton("Back to Menu", skin, "small-font"); Table buttonTable = new Table(skin); baseTable.add(myHeader).row(); baseTable.add(myCredits).row(); baseTable.add(musicHeader).row(); baseTable.add(musicCredits).row(); baseTable.add(artHeader).row(); baseTable.add(artCredits).row(); baseTable.add(buttonTable); //menuTable.setBackground("console2"); // Set the color of the BACKGROUND on the buttons Color buttonColor = Color.SKY; exitButton.setColor(buttonColor); // Set the color of the TEXT on the buttons exitButton.getLabel().setColor(new Color(0.91f, 0.91f, 0.91f, 1)); buttonTable.defaults().expand().fill().padBottom(4f).padTop(2f); buttonTable.add(exitButton).width(180f).height(60f); //buttonTable.padTop(20f).padBottom(20f); buttonTable.left(); // Add baseTable containing buttonTable to the next row of mainTable //mainTable.add(buttonTable); mainTable.add(baseTable); // Add mainTable to the stage stage.addActor(mainTable); exitButton.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { Gdx.app.log("CreditsScreen", "Exiting to main menu"); //game.setScreen(new AnimatorMenuScreen(game)); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); } }); //Use an InputMultiplexer so that the Stage and keyDown input processors can both be used InputMultiplexer multiplexer = new InputMultiplexer(); multiplexer.addProcessor(stage); multiplexer.addProcessor(new InputAdapter() { // If the back key is pressed, go to main menu // This also handles the Android 'back' button @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.BACK) { // Handle the back button Gdx.app.log("CreditsScreen", "KeyDown: BACK pressed"); //AnimatorMenuScreen newMenu = new AnimatorMenuScreen(batch, game); //game.setScreen(newMenu); //game.setScreen(parent); //((Game) Gdx.app.getApplicationListener()).setScreen(parent); ((Game) Gdx.app.getApplicationListener()).setScreen(new AnimatorMenuScreen(game)); return true; } return false; } }); Gdx.input.setInputProcessor(multiplexer); }
From source file:com.mangecailloux.pebble.constant.ConstantEditor.java
License:Apache License
/** * <p>Refresh the flickTable according to the state of the CE.</p> *///from w w w . j av a2 s . c o m private void refreshFlickTable() { flickTable.clear(); // if the CE is not open we just clear the table. if (open) { updateRootBackButtonsVisibility(); int buttonPoolIndex = 0; int constantTablePoolIndex = 0; if (currentDirectory.children != null) { for (int i = 0; i < currentDirectory.children.size; i++) { TextButton button = null; // No more free button remaining in the pool, we need to add new button if (buttonPoolIndex == buttonPool.size) { TextButtonStyle style = null; if (skin.has("constantEditor", TextButtonStyle.class)) style = skin.get("constantEditor", TextButtonStyle.class); else style = skin.get(TextButtonStyle.class); button = new TextButton(currentDirectory.children.get(i).name, style); button.setName("directory" + i); button.addListener(buttonClickListener); buttonPool.add(button); } else // we get the button in the pool. { button = buttonPool.get(buttonPoolIndex); button.getLabel().setText(currentDirectory.children.get(i).name); } buttonPoolIndex++; // we add the button to the table. if (button != null) { flickTable.row(); flickTable.add(button).top().expandX().fill().minSize(buttonMinimalSize, buttonMinimalSize); } } } if (currentDirectory.elements != null) { for (int i = 0; i < currentDirectory.elements.size; i++) { ConstantTable constantTable = null; // No more free ConstantTable remaining in the pool, we need to add new one if (constantTablePoolIndex == constantTablePool.size) { constantTable = new ConstantTable(skin, constantTablePoolIndex, buttonMinimalSize / 2, textFieldListener); constantTablePool.add(constantTable); } else // we get the ConstantTable in the pool. { constantTable = constantTablePool.get(constantTablePoolIndex); } constantTablePoolIndex++; if (constantTable != null) { constantTable.initFromConstant(currentDirectory.elements.get(i)); // layout flickTable.row(); flickTable.add(constantTable).center().expandX().fillX().minSize(buttonMinimalSize, buttonMinimalSize); } } } } }
From source file:com.ray3k.skincomposer.MenuList.java
License:Open Source License
public void updateContents() { setSize(0.0f, 0.0f);/*from w w w. j av a2 s .c o m*/ clearChildren(); buttons.clear(); int index = 0; for (T item : items) { TextButton textButton = new TextButton(item.toString(), style.textButtonStyle); textButton.getLabel().setAlignment(Align.left); if (getCells().size > 0) { row(); } add(textButton); if (index < shortcuts.size && shortcuts.get(index) != null && style.labelStyle != null) { Label label = new Label(shortcuts.get(index), style.labelStyle); textButton.add(label).padLeft(5.0f); } int i = index++; textButton.addListener(new ChangeListener() { @Override public void changed(ChangeListener.ChangeEvent event, Actor actor) { selectedIndex = i; selectedItem = item; fire(new MenuListEvent()); } }); buttons.add(textButton); } validate(); float width = style.background.getLeftWidth() + style.background.getRightWidth(); for (int i = 0; i < getColumns(); i++) { width += getColumnWidth(i); } float height = style.background.getLeftWidth() + style.background.getRightWidth(); for (int i = 0; i < getRows(); i++) { height += getRowHeight(i); } for (Cell cell : getCells()) { cell.growX(); } setSize(width, height); }
From source file:io.piotrjastrzebski.sfg.ui.GameOverDialog.java
License:Open Source License
private Actor createPremiumButton() { // we use table container so padding doesnt get stuck in the dialog final Table premiumTable = new Table(); final TextButton premiumButton = new TextButton(assets.getText(Assets.GET_PREMIUM), assets.getSkin(), "premium"); premiumButton.getLabel().setFontScale(1.25f); premiumTable.add(premiumButton).pad(0, 0, 20, 0); // dialog doesnt support contained keys, so we have to add both table and button setObject(premiumButton, RESULT.PREMIUM); setObject(premiumTable, RESULT.PREMIUM); return premiumTable; }
From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseWithGUI.java
License:Open Source License
private TextButton createAngleButton() { final TextButton textButton = new TextButton(null, skin); textButton.addListener(new ClickListener() { @Override/* w w w .j a v a 2 s .c o m*/ public void clicked(InputEvent event, float x, float y) { releaseCard(textButton.getLabel().getColor()); } }); return textButton; }
From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseWithGUI.java
License:Open Source License
/** * Creates one angle-button for each cheat color. These can be clicked * to release the card with the same color as the text of the button. * Also creates a {@link Runnable} that keeps the buttons updated. *//* w w w . ja v a 2 s.c om*/ private Table createAngleButtons() { final Table table = new Table(); // create buttons float width = new TextButton("360.0", skin).getPrefWidth(); final TextButton[] textButtons = new TextButton[cardHouseDef.cheatColors.length]; for (int i = 0; i < textButtons.length; i++) { final TextButton textButton = createAngleButton(); textButton.setVisible(false); table.add(textButton).width(width).pad(SceneUtil.getPreferredPadding(stage)).row(); textButtons[i] = textButton; } // prepare updates timer.remove(angleUpdater); angleUpdater = new Runnable() { @Override public void run() { if (renderCount % 5 != 0) return; Array<PPPolygon> coloredCards = cardHouse.getColoredCards(); int i = 0; for (TextButton textButton : textButtons) { // is there a colored card for this button? boolean gotCard = coloredCards.size > i; if (gotCard != textButton.isVisible()) textButton.setVisible(gotCard); if (gotCard) { PPPolygon card = coloredCards.get(i); // compute an intuitive angle float angleRad = card.getPhysicsThing().getBody().getAngle(); float angleDeg = angleRad * MathUtils.radiansToDegrees; angleDeg = Math.abs(angleDeg); angleDeg %= 180; if (angleDeg > 90) angleDeg = 180 - angleDeg; angleDeg = Util.roundToNearestN(angleDeg, 0.1f); // convert to text and update button String decimals = Util.getDecimals(angleDeg, 1); int noDecimals = (int) angleDeg; String angleText = noDecimals + "." + decimals; textButton.setText(angleText); // update the angleText for the angleLabel Color color = card.getOutlinePolygons().first().getColor(); if (color == cardHouseDef.cheatColors[0]) CardHouseWithGUI.this.angleText = angleText; textButton.getLabel().setColor(color); } i++; } } }; timer.runOnRender(angleUpdater); return table; }