Search in sources :

Example 16 with Image

use of com.badlogic.gdx.scenes.scene2d.ui.Image in project AmazingMaze by TheVirtualMachine.

the class MazeScreen method setupHUD.

/** Create the game HUD. */
private void setupHUD() {
    hud = new Stage(new ScreenViewport(), game.batch);
    Table table = new Table();
    table.setFillParent(true);
    table.top().left();
    hud.addActor(table);
    Label level = new Label("Level " + game.save.getLevel(), game.assets.skin, Assets.HUD_STYLE);
    table.add(level).colspan(2);
    table.row();
    Image lifeIcon = new Image(game.assets.manager.get(Assets.LIFE_HUD_IMAGE, Texture.class));
    table.add(lifeIcon).pad(Gdx.graphics.getWidth() / 128).left();
    livesLeft = new Label("", game.assets.skin, Assets.HUD_STYLE);
    table.add(livesLeft);
    updateLives(-2);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Example 17 with Image

use of com.badlogic.gdx.scenes.scene2d.ui.Image in project gdx-skineditor by cobolfoo.

the class ColorPickerDialog method updateTable.

/**
	 * Refresh table content with colors from the skin
	 */
public void updateTable() {
    tableColors.clear();
    tableColors.add(new Label("Color Name", game.skin, "title")).left().width(170);
    tableColors.add(new Label("Value", game.skin, "title")).colspan(2).left().width(60).padRight(50);
    tableColors.row();
    Iterator<String> it = colors.keys().iterator();
    while (it.hasNext()) {
        final String key = it.next();
        final Color color = colors.get(key);
        tableColors.add(key).left();
        // Create drawable on the fly
        Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
        pixmap.setColor(color);
        pixmap.fill();
        pixmap.setColor(Color.BLACK);
        pixmap.drawRectangle(0, 0, 18, 18);
        Texture texture = new Texture(pixmap);
        pixmap.dispose();
        tableColors.add(new Image(texture));
        tableColors.add(color.toString()).left();
        TextButton buttonSelect = new TextButton("Select", game.skin);
        buttonSelect.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                try {
                    field.set(game.screenMain.paneOptions.currentStyle, color);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                hide();
                game.screenMain.panePreview.refresh();
                game.screenMain.paneOptions.updateSelectedTableFields();
                game.screenMain.saveToSkin();
            }
        });
        TextButton buttonRemove = new TextButton("Remove", game.skin);
        buttonRemove.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                Dialog dlg = new Dialog("Delete Style", game.skin) {

                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == false) {
                            return;
                        }
                        if (isColorInUse(color) == true) {
                            game.showNotice("Error", "Color already in use!", game.screenMain.stage);
                        } else {
                            colors.remove(key);
                            // update table
                            updateTable();
                            game.screenMain.saveToSkin();
                        }
                    }
                };
                dlg.pad(20);
                dlg.getContentTable().add("You are sure you want to delete this color?");
                dlg.button("OK", true);
                dlg.button("Cancel", false);
                dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
                dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
                dlg.show(game.screenMain.stage);
            }
        });
        if (field != null) {
            tableColors.add(buttonSelect).padRight(5);
        }
        tableColors.add(buttonRemove);
        tableColors.row();
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Color(com.badlogic.gdx.graphics.Color) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 18 with Image

use of com.badlogic.gdx.scenes.scene2d.ui.Image in project gdx-skineditor by cobolfoo.

the class DrawablePickerDialog method updateTable.

/**
	 * 
	 */
public void updateTable() {
    tableDrawables.clear();
    Iterator<String> keys = items.keys().iterator();
    int count = 0;
    while (keys.hasNext()) {
        final String key = keys.next();
        if (key.startsWith("widgets/")) {
            continue;
        }
        Button buttonItem = new Button(game.skin);
        Image img = null;
        if (items.get(key) instanceof Drawable) {
            img = new Image((Drawable) items.get(key));
        } else {
            img = new Image((TextureRegion) items.get(key));
        }
        if (zoom == true) {
            buttonItem.add(img).expand().fill().pad(5);
        } else {
            buttonItem.add(img).expand().pad(5);
        }
        buttonItem.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (field == null) {
                    return;
                }
                try {
                    // game.screenMain.paneOptions.refreshSelection();
                    if (items.get(key) instanceof Drawable) {
                        field.set(game.screenMain.paneOptions.currentStyle, items.get(key));
                    } else {
                        boolean ninepatch = false;
                        FileHandle test = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/assets/" + key + ".9.png");
                        if (test.exists() == true) {
                            ninepatch = true;
                        }
                        if (ninepatch == true) {
                            game.skinProject.add(key, new NinePatchDrawable(new NinePatch((TextureRegion) items.get(key))));
                            field.set(game.screenMain.paneOptions.currentStyle, game.skinProject.getDrawable(key));
                        } else {
                            game.skinProject.add(key, new SpriteDrawable(new Sprite((TextureRegion) items.get(key))));
                            field.set(game.screenMain.paneOptions.currentStyle, game.skinProject.getDrawable(key));
                        }
                    }
                    game.screenMain.saveToSkin();
                    hide();
                    game.screenMain.panePreview.refresh();
                    game.screenMain.paneOptions.updateSelectedTableFields();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        String objectType = items.get(key).getClass().getSimpleName();
        objectType = objectType.replace("Drawable", "");
        buttonItem.row();
        buttonItem.add(new Label(key, game.skin));
        buttonItem.row();
        buttonItem.add(new Label(objectType, game.skin, "title"));
        buttonItem.row();
        buttonItem.setClip(true);
        tableDrawables.add(buttonItem).width(160).height(184).pad(5);
        if (count == 4) {
            count = 0;
            tableDrawables.row();
            continue;
        }
        count++;
    }
}
Also used : SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) FileHandle(com.badlogic.gdx.files.FileHandle) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Aggregations

Image (com.badlogic.gdx.scenes.scene2d.ui.Image)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)16 Texture (com.badlogic.gdx.graphics.Texture)15 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)9 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)6 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)6 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)5 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)5 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)4 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)3 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)2 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)2