Example usage for com.badlogic.gdx.scenes.scene2d.ui Table layout

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Table layout

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Table layout.

Prototype

public void layout() 

Source Link

Usage

From source file:com.andgate.ikou.view.LevelSelectScreen.java

License:Open Source License

public void buildStage() {
    stage.clear();//w  ww .  ja v  a2s.c  o m
    stage.getViewport().setWorldSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);

    // get the level and floor select tables ready
    final Table levelSelectorTable = buildLevelSelectorTable();
    final Table floorSelectTable = buildFloorSelectTable();

    final Table table = new Table();
    table.add(levelSelectorTable).expand().fill();

    if (game.worldWidth < game.worldHeight)
        table.row();

    table.add(floorSelectTable).fill().expand();

    table.setFillParent(true);

    stage.addActor(table);
    stage.setDebugAll(true);

    // Build the layout's dimensional information.
    table.pack();
    table.layout();

    // Then get the width/height of the container
    int w = (int) previewContainer.getWidth();
    int h = (int) previewContainer.getHeight();

    levelPreview.setSize(w, h);
    previewContainer.setBackground(levelPreview.getDrawable());
}

From source file:com.ridiculousRPG.ui.ActorsOnStageService.java

License:Apache License

private void debugTableLayout(Array<Actor> actors) {
    if (actors == null)
        return;/*  w  ww  .jav a2  s.c o m*/
    for (int i = actors.size - 1; i > -1; i--) {
        Actor a = actors.get(i);
        if (a instanceof Table) {
            Table tbl = (Table) a;
            if (tbl.getDebug() != Debug.all) {
                tbl.debug(Debug.all);
                tbl.layout();
            }
        }
        if (a instanceof Group) {
            debugTableLayout(((Group) a).getChildren());
        }
    }
}

From source file:com.vlaaad.dice.ui.windows.DiceWindow.java

License:Open Source License

@Override
protected void doShow(final UserData userData) {
    final Table items = new Table();
    final ScrollPane pane = new ScrollPane(items, new ScrollPane.ScrollPaneStyle()) {

        @Override//from ww  w.  jav  a 2 s  . c o m
        public void layout() {
            float w = items.getPrefWidth();
            float h = Math.min(getParent().getHeight(), items.getPrefHeight());
            if (w != getWidth() || h != getHeight()) {
                setSize(w, h);
                invalidateHierarchy();
            }
            super.layout();
        }
    };
    pane.setTouchable(Touchable.childrenOnly);
    pane.setOverscroll(false, false);
    pane.setCancelTouchFocus(false);
    pane.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            pane.layout();
            pane.layout();
            items.layout();
            if (actor instanceof Layout)
                ((Layout) actor).layout();
            pane.layout();
            pane.layout();
            pane.scrollTo(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight() + 100);
        }
    });

    Iterable<Die> dice = userData.dice();
    int i = 1;
    int count = userData.diceCount();
    for (Die die : dice) {
        DiePane diePane = new DiePane(die, userData, diceWindowGroup);
        table.add(diePane);
        diePane.setWidth(0);
        diePane.pack();
        diePane.setWidth(ViewController.CELL_SIZE * 6.6f);
        Cell cell = items.add(diePane).fillX().maxWidth(ViewController.CELL_SIZE * 6.6f);
        if (i != count) {
            cell.padBottom(-1);
        }
        cell.row();
        map.put(die, diePane);
        diePane.info.addListener(createMinimizeListener(die, dice));
        i++;
    }
    items.pack();
    table.add(pane).width(items.getPrefWidth());//.size(items.getPrefWidth(), 200);
}

From source file:de.longri.cachebox3.gui.dialogs.NewDB_InputBox.java

License:Open Source License

private static Table createContentBox() {
    Table contentBox = new Table();

    VisTextField textField = new VisTextField();
    textField.setMessageText(Translation.Get("EnterNewDBName"));

    VisCheckBox checkBox = new VisCheckBox("");
    checkBox.setText(Translation.Get("UseDefaultRep"));

    float pad = CB.scaledSizes.MARGIN;
    contentBox.add(textField).pad(pad).left().fillX();
    contentBox.row();// w  w  w  .j a v  a2s . com
    contentBox.add(checkBox).pad(pad).left().fillX();

    contentBox.pack();
    contentBox.layout();

    return contentBox;
}

From source file:headmade.arttag.screens.GameOverScreen.java

License:Apache License

