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

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

Introduction

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

Prototype

public Table pad(float pad) 

Source Link

Document

Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value.

Usage

From source file:com.badlogic.gdx.tests.gwt.GwtTestWrapper.java

License:Apache License

@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");

    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    container = new Table();
    ui.addActor(container);/*from w  w  w  .j  a  v a 2 s  .co m*/
    container.debug();
    Table table = new Table();
    ScrollPane scroll = new ScrollPane(table);
    container.add(scroll).expand().fill();
    table.pad(10).defaults().expandX().space(4);
    for (final Instancer instancer : tests) {
        table.row();
        TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
        button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
                test = instancer.instance();
                Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
                test.create();
                test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
        });
        table.add(button).expandX().fillX();
    }
    container.row();
    container.add(
            new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE)))
            .pad(5, 5, 5, 5);

    Gdx.input = new InputWrapper(Gdx.input) {
        @Override
        public boolean keyUp(int keycode) {
            if (keycode == Keys.ESCAPE) {
                if (test != null) {
                    Gdx.app.log("GdxTestGwt", "Exiting current test.");
                    dispose = true;
                }
            }
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
                if (test != null) {
                    dispose = true;
                }
            }
            return false;
        }
    };
    ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);

    Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}

From source file:com.bladecoder.engine.ui.DebugScreen.java

License:Apache License

@Override
public void show() {
    float size = DPIUtils.getPrefButtonSize();
    float margin = DPIUtils.getMarginSize();

    stage = new Stage(new ScreenViewport());

    table = new Table(ui.getSkin());
    table.setFillParent(true);/*from w  w w  .j  a  va  2s .  c  o  m*/
    table.left().top();
    table.pad(margin);

    table.addListener(new InputListener() {
        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            return true;
        }
    });

    stage.setKeyboardFocus(table);

    Button back = new Button(ui.getSkin(), "back");

    back.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.SCENE_SCREEN);
        }
    });

    Label title = new Label("DEBUG SCREEN", ui.getSkin(), "title");

    Table header = new Table();
    header.padBottom(margin);
    Container<Button> cont = new Container<Button>(back);
    cont.size(size);
    header.add(cont);
    header.add(title).fillX().expandX().left();
    table.add(header).colspan(3).fillX().expandX().left();

    // ------------- SPEED
    speedText = new TextField(Float.toString(((SceneScreen) ui.getScreen(Screens.SCENE_SCREEN)).getSpeed()),
            ui.getSkin());
    TextButton speedButton = new TextButton("Set Speed", ui.getSkin());
    speedButton.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            SceneScreen scnScr = (SceneScreen) ui.getScreen(Screens.SCENE_SCREEN);
            scnScr.setSpeed(Float.parseFloat(speedText.getText()));
        }
    });

    speedButton.pad(2, 3, 2, 3);
    HorizontalGroup sGroup = new HorizontalGroup();
    sGroup.space(10);
    sGroup.addActor(speedText);
    sGroup.addActor(speedButton);

    table.row().pad(5).align(Align.left);
    table.add(new Label("Game Speed: ", ui.getSkin(), "debug"));
    table.add(sGroup);

    // ------------- RECORDING

    final Recorder r = ui.getRecorder();
    TextButton play = new TextButton(r.isPlaying() ? "Stop" : "Play", ui.getSkin());
    rec = new TextButton(r.isRecording() ? "Stop Rec" : "Rec", ui.getSkin());
    play.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final Recorder r = ui.getRecorder();

            if (!r.isPlaying()) {
                r.setFilename(recordings.getSelected());
                r.load();
                r.setPlaying(true);
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            } else {
                r.setPlaying(false);
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        }
    });

    rec.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final Recorder r = ui.getRecorder();

            if (r.isPlaying()) {
                r.setPlaying(false);
            }

            if (!r.isRecording())
                r.setFilename(recFilename.getText());

            r.setRecording(!r.isRecording());
            rec.setText(r.isRecording() ? "Stop Rec" : "Rec");

            if (r.isRecording())
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
        }
    });

    recordings = new SelectBox<String>(ui.getSkin());

    String[] testFiles = EngineAssetManager.getInstance().listAssetFiles("/tests");
    ArrayList<String> al = new ArrayList<String>();

    for (String file : testFiles)
        if (file.endsWith(Recorder.RECORD_EXT))
            al.add(file.substring(0, file.indexOf(Recorder.RECORD_EXT)));

    FileHandle[] testFiles2 = EngineAssetManager.getInstance().getUserFolder().list();

    for (FileHandle file : testFiles2)
        if (file.name().endsWith(Recorder.RECORD_EXT))
            al.add(file.name().substring(0, file.name().indexOf(Recorder.RECORD_EXT)));

    recordings.setItems(al.toArray(new String[al.size()]));

    play.pad(2, 3, 2, 3);
    rec.pad(2, 3, 2, 3);

    recFilename = new TextField(r.getFileName(), ui.getSkin());

    HorizontalGroup rGroup = new HorizontalGroup();
    rGroup.space(10);
    rGroup.addActor(recordings);
    rGroup.addActor(play);
    rGroup.addActor(new Label("Rec. Filename", ui.getSkin(), "debug"));
    rGroup.addActor(recFilename);
    rGroup.addActor(rec);

    table.row().pad(5).align(Align.left);
    table.add(new Label("Game Recording: ", ui.getSkin(), "debug"));
    table.add(rGroup);

    // ------------- SCENES
    TextButton go = new TextButton("Go", ui.getSkin());
    go.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            World.getInstance().resume();
            World.getInstance().setCutMode(false);
            World.getInstance().setCurrentScene(scenes.getSelected());
            ui.setCurrentScreen(Screens.SCENE_SCREEN);
        }
    });

    go.pad(2, 3, 2, 3);

    scenes = new SelectBox<String>(ui.getSkin());
    scenes.setItems(World.getInstance().getScenes().keySet()
            .toArray(new String[World.getInstance().getScenes().size()]));

    HorizontalGroup scGroup = new HorizontalGroup();
    scGroup.space(10);
    scGroup.addActor(scenes);
    scGroup.addActor(go);

    table.row().pad(5).align(Align.left);
    table.add(new Label("Go to Scene: ", ui.getSkin(), "debug"));
    table.add(scGroup);

    // ------------- TESTERBOT
    final TesterBot bot = ui.getTesterBot();

    TextButton runBot = new TextButton(bot.isEnabled() ? "Stop" : "Run", ui.getSkin());
    runBot.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final TesterBot bot = ui.getTesterBot();

            bot.setMaxWaitInverval(Float.parseFloat(testerTimeConf.getText()));
            bot.setInSceneTime(Float.parseFloat(inSceneTimeConf.getText()));
            bot.setExcludeList(testerExcludeList.getText());
            bot.setEnabled(!bot.isEnabled());

            ui.setCurrentScreen(Screens.SCENE_SCREEN);
        }
    });

    runBot.pad(2, 3, 2, 3);

    testerTimeConf = new TextField(Float.toString(bot.getMaxWaitInverval()), ui.getSkin());
    inSceneTimeConf = new TextField(Float.toString(bot.getInSceneTime()), ui.getSkin());
    testerExcludeList = new TextField(bot.getExcludeList(), ui.getSkin());

    TextButton testerLeaveConf = new TextButton("Leave", ui.getSkin(), "toggle");
    testerLeaveConf.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final TesterBot bot = ui.getTesterBot();

            bot.setRunLeaveVerbs(!bot.isRunLeaveVerbs());
        }
    });

    testerLeaveConf.setChecked(bot.isRunLeaveVerbs());

    TextButton testerGotoConf = new TextButton("Goto", ui.getSkin(), "toggle");
    testerGotoConf.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final TesterBot bot = ui.getTesterBot();

            bot.setRunGoto(!bot.isRunGoto());
        }
    });

    testerGotoConf.setChecked(bot.isRunGoto());

    TextButton testerPassText = new TextButton("Pass Texts", ui.getSkin(), "toggle");
    testerPassText.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final TesterBot bot = ui.getTesterBot();

            bot.setPassTexts(!bot.isPassTexts());
        }
    });

    testerPassText.setChecked(bot.isPassTexts());

    TextButton testerWaitWhenWalking = new TextButton("Wait When Walking", ui.getSkin(), "toggle");
    testerWaitWhenWalking.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            final TesterBot bot = ui.getTesterBot();

            bot.setWaitWhenWalking(!bot.isWaitWhenWalking());
        }
    });

    testerWaitWhenWalking.setChecked(bot.isWaitWhenWalking());

    HorizontalGroup botGroup = new HorizontalGroup();
    botGroup.space(10);

    botGroup.addActor(testerLeaveConf);
    botGroup.addActor(testerGotoConf);
    botGroup.addActor(testerPassText);
    botGroup.addActor(testerWaitWhenWalking);

    HorizontalGroup botGroup2 = new HorizontalGroup();
    botGroup2.space(10);

    botGroup2.addActor(new Label("Excl. List: ", ui.getSkin(), "debug"));
    botGroup2.addActor(testerExcludeList);
    botGroup2.addActor(new Label("Interval: ", ui.getSkin(), "debug"));
    botGroup2.addActor(testerTimeConf);
    botGroup2.addActor(new Label("Scn Time: ", ui.getSkin(), "debug"));
    botGroup2.addActor(inSceneTimeConf);
    botGroup2.addActor(runBot);

    table.row().pad(5).align(Align.left);
    table.add(new Label("Tester Bot: ", ui.getSkin(), "debug"));
    table.add(botGroup);
    table.row().pad(5).align(Align.left);
    table.add();
    table.add(botGroup2);

    // ------------- VERSION LABEL NOT IN TABLE
    String versionString = Config.getProperty(Config.TITLE_PROP, "title unspecified") + " v"
            + Config.getProperty(Config.VERSION_PROP, "unspecified") + "\n" + "Blade Engine: v"
            + Config.getProperty("bladeEngineVersion", "unspecified") + "\n" + "libGdx: v"
            + Config.getProperty("gdxVersion", "unspecified") + "\n" + "RoboVM: v"
            + Config.getProperty("roboVMVersion", "unspecified") + "\n";
    //             + "Gdx.app.getVersion: " + Gdx.app.getVersion();

    Label version = new Label(versionString, ui.getSkin(), "debug");
    version.setColor(Color.LIGHT_GRAY);
    Table versionStack = new Table();
    versionStack.defaults().pad(DPIUtils.getSpacing());
    versionStack.pad(0);
    versionStack.add(version);
    versionStack.bottom().left();
    versionStack.setFillParent(true);
    versionStack.pack();
    table.row();
    table.add(versionStack).colspan(3).left();

    table.pack();

    ScrollPane scrollPane = new ScrollPane(table);
    scrollPane.setFillParent(true);
    stage.addActor(scrollPane);

    pointer = new Pointer(ui.getSkin());
    stage.addActor(pointer);

    Gdx.input.setInputProcessor(stage);
}

From source file:com.bladecoder.engine.ui.LoadSaveScreen.java

License:Apache License

@Override
public void show() {
    float size = DPIUtils.getPrefButtonSize();
    float pad = DPIUtils.getMarginSize();
    final Skin skin = ui.getSkin();
    final World world = World.getInstance();

    // loadScreenMode = ui.getScreen(Screens.LOAD_GAME_SCREEN) == this;
    loadScreenMode = world.getCurrentScene() == null;

    stage = new Stage(new ScreenViewport());

    slotWidth = (int) (stage.getViewport().getWorldWidth() / (ROW_SLOTS + 1) - 2 * pad);
    slotHeight = (int) (slotWidth * stage.getViewport().getScreenHeight()
            / stage.getViewport().getScreenWidth());

    LoadSaveScreenStyle style = skin.get(LoadSaveScreenStyle.class);

    Drawable bg = style.background;// w w  w.j  av a2  s  .  co m

    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));
    }

    Table table = new Table(skin);
    table.setFillParent(true);
    table.center();
    table.pad(pad);

    Label title = new Label(loadScreenMode ? I18N.getString("ui.load") : I18N.getString("ui.save"), skin,
            "title");

    Button back = new Button(skin, "back");

    back.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.MENU_SCREEN);
        }
    });

    Table header = new Table();
    // header.padBottom(pad);
    Container<Button> cont = new Container<Button>(back);
    cont.size(size);
    header.add(cont);
    header.add(title).fillX().expandX().left();
    table.add(header).fillX().expandX().left();

    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;
        }
    });

    final PagedScrollPane scroll = new PagedScrollPane();
    scroll.setFlingTime(0.1f);
    scroll.setPageSpacing(25);

    Table slots = new Table().pad(pad);
    slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
    int c = 0;

    // Add "new slot" slot for save screen
    if (!loadScreenMode) {
        slots.add(getSlotButton(Long.toString(new Date().getTime()))).fill().expand();
        c++;
    }

    final List<String> sl = getSlots();

    Collections.sort(sl);

    for (int j = sl.size() - 1; j >= 0; j--) {

        String s = sl.get(j);

        if (c % ROW_SLOTS == 0 && c % (ROW_SLOTS * COL_SLOTS) != 0)
            slots.row();

        if (c != 0 && c % (ROW_SLOTS * COL_SLOTS) == 0) {
            scroll.addPage(slots);
            slots = new Table().pad(pad);
            slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
        }

        Button removeButton = new Button(skin, "delete_game");
        removeButton.setName(s);
        removeButton.addListener(removeClickListener);

        Container<Button> container = new Container<Button>(removeButton);
        container.size(DPIUtils.getPrefButtonSize() * .75f);
        container.align(Align.topRight);

        slots.stack(getSlotButton(s), container).fill().expand();

        c++;
    }

    // Add last page
    if (slots.getCells().size > 0)
        scroll.addPage(slots);

    table.row();

    if (loadScreenMode && sl.size() == 0) {
        Label lbl = new Label(I18N.getString("ui.noSavedGames"), skin, "title");
        lbl.setAlignment(Align.center);
        table.add(lbl).expand().fill();
    } else {
        table.add(scroll).expand().fill();
    }

    table.pack();

    stage.setKeyboardFocus(table);
    stage.addActor(table);

    pointer = new Pointer(ui.getSkin());
    stage.addActor(pointer);

    Gdx.input.setInputProcessor(stage);
}

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;/*ww  w  .  j  a  v a2s .  c o  m*/

    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.cookbook.samples.client.GwtSampleWrapper.java

License:Apache License

@Override
public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    Gdx.app.log("GdxSampleGwt", "Setting up for " + tests.length + " tests.");

    ui = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    container = new Table();
    ui.addActor(container);/*from   ww  w  . j  av a  2s . com*/
    container.debug();
    Table table = new Table();
    ScrollPane scroll = new ScrollPane(table);
    container.add(scroll).expand().fill();
    table.pad(10).defaults().expandX().space(4);
    for (final Instancer instancer : tests) {
        table.row();
        TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
        button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                ((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
                test = instancer.instance();
                Gdx.app.log("GdxSampleGwt", "Clicked on " + test.getClass().getName());
                test.create();
                test.setPlatformResolver(new WebResolver());
                test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
        });
        table.add(button).expandX().fillX();
    }
    container.row();
    container.add(
            new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE)))
            .pad(5, 5, 5, 5);

    Gdx.input = new InputWrapper(Gdx.input) {
        @Override
        public boolean keyUp(int keycode) {
            if (keycode == Keys.ESCAPE) {
                if (test != null) {
                    Gdx.app.log("GdxSampleGwt", "Exiting current test.");
                    dispose = true;
                }
            }
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
                if (test != null) {
                    dispose = true;
                }
            }
            return false;
        }
    };
    ((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);

    Gdx.app.log("GdxSampleGwt", "Test picker UI setup complete.");
}

From source file:com.nhydock.storymode.scenes.title.TitleSequence.java

@Override
public void init() {
    final TitleSequence ui = this;

    // create title sequence
    final Skin skin = manager.get(DataDirs.Home + "title.json", Skin.class);
    final Skin uiskin = shared.getResource(DataDirs.Home + "uiskin.json", Skin.class);

    //clouds//from   ww w. ja  va  2  s. co  m
    {

        Image goddess = new Image(uiskin, "goddess");
        goddess.setSize(32, 32);
        goddess.setPosition(getWidth(), getHeight() - 96f);
        goddess.setOrigin(Align.center);
        addActor(goddess);

        Image cloudsPan1 = new Image(new TiledDrawable(uiskin.getRegion("clouds")));
        Image cloudsPan2 = new Image(new TiledDrawable(uiskin.getRegion("clouds")));
        cloudsPan1.setWidth(getWidth() * 5);
        cloudsPan2.setWidth(getWidth() * 5);

        cloudsPan1.setPosition(0, 0, Align.topLeft);
        cloudsPan2.setPosition(0, 0, Align.topLeft);
        addActor(cloudsPan1);
        addActor(cloudsPan2);

        cloudsPan1.addAction(Actions.sequence(Actions.moveToAligned(getWidth(), 0, Align.topRight),
                Actions.delay(10f), Actions.parallel(Actions.moveBy(0, 140f, 3f, Interpolation.sineOut),
                        Actions.moveBy(getWidth() * 5, 0, 50f))));

        cloudsPan2.addAction(Actions.sequence(Actions.moveToAligned(getWidth(), 0, Align.topRight),
                Actions.delay(10f), Actions.parallel(Actions.moveBy(0, 80f, 3f, Interpolation.sineOut),
                        Actions.moveBy(getWidth() * 5, 0, 40f))));

        goddess.addAction(Actions.sequence(Actions.delay(20f),
                Actions.parallel(Actions.repeat(5, Actions.rotateBy(360, .4f)),
                        Actions.moveBy(-getWidth() - 32, 0f, 2f)),
                Actions.delay(1f),
                Actions.addAction(Actions.moveBy(0, getHeight(), 1f, Interpolation.sineIn), cloudsPan1),
                Actions.addAction(Actions.moveBy(0, getHeight(), 1f, Interpolation.sineIn), cloudsPan2)));
    }

    // initial text
    {
        Table textGrid = new Table();
        textGrid.setFillParent(true);
        textGrid.pad(40f);

        Label text = new Label(
                "This game is Shareware!\n\nThat means it's completely free to download and distribute.\n\nIf you'd like to be nice, you can donate and learn more at http://nhydock.github.io/Storymode",
                skin);
        text.setWrap(true);
        text.setAlignment(Align.center);
        text.addAction(Actions.sequence(Actions.alpha(0f), Actions.alpha(1f, 1f)));
        textGrid.add(text).expandX().fillX();
        text = new Label("~Thanks a bunch!", skin);
        text.setWrap(true);
        text.setAlignment(Align.right);
        text.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(3f), Actions.alpha(1f, 1f)));
        textGrid.row();
        textGrid.add(text).expandX().fillX().padRight(60f);
        textGrid.addAction(Actions.sequence(Actions.alpha(1f), Actions.delay(8f), Actions.alpha(0f, 2f),
                Actions.run(new PlayBGM(manager.get(DataDirs.Audio + "title.mp3", Music.class)))));
        addActor(textGrid);
    }

    // credits animation
    {
        Table textGrid = new Table();
        textGrid.setFillParent(true);
        textGrid.pad(40f);

        Label text = new Label("Graphics, Programming, Project Lead", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label("Nicholas Hydock", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label(" ", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label("Ideas, Suggestions, Emotional Support, & Bros4Lyfe", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label("Patrick Flanagan", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label("Matthew Hydock", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();
        textGrid.row();
        text = new Label("Andrew Hoffman", skin);
        text.setAlignment(Align.center);
        textGrid.add(text).expandX().fillX();

        textGrid.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(10f), Actions.alpha(1f, .75f),
                Actions.delay(4f), Actions.alpha(0f, .75f)));
        addActor(textGrid);
    }

    // display tool logos
    {
        Group group = new Group();
        Image tools = new Image(skin.getDrawable("tools"));
        tools.setPosition(getWidth() / 2 - tools.getWidth() / 2, getHeight() / 2 - tools.getHeight() / 2);
        Label label = new Label(
                "All music is licensed under Creative-Commons BY(-NC) or other permissive licenses.\nAll attribution can be found in the README",
                skin, "small");
        label.setPosition(getWidth() / 2f, getHeight() / 2f - 80f, Align.top);
        label.setAlignment(Align.center);
        group.addActor(tools);
        group.addActor(label);
        group.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(16f), Actions.alpha(1f, .75f),
                Actions.delay(4f), Actions.alpha(0f, .75f)));
        addActor(group);
    }

    // cool animation
    {
        Group cool = new Group();
        cool.setSize(getWidth(), getHeight());
        Group group = new Group();
        Image cliff = new Image(skin.getRegion("cliff"));
        group.addAction(Actions.sequence(Actions.moveTo(0, -cliff.getHeight()), Actions.delay(24f),
                Actions.moveTo(0, 0, 4f)));
        group.addActor(cliff);
        final Image character = new Image(skin.getRegion("back"));
        character.setSize(96f, 96f);
        group.addActor(character);
        character.addAction(
                Actions.sequence(Actions.moveTo(200f, 200f), Actions.delay(31f), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        character.setDrawable(skin.getDrawable("character"));
                    }

                }), Actions.moveTo(-character.getWidth() / 2, -character.getHeight(), 1f), Actions.delay(10f),
                        Actions.run(new Runnable() {

                            @Override
                            public void run() {
                                character.setDrawable(skin.getDrawable("back"));
                            }

                        }), Actions.moveTo(200f, 200f, 1f), Actions.delay(.2f), Actions.run(new Runnable() {

                            @Override
                            public void run() {
                                character.setDrawable(skin.getDrawable("character"));
                            }

                        })));

        Image castle = new Image(skin.getRegion("castle"));
        castle.addAction(
                Actions.sequence(Actions.moveToAligned(getWidth() - castle.getWidth(), 0f, Align.topLeft),
                        Actions.delay(24f), Actions.moveBy(0, getHeight(), 4f)));
        Image lightning = new Image(skin.getRegion("lightning"));
        lightning.setPosition(getWidth() - castle.getWidth(), getHeight() - castle.getHeight());
        lightning.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(29f), Actions.alpha(1f, .1f),
                Actions.delay(.3f), Actions.alpha(.3f, .3f), Actions.alpha(1f, .1f), Actions.delay(.3f),
                Actions.alpha(0f, 1f)));

        Image logo = new Image(skin.getRegion("logo"));
        logo.addAction(Actions.sequence(Actions.alpha(0f),
                Actions.moveTo(0, getHeight() - logo.getHeight() + 5f), Actions.delay(34f),
                Actions.alpha(1f, 1f),
                Actions.forever(Actions.sequence(Actions.moveTo(0, getHeight() - logo.getHeight() + 5f, 2f),
                        Actions.moveTo(0, getHeight() - logo.getHeight() - 5f, 2f)))));

        Table table = new Table();

        Label label = new Label("Title theme", skin, "small");
        label.setAlignment(Align.right);
        table.add(label).expandX().fillX();
        table.row();
        label = new Label("Anamanaguchi - Helix Nebula", skin, "small");
        label.setAlignment(Align.right);
        table.add(label).expandX().fillX();
        table.row();
        table.pad(10f);
        table.pack();
        table.addAction(Actions.sequence(Actions.alpha(0f), Actions.moveTo(getWidth() - table.getWidth(), 0),
                Actions.delay(40f), Actions.alpha(1f, 1f)));

        cool.addActor(castle);
        cool.addActor(lightning);
        cool.addActor(group);
        cool.addActor(logo);
        cool.addActor(table);

        cool.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(24f), Actions.alpha(1f),
                Actions.delay(40f), Actions.alpha(0f, 1f), Actions.delay(1f), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        SceneManager.switchToScene("title");
                    }

                }), Actions.delay(1.5f), Actions.run(new Runnable() {

                    @Override
                    public void run() {
                    }

                })));
        addActor(cool);

        final Label startLabel = new Label("Press Start", skin);
        startLabel.setPosition(getWidth() - 360f, 120f);
        startLabel.addAction(Actions.sequence(Actions.alpha(0f), Actions.delay(38f), Actions.alpha(1f, .3f),
                Actions.run(new Runnable() {

                    @Override
                    public void run() {
                        ui.addListener(new InputListener() {
                            @Override
                            public boolean touchDown(InputEvent evt, float x, float y, int pointer,
                                    int button) {
                                if (button == Buttons.LEFT) {
                                    SceneManager.switchToScene("newgame");
                                    return true;
                                }
                                return false;
                            }
                        });
                    }

                }), Actions.delay(24f), Actions.alpha(0f, 1f)));
        addActor(startLabel);

    }

    // make sure all initial steps are set
    act();

    addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent evt, int keycode) {
            // skip the intro
            if (Input.ACCEPT.match(keycode) || Input.CANCEL.match(keycode)) {
                SceneManager.switchToScene("newgame");
                return true;
            }
            return false;
        }

        @Override
        public boolean touchDown(InputEvent evt, float x, float y, int pointer, int button) {
            if (button == Buttons.RIGHT) {
                SceneManager.switchToScene("newgame");
                return true;
            }
            return false;
        }
    });
}

From source file:com.pucpr.game.states.AboutState.java

@Override
public void create() {
    Gdx.input.setInputProcessor(this);
    stage = new Stage();

    Gdx.graphics.setVSync(false);//from  www. ja va 2s  . c  o  m

    container = new Table();
    stage.addActor(container);
    container.setFillParent(true);

    final Table table = new Table();

    final ScrollPane scroll = new ScrollPane(table, manager.getSkin());

    table.pad(10).defaults().expandX().space(4);
    table.row();
    Label label = new Label("Progrador", manager.getSkin());
    table.add(label).expandX().fillX();
    label = new Label("Luis Carlos Boch", manager.getSkin());
    table.add(label).expandX().fillX();
    table.row();
    label = new Label("Progrador", manager.getSkin());
    table.add(label).expandX().fillX();
    label = new Label("Felipe Alan Belini Rocha", manager.getSkin());
    table.add(label).expandX().fillX();

    container.add(scroll).expand().fill().colspan(2);
}

From source file:com.pucpr.game.states.game.basic.Conversation.java

public void showMessage() {
    if (!finished && !aborted) {
        startedMessage = System.currentTimeMillis();
        waitMessageWithoutMessage = null;
        final Container container = new Container();
        final Table table = new Table(info.getGameState().getManager().getSkin());
        container.setActor(table);//from w w  w .  jav a  2  s. com
        container.setOrigin(Align.topLeft);
        table.row().align(Align.left);

        if (currentMessage.getImage() != null) {
            final Texture img = currentMessage.getImage();
            table.add(new Image(img)).center();
        } else {
            final TextButton button = new TextButton(currentMessage.getObject().getName(), table.getSkin());
            button.setWidth(150);
            table.add(button).left();
            table.row().align(Align.left);
        }

        final TextButton button = new TextButton(currentMessage.getMessage(), table.getSkin());
        button.setWidth(150);
        table.add(button).left();

        table.setWidth(150);
        table.setHeight(100);
        table.pad(0).defaults().expandX().space(0);
        container.setWidth(250f);
        container.setHeight(100f);
        container.setX((Gdx.graphics.getWidth() / 2) - 100);
        container.setY(500);

        currentMessage.setActor(container);
        currentMessage.doAction();

        final Stage stage = info.getGameState().getStage();
        stage.addActor(container);
    }
}

From source file:com.pucpr.game.states.game.basic.ScreenInfo.java

public void showTimeOut(Long timeOut) {
    if (timeOut != null) {
        this.timeOut = timeOut;
        this.showTimeOut = true;
        final Container container = new Container();
        final Table table = new Table(gameState.getManager().getSkin());

        container.setActor(table);//from w w w. j  a va 2 s.  co  m
        container.setOrigin(Align.topLeft);

        table.row().align(Align.left);

        timeOutInfo = new TextButton("", table.getSkin());
        timeOutInfo.setWidth(Gdx.graphics.getWidth());
        table.add(timeOutInfo).left();
        timeOutInfo.setText(String.valueOf(timeOut));

        table.setWidth(Gdx.graphics.getWidth());
        table.setHeight(Gdx.graphics.getWidth());
        table.pad(0).defaults().expandX().space(0);
        container.setWidth(200f);
        container.setHeight(50f);

        final Stage stage = gameState.getStage();

        container.setX((Gdx.graphics.getWidth()) - 300);
        container.setY(500);
        stage.addActor(container);
        timeOutContainer = container;

        lastTimeOutMili = System.currentTimeMillis();
    } else {
        hideTimeOut();
    }

}

From source file:com.pucpr.game.states.game.basic.ScreenInfo.java

/**
 * Show image on center of screen by the configured time
 *
 * @param path//  ww  w.ja  v  a 2 s  .  c  om
 * @param ms
 */
public void showImage(String path, long ms) {
    this.timeOutImage = ms;
    final Container container = new Container();
    final Table table = new Table(gameState.getManager().getSkin());

    container.setActor(table);
    container.setOrigin(Align.topLeft);

    table.row().align(Align.left);

    final Image image = new Image(manager.getResourceLoader().getTexture(path));
    table.add(image).left();

    table.setWidth(Gdx.graphics.getWidth());
    table.setHeight(Gdx.graphics.getWidth());
    table.pad(0).defaults().expandX().space(0);

    container.setWidth(Gdx.graphics.getWidth());
    container.setHeight(Gdx.graphics.getHeight());

    table.setWidth(Gdx.graphics.getWidth());
    table.setHeight(Gdx.graphics.getHeight());

    //        container.setX(0 - (Gdx.graphics.getWidth() / 2) + 60);
    //        container.setY((Gdx.graphics.getWidth() / 2) - 20);
    final Stage stage = gameState.getStage();

    //        container.setX();
    //        container.setY(500);
    stage.addActor(container);
    imageContainer = container;
    lastImageMili = System.currentTimeMillis();
    showImage = true;
}