List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Table add
public Cell<Label> add(String text)
From source file:Credits.java
License:Apache License
public Credits() { Sink.setBackground("title"); Table grid = new Table(); grid.setSize(Sink.targetWidth, Sink.targetHeight); grid.setFillParent(true);/* w w w. j a v a 2 s . c om*/ grid.setPosition(0, 0); grid.top().left(); grid.center(); grid.setPosition(0, -250); grid.addAction(Actions.moveTo(0, 110, 2.0f)); grid.center(); /* ________________________ * |_______Credits__________| * | | | * | | | * | | | * |__________|_____________| * |_________Back___________| */ TextButton title = new TextButton("Credits", Asset.skin); TextButton back = new TextButton("Back", Asset.skin); back.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); Sink.setScene("Menu"); } }); grid.add(title).size(200, 75); grid.row(); grid.add(back).size(200, 75).center(); Sink.addActor(grid); }
From source file:Levels.java
License:Apache License
public Levels() { Table grid = new Table(); grid.setSize(Sink.targetWidth, Sink.targetHeight); grid.setFillParent(true);//from w ww. j a va 2 s . c o m grid.setPosition(0, 0); grid.top().left(); grid.center(); grid.setPosition(-999, 0); grid.addAction(Actions.moveTo(0, 0, 0.3f)); grid.top().left().pad(10, 10, 10, 10); /* _____________________ * | [1] [2] [3] [4] [5] | * | | * | | * | | * |_____________________| */ for (int i = 0; i < maxLevel; i++) { final int index = i; TextButton btn = new TextButton("" + (i + 1), Asset.skin); if (i > Config.levels() - 0) btn.setVisible(false); if (i % 5 == 0) grid.row(); grid.add(btn).size(100, 100).pad(5, 0, 0, 0).expandX(); btn.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); Game.currentLevel = index; Sink.setScene("Game"); } }); } Sink.addActor(grid); }
From source file:ac.uk.dmu.ash.game.screen.CreditsScreen.java
License:Open Source License
/** * Creates a new {@link CreditsScreen}./*from www . ja v a 2s . c om*/ * @param game The game instance. * @param assets The game assets */ public CreditsScreen(final Game game, final AssetManager assets) { this.assets = assets; Gdx.input.setInputProcessor(stage); Table fpsTable = createTableWithLabel(assets, "ui_skin", Align.left, (Align.top | Align.left), "fps:"); fpsLabel = (Label) fpsTable.getCells().get(0).getWidget(); stage.addActor(fpsTable); Table creditsTable = createTableWithLabel(assets, "ui_skin", CREDITS); stage.addActor(creditsTable); TextButton backButton = createTextButton(assets, "ui_skin", "Back", new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { dispose(); game.setScreen(new MainMenuScreen(game, assets)); } }); Table buttonsTable = createTable(Align.left | Align.bottom); buttonsTable.add(backButton); stage.addActor(buttonsTable); }
From source file:at.highstreeto.xnllayoutparser.element.CellParser.java
License:Apache License
@Override public Actor load(Element element, LayoutParserContext context) throws LayoutParseException { Table table = (Table) context.getActorByElement(element.getParent().getParent()); Element child = element.getChild(0); Actor actor = context.getParsers().getParserByElementName(child).load(child, context); Cell<?> cell = table.add(actor); if (element.getAttributes().containsKey("fill")) { if ("x".equals(element.getAttribute("fill"))) { cell.fillX();// w w w . j a va 2 s .c om } else if ("y".equals(element.getAttribute("fill"))) { cell.fillY(); } else if ("xy".equals(element.getAttribute("fill"))) { cell.fill(); } else { throw new LayoutParseException(); } } if (element.getAttributes().containsKey("expand")) { if ("x".equals(element.getAttribute("expand"))) { cell.expandX(); } else if ("y".equals(element.getAttribute("expand"))) { cell.expandY(); } else if ("xy".equals(element.getAttribute("expand"))) { cell.expand(); } else { throw new LayoutParseException(); } } // 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)) { cell.center(); } else if ("t".equals(i)) { cell.top(); } else if ("b".equals(i)) { cell.bottom(); } else if ("l".equals(i)) { cell.left(); } else if ("r".equals(i)) { cell.right(); } } } // Padding - Format: Top Left Bottom Right if (element.getAttributes().containsKey("pad")) { String[] pads = element.getAttribute("pad").split(" "); if (pads.length == 4) { float top = Float.parseFloat(pads[0]); float right = Float.parseFloat(pads[1]); float bottom = Float.parseFloat(pads[2]); float left = Float.parseFloat(pads[3]); cell.pad(top, left, bottom, right); } else { throw new LayoutParseException(); } } if (element.getAttributes().containsKey("colspan")) { int colspan = Integer.parseInt(element.getAttribute("colspan")); cell.colspan(colspan); } return null; }
From source file:ateamproject.kezuino.com.github.render.screens.GameScreen.java
public void showPlayersView() { this.playerMenu.clear(); TextButton btExit = new TextButton("Oke", skin); btExit.addListener(new ClickListener() { @Override//from w ww . j ava 2 s . c o m public void clicked(InputEvent event, float x, float y) { getSession().setPlayerMenuShowing(false); playerMenu.hide(); } }); this.playerMenu.add(btExit); Table scrollTable = new Table(skin); ArrayList<String> people = new ArrayList<>(); PacketGetKickInformation packetGetKickInfo = new PacketGetKickInformation(); Client.getInstance().send(packetGetKickInfo); people.addAll(packetGetKickInfo.getResult()); for (String person : people) { String[] peopleResult = person.split(" "); TextButton bKick = new TextButton("Kick", skin); bKick.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { PacketSetKickInformation packetKick = new PacketSetKickInformation( UUID.fromString(peopleResult[4]), null); Client.getInstance().send(packetKick); PacketGetKickInformation packetKickInfo = new PacketGetKickInformation(); Client.getInstance().send(packetKickInfo); people.clear(); people.addAll(packetKickInfo.getResult()); } }); scrollTable.add(peopleResult[0]); scrollTable.columnDefaults(0); scrollTable.add(bKick); scrollTable.columnDefaults(1); scrollTable.add(peopleResult[1] + "/" + peopleResult[2]); scrollTable.columnDefaults(2); scrollTable.row(); if (peopleResult[3].equals("true")) { bKick.setDisabled(true); bKick.setTouchable(Touchable.disabled); bKick.setColor(255, 0, 0, 100); } } playerMenu.add(scrollTable); this.playerMenu.show(stage); getSession().showPlayerMenu(); }
From source file:ateamproject.kezuino.com.github.render.screens.HighscoreScreen.java
public HighscoreScreen(Game game, boolean top10HighscoreReached) { super(game);/*from w ww. j a v a 2s . c om*/ TextButton btnBack = new TextButton("Terug", skin); btnBack.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (top10HighscoreReached) { game.setScreen(new CreditsScreen(game)); } else { game.setScreen(new MainScreen(game)); } } }); float x = 240; float y = stage.getHeight() / 4; btnBack.setSize(200, 40); btnBack.setPosition(stage.getWidth() / 2 - btnBack.getWidth() / 2, stage.getHeight() / 4 - btnBack.getHeight() / 2); Label lblTitle = new Label("Highscore", skin); if (top10HighscoreReached) { lblTitle = new Label("Gefeliciteerd met een top 10 plek!", skin); btnBack.setText("Haal mijn prijs op"); } lblTitle.setColor(Color.YELLOW); lblTitle.setPosition(stage.getWidth() / 2 - lblTitle.getWidth() / 2, stage.getHeight() - 50); PacketGetHighscores packet = new PacketGetHighscores(Client.getInstance().getId()); Client.getInstance().send(packet); Table table = new Table(); table.setSkin(skin); int rankNr = 0; for (Map.Entry<String, Integer> entry : packet.getResult().entrySet()) { rankNr++; table.add(new Label(Integer.toString(rankNr), skin)).padRight(50); table.add(new Label(entry.getKey(), skin)).padRight(50); table.add(new Label(Integer.toString(entry.getValue()), skin)); table.row(); } table.setPosition(stage.getWidth() / 2 - table.getWidth() / 2, stage.getHeight() - 190); stage.addActor(btnBack); stage.addActor(lblTitle); stage.addActor(table); backgroundMusic = Assets.getMusicStream("menu.mp3"); }
From source file:be.ac.ucl.lfsab1509.bouboule.game.screen.MenuScreen.java
License:Open Source License
@Override public void show() { super.show(); // Set Background addBackGroundShift("GdxMenus/main/mainmenubg.jpg"); // Add Button image addBackGround("GdxMenus/main/mainmenubuttons.png"); // Create the 2 Bouboules out of the screen final Image imgBoubouleR = addImage("GdxMenus/main/boubouleright.png", GlobalSettings.APPWIDTH, 1f); final Image imgBoubouleL = addImage("GdxMenus/main/boubouleleft.png", -GlobalSettings.APPWIDTH, 1f); // add action on the bouboule final ActionBouboul actionbouL = new ActionBouboul(false); this.stage.addAction(actionbouL); actionbouL.setActor(imgBoubouleL);/* w w w .ja v a 2 s. c o m*/ final ActionBouboul actionbouR = new ActionBouboul(true); this.stage.addAction(actionbouR); actionbouR.setActor(imgBoubouleR); // add the title title = new Label("BOUBOULE", getSkin(), "darktimes-font", new Color(.388f, .733f, .984f, 1f)); title.setAlignment(Align.center); // center title.setWidth(GlobalSettings.APPWIDTH); // title.setColor(.2f, .7098f, .898f, 1f); // android color // add the title in a table in order to rotate it. Table tableTitle = new Table(); tableTitle.add(title); tableTitle.setTransform(true); tableTitle.setWidth(GlobalSettings.APPWIDTH); // all the width tableTitle.setX(0); tableTitle.setY((int) (1050 * GlobalSettings.HD) - GlobalSettings.SHIFT_BG_HEIGHT / 2); tableTitle.setOrigin(GlobalSettings.APPWIDTH / 2, tableTitle.getHeight() / 2); // at the center stage.addActor(tableTitle); // add action on the title final ActionTitle actiontitle = new ActionTitle(); this.stage.addAction(actiontitle); actiontitle.setActor(tableTitle); // Add 5 button transparent Button playButton, paramButton, scoreButton, boubouleButton, titleButton; if (GlobalSettings.ISHD) { playButton = createButton("transparent", 690, 250, 312, 1150); paramButton = createButton("transparent", 690, 250, 312, 887); scoreButton = createButton("transparent", 690, 250, 312, 615); boubouleButton = createButton("transparent", 1000, 600, 200, 0); titleButton = createButton("transparent", 1000, 1000, 200, 1450); } else { playButton = createButton("transparent", 430, 160, 200, 725); paramButton = createButton("transparent", 430, 160, 200, 555); scoreButton = createButton("transparent", 430, 160, 200, 385); boubouleButton = createButton("transparent", 500, 350, 200, 0); titleButton = createButton("transparent", 500, 500, 200, 885); } // Listener for the button playButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (GlobalSettings.GAME.isPlayingGame()) setScreenWithFading(null); else setScreenWithFading(new WorldScreen()); } }); paramButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { setScreenWithFading(new ParamScreen()); } }); scoreButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { if (GlobalSettings.GAMECENTER != null) { GlobalSettings.GAMECENTER.showLeaderboard(); } else { Dialog dialog = new Dialog(" HighScore ", getSkin(), "default") { // improved default skin? // protected void result(Object object) {} // Just hide the dialog }.text("\n" + getHighScoreText() + " ").button(" Close ", null).show(stage); dialog.setX((GlobalSettings.APPWIDTH - dialog.getWidth()) / 2); } } }); boubouleButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { final ActionBouboul actionbouL = new ActionBouboul(false); actionbouL.init(); stage.addAction(actionbouL); actionbouL.setActor(imgBoubouleL); final ActionBouboul actionbouR = new ActionBouboul(true); actionbouR.init(); stage.addAction(actionbouR); actionbouR.setActor(imgBoubouleR); } }); titleButton.addListener(new ClickListener() { public void clicked(InputEvent event, float x, float y) { actiontitle.switchName(); } }); }
From source file:ca.hiphiparray.amazingmaze.FishMiniGame.java
License:Open Source License
/** Create the pause menu. */ private void setupPauseMenu() { pauseMenu = new Stage(new ScreenViewport(), game.batch); Table table = new Table(); table.setFillParent(true);/*from ww w . jav a 2 s.c om*/ table.center(); pauseMenu.addActor(table); TextButton resumeButton = new TextButton("Resume", game.assets.skin); resumeButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { paused = false; } }); table.add(resumeButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); table.row(); TextButton settingsButton = new TextButton("Settings", game.assets.skin); final Screen sourceScreen = this; settingsButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { game.settingsScreen.setSourceScreen(sourceScreen); game.setScreen(game.settingsScreen); } }); table.add(settingsButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); table.row(); TextButton quitButton = new TextButton("Quit", game.assets.skin); quitButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { game.save.setLevel(game.save.getLevel() - 1); game.setScreen(game.menuScreen); } }); table.add(quitButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); }
From source file:ca.hiphiparray.amazingmaze.MazeScreen.java
License:Open Source License
/** Create the pause menu. */ private void setupPauseMenu() { pauseMenu = new Stage(new ScreenViewport(), game.batch); Table table = new Table(); table.setFillParent(true);/*from w w w. j a v a2s . c o m*/ table.center(); pauseMenu.addActor(table); TextButton resumeButton = new TextButton("Resume", game.assets.skin); resumeButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { paused = false; } }); table.add(resumeButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); table.row(); TextButton settingsButton = new TextButton("Settings", game.assets.skin); final Screen sourceScreen = this; settingsButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { game.settingsScreen.setSourceScreen(sourceScreen); game.setScreen(game.settingsScreen); } }); table.add(settingsButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); table.row(); TextButton quitButton = new TextButton("Main Menu", game.assets.skin); quitButton.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { game.setScreen(game.menuScreen); } }); table.add(quitButton).pad(10).width(Gdx.graphics.getWidth() / 4).height(Gdx.graphics.getHeight() / 8); }
From source file:ca.hiphiparray.amazingmaze.MazeScreen.java
License:Open Source License
/** Create the game HUD. */ private void setupHUD() { hud = new Stage(new ScreenViewport(), game.batch); Table table = new Table(); table.setFillParent(true);/*from w w w . ja va2s .co m*/ table.top().left(); hud.addActor(table); Label level = new Label("Level " + game.save.getLevel(), game.assets.skin, Assets.HUD_STYLE); table.add(level).colspan(2); table.row(); Image lifeIcon = new Image(game.assets.manager.get(Assets.LIFE_HUD_IMAGE, Texture.class)); table.add(lifeIcon).pad(Gdx.graphics.getWidth() / 128).left(); livesLeft = new Label("", game.assets.skin, Assets.HUD_STYLE); table.add(livesLeft); updateLives(-2); }