public GameOverScreen(DirectedGame game) {
    super(game);//from  w w  w  .  jav  a2s  .c  om

    final OrthographicCamera cam = (OrthographicCamera) camera;
    cam.zoom = 1f;

    final Table rootTable = new Table(Assets.instance.skin);
    rootTable.setFillParent(true);
    // rootTable.setBackground(Assets.instance.skin.getDrawable(AssetTextures.paper));

    continueButton = new JigglyImageTextButton("Continue", Assets.instance.skin, "play",
            ActionFactory.wiggleRepeat(3f, 0.5f));
    continueButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            nextScreen();
            return true;
        }
    });
    continueButton.getLabelCell().padRight(10f);

    final int cash = Player.instance.getCash();
    final Label score = new Label("$" + cash, Assets.instance.skin, "dollar");
    final Label highScore = new Label("$" + ArtTag.highScore, Assets.instance.skin, "dollar");

    rootTable.setFillParent(true);
    rootTable.add("GAME OVER").center().colspan(2).pad(20).getActor().scaleBy(2);
    rootTable.row();

    rootTable.add("Your Score").right();
    rootTable.add(score).space(20).pad(20);
    rootTable.row();

    rootTable.add("High Score").right();
    rootTable.add(highScore).space(20).pad(20);
    rootTable.row();

    if (cash > ArtTag.highScore) {
        ArtTag.highScore = cash;
        rootTable.add("Congratulations!\nYou set a new High Score").space(20).pad(20).colspan(2);
        rootTable.row();
    }

    rootTable.add(continueButton).center().colspan(2).space(20).pad(20);

    // buildTagTable(rootTable);
    // rootTable.setDebug(true);
    rootTable.layout();

    stage.addActor(rootTable);

    stage.addListener(new InputListener() {

        @Override
        public boolean scrolled(InputEvent event, float x, float y, int amount) {
            if (rootTable.getDebug()) {
                final OrthographicCamera cam = (OrthographicCamera) camera;
                cam.zoom += amount * 0.5f;
                cam.zoom = MathUtils.clamp(cam.zoom, 0.5f, 10f);
                cam.update();
            }
            return true;
        }

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.F12) {
                rootTable.setDebug(!rootTable.getDebug());
                return true;
            } else if (keycode == Keys.ALT_LEFT || keycode == Keys.ALT_RIGHT || keycode == Keys.Z
                    || keycode == Keys.SPACE) {
                nextScreen();
                return true;
            }
            return super.keyDown(event, keycode);
        }

    });
}

From source file:headmade.arttag.screens.RatingScreen.java

License:Apache License

public RatingScreen(DirectedGame game, JobDescription jobDescription) {
    super(game);//w w  w .  ja v a  2 s  . com

    final OrthographicCamera cam = (OrthographicCamera) camera;
    cam.zoom = 1f;

    this.jobDesc = jobDescription;

    final Table rootTable = new Table(Assets.instance.skin);
    rootTable.setFillParent(true);
    // rootTable.setBackground(Assets.instance.skin.getDrawable(AssetTextures.paper));

    jobDescActor = new Label(jobDescription.desc, Assets.instance.skin, "jobDesc");
    // jobDescActor.setWrap(true);
    jobDescActor.setWidth(camera.viewportWidth / 4);

    continueButton = new JigglyImageTextButton("Continue", Assets.instance.skin, "play",
            ActionFactory.wiggleRepeat(3f, 0.5f));
    continueButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            nextScreen();
            return true;
        }
    });
    continueButton.getLabelCell().padRight(10f);

    rootTable.setFillParent(true);
    rootTable.add("Mission").space(20).pad(20).right();
    rootTable.add(jobDescActor).center().expand();
    rootTable.row();

    int cash = 100;
    if (Player.instance.inventory.size == 0) {
        cash = 0;
        rootTable.add("You did not steal anything and failed the mission.").center().colspan(2).space(20)
                .pad(20);
        rootTable.row();
    } else {
        for (int i = 0; i < Player.instance.inventory.size; i++) {
            final Art art = Player.instance.inventory.get(i);
            final Image img = new Image(art.getTexture());
            img.setScaling(Scaling.fit);
            // img.setWidth(camera.viewportWidth / Player.instance.inventory.size);
            // img.setHeight(camera.viewportHeight / 5);
            if (art.matchesDescription(jobDescription)) {
                cash += 1000 + MathUtils.random(100);
            }
            if (art.isCorrectlyTagged()) {
                cash += 1000 + MathUtils.random(100);
            } else if (art.isIncorrectlyTagged()) {
                cash /= 10;
            }

            Gdx.app.log(TAG, "Cash reward " + cash + " art.matchesDescription() "
                    + art.matchesDescription(jobDescription) + " art.isCorrectlyTagged() "
                    + art.isCorrectlyTagged() + " art.isIncorrectlyTagged() " + art.isIncorrectlyTagged());
            Gdx.app.log(TAG, "Multiplying by Player Accuracy " + Player.instance.getAccuracy());
            cash *= (0.2f + Player.instance.getAccuracy());

            rootTable.add(i == 0 ? "Loot" : "").space(20).pad(20).right();
            rootTable.add(img).center().pad(10f).expand();
            rootTable.row();
        }
    }

    Player.instance.increaseCash(cash);
    final Label earningActor = new Label("$" + cash, Assets.instance.skin, "dollar");

    rootTable.add("Reward").space(20).pad(20);
    rootTable.add(earningActor).pad(10f);
    rootTable.row();

    rootTable.add(continueButton).center().colspan(2).space(20).pad(20);

    // buildTagTable(rootTable);
    // rootTable.setDebug(true);
    rootTable.layout();

    stage.addActor(rootTable);

    stage.addListener(new InputListener() {

        @Override
        public boolean scrolled(InputEvent event, float x, float y, int amount) {
            if (rootTable.getDebug()) {
                final OrthographicCamera cam = (OrthographicCamera) camera;
                cam.zoom += amount * 0.5f;
                cam.zoom = MathUtils.clamp(cam.zoom, 0.5f, 10f);
                cam.update();
            }
            return true;
        }

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.F12) {
                rootTable.setDebug(!rootTable.getDebug());
                return true;
            } else if (keycode == Keys.ALT_LEFT || keycode == Keys.ALT_RIGHT || keycode == Keys.Z
                    || keycode == Keys.SPACE) {
                nextScreen();
                return true;
            }
            return super.keyDown(event, keycode);
        }

    });
}