List of usage examples for com.badlogic.gdx Preferences flush
public void flush();
From source file:io.github.deathsbreedgames.spacerun.screens.GameOverScreen.java
public GameOverScreen(AssetManager manager) { super("MainMenu", manager); Preferences prefs = Gdx.app.getPreferences("SpaceRun"); // Set high score if (GlobalVars.score > GlobalVars.highScore) { GlobalVars.highScore = GlobalVars.score; prefs.putInteger("HighScore", GlobalVars.highScore); if (Gdx.app.getType() == ApplicationType.Android && GlobalVars.actionResolver.getSignedInGPGS()) { GlobalVars.actionResolver.submitScoreGPGS(GlobalVars.highScore); }// w w w . j ava 2 s . c o m } prefs.putInteger("KillCount", GlobalVars.killCount); prefs.flush(); // Setup draw camera = new OrthographicCamera(GlobalVars.width, GlobalVars.height); camera.position.set(GlobalVars.width / 2, GlobalVars.height / 2, 0f); camera.update(); batch = new SpriteBatch(); font = new BitmapFont(); font.scale(0.5f); // Setup buttons mainStage = new Stage(new StretchViewport(GlobalVars.width, GlobalVars.height)); buttonAtlas = manager.get("gfx/ui/buttons.pack", TextureAtlas.class); buttonSkin = new Skin(buttonAtlas); Gdx.input.setInputProcessor(mainStage); buttonFont = new BitmapFont(); buttonFont.scale(0.3f); TextButtonStyle buttonStyle = new TextButtonStyle(); buttonStyle.up = buttonSkin.getDrawable("MainMenu-normal"); buttonStyle.down = buttonSkin.getDrawable("MainMenu-down"); buttonStyle.over = buttonSkin.getDrawable("MainMenu-hover"); buttonStyle.font = buttonFont; TextButton menuButton = new TextButton(GlobalVars.gameBundle.get("mainmenu"), buttonStyle); menuButton.setPosition(GlobalVars.width / 2 - menuButton.getWidth() / 2, 10f); mainStage.addActor(menuButton); menuButton.addListener(new ChangeListener() { public void changed(ChangeEvent e, Actor a) { setNextScreen("MainMenu"); setDone(true); } }); }
From source file:io.piotrjastrzebski.dungen.DungenScreen.java
License:Apache License
public DungenScreen(DungenGame game) { super();//from www. j ava 2 s. c o m this.game = game; genSettings = new GenSettings().setGridSize(.25f).setCount(150).setSpawnWidth(20).setSpawnHeight(10) .setRoomWidth(4).setRoomHeight(4).setMainRoomScale(1.15f).setReconnectChance(.2f) .setHallwaysWidth(2).setB2bIters(100); drawSettings = new DrawSettings().setDrawExtra(true).setDrawMain(true).setDrawHallWays(true) .setDrawUnused(true); generator = new DungeonGenerator(); generator.init(genSettings); grid = new Grid(); grid.setSize(genSettings.getGridSize()); genGui = new GenSettingsGUI(this, this); genGui.setDefaults(genSettings); stage.addActor(genGui); genGui.setPosition(10, 10); drawGui = new DrawSettingsGUI(this); drawGui.setDefaults(drawSettings); stage.addActor(drawGui); drawGui.setPosition(10, stage.getHeight() - drawGui.getHeight() - 10); multiplexer.addProcessor(this); multiplexer.addProcessor(new GestureDetector(this)); helpGUI = new HelpGUI(); VisTable helpCont = new VisTable(); helpCont.setFillParent(true); VisTextButton showHelp = new VisTextButton("Help!"); showHelp.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { helpGUI.show(stage); } }); helpCont.add(showHelp).right().top().expand().pad(10); stage.addActor(helpCont); Preferences dungen = Gdx.app.getPreferences("Dungen"); if (!dungen.getBoolean("help-shown", false)) { helpGUI.show(stage); dungen.putBoolean("help-shown", true); dungen.flush(); } }
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// www. java 2 s . c om 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()); }
From source file:releasethekraken.screen.SettingsScreen.java
/** * Constructs a new PauseScreen/*from w ww . ja v a 2s . c om*/ * @param rtk The ReleaseTheKraken instance. This is final so that the * anonymous inner classes can access it. */ public SettingsScreen(final ReleaseTheKraken rtk) { super(rtk); final Preferences settings = Gdx.app.getPreferences("ReleaseTheKraken_Settings.xml"); boolean fullscreen = settings.getBoolean("fullscreen"); this.renderer = new UiRenderer(); float scrWidth = Gdx.graphics.getWidth(); float scrHeight = Gdx.graphics.getHeight(); float textWidth = 0.2F; float textHeight = 0.2F; this.renderer.uiObjects.add(new UiText(this.renderer, scrWidth / 2, scrHeight * 0.75F, textWidth, textHeight, "Welcome to the settings menu!")); float buttonWidth = 0.3F; float buttonHeight = 0.08F; float buttonY = 0.5F; //Add the resume button UiButton backButton = new UiButton(this.renderer, scrWidth / 2 - (scrWidth * buttonWidth / 2), scrHeight * buttonY, buttonWidth, buttonHeight, "Back", Color.GRAY) { @Override public void onClick(int mouseButton) { super.onClick(mouseButton); //Go back by popping this screen, and disposing it rtk.popScreen().dispose(); } }; backButton.setToolTip(new TextToolTip(this.renderer, "Return to Previous Screen")); this.renderer.uiObjects.add(backButton); buttonY = 0.3F; //Add the main menu button UiButton screenSize = new UiButton(this.renderer, scrWidth / 2 - (scrWidth * buttonWidth / 2), scrHeight * buttonY, buttonWidth, buttonHeight, fullscreen ? "Disable Fullscreen" : "Enable Fullscreen", Color.GRAY) { @Override public void onClick(int mouseButton) { super.onClick(mouseButton); //This alters the settings folder and crashes the game on mac. Needs some work. boolean fullscreen = settings.getBoolean("fullscreen"); fullscreen = !fullscreen; settings.putBoolean("fullscreen", fullscreen); settings.flush(); this.text = fullscreen ? "Disable Fullscreen" : "Enable Fullscreen"; } }; screenSize.setToolTip(new TextToolTip(this.renderer, "Requires you to restart the game")); this.renderer.uiObjects.add(screenSize); this.renderer.uiObjects.sort(); //Sort the UI objects once they are all added ReleaseTheKraken.inputHandler.registerKeyListener(this); //Register as a key listener }