List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Table right
public Table right()
From source file:at.highstreeto.xnllayoutparser.element.TableParser.java
License:Apache License
@Override public Actor load(Element element, LayoutParserContext context) throws LayoutParseException { Table table = new Table(); if (element.getAttributes().containsKey("fillParent")) { table.setFillParent(element.getBooleanAttribute("fillParent")); }//w w w .j ava 2s . c o m if (element.getAttributes().containsKey("debug")) { String[] parts = element.getAttribute("debug").split(" "); for (String i : parts) { if ("cell".equals(i)) { table.debugCell(); } else if ("table".equals(i)) { table.debugTable(); } } } // Combination of c (Center), t (Top), b (Bottom), l (Left), r (Right) if (element.getAttributes().containsKey("align")) { String[] parts = element.getAttribute("align").split(" "); for (String i : parts) { if ("c".equals(i)) { table.center(); } else if ("t".equals(i)) { table.top(); } else if ("b".equals(i)) { table.bottom(); } else if ("l".equals(i)) { table.left(); } else if ("r".equals(i)) { table.right(); } } } context.addActor(table, element); ElementParserHelper.setActorName(element, table); for (int i = 0; i < element.getChildCount(); i++) { Element child = element.getChild(i); context.getParsers().getParserByElementName(child).load(child, context); } return table; }
From source file:com.mygdx.java.screens.MenuScreen.java
License:Apache License
private Table buildControlsLayer() { Table layer = new Table(); layer.right().bottom(); // + Play Button btnMenuPlay = new Button(skinCanyonBunny, "play"); layer.add(btnMenuPlay);//from w w w . j a v a 2s . co m btnMenuPlay.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { onPlayClicked(); } }); layer.row(); // + Options Button btnMenuOptions = new Button(skinCanyonBunny, "options"); layer.add(btnMenuOptions); btnMenuOptions.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { onOptionsClicked(); } }); if (debugEnabled) layer.debug(); return layer; }
From source file:com.torrosoft.triviazo.screens.MenuScreen.java
License:Open Source License
@Override public void show() { super.show(); // retrieve the default table actor final Table table = super.getTable(); final Texture img = new Texture(Gdx.files.internal("images/menu.png")); final Drawable drawable = new TextureRegionDrawable(new TextureRegion(img)); table.setBackground(drawable);//from w ww . j av a 2 s . c o m table.pad(PADDING_TOP, PADDING_LEFT, PADDING_BOTTOM, PADDING_RIGHT); table.right().top(); // Position of the menu in the screen table.add(" ").spaceBottom(BUTTON_SPACING); table.row(); // register the button "start game" final TextButton startGameButton = new TextButton("Un jugador", getSkin()); startGameButton.addListener(new DefaultButtonListener() { @Override public void touchUp(final InputEvent event, final float x, final float y, final int pointer, final int button) { super.touchUp(event, x, y, pointer, button); game.getSoundManager().play(TriviazoSound.CLICK); game.setScreen(new GameModeScreen(game)); } }); table.add(startGameButton).size(BUTTON_WIDTH, BUTTON_HEIGHT).uniform().spaceBottom(BUTTON_SPACING); table.row(); final TextButton multiPlayerButton = new TextButton("Multijugador", getSkin()); multiPlayerButton.addListener(new DefaultButtonListener() { @Override public void touchUp(final InputEvent event, final float x, final float y, final int pointer, final int button) { super.touchUp(event, x, y, pointer, button); game.getSoundManager().play(TriviazoSound.CLICK); // TODO multiPlayerButton // game.setScreen(new GameOverScreen(game, 5, 8)); game.setScreen(new TempusFugit(game)); } }); // table.add(multiPlayerButton).size(BUTTON_WIDTH, // BUTTON_HEIGHT).uniform().spaceBottom(BUTTON_SPACING); // table.row(); final TextButton hallOfFameButton = new TextButton("Hall of Fame", getSkin()); hallOfFameButton.addListener(new DefaultButtonListener() { @Override public void touchUp(final InputEvent event, final float x, final float y, final int pointer, final int button) { super.touchUp(event, x, y, pointer, button); game.getSoundManager().play(TriviazoSound.CLICK); game.setScreen(new HallOfFameScreen(game)); } }); table.add(hallOfFameButton).size(BUTTON_WIDTH, BUTTON_HEIGHT).uniform().spaceBottom(BUTTON_SPACING); table.row(); final TextButton optionsButton = new TextButton("Preferencias", getSkin()); optionsButton.addListener(new DefaultButtonListener() { @Override public void touchUp(final InputEvent event, final float x, final float y, final int pointer, final int button) { super.touchUp(event, x, y, pointer, button); game.getSoundManager().play(TriviazoSound.CLICK); game.setScreen(new PreferencesScreen(game)); } }); table.add(optionsButton).uniform().fill().spaceBottom(BUTTON_SPACING); table.row(); final TextButton creditsButton = new TextButton("Crditos", getSkin()); creditsButton.addListener(new DefaultButtonListener() { @Override public void touchUp(final InputEvent event, final float x, final float y, final int pointer, final int button) { super.touchUp(event, x, y, pointer, button); game.getSoundManager().play(TriviazoSound.CLICK); game.setScreen(new AboutScreen(game)); } }); table.add(creditsButton).uniform().fill(); }
From source file:de.bitbrain.craft.ui.widgets.ItemWidget.java
License:Open Source License
private Actor generateRight(Item item) { VerticalGroup layout = new VerticalGroup(); layout.align(Align.left);/*ww w .j a v a2 s . c om*/ layout.padLeft(15f); name.setColor(item.getRarity().getColor()); name.setFontScale(0.90f); layout.addActor(name); Table descContainer = new Table(); level = new StarLevelWidget(item.getLevel(), 7); availability = new AvailabilityIcon(item); descContainer.add(level); descContainer.right().add(availability).padLeft(70f).padTop(27f); layout.addActor(descContainer); layout.setTouchable(Touchable.disabled); return layout; }
From source file:gui.screen.MainPlayerHud.java
public MainPlayerHud(final EntityManager entityManager, Game game, Server server, Client client, final MapLoader map, OrthographicCamera camera) { super(game, client, server); deathMessageArray = new ArrayList<>(); textMessageArray = new ArrayList<>(); //Initialise Objects this.stage = new Stage(new StretchViewport(Constants.SCREENWIDTH, Constants.SCREENHEIGHT)); this.stack = new Stack(); //A container in wich you can place multiple widgets to "stack" them this.touchTable.setSize(stage.getWidth(), stage.getHeight()); this.camera = camera; touchTable.setTouchable(Touchable.enabled); stage.addActor(touchTable);/* ww w .ja v a2s . c om*/ this.entityManager = entityManager; //Initialise Font this.generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/lunchtime-doubly-so/lunchds.ttf")); this.parameter = new FreeTypeFontParameter(); parameter.size = 15; //Table settings Table backgroundTable = new Table(); backgroundTable.top(); backgroundTable.setFillParent(true); //Table settings 2 Table foregroundTable = new Table(); foregroundTable.top(); foregroundTable.setFillParent(true); /**------------------------EXIT DIALOG------------------------**/ exitDialog = new Dialog("Confirm exit", TextureManager.skin) { @Override public void result(Object obj) { boolean result = (boolean) obj; if (result == true) { //Stop music AudioManager.getCurrentMusic().stop(); quitGame(); } else { Gdx.input.setCursorCatched(true); } } }; exitDialog.text("Are you sure you want to quit?"); exitDialog.button("Yes", true); //sends "true" as the result exitDialog.button("No", false); //sends "false" as the result if (Constants.ISRUNNINGONSMARTPHONE && Constants.TOUCHSCREEN) { touchTable.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int buttonCode) { Player player = entityManager.getPlayerManager().getCurrentPlayerObject(); if (player != null) { // Calculate correct world position ThinGridCoordinates aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); // Change to block center ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim)); aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2); aim.setY( blockCenter.getY() + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2); goToCoordiantes = aim; } return true; } @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { Player player = entityManager.getPlayerManager().getCurrentPlayerObject(); if (player != null) { // Calculate correct world position ThinGridCoordinates aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); // Change to block center ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim)); aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2); aim.setY( blockCenter.getY() + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2); goToCoordiantes = aim; } } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { } }); } /*-------------------------MOVEMENT TOUCHPAD--------------------------*/ if (Constants.ISRUNNINGONSMARTPHONE && Constants.TOUCHPAD) { //Create a touchpad skin touchpadSkin = new Skin(); //Set background image touchpadSkin.add("touchBackground", new Texture("hud/touchBackground.png")); //Set knob image touchpadSkin.add("touchKnob", new Texture("hud/touchKnob.png")); //Create TouchPad Style touchpadStyle = new Touchpad.TouchpadStyle(); //Create Drawable's from TouchPad skin touchBackground = touchpadSkin.getDrawable("touchBackground"); touchKnob = touchpadSkin.getDrawable("touchKnob"); //Apply the Drawables to the TouchPad Style touchpadStyle.background = touchBackground; touchpadStyle.knob = touchKnob; //Create new TouchPad with the created style touchpad = new Touchpad(10, touchpadStyle); //setBounds(x,y,width,height) touchpad.setBounds(15, 15, 150, 150); stage.addActor(touchpad); touchpad.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int buttonCode) { return true; } @Override public void touchDragged(InputEvent event, float screenX, float screenY, int pointer) { ThinGridCoordinates aim = null; Player player = entityManager.getPlayerManager().getCurrentPlayerObject(); if (player != null) { // Left if (touchpad.getKnobPercentX() < -0.5) { float x = 370; float y = 250; // Calculate correct world position aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); //Right } else if (touchpad.getKnobPercentX() > 0.5) { float x = 460; float y = 250; // Calculate correct world position aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); } // Down if (touchpad.getKnobPercentY() < -0.5) { float x = 415; float y = 200; // Calculate correct world position aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); // Up } else if (touchpad.getKnobPercentY() > 0.5) { float x = 415; float y = 300; // Calculate correct world position aim = new ThinGridCoordinates( player.getPosition().getX() + (x - touchTable.getWidth() / 2f), player.getPosition().getY() + (y - touchTable.getHeight() / 2f)); aim = new ThinGridCoordinates(aim.getX() - (x - touchTable.getWidth() / 2f) / 3.5f, aim.getY() - (y - touchTable.getHeight() / 2f) / 3.5f); } if (aim != null) { // Change to block center ThinGridCoordinates blockCenter = new ThinGridCoordinates(new MapCellCoordinates(aim)); aim.setX(blockCenter.getX() + (Constants.MAPTEXTUREWIDTH - Constants.PLAYERWIDTH) / 2); aim.setY(blockCenter.getY() + (Constants.MAPTEXTUREHEIGHT - Constants.PLAYERHEIGHT / 4) / 2); } goToCoordiantes = aim; } } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { InputHandler.setAnyKey(false); InputHandler.resetMovementKeys(); } }); } /*-------------------------ACTION TOUCHPAD--------------------------*/ if (Constants.ISRUNNINGONSMARTPHONE) { Table table = new Table(); table.setFillParent(true); table.right().bottom().toFront(); /*-------------------------PLACE BOMB--------------------------*/ placeBombButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int buttonCode) { InputHandler.setAnyKey(true); InputHandler.setPlaceBombKey(true); return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { InputHandler.setAnyKey(false); InputHandler.setPlaceBombKey(false); } }); placeBombButton.setSize(100, 100); table.add(placeBombButton).size(placeBombButton.getWidth(), placeBombButton.getHeight()).padBottom(10) .padRight(10); stage.addActor(table); /*-------------------------TRIGGER REMOTE BUTTON--------------------------*/ Table table1 = new Table(); table1.right().bottom().toFront(); triggerRemoteButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int buttonCode) { InputHandler.setAnyKey(true); InputHandler.setRemoteKey(true); return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { InputHandler.setAnyKey(false); InputHandler.setRemoteKey(false); } }); triggerRemoteButton.setSize(60, 60); table1.add(triggerRemoteButton).size(triggerRemoteButton.getWidth(), triggerRemoteButton.getHeight()); table1.setPosition(685, 80); stage.addActor(table1); /*-------------------------TELEPORT BUTTON--------------------------*/ Table table2 = new Table(); table1.right().bottom().toFront(); teleportButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int buttonCode) { InputHandler.setAnyKey(true); InputHandler.setTeleportKey(true); return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { InputHandler.setAnyKey(false); InputHandler.setTeleportKey(false); } }); teleportButton.setSize(60, 60); table2.add(teleportButton).size(teleportButton.getWidth(), teleportButton.getHeight()); table2.setPosition(Constants.SCREENWIDTH - 65, 155); stage.addActor(table2); } /*-------------------------RESIZE ELEMENTS IN HUD--------------------------*/ if (Constants.ISRUNNINGONSMARTPHONE) { scaleCounterHud = 4; // Default 3 scaleInventoryImg = 1.8f; // Default 1.5 addToPositionX = 20; // Default -2 scaleTextMessage = 6; // Default 5 Constants.DEFAULTZOOM = 0.7f; // Default 1f } /*-------------------------GO BACK TO MENU BUTTON--------------------------*/ if (Constants.ISRUNNINGONSMARTPHONE) { Table table = new Table(); goToMenuButton.addListener(new InputListener() { @Override public boolean touchDown(InputEvent event, float screenX, float screenY, int pointer, int buttonCode) { InputHandler.setAnyKey(true); InputHandler.setEscKey(true); return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { InputHandler.setAnyKey(false); InputHandler.setEscKey(false); } }); goToMenuButton.setSize(70, 70); table.add(goToMenuButton).size(goToMenuButton.getWidth(), goToMenuButton.getHeight()); table.setSize(goToMenuButton.getWidth(), goToMenuButton.getHeight()); table.padTop(40); table.padRight(40); table.setPosition(Constants.SCREENWIDTH - table.getWidth(), Constants.SCREENHEIGHT - table.getHeight()); stage.addActor(table); } /*-------------------------SCREEN MESSAGE--------------------------*/ Table messageLabel = new Table(); messageLabel.setFillParent(true); messageLabel.right(); parameter.size = 4 * (int) scaleTextMessage; deathMessageLabel = new Label("", new Label.LabelStyle(generator.generateFont(parameter), Color.valueOf("f7472c"))); deathMessageLabel.setAlignment(Align.center); deathMessageLabel.setSize(200, 50); messageLabel.add(deathMessageLabel); textMessageLabel = new Label("", new Label.LabelStyle(generator.generateFont(parameter), Color.YELLOW)); textMessageLabel.setAlignment(Align.center); textMessageLabel.setSize(200, 50); messageLabel.add(textMessageLabel); stage.addActor(messageLabel); /*-------------------------LIFE & COUNTER HUD--------------------------*/ parameter.size = 5 * (int) scaleCounterHud; //Labels (textfields) bombCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE)); coinCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE)); speedCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE)); rangeCounterLabel = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.WHITE)); //Live & coins display image uiCounterImage = new Image(TextureManager.hudCounterFullLive); //Calculate image width (scaledCounterX) and image height (scaleY) float scaledCounterX = TextureManager.hudCounterFullLive.getWidth() * scaleCounterHud; float scaledCounterY = TextureManager.hudCounterFullLive.getHeight() * scaleCounterHud; //Add image to background messageLabel backgroundTable.add(uiCounterImage).width(scaledCounterX).height(scaledCounterY); //Add label to foreground messageLabel foregroundTable.row().expandX().padTop(8 * scaleCounterHud); foregroundTable.add(bombCounterLabel).padLeft(40 * scaleCounterHud); foregroundTable.add(coinCounterLabel).padLeft(16 * scaleCounterHud); foregroundTable.add(rangeCounterLabel).padLeft(13 * scaleCounterHud); foregroundTable.add(speedCounterLabel).padLeft(18 * scaleCounterHud); //Set container to the height of the image and position it on the top left stack.setWidth(scaledCounterX); stack.setHeight(scaledCounterY); stack.setPosition(0, 470 - scaledCounterY); //End messageLabel and container (stack) stack.add(backgroundTable); stack.add(foregroundTable); stage.addActor(stack); /*-------------------------BOMB INVENTORY HUD--------------------------*/ // Inventory Image uiInventoryImage = new Image(TextureManager.hudInventoryHiglighted1); uiInventoryImage.setWidth(280 * scaleInventoryImg);// 1,5x bigger uiInventoryImage.setHeight(32 * scaleInventoryImg); uiInventoryImage.setPosition((Constants.SCREENWIDTH - uiInventoryImage.getWidth()) / 2 + addToPositionX, 5); stage.addActor(uiInventoryImage); // Price labels bombPrice1 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice2 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice3 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice4 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice5 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice6 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice7 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice8 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); bombPrice9 = new Label("000", new Label.LabelStyle(generator.generateFont(parameter), Color.GOLD)); Table pricesTable = new Table(); pricesTable.setFillParent(true); //31x31 pricesTable.add(bombPrice1).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice2).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice3).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice4).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice5).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice6).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice7).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice8).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesTable.add(bombPrice9).width(31 * scaleInventoryImg).height(31 * scaleInventoryImg); pricesLabelGroup.addActor(pricesTable); pricesLabelGroup.setPosition((Constants.SCREENWIDTH - pricesLabelGroup.getWidth()) / 2 + addToPositionX + 3, 15); stage.addActor(pricesLabelGroup); if (Constants.ISRUNNINGONSMARTPHONE) { Table touchTable = new Table(); touchTable.add(getContainerWithBombListener(1)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(2)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(3)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(4)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(5)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(6)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(7)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(8)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.add(getContainerWithBombListener(9)).width(31 * scaleInventoryImg) .height(31 * scaleInventoryImg); touchTable.setPosition((Constants.SCREENWIDTH - touchTable.getWidth()) / 2 + addToPositionX, 35); stage.addActor(touchTable); } generator.dispose(); }