List of usage examples for com.badlogic.gdx Preferences putString
public Preferences putString(String key, String val);
From source file:app.badlogicgames.superjumper.RegisterScreen.java
License:Apache License
private void savePref() { Preferences prefs = Gdx.app.getPreferences("my-preferences"); if (Util.NAME.length() > 0 && Util.EMAIL.length() > 0 && Util.PASSWORD.length() > 0) { prefs.putString("name", Util.NAME); prefs.putString("email", Util.EMAIL); prefs.putString("password", Util.PASSWORD); prefs.flush();/* w w w.j ava2s.c o m*/ notification = "Saved Successfully"; game.setScreen(new MainMenuScreen(game)); } else { notification = "All Fields are mandatory"; } }
From source file:com.a2client.Config.java
License:Open Source License
public static void SaveOptions() { // Preferences p = getPrefs(); Preferences p = Gdx.app.getPreferences(CONFIG_FILE); p.putInteger("window_width", WindowWidth); p.putInteger("window_height", WindowHeight); p.putInteger("screen_width", ScreenWidth_to_save); p.putInteger("screen_height", ScreenHeight_to_save); p.putInteger("frame_rate", FrameFate); p.putBoolean("use_vsync", vSync); p.putBoolean("reduce_bg", ReduceInBackground); p.putBoolean("start_fullscreen", isFullscreen); // AppSettings.put("sound_enabled", SoundEnabled); // AppSettings.put("sound_vol", SoundVolume); // AppSettings.put("music_vol", MusicVolume); // AppSettings.put("debug_engine", DebugEngine); p.putString("language", current_lang); // AppSettings.put("count_objs", count_objs); // AppSettings.put("hide_overlapped", hide_overlapped); // AppSettings.put("move_inst_left_mouse", move_inst_left_mouse); // AppSettings.put("zoom_by_wheel", zoom_by_wheel); // AppSettings.put("zoom_over_mouse", zoom_over_mouse); // AppSettings.put("fullscreen_alt_enter", fullscreen_alt_enter); // AppSettings.put("minimap_draw_objects", minimap_draw_objects); p.putString("account", account); if (save_pass) { p.putString("password", password); } else {/*from ww w.j av a2s .co m*/ p.putString("password", ""); } p.putBoolean("save_pass", save_pass); p.flush(); }
From source file:com.esotericsoftware.spine.SkeletonViewer.java
License:Open Source License
void loadSkeleton(FileHandle skeletonFile, boolean reload) { if (skeletonFile == null) return;/* ww w . j a v a 2 s.co m*/ // A regular texture atlas would normally usually be used. This returns a white image for images not found in the atlas. Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(new Color(1, 1, 1, 0.33f)); pixmap.fill(); final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32); pixmap.dispose(); String atlasFileName = skeletonFile.nameWithoutExtension(); if (atlasFileName.endsWith(".json")) atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension(); FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas"); if (!atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt"); TextureAtlasData data = !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false); TextureAtlas atlas = new TextureAtlas(data) { public AtlasRegion findRegion(String name) { AtlasRegion region = super.findRegion(name); return region != null ? region : fake; } }; try { String extension = skeletonFile.extension(); if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) { SkeletonJson json = new SkeletonJson(atlas); json.setScale(ui.scaleSlider.getValue()); skeletonData = json.readSkeletonData(skeletonFile); } else { SkeletonBinary binary = new SkeletonBinary(atlas); binary.setScale(ui.scaleSlider.getValue()); skeletonData = binary.readSkeletonData(skeletonFile); } } catch (Exception ex) { ex.printStackTrace(); ui.toast("Error loading skeleton: " + skeletonFile.name()); lastModifiedCheck = 5; return; } skeleton = new Skeleton(skeletonData); skeleton.setToSetupPose(); skeleton = new Skeleton(skeleton); skeleton.updateWorldTransform(); state = new AnimationState(new AnimationStateData(skeletonData)); this.skeletonFile = skeletonFile; Preferences prefs = Gdx.app.getPreferences("spine-skeletontest"); prefs.putString("lastFile", skeletonFile.path()); prefs.flush(); lastModified = skeletonFile.lastModified(); lastModifiedCheck = checkModifiedInterval; // Populate UI. ui.skeletonLabel.setText(skeletonFile.name()); { Array<String> items = new Array(); for (Skin skin : skeletonData.getSkins()) items.add(skin.getName()); ui.skinList.setItems(items); } { Array<String> items = new Array(); for (Animation animation : skeletonData.getAnimations()) items.add(animation.getName()); ui.animationList.setItems(items); } // Configure skeleton from UI. skeleton.setSkin(ui.skinList.getSelected()); state.setAnimation(0, ui.animationList.getSelected(), ui.loopCheckbox.isChecked()); if (reload) ui.toast("Reloaded."); }
From source file:com.kasetagen.game.bubblerunner.screen.BubbleRunnerMenu.java
License:Creative Commons License
private void assembleOptionsGroup(TextureAtlas atlas) { /*//from w ww.j a v a 2 s . c o m * Gather values */ float sfxVolValue = gameProcessor.getStoredFloat(GameOptions.SFX_MUSIC_VOLUME_PREF_KEY); sfxVolValue = sfxVolValue < 0f ? 0f : sfxVolValue; float bgVolValue = gameProcessor.getStoredFloat(GameOptions.BG_MUSIC_VOLUME_PREF_KEY); bgVolValue = bgVolValue < 0f ? 0f : bgVolValue; charValue = gameProcessor.getStoredString(GameOptions.CHARACTER_SELECT_KEY); if (charValue == null || "".equals(charValue.trim())) { charValue = AnimationUtil.CHARACTER_2; } /* * Gather Reference Interatctions */ Skin skin = gameProcessor.getAssetManager().get(AssetsUtil.DEFAULT_SKIN, AssetsUtil.SKIN); sfx = gameProcessor.getAssetManager().get(AssetsUtil.SND_SHIELD_ON, AssetsUtil.SOUND); /* * Add Scaffolding */ GenericActor runnerScaffold = new GenericActor(0f, 0f, optionsGroup.getWidth(), optionsGroup.getHeight(), atlas.findRegion(AtlasUtil.ANI_OPTIONS_RUNNERSCAFFOLD), Color.WHITE); optionsGroup.addActor(runnerScaffold); GenericActor volumeScaffold = new GenericActor(0f, 0f, optionsGroup.getWidth(), optionsGroup.getHeight(), atlas.findRegion(AtlasUtil.ANI_OPTIONS_VOLUMESCAFFOLD), Color.WHITE); optionsGroup.addActor(volumeScaffold); Animation techAAni = new Animation(1f / 2f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_TECH_A)); AnimatedActor techA = new AnimatedActor(TECHA_X, TECHA_Y, TECHA_W, TECHA_H, techAAni, 0f); optionsGroup.addActor(techA); Animation techBAni = new Animation(1f / 2f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_TECH_B)); AnimatedActor techB = new AnimatedActor(TECHB_X, TECHB_Y, TECHB_W, TECHB_H, techBAni, 0f); optionsGroup.addActor(techB); /* * Add Player Buttons */ Animation charAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_CHARSELECT)); charIndicator = new AnimatedActor(CHAR_SEL_X, CHAR_SEL_Y, CHAR_SEL_W, CHAR_SEL_H, charAni, 0f); charIndicator.setTargetKeyFrame(1); optionsGroup.addActor(charIndicator); Animation edynDefCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_SELECT), Animation.PlayMode.REVERSED); Animation edynCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_SELECT)); edynCircle = new AnimatedActor(EDYN_CIRCLE_X, EDYN_CIRCLE_Y, EDYN_CIRCLE_W, EDYN_CIRCLE_H, edynDefCircleAni, 0f); edynCircle.addStateAnimation("SELECTED", edynCircleAni); edynCircle.setIsLooping(false); optionsGroup.addActor(edynCircle); Array<TextureAtlas.AtlasRegion> edynImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDYN_EYES); TextureRegionDrawable edynUp = new TextureRegionDrawable(edynImgs.get(0)); TextureRegionDrawable edynDown = new TextureRegionDrawable(edynImgs.get(1)); edynSelect = new ImageButton(edynUp, edynDown, edynDown); edynSelect.setSize(CHAR_CIRCLE_SIZE, CHAR_CIRCLE_SIZE); edynSelect.setPosition(EDYN_SELECT_X, CHAR_CIRCLE_Y); edynSelect.addListener(listener); edynSelect.setChecked(AnimationUtil.CHARACTER_2.equals(charValue)); optionsGroup.addActor(edynSelect); Animation eddyDefCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_SELECT), Animation.PlayMode.REVERSED); Animation eddyCircleAni = new Animation(0.5f / 10f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_SELECT)); eddyCircle = new AnimatedActor(EDISON_CIRCLE_X, EDISON_CIRCLE_Y, EDISON_CIRCLE_W, EDISON_CIRCLE_H, eddyDefCircleAni, 0f); eddyCircle.addStateAnimation("SELECTED", eddyCircleAni); eddyCircle.setIsLooping(false); optionsGroup.addActor(eddyCircle); Array<TextureAtlas.AtlasRegion> edisonImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_EDISON_EYES); TextureRegionDrawable edisonUp = new TextureRegionDrawable(edisonImgs.get(0)); TextureRegionDrawable edisonDown = new TextureRegionDrawable(edisonImgs.get(1)); edisonSelect = new ImageButton(edisonUp, edisonDown, edisonDown); edisonSelect.setSize(CHAR_CIRCLE_SIZE, CHAR_CIRCLE_SIZE); edisonSelect.setPosition(EDISON_SELECT_X, CHAR_CIRCLE_Y); edisonSelect.addListener(listener); edisonSelect.setChecked(AnimationUtil.CHARACTER_1.equals(charValue)); optionsGroup.addActor(edisonSelect); charDataSaver = new IDataSaver() { @Override public void updatePreferences(Preferences prefs) { prefs.putString(GameOptions.CHARACTER_SELECT_KEY, charValue); } }; /* * Add Main Menu Button */ Array<TextureAtlas.AtlasRegion> mmImgs = atlas.findRegions(AtlasUtil.ANI_OPTIONS_MAINMENU); TextureRegionDrawable mmDown = new TextureRegionDrawable(mmImgs.get(1)); mainMenuButton = new ImageButton(new TextureRegionDrawable(mmImgs.get(0)), mmDown, mmDown); mainMenuButton.setSize(MM_W, MM_H); mainMenuButton.setPosition(MM_X, MM_Y); mainMenuButton.addListener(listener); optionsGroup.addActor(mainMenuButton); /* * Add Sliders */ Animation bgAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_MUSIC)); bgIndicator = new AnimatedActor(MUSIC_X, MUSIC_Y, MUSIC_W, MUSIC_H, bgAni, 0f); bgIndicator.setTargetKeyFrame(0); optionsGroup.addActor(bgIndicator); bgVolumeSet = new Slider(0f, 1f, 0.1f, false, skin); bgVolumeSet.setValue(bgVolValue); bgVolumeSet.setPosition(319f, 190f); bgVolumeSet.setSize(500f, 20f); optionsGroup.addActor(bgVolumeSet); bgDataSaver = new IDataSaver() { @Override public void updatePreferences(Preferences prefs) { prefs.putFloat(GameOptions.BG_MUSIC_VOLUME_PREF_KEY, bgVolumeSet.getValue()); } }; bgVolumeSet.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { gameProcessor.saveGameData(bgDataSaver); gameProcessor.setBGMusicVolume(bgVolumeSet.getValue()); } }); Animation sfxAni = new Animation(1f, atlas.findRegions(AtlasUtil.ANI_OPTIONS_SFX)); sfxIndicator = new AnimatedActor(SFX_X, SFX_Y, SFX_W, SFX_H, sfxAni, 0f); sfxIndicator.setTargetKeyFrame(0); optionsGroup.addActor(sfxIndicator); sfxVolumeSet = new Slider(0f, 1f, 0.1f, false, skin); sfxVolumeSet.setValue(sfxVolValue); sfxVolumeSet.setPosition(208f, 68f); sfxVolumeSet.setSize(500f, 20f); optionsGroup.addActor(sfxVolumeSet); sfxDataSaver = new IDataSaver() { @Override public void updatePreferences(Preferences prefs) { prefs.putFloat(GameOptions.SFX_MUSIC_VOLUME_PREF_KEY, sfxVolumeSet.getValue()); } }; sfxVolumeSet.addListener(new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { gameProcessor.saveGameData(sfxDataSaver); sfx.play(sfxVolumeSet.getValue()); } }); selectCharacter(edynSelect.isChecked()); TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); style.font = gameProcessor.getAssetManager().get(AssetsUtil.NEUROPOL_32, AssetsUtil.BITMAP_FONT); style.fontColor = Color.CYAN; TextButton credits = new TextButton("BG Music By DST under Creative Commons License", style); credits.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { Gdx.net.openURI("http://creativecommons.org/licenses/by/3.0/legalcode"); Gdx.net.openURI("http://www.nosoapradio.us/"); } }); credits.setPosition(optionsGroup.getWidth() / 2 - (credits.getWidth() / 2), 0f); optionsGroup.addActor(credits); }
From source file:com.maplescot.loggerbill.misc.Profile.java
License:Creative Commons License
public void save(Preferences prefs) { ckSum = makeCkSum();//from w w w .ja v a 2 s . c o m ckSumV = ckVersion; prefs.putBoolean(soundOnStr, soundOn); prefs.putBoolean(musicOnStr, musicOn); prefs.putLong(totalPlaysStr, totalPlays); prefs.putLong(totalChunksStr, totalChunks); prefs.putLong(totalTimeStr, totalTime); prefs.putLong(bestChunksStr, bestChunks); prefs.putFloat(bestCPSStr, bestCPS); prefs.putString(gplusStr, gplusId); prefs.putString(CKSUM, ckSum); prefs.putLong(CKSUMV, ckSumV); prefs.putString(achievementsStr, saveAchievements()); }
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 ww w . j a v a 2 s. c o m*/ } 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 w w w . ja v a2s . c om*/ 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: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 ww w. j a v a 2 s. com 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()); }