Search in sources :

Example 46 with FileHandle

use of com.badlogic.gdx.files.FileHandle 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)

Example 47 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project gdx-skineditor by cobolfoo.

the class FontPickerDialog method updateTable.

/**
	 * 
	 */
public void updateTable() {
    fonts = game.skinProject.getAll(BitmapFont.class);
    tableFonts.clear();
    tableFonts.add(new Label("Font Name", game.skin, "title")).left().width(170);
    tableFonts.add(new Label("Value", game.skin, "title")).colspan(3).left().width(60).padRight(50).expandX().fillX();
    tableFonts.row();
    Iterator<String> it = fonts.keys().iterator();
    while (it.hasNext()) {
        final String key = it.next();
        final BitmapFont font = fonts.get(key);
        tableFonts.add(key).left();
        Label.LabelStyle labelStyle = new Label.LabelStyle();
        labelStyle.font = font;
        labelStyle.fontColor = Color.WHITE;
        tableFonts.add(new Label("Sample Text", labelStyle)).left();
        TextButton buttonSelect = new TextButton("Select", game.skin);
        buttonSelect.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                try {
                    // Since we have reloaded everything we have to get
                    // field back
                    game.screenMain.paneOptions.refreshSelection();
                    field.set(game.screenMain.paneOptions.currentStyle, font);
                } 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 Font", game.skin) {

                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == false) {
                            return;
                        }
                        if (isFontInUse(font) == true) {
                            game.showNotice("Error", "Bitmap font already in use!", getStage());
                        } else {
                            // Remove files from disk (fnt and png)
                            FileHandle targetFont = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/" + key + ".fnt");
                            FileHandle targetImage = new FileHandle("projects/" + game.screenMain.getcurrentProject() + "/assets/" + key + ".png");
                            targetFont.delete();
                            targetImage.delete();
                            fonts.remove(key);
                            // update table
                            updateTable();
                            game.screenMain.saveToSkin();
                        }
                    }
                };
                dlg.pad(20);
                dlg.getContentTable().add("You are sure you want to delete this bitmap font?");
                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(getStage());
            }
        });
        if (field != null) {
            tableFonts.add(buttonSelect).left();
        }
        tableFonts.add(buttonRemove).left().expandX();
        tableFonts.row();
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) FileHandle(com.badlogic.gdx.files.FileHandle) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 48 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project gdx-skineditor by cobolfoo.

the class MainScreen method saveToSkin.

/**
	 * Save everything to skin
	 */
public void saveToSkin() {
    FileHandle projectFolder = Gdx.files.local("projects").child(currentProject);
    FileHandle[] items = projectFolder.child("backups").list();
    Array<String> sortedItems = new Array<String>();
    for (FileHandle item : items) {
        sortedItems.add(item.name());
    }
    sortedItems.sort();
    // Keep only last ten files
    int count = 0;
    for (String item : sortedItems) {
        if (count++ > 8) {
            // Remove file 
            projectFolder.child("backups").child(item).delete();
        }
    }
    FileHandle projectFile = projectFolder.child("uiskin.json");
    FileHandle backupFile = projectFolder.child("backups").child("uiskin_" + (TimeUtils.millis() / 1000) + ".json");
    projectFile.copyTo(backupFile);
    game.skinProject.save(projectFile);
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 49 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project gdx-skineditor by cobolfoo.

the class WelcomeScreen method refreshProjects.

/**
	 * 
	 */
public void refreshProjects() {
    Array<String> items = new Array<String>();
    FileHandle[] projects = Gdx.files.local("projects").list();
    for (FileHandle project : projects) {
        if (project.child("uiskin.json").exists() == true) {
            items.add(project.name());
        }
    }
    items.sort();
    listProjects.setItems(items);
}
Also used : Array(com.badlogic.gdx.utils.Array) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 50 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project gdx-skineditor by cobolfoo.

the class NinePatchEditorDialog method refreshPreview.

public void refreshPreview() {
    Gdx.app.log("NinePatchEditorDialog", "refresh preview.");
    Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
    Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth() + 2), (int) (pixmapImage.getHeight() + 2), Pixmap.Format.RGBA8888);
    pixmap.drawPixmap(pixmapImage, 1, 1);
    pixmap.setColor(Color.BLACK);
    // Range left
    int h = pixmapImage.getHeight() + 1;
    pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart), 0, (int) (h * rangeLeft.rangeStop));
    // Range top
    int w = pixmapImage.getWidth() + 1;
    pixmap.drawLine((int) (w * rangeTop.rangeStart), 0, (int) (w * rangeTop.rangeStop), 0);
    // Range right
    h = pixmapImage.getHeight() + 1;
    pixmap.drawLine(pixmapImage.getWidth() + 1, (int) (h * rangeRight.rangeStart), pixmapImage.getWidth() + 1, (int) (h * rangeRight.rangeStop));
    // Range bottom
    w = pixmapImage.getWidth() + 1;
    pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight() - 1, (int) (w * rangeBottom.rangeStop), pixmap.getHeight() - 1);
    PixmapIO.writePNG(tmpFile, pixmap);
    pixmapImage.dispose();
    pixmap.dispose();
    FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
    TexturePacker.Settings settings = new TexturePacker.Settings();
    TexturePacker.process(settings, fh.path(), fh.path(), "pack");
    TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
    NinePatch np = ta.createPatch("button");
    NinePatchDrawable drawable = new NinePatchDrawable(np);
    reviewTablePreview();
    buttonPreview1.getStyle().up = drawable;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker) Pixmap(com.badlogic.gdx.graphics.Pixmap) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)79 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)23 IOException (java.io.IOException)22 Array (com.badlogic.gdx.utils.Array)18 File (java.io.File)18 Element (com.badlogic.gdx.utils.XmlReader.Element)9 Texture (com.badlogic.gdx.graphics.Texture)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)4 Json (com.badlogic.gdx.utils.Json)4 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3 Color (com.badlogic.gdx.graphics.Color)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Writer (java.io.Writer)3