List of usage examples for com.badlogic.gdx Preferences flush
public void flush();
From source file:com.gamestudio24.martianrun.utils.GameManager.java
License:Apache License
public void incrementAchievementCount(String id, int steps) { Preferences preferences = getPreferences(); int count = preferences.getInteger(getAchievementCountId(id), 0); count += steps;/*from ww w . j a v a 2 s. c o m*/ preferences.putInteger(getAchievementCountId(id), count); preferences.flush(); }
From source file:com.redthirddivision.astilade.entities.mobs.Player.java
License:Apache License
public static void savePlayer(Player player) { LogHelper.info("Saving player data"); Preferences prefs = Gdx.app.getPreferences(Astilade.TITLE); prefs.putFloat("playerX", player.position.x); prefs.putFloat("playerY", player.position.y); prefs.flush(); LogHelper.info("Player data saved"); }
From source file:com.subzero.runners.android.AndroidLauncher.java
License:Open Source License
@Override public void queryPurchases(Preferences pref) { this.pref = pref; try {/*from www . j a va2 s . c o m*/ Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null); int response = ownedItems.getInt("RESPONSE_CODE"); if (response == 0) { ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); for (int i = 0; i < ownedSkus.size(); i++) { String name = null; if (ownedSkus.get(i).equals("ryan")) name = "Ryan"; else if (ownedSkus.get(i).equals("ash")) name = "Ash"; else if (ownedSkus.get(i).equals("rob")) name = "Rob"; else if (ownedSkus.get(i).equals("battle_cat")) name = "BattleCat"; else if (ownedSkus.get(i).equals("xorp")) name = "Xorp"; else if (ownedSkus.get(i).equals("rootsworth")) name = "Rootsworth"; else if (ownedSkus.get(i).equals("snap")) name = "Snap"; else if (ownedSkus.get(i).equals("metatron")) name = "Metatron"; else if (ownedSkus.get(i).equals("abaddon")) name = "Abaddon"; pref.putBoolean(name, true); pref.flush(); } } } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.theosirian.ppioo.util.GameData.java
License:Open Source License
public GameData save() { Preferences state = Gdx.app.getPreferences(saveName); for (Player player : players) { if (player.isOwned()) { String key = "player-" + player.getId(); state.putBoolean(key, true); state.putLong(key + "-date_acquired", player.getDateAcquired().getTime()); state.putInteger(key + "-victories", player.getVictories()); state.putInteger(key + "-defeats", player.getDefeats()); }/*from w w w . ja v a2 s.co m*/ } for (Fan fan : fans) { if (fan.isOwned()) { String key = "fan-" + fan.getId(); state.putBoolean(key, true); state.putLong(key + "-date_acquired", fan.getDateAcquired().getTime()); state.putInteger(key + "-victories", fan.getVictories()); state.putInteger(key + "-defeats", fan.getDefeats()); } } state.putInteger("money", money); state.putInteger("victories", victories); state.putInteger("defeats", defeats); state.flush(); return this; }
From source file:de.hasait.tanks.app.common.MainMenuScreen.java
License:Apache License
@Override protected void renderInternal(final float pDelta) { final ConfiguredActionFactory configuredActionFactory = _configuredActionFactory.get(); if (configuredActionFactory != null) { drawText(0, ">>> Waiting for action <<<", AlignH.CENTER, AlignV.TOP); if (configuredActionFactory.isFinished()) { _configuredActionFactory.set(null); }/*from w w w. j a v a2 s.c om*/ } if (_connect) { _connect = false; final String roomName = _roomNameField.getText(); if (Util.isBlank(roomName)) { return; } final Preferences preferences = obtainPreferences(); preferences.putString(PREFKEY__ROOM_NAME, roomName); final GameConfig config = new GameConfig(); config.setRoomName(roomName); config.setWishPiecesX(40); config.setWishPiecesY(24); for (int i = 0; i < _playerNameFields.size(); i++) { final TextField playerNameField = _playerNameFields.get(i); final String playerName = playerNameField.getText(); if (Util.isBlank(playerName)) { continue; } final PlayerConfig playerConfig = (PlayerConfig) playerNameField.getUserObject(); playerConfig.setName(playerName.trim()); config.getPlayers().add(playerConfig); preferences.putString(PREFKEY__PLAYER_CONFIG + i, Util.serializeToString(playerConfig)); } if (config.getPlayers().isEmpty()) { return; } preferences.flush(); setScreen(new ConnectingScreen(getContext(), config)); } }
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 ww w .j av a2s. c o 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:edu.lehigh.cse.lol.Facts.java
License:Open Source License
/** * Save a fact about the current game session. If the factName has already * been used for this game session, the new value will overwrite the old. * * @param factName The name for the fact being saved * @param factValue The integer value that is the fact being saved *///from w w w .java 2s. c o m public static void putGameFact(String factName, int factValue) { Preferences prefs = Gdx.app.getPreferences(Lol.sGame.mStorageKey); prefs.putInteger(factName, factValue); prefs.flush(); }
From source file:eu.rubenrosado.inmisericordia.LSGame.java
License:Open Source License
/** * Save the game in JSon/* w w w .java 2s . com*/ */ public void saveGame() { Json json = new Json(); String hero = json.toJson(PlayGame.hero, Hero.class); String monsters = json.toJson(PlayGame.monsters, Monster.class); FileHandle file = Gdx.files.local("hero.sav"); file.writeString(hero, false); file = Gdx.files.local("monsters.sav"); file.writeString(monsters, false); Preferences pref = Gdx.app.getPreferences(".sav"); if (!pref.getBoolean("savedgame", false)) { pref.putBoolean("savedgame", true); } pref.flush(); }
From source file:eu.rubenrosado.inmisericordia.LSGame.java
License:Open Source License
/** * Delete saved game/*from w w w.j av a 2 s. co m*/ */ public void deleteGame() { Preferences pref = Gdx.app.getPreferences(".sav"); pref.putBoolean("savedgame", false); pref.flush(); Gdx.files.local("hero.sav").delete(); Gdx.files.local("monsters.sav").delete(); }
From source file:headmade.arttag.screens.IntroScreen.java
License:Apache License
@Override public void preDraw(float delta) { super.preDraw(delta); if (!isInitialised) { Gdx.app.log(TAG, "Loading Prefs"); isInitialised = true;//from ww w. j a v a 2 s. c o m ArtTag.gameSettings = new GameSettings(); final Preferences prefs = Gdx.app.getPreferences("ArtTreacheryPrefs"); ArtTag.gameSettings.screenWidth = prefs.getInteger("screenWidth", 1280); ArtTag.gameSettings.screenHeight = prefs.getInteger("screenHeight", 1024); ArtTag.gameSettings.fullscreen = prefs.getBoolean("fullscreen", false); ArtTag.gameSettings.blur = prefs.getInteger("blur", 1); ArtTag.gameSettings.rays = prefs.getInteger("rays", 64); ArtTag.gameSettings.handleResAuto = prefs.getBoolean("handleResAuto", true); Gdx.app.log(TAG, "Saving Prefs"); prefs.putInteger("screenWidth", ArtTag.gameSettings.screenWidth); prefs.putInteger("screenHeight", ArtTag.gameSettings.screenHeight); prefs.putBoolean("fullscreen", ArtTag.gameSettings.fullscreen); prefs.putInteger("blur", ArtTag.gameSettings.blur); prefs.putInteger("rays", ArtTag.gameSettings.rays); prefs.putBoolean("handleResAuto", ArtTag.gameSettings.handleResAuto); prefs.flush(); if (Gdx.graphics.supportsDisplayModeChange() && ArtTag.gameSettings.handleResAuto == false) { Gdx.app.log(TAG, "Trying to set Displaymode"); Gdx.graphics.setDisplayMode(ArtTag.gameSettings.screenWidth, ArtTag.gameSettings.screenHeight, ArtTag.gameSettings.fullscreen); // Gdx.gl.glViewport(0, 0, ArtTag.gameSettings.screenWidth, ArtTag.gameSettings.screenHeight); } } Assets.assetsManager.update(); if (!isStarted && MathUtils.isEqual(1f, Assets.assetsManager.getProgress())) { // done loading eh Assets.instance.onFinishLoading(); startGame(); isStarted = true; // final TextButton startButton = new TextButton("Start", Assets.instance.skin); // startButton.addListener(new InputListener() { // // @Override // public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { // startGame(); // return super.touchDown(event, x, y, pointer, button); // } // }); } }