Example usage for com.badlogic.gdx.scenes.scene2d.ui Container align

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Container align

Introduction

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

Prototype

int align

To view the source code for com.badlogic.gdx.scenes.scene2d.ui Container align.

Click Source Link

Usage

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;// ww w .  ja  v a 2s.  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));
    }

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