List of usage examples for com.badlogic.gdx Preferences getString
public String getString(String key);
From source file:app.badlogicgames.superjumper.RegisterScreen.java
License:Apache License
private static void readPref() { Preferences prefs = Gdx.app.getPreferences("my-preferences"); Util.NAME = prefs.getString("name"); Util.EMAIL = prefs.getString("email"); Util.PASSWORD = prefs.getString("password"); }
From source file:at.therefactory.jewelthief.input.MenuScreenInputAdapter.java
License:Open Source License
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { super.touchUp(screenX, screenY, pointer, button); Preferences prefs = JewelThief.getInstance().getPreferences(); numTouches = Math.max(0, numTouches - 1); if (menuScreen.buttonExitToMainMenu.isPressed()) { menuScreen.buttonExitToMainMenu.release(); menuScreen.setShowLicenseYOffset(0); menuScreen.setState(MenuScreen.MenuState.ShowMenu); } else if (menuScreen.getState().equals(MenuScreen.MenuState.ShowAbout)) { if (menuScreen.buttonShowLicense.isPressed()) { menuScreen.buttonShowLicense.release(); if (menuScreen.getShowLicenseYOffset() == 0) { menuScreen.setShowLicenseYOffset(54); } else { menuScreen.setShowLicenseYOffset(0); }// w ww. j a va 2 s . c o m } else if (menuScreen.buttonSoundtrack.isPressed()) { menuScreen.buttonSoundtrack.release(); Gdx.net.openURI(URL_TO_SOUNDTRACK); } else if (menuScreen.buttonRate.isPressed()) { menuScreen.buttonRate.release(); Gdx.net.openURI(URL_TO_PLAY_STORE); } } else if (menuScreen.getState().equals(MenuScreen.MenuState.ShowHighscores)) { if (menuScreen.buttonUpdateHighscores.isPressed()) { menuScreen.buttonUpdateHighscores.release(); menuScreen.setFetchingHighscores(true); HttpServer.fetchHighscores(menuScreen, prefs.getString(PrefsKeys.ID), prefs.getString(PrefsKeys.PLAYER_NAME), prefs.getInteger(PrefsKeys.BEST_SCORE_NUM_JEWELS), prefs.getInteger(PrefsKeys.BEST_SCORE_NUM_SECONDS)); } } else if (menuScreen.getState().equals(MenuScreen.MenuState.ShowSettings)) { if (menuScreen.buttonChangePlayername.isPressed()) { menuScreen.buttonChangePlayername.release(); Gdx.input.getTextInput(listener, bundle.get(PLEASE_ENTER_YOUR_NAME), prefs.getString(PrefsKeys.PLAYER_NAME), ""); } else if (menuScreen.buttonToggleSound.isPressed()) { menuScreen.buttonToggleSound.release(); menuScreen.buttonToggleSound.nextState(); prefs.putBoolean(PrefsKeys.ENABLE_SOUND, !prefs.getBoolean(PrefsKeys.ENABLE_SOUND)); prefs.flush(); } else if (menuScreen.buttonToggleMusic.isPressed()) { menuScreen.buttonToggleMusic.release(); menuScreen.buttonToggleMusic.nextState(); prefs.putBoolean(PrefsKeys.ENABLE_MUSIC, !prefs.getBoolean(PrefsKeys.ENABLE_MUSIC)); prefs.flush(); if (prefs.getBoolean(PrefsKeys.ENABLE_MUSIC)) { JewelThief.getInstance().playMusicFile(true); } else { JewelThief.getInstance().pauseMusic(); } } else if (menuScreen.buttonChangeLanguage.isPressed()) { menuScreen.buttonChangeLanguage.release(); menuScreen.buttonChangeLanguage.nextState(); bundle = JewelThief.getInstance() .setLocale(menuScreen.buttonChangeLanguage.getState() == 0 ? "en" : "de"); menuScreen.setBundle(bundle); } else if (menuScreen.buttonResetHighscore.isPressed()) { menuScreen.buttonResetHighscore.release(); if (timestampLastClickOnResetHighscoreSettingButton > System.currentTimeMillis() - 1000) { timestampLastClickOnResetHighscoreSettingButton = 0; prefs.remove(PrefsKeys.MY_RANK); prefs.remove(PrefsKeys.BEST_SCORE); prefs.remove(PrefsKeys.BEST_SCORE_NUM_JEWELS); prefs.remove(PrefsKeys.BEST_SCORE_NUM_SECONDS); JewelThief.getInstance().toast(bundle.get(HIGHSCORE_IS_RESET), true); } else { timestampLastClickOnResetHighscoreSettingButton = System.currentTimeMillis(); JewelThief.getInstance().toast(bundle.get(TAP_AGAIN_TO_RESET_HIGHSCORE), false); } } } // main menu else { if (menuScreen.buttonStartSinglePlayerGame.isPressed()) { JewelThief.getInstance().showIntroScreen(); menuScreen.buttonStartSinglePlayerGame.release(); } else if (menuScreen.buttonShowHighscores.isPressed()) { deltaY = 0; menuScreen.setScrollbarPositionY(Config.INITIAL_SCROLLBAR_POSITION_Y); if (prefs.contains(PrefsKeys.CACHED_HIGHSCORES)) { menuScreen.setHighscores(prefs.getString(PrefsKeys.CACHED_HIGHSCORES).split("\n")); } menuScreen.setState(MenuScreen.MenuState.ShowHighscores); menuScreen.buttonShowHighscores.release(); } else if (menuScreen.buttonShowSettings.isPressed()) { menuScreen.setState(MenuScreen.MenuState.ShowSettings); menuScreen.buttonShowSettings.release(); } else if (menuScreen.buttonShowAbout.isPressed()) { menuScreen.setState(MenuScreen.MenuState.ShowAbout); menuScreen.buttonShowAbout.release(); } } lastDeltaY = -deltaY; touchDragging = false; return true; }
From source file:com.tussle.main.Utility.java
License:Open Source License
public static Preferences getPreferencesFor(String name) { Preferences top = Gdx.app.getPreferences("Tussle"); return Gdx.app.getPreferences(top.getString(name)); }
From source file:de.longri.cachebox3.develop.tools.skin_editor.actors.MenuBar.java
License:Apache License
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/*from www . j a v a 2 s . co m*/ protected void result(Object object) { if ((Boolean) object == true) { if (textDirectory.getText().isEmpty() == true) { game.showMsgDlg("Warning", "Directory field is empty!", game.screenMain.stage); return; } FileHandle targetDirectory = new FileHandle(textDirectory.getText()); if (targetDirectory.exists() == false) { game.showMsgDlg("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("skin.")) { Gdx.app.log("MenuBar", "Copying file: " + file.name() + " ..."); FileHandle target = targetDirectory.child(file.name()); file.copyTo(target); } else if (file.name().startsWith("svg")) { // create "svg" folder FileHandle targetFolder = targetDirectory.child("svg"); targetFolder.mkdirs(); for (FileHandle svgFfile : file.list()) { FileHandle target = targetFolder.child(svgFfile.name()); svgFfile.copyTo(target); Gdx.app.log("MenuBar", "Copying file: " + svgFfile.name() + " ..."); } } else if (file.name().startsWith("fonts")) { // create "fonts" folder FileHandle targetFolder = targetDirectory.child("fonts"); targetFolder.mkdirs(); for (FileHandle fontFfile : file.list()) { FileHandle target = targetFolder.child(fontFfile.name()); fontFfile.copyTo(target); Gdx.app.log("MenuBar", "Copying file: " + fontFfile.name() + " ..."); } } } game.showMsgDlg("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(); // } fileChooser.setListener(new FileChooserAdapter() { @Override public void selected(Array<FileHandle> fileList) { FileHandle selectedFolder = fileList.get(0); textDirectory.setText(selectedFolder.file().getAbsolutePath()); // Store to file prefs.putString("export_to_directory", selectedFolder.file().getAbsolutePath()); prefs.flush(); } }); FileHandle directory = Gdx.files.absolute(prefs.getString("export_to_directory")); fileChooser.setDirectory(directory); //displaying chooser with fade in animation getStage().addActor(fileChooser.fadeIn()); } }); 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()); }
From source file:net.bplaced.therefactory.voraciousviper.screens.TitleScreen.java
License:Open Source License
private void synchronizeCheckedStatesOfSettingsButtons() { Preferences prefs = SettingsManager.getInstance().get(); buttonsSettings[0][0].setChecked(prefs.getString(PrefsKeys.Language).equals(Locale.ENGLISH.toString())); buttonsSettings[0][1].setChecked(prefs.getString(PrefsKeys.Language).equals(Locale.GERMAN.toString())); buttonsSettings[1][0].setChecked(prefs.getBoolean(PrefsKeys.Music)); ((RetroImageToggleButton) buttonsSettings[1][0]).setToggled(prefs.getBoolean(PrefsKeys.Music)); buttonsSettings[1][1].setChecked(prefs.getBoolean(PrefsKeys.Sound)); ((RetroImageToggleButton) buttonsSettings[1][1]).setToggled(prefs.getBoolean(PrefsKeys.Sound)); buttonsSettings[3][0].setChecked(prefs.getString(PrefsKeys.Controls).equals(PrefsKeys.ControlsTouchAreas)); buttonsSettings[3][1].setChecked(prefs.getString(PrefsKeys.Controls).equals(PrefsKeys.ControlsTouchPad)); buttonsSettings[3][2].setChecked(prefs.getString(PrefsKeys.Controls).equals(PrefsKeys.ControlsRelative)); for (RetroTextButton button : buttonsMainMenu) { button.autoSize();//from w w w .j a v a 2 s . c o m } ((RetroTextButton) buttonsSettings[2][0]).autoSize(); updatePlayernameText(); }
From source file:org.shadebob.skineditor.actors.MenuBar.java
License:Apache License
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/*from w w w . jav a2s .co m*/ 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() == "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); // TODO falls 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()); }