Java Code Examples for com.badlogic.gdx.Preferences#getString()

The following examples show how to use com.badlogic.gdx.Preferences#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectController.java    From talos with Apache License 2.0 6 votes vote down vote up
public void reportProjectFileInterraction(FileHandle handle) {
    Preferences prefs = TalosMain.Instance().Prefs();
    String data = prefs.getString("recents");
    Array<RecentsEntry> list = new Array<>();
    //read
    Json json = new Json();
    try {
        if (data != null && !data.isEmpty()) {
            list = json.fromJson(list.getClass(), data);
        }
    } catch( Exception e) {

    }
    RecentsEntry newEntry = new RecentsEntry(handle.path(), TimeUtils.millis());
    list.removeValue(newEntry, false);
    list.add(newEntry);
    //sort
    list.sort(recentsEntryComparator);
    //write
    String result = json.toJson(list);
    prefs.putString("recents", result);
    prefs.flush();
    updateRecentsList();
}
 
Example 2
Source File: ProjectController.java    From talos with Apache License 2.0 6 votes vote down vote up
public Array<String> updateRecentsList() {
    Preferences prefs = TalosMain.Instance().Prefs();
    String data = prefs.getString("recents");
    Array<String> list = new Array<>();
    //read

    try {
        Json json = new Json();
        if (data != null && !data.isEmpty()) {
            Array<RecentsEntry> rList = new Array<>();
            rList = json.fromJson(rList.getClass(), data);
            for (RecentsEntry entry : rList) {
                list.add(entry.path);
            }
        }

        TalosMain.Instance().UIStage().Menu().updateRecentsList(list);
    } catch (Exception e) {

    }

    return list;
}
 
Example 3
Source File: KTXProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
protected File loadTempFilePath() {
    try {
        Preferences preferences = Gdx.app.getPreferences(PREFERENCES_FILE);
        int revision = preferences.getInteger(prefKeyFileRevision, -1);
        // Check if the revisions are the same
        if (this.fileRevision != revision) return null;

        String absolutePath = preferences.getString(prefKeyFilePath, null);
        if (absolutePath != null) {
            return new File(absolutePath);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 4
Source File: KtxEtc2Processor.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
protected File loadTempFilePath() {
    try {
        Preferences preferences = Gdx.app.getPreferences(PREFERENCES_FILE);
        int revision = preferences.getInteger(prefKeyFileRevision, -1);
        // Check if the revisions are the same
        if (this.fileRevision != revision) return null;

        String absolutePath = preferences.getString(prefKeyFilePath, null);
        if (absolutePath != null) {
            return new File(absolutePath);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 5
Source File: GlobalConfiguration.java    From SIFTrain with MIT License 6 votes vote down vote up
public static void loadConfiguration() {
    Preferences prefs = Gdx.app.getPreferences("sif_train_config");
    offset = prefs.getInteger("offset", 0);
    inputOffset = prefs.getInteger("input_offset", 0);
    songVolume = prefs.getInteger("song_vol", 100);
    feedbackVolume = prefs.getInteger("feedback_vol", 100);
    pathToBeatmaps = prefs.getString("path_to_beatmaps", Gdx.files.getExternalStoragePath() + "beatmaps");
    playHintSounds = prefs.getBoolean("play_hint_sounds", false);
    noteSpeed = prefs.getInteger("note_speed", 6);
    overallDifficulty = prefs.getInteger("overall_difficulty", 7);
    // default to song name sorting
    sortMode = prefs.getInteger("sorting_mode", SongUtils.SORTING_MODE_SONG_NAME);
    sortOrder = prefs.getInteger("sorting_order", SongUtils.SORTING_MODE_ASCENDING);
    // default to the new mode
    randomMode = prefs.getInteger("random_mode", SongUtils.RANDOM_MODE_NEW);
    // sync mode
    syncMode = prefs.getInteger("sync_mode", SongUtils.SYNC_MODE_1);

}
 
Example 6
Source File: DicePreferences.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public DicePreferences(Preferences preferences, App app) {
    this.preferences = preferences;
    this.app = app;
    volume = preferences.getFloat("volume", 0.5f);
    language = preferences.getString("language", Locale.getDefault().getLanguage());
    scale = preferences.getInteger("scale", (int) ScreenHelper.scaleFor(Gdx.graphics.getWidth(), Gdx.app.getType() == Application.ApplicationType.Desktop));
    rated = preferences.getBoolean("rated");
    music = preferences.getBoolean("music", true);
    servicesPaneShownByDefault = preferences.getBoolean("services-pane", false);
    applyVolume();
    applyMusic();
}
 
Example 7
Source File: MainMenuScreen.java    From killingspree with MIT License 5 votes vote down vote up
@Override
public void show() {
    font = game.getFont(170);
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    viewport = new FitViewport(1280, 720, camera);
    camera.setToOrtho(false, 1280, 720);
    buttons = new ArrayList<MyButton>();
    addAllButtons();
    final Preferences prefs = Gdx.app.getPreferences("profile");
    String name = prefs.getString("name");
    name = name.trim();
    if (name.length() == 0) {
        Gdx.input.getTextInput(new TextInputListener() {
            
            @Override
            public void input(String text) {
                prefs.putString("name", text);
                prefs.flush();
            }
            
            @Override
            public void canceled() {
            }
        }, "Enter name", "");
    }
}
 
Example 8
Source File: MainMenuScreen.java    From killingspree with MIT License 5 votes vote down vote up
private void startServer(boolean lonely) {
    Preferences prefs = Gdx.app.getPreferences("profile");
    GameScreen gameScreen = new GameScreen(game);
    gameScreen.startServer(lonely);
    String name = prefs.getString("name");
    gameScreen.loadLevel("maps/retro-small.tmx", "localhost",
            name);
    game.setScreen(gameScreen);
}
 
Example 9
Source File: MenuBar.java    From gdx-skineditor with Apache License 2.0 4 votes vote down vote up
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());
	
}