Search in sources :

Example 1 with Cell

use of com.badlogic.gdx.scenes.scene2d.ui.Cell 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 2 with Cell

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

the class DialogFreeTypeFont method updateDisabledFields.

private void updateDisabledFields() {
    CheckBox checkBox = findActor("serializerCheckBox");
    SelectBox selectBox = findActor("previewSelectBox");
    selectBox.setDisabled(checkBox.isChecked());
    boolean notValid = false;
    if (checkBox.isChecked()) {
        if (data.color == null)
            notValid = true;
        else if (data.file == null || !data.file.exists())
            notValid = true;
        else if (!MathUtils.isZero(data.borderWidth) && data.borderColor == null)
            notValid = true;
        else if ((data.shadowOffsetX != 0 || data.shadowOffsetY != 0) && data.shadowColor == null)
            notValid = true;
    }
    if (notValid) {
        TextField textField = findActor("previewField");
        Cell cell = ((Table) textField.getParent()).getCell(textField);
        previewStyle.font = skin.get("free-type-preview", TextFieldStyle.class).font;
        textField = new TextField(previewText, previewStyle);
        textField.setName("previewField");
        textField.setAlignment(Align.center);
        cell.setActor(textField);
    } else {
        data.createBitmapFont(main);
        if (data.bitmapFont != null) {
            TextField textField = findActor("previewField");
            Cell cell = ((Table) textField.getParent()).getCell(textField);
            previewStyle.font = data.bitmapFont;
            textField = new TextField(previewText, previewStyle);
            textField.setName("previewField");
            textField.setAlignment(Align.center);
            cell.setActor(textField);
        }
    }
    if (!StyleData.validate(((TextField) findActor("fontName")).getText()))
        notValid = true;
    for (FontData font : main.getJsonData().getFonts()) {
        if (font.getName().equals(data.name)) {
            notValid = true;
            break;
        }
    }
    for (FreeTypeFontData font : main.getJsonData().getFreeTypeFonts()) {
        if (font.name.equals(data.name) && (mode == Mode.NEW || !font.name.equals(originalData.name))) {
            notValid = true;
            break;
        }
    }
    TextButton textButton = findActor("okButton");
    textButton.setDisabled(notValid);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell)

Example 3 with Cell

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

the class MenuList method updateContents.

public void updateContents() {
    setSize(0.0f, 0.0f);
    clearChildren();
    buttons.clear();
    int index = 0;
    for (T item : items) {
        TextButton textButton = new TextButton(item.toString(), style.textButtonStyle);
        textButton.getLabel().setAlignment(Align.left);
        if (getCells().size > 0) {
            row();
        }
        add(textButton);
        if (index < shortcuts.size && shortcuts.get(index) != null && style.labelStyle != null) {
            Label label = new Label(shortcuts.get(index), style.labelStyle);
            textButton.add(label).padLeft(5.0f);
        }
        int i = index++;
        textButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                selectedIndex = i;
                selectedItem = item;
                fire(new MenuListEvent());
            }
        });
        buttons.add(textButton);
    }
    validate();
    float width = style.background.getLeftWidth() + style.background.getRightWidth();
    for (int i = 0; i < getColumns(); i++) {
        width += getColumnWidth(i);
    }
    float height = style.background.getLeftWidth() + style.background.getRightWidth();
    for (int i = 0; i < getRows(); i++) {
        height += getRowHeight(i);
    }
    for (Cell cell : getCells()) {
        cell.growX();
    }
    setSize(width, height);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell)

Example 4 with Cell

use of com.badlogic.gdx.scenes.scene2d.ui.Cell in project Red-Team by CSC480-18S.

the class GameBoardTable method setTile.

public void setTile(int x, int y, String letter) {
    System.out.println("setting tile:" + letter);
    Cell center = board.getCells().get(x + (11 * (10 - y)));
    Image i = new Image(TextureManager.getInstance().getTileTexture(letter));
    i.setName(letter.toLowerCase());
    center.setActor(i);
}
Also used : Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell)

Aggregations

Cell (com.badlogic.gdx.scenes.scene2d.ui.Cell)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)3 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2 Texture (com.badlogic.gdx.graphics.Texture)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)1 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1