Search in sources :

Example 6 with Preferences

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

the class MenuBar method showExportDialog.

/*
	 * Show export dialog
	 */
protected void showExportDialog() {
    final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject());
    final TextField textDirectory = new TextField(prefs.getString("export_to_directory"), game.skin);
    Dialog dlg = new Dialog("Export to Directory", game.skin) {

        @Override
        protected void result(Object object) {
            if ((Boolean) object == true) {
                if (textDirectory.getText().isEmpty() == true) {
                    game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage);
                    return;
                }
                FileHandle targetDirectory = new FileHandle(textDirectory.getText());
                if (targetDirectory.exists() == false) {
                    game.showNotice("Warning", "Directory not found!", game.screenMain.stage);
                    return;
                }
                // Copy uiskin.* and *.fnt 
                FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject());
                for (FileHandle file : projectFolder.list()) {
                    if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) {
                        Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ...");
                        FileHandle target = targetDirectory.child(file.name());
                        file.copyTo(target);
                    }
                }
                game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage);
            }
        }
    };
    dlg.pad(20);
    Table table = dlg.getContentTable();
    table.padTop(20);
    table.add("Directory:");
    table.add(textDirectory).width(320);
    TextButton buttonChoose = new TextButton("...", game.skin);
    buttonChoose.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            // Need to steal focus first with this hack (Thanks to Z-Man)
            Frame frame = new Frame();
            frame.setUndecorated(true);
            frame.setOpacity(0);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.toFront();
            frame.setVisible(false);
            frame.dispose();
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int ret = chooser.showOpenDialog(null);
            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = chooser.getSelectedFile();
                textDirectory.setText(f.getAbsolutePath());
                // Store to file
                prefs.putString("export_to_directory", f.getAbsolutePath());
                prefs.flush();
            }
        }
    });
    table.add(buttonChoose);
    table.row();
    table.padBottom(20);
    dlg.button("Export", 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());
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Frame(java.awt.Frame) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) FileHandle(com.badlogic.gdx.files.FileHandle) JFileChooser(javax.swing.JFileChooser) DrawablePickerDialog(org.shadebob.skineditor.DrawablePickerDialog) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) ColorPickerDialog(org.shadebob.skineditor.ColorPickerDialog) FontPickerDialog(org.shadebob.skineditor.FontPickerDialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) Preferences(com.badlogic.gdx.Preferences) File(java.io.File)

Example 7 with Preferences

use of com.badlogic.gdx.Preferences in project libgdx by libgdx.

the class LwjglApplication method getPreferences.

@Override
public Preferences getPreferences(String name) {
    if (preferences.containsKey(name)) {
        return preferences.get(name);
    } else {
        Preferences prefs = new LwjglPreferences(new LwjglFileHandle(new File(preferencesdir, name), preferencesFileType));
        preferences.put(name, prefs);
        return prefs;
    }
}
Also used : Preferences(com.badlogic.gdx.Preferences) File(java.io.File)

Example 8 with Preferences

use of com.badlogic.gdx.Preferences in project libgdx by libgdx.

the class LwjglCanvas method getPreferences.

@Override
public Preferences getPreferences(String name) {
    if (preferences.containsKey(name)) {
        return preferences.get(name);
    } else {
        Preferences prefs = new LwjglPreferences(name, ".prefs/");
        preferences.put(name, prefs);
        return prefs;
    }
}
Also used : Preferences(com.badlogic.gdx.Preferences)

Example 9 with Preferences

use of com.badlogic.gdx.Preferences in project libgdx by libgdx.

the class PreferencesTest method create.

public void create() {
    Preferences prefs = Gdx.app.getPreferences(".test");
    if (prefs.contains("bool")) {
        if (prefs.getBoolean("bool") != true)
            throw new GdxRuntimeException("bool failed");
        if (prefs.getInteger("int") != 1234)
            throw new GdxRuntimeException("int failed");
        if (prefs.getLong("long") != Long.MAX_VALUE)
            throw new GdxRuntimeException("long failed");
        if (prefs.getFloat("float") != 1.2345f)
            throw new GdxRuntimeException("float failed");
        if (!prefs.getString("string").equals("test!"))
            throw new GdxRuntimeException("string failed");
    }
    prefs.clear();
    prefs.putBoolean("bool", true);
    prefs.putInteger("int", 1234);
    prefs.putLong("long", Long.MAX_VALUE);
    prefs.putFloat("float", 1.2345f);
    prefs.putString("string", "test!");
    prefs.flush();
    if (prefs.getBoolean("bool") != true)
        throw new GdxRuntimeException("bool failed");
    if (prefs.getInteger("int") != 1234)
        throw new GdxRuntimeException("int failed");
    if (prefs.getLong("long") != Long.MAX_VALUE)
        throw new GdxRuntimeException("long failed");
    if (prefs.getFloat("float") != 1.2345f)
        throw new GdxRuntimeException("float failed");
    if (!prefs.getString("string").equals("test!"))
        throw new GdxRuntimeException("string failed");
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Preferences(com.badlogic.gdx.Preferences)

Example 10 with Preferences

use of com.badlogic.gdx.Preferences in project libgdx by libgdx.

the class Lwjgl3Application method getPreferences.

@Override
public Preferences getPreferences(String name) {
    if (preferences.containsKey(name)) {
        return preferences.get(name);
    } else {
        Preferences prefs = new Lwjgl3Preferences(new Lwjgl3FileHandle(new File(config.preferencesDirectory, name), config.preferencesFileType));
        preferences.put(name, prefs);
        return prefs;
    }
}
Also used : Preferences(com.badlogic.gdx.Preferences) File(java.io.File)

Aggregations

Preferences (com.badlogic.gdx.Preferences)10 File (java.io.File)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 Mesh (com.badlogic.gdx.graphics.Mesh)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Texture (com.badlogic.gdx.graphics.Texture)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 Dialog (com.badlogic.gdx.scenes.scene2d.ui.Dialog)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 Frame (java.awt.Frame)1