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());
}
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;
}
}
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;
}
}
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");
}
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;
}
}
Aggregations