Search in sources :

Example 46 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project bladecoder-adventure-engine by bladecoder.

the class RetroSceneScreen method show.

@Override
public void show() {
    retrieveAssets(ui.getUIAtlas());
    stage = new Stage(screenViewport);
    // stage.addActor(textManagerUI);
    stage.addActor(dialogUI);
    stage.addActor(menuButton);
    stage.addActor(verbUI);
    stage.addActor(pointer);
    menuButton.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.MENU_SCREEN);
        }
    });
    worldViewportStage = new Stage(worldViewport);
    worldViewportStage.addActor(textManagerUI);
    final InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(stage);
    multiplexer.addProcessor(inputProcessor);
    Gdx.input.setInputProcessor(multiplexer);
    if (World.getInstance().isDisposed()) {
        try {
            World.getInstance().load();
        } catch (Exception e) {
            EngineLogger.error("ERROR LOADING GAME", e);
            dispose();
            Gdx.app.exit();
        }
    }
    World.getInstance().resume();
}
Also used : InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Stage(com.badlogic.gdx.scenes.scene2d.Stage) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) IOException(java.io.IOException)

Example 47 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project bladecoder-adventure-engine by bladecoder.

the class MenuScreen method show.

@Override
public void show() {
    stage = new Stage(new ScreenViewport());
    final Skin skin = ui.getSkin();
    final World world = World.getInstance();
    final MenuScreenStyle style = getStyle();
    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;
    float scale = 1;
    if (bg == null && style.bgFile != null) {
        bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
        bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        scale = (float) bgTexFile.getHeight() / (float) stage.getViewport().getScreenHeight();
        int width = (int) (stage.getViewport().getScreenWidth() * scale);
        int x0 = (int) ((bgTexFile.getWidth() - width) / 2);
        bg = new TextureRegionDrawable(new TextureRegion(bgTexFile, x0, 0, width, bgTexFile.getHeight()));
    }
    menuButtonTable.clear();
    if (bg != null)
        menuButtonTable.setBackground(bg);
    menuButtonTable.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;
        }
    });
    menuButtonTable.align(getAlign());
    menuButtonTable.pad(DPIUtils.getMarginSize() * 2);
    menuButtonTable.defaults().pad(DPIUtils.getSpacing()).width(buttonWidth).align(getAlign());
    // menuButtonTable.debug();
    stage.setKeyboardFocus(menuButtonTable);
    if (style.showTitle && style.titleStyle != null) {
        Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin, style.titleStyle);
        title.setAlignment(getAlign());
        menuButtonTable.add(title).padBottom(DPIUtils.getMarginSize() * 2);
        menuButtonTable.row();
    }
    if (style.titleFile != null) {
        titleTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.titleFile));
        titleTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        Image img = new Image(titleTexFile);
        menuButtonTable.add(img).width((float) titleTexFile.getWidth() / scale).height((float) titleTexFile.getHeight() / scale).padBottom(DPIUtils.getMarginSize() * 2);
        menuButtonTable.row();
    }
    if (world.savedGameExists() || world.getCurrentScene() != null) {
        TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle);
        continueGame.getLabel().setAlignment(getAlign());
        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);
            }
        });
        menuButtonTable.add(continueGame);
        menuButtonTable.row();
    }
    TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
    newGame.getLabel().setAlignment(getAlign());
    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();
                                ui.setCurrentScreen(Screens.SCENE_SCREEN);
                            } catch (Exception e) {
                                EngineLogger.error("IN NEW GAME", e);
                                Gdx.app.exit();
                            }
                        }
                    }
                };
                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();
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);
                } catch (Exception e) {
                    EngineLogger.error("IN NEW GAME", e);
                    Gdx.app.exit();
                }
            }
        }
    });
    menuButtonTable.add(newGame);
    menuButtonTable.row();
    TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
    loadGame.getLabel().setAlignment(getAlign());
    loadGame.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN);
        }
    });
    menuButtonTable.add(loadGame);
    menuButtonTable.row();
    TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
    quit.getLabel().setAlignment(getAlign());
    quit.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            Gdx.app.exit();
        }
    });
    menuButtonTable.add(quit);
    menuButtonTable.row();
    menuButtonTable.pack();
    stage.addActor(menuButtonTable);
    // 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);
        }
    });
    iconStackTable.clear();
    iconStackTable.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(), DPIUtils.getPrefButtonSize());
    iconStackTable.pad(DPIUtils.getMarginSize() * 2);
    if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
        iconStackTable.add(debug);
        iconStackTable.row();
    }
    iconStackTable.add(help);
    iconStackTable.row();
    iconStackTable.add(credits);
    iconStackTable.bottom().right();
    iconStackTable.setFillParent(true);
    iconStackTable.pack();
    stage.addActor(iconStackTable);
    Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
    version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
    version.addListener(new ClickListener() {

        int count = 0;

        long time = System.currentTimeMillis();

        public void clicked(InputEvent event, float x, float y) {
            if (System.currentTimeMillis() - time < 500) {
                count++;
            } else {
                count = 0;
            }
            time = System.currentTimeMillis();
            if (count == 4) {
                EngineLogger.toggle();
                if (World.getInstance().isDisposed())
                    return;
                if (EngineLogger.debugMode()) {
                    iconStackTable.row();
                    iconStackTable.add(debug);
                } else {
                    Cell<?> cell = iconStackTable.getCell(debug);
                    iconStackTable.removeActor(debug);
                    cell.reset();
                }
            }
        }
    });
    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);
    if (style.musicFile != null) {
        music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile));
        music.setLooping(true);
        music.play();
    }
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) World(com.bladecoder.engine.model.World) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 48 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project bladecoder-adventure-engine by bladecoder.

the class DebugScreen method show.

@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);
    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);
    // ------------- LOAD CHAPTER
    table.row().pad(5).align(Align.left);
    table.add(new Label("Load Chapter: ", ui.getSkin(), "debug"));
    HorizontalGroup chGroup = new HorizontalGroup();
    chGroup.space(10);
    final TextField chapter = new TextField("", ui.getSkin());
    chGroup.addActor(chapter);
    TextButton loadButton = new TextButton("Load", ui.getSkin());
    loadButton.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            String c = chapter.getText();
            if (!c.isEmpty()) {
                try {
                    World.getInstance().loadChapter(c);
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);
                } catch (IOException e) {
                    EngineLogger.error("Loading chapter.", e);
                }
            }
        }
    });
    chGroup.addActor(loadButton);
    table.add(chGroup);
    // ------------- SCENES
    final TextButton testScene = new TextButton("Run Test Verb", ui.getSkin(), "toggle");
    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);
            if (testScene.isChecked())
                World.getInstance().setTestScene(scenes.getSelected());
            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);
    scGroup.addActor(testScene);
    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(Config.BLADE_ENGINE_VERSION_PROP, "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);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ArrayList(java.util.ArrayList) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) IOException(java.io.IOException) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Example 49 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project Eidolons by IDemiurge.

the class PrestartScreen method init.

private void init() {
    stage = new Stage();
    menu = new PrestartMenu();
    stage.addActor(menu);
    menu.setPosition(GdxMaster.centerWidth(menu), GdxMaster.centerHeight(menu));
    Gdx.input.setInputProcessor(stage);
    initialized = true;
}
Also used : Stage(com.badlogic.gdx.scenes.scene2d.Stage)

Example 50 with Stage

use of com.badlogic.gdx.scenes.scene2d.Stage in project skin-composer by raeleus.

the class DialogDrawables method tiledDrawableSettingsDialog.

private void tiledDrawableSettingsDialog(DrawableData drawable) {
    DialogColors dialog = new DialogColors(main, (StyleProperty) null, true, (ColorData colorData) -> {
        if (colorData != null) {
            final Spinner minWidthSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            final Spinner minHeightSpinner = new Spinner(0.0f, 1.0f, true, Spinner.Orientation.HORIZONTAL, getSkin());
            TextField textField = new TextField("", getSkin()) {

                @Override
                public void next(boolean up) {
                    if (up) {
                        getStage().setKeyboardFocus(minHeightSpinner.getTextField());
                        minHeightSpinner.getTextField().selectAll();
                    } else {
                        getStage().setKeyboardFocus(minWidthSpinner.getTextField());
                        minWidthSpinner.getTextField().selectAll();
                    }
                }
            };
            Dialog tileDialog = new Dialog("Tiled Drawable Settings", getSkin(), "bg") {

                @Override
                protected void result(Object object) {
                    super.result(object);
                    if (object instanceof Boolean && (boolean) object == true) {
                        tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                    }
                    getStage().setScrollFocus(scrollPane);
                }

                @Override
                public Dialog show(Stage stage) {
                    Dialog dialog = super.show(stage);
                    stage.setKeyboardFocus(textField);
                    return dialog;
                }
            };
            tileDialog.getTitleTable().padLeft(5.0f);
            tileDialog.getContentTable().padLeft(10.0f).padRight(10.0f).padTop(5.0f);
            tileDialog.getButtonTable().padBottom(15.0f);
            tileDialog.getContentTable().add(new Label("Please enter a name for the TiledDrawable: ", getSkin()));
            tileDialog.button("OK", true);
            tileDialog.button("Cancel", false).key(Keys.ESCAPE, false);
            TextButton okButton = (TextButton) tileDialog.getButtonTable().getCells().first().getActor();
            okButton.addListener(main.getHandListener());
            tileDialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
            tileDialog.getContentTable().row();
            textField.setText(drawable.name);
            textField.selectAll();
            tileDialog.getContentTable().add(textField);
            tileDialog.getContentTable().row();
            Table table = new Table();
            table.defaults().space(10.0f);
            tileDialog.getContentTable().add(table);
            Label label = new Label("MinWidth:", getSkin());
            table.add(label);
            minWidthSpinner.setValue(drawable.minWidth);
            minWidthSpinner.setMinimum(0.0f);
            table.add(minWidthSpinner).minWidth(150.0f);
            minWidthSpinner.setTransversalPrevious(textField);
            minWidthSpinner.setTransversalNext(minHeightSpinner.getTextField());
            table.row();
            label = new Label("MinHeight:", getSkin());
            table.add(label);
            minHeightSpinner.setValue(drawable.minHeight);
            minHeightSpinner.setMinimum(0.0f);
            table.add(minHeightSpinner).minWidth(150.0f);
            minHeightSpinner.setTransversalPrevious(minWidthSpinner.getTextField());
            minHeightSpinner.setTransversalNext(textField);
            textField.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    boolean disable = !DrawableData.validate(textField.getText());
                    if (!disable) {
                        if (!drawable.name.equals(textField.getText())) {
                            for (DrawableData data : main.getAtlasData().getDrawables()) {
                                if (data.name.equals(textField.getText())) {
                                    disable = true;
                                    break;
                                }
                            }
                        }
                    }
                    okButton.setDisabled(disable);
                }
            });
            textField.setTextFieldListener(new TextField.TextFieldListener() {

                @Override
                public void keyTyped(TextField textField, char c) {
                    if (c == '\n') {
                        if (!okButton.isDisabled()) {
                            tiledDrawableSettings(drawable, colorData, (float) minWidthSpinner.getValue(), (float) minHeightSpinner.getValue(), textField.getText());
                            tileDialog.hide();
                        }
                    }
                }
            });
            textField.addListener(main.getIbeamListener());
            tileDialog.show(getStage());
        }
    });
    dialog.setFillParent(true);
    dialog.show(getStage());
    dialog.refreshTable();
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Spinner(com.ray3k.skincomposer.Spinner) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ColorData(com.ray3k.skincomposer.data.ColorData) DrawableData(com.ray3k.skincomposer.data.DrawableData) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)107 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)46 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)46 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)38 Texture (com.badlogic.gdx.graphics.Texture)36 Actor (com.badlogic.gdx.scenes.scene2d.Actor)32 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)30 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)30 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)28 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)22 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)22 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)20 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)19 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)18 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)15 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)13 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)12 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)11 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)10 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)10