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

The following examples show how to use com.badlogic.gdx.Preferences#flush() . 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: GameOverScreen.java    From libgdx-2d-tutorial with MIT License 6 votes vote down vote up
public GameOverScreen (SpaceGame game, int score) {
	this.game = game;
	this.score = score;
	
	//Get highscore from save file
	Preferences prefs = Gdx.app.getPreferences("spacegame");
	this.highscore = prefs.getInteger("highscore", 0);
	
	//Check if score beats highscore
	if (score > highscore) {
		prefs.putInteger("highscore", score);
		prefs.flush();
	}
	
	//Load textures and fonts
	gameOverBanner = new Texture("game_over.png");
	scoreFont = new BitmapFont(Gdx.files.internal("fonts/score.fnt"));
	
	game.scrollingBackground.setSpeedFixed(true);
	game.scrollingBackground.setSpeed(ScrollingBackground.DEFAULT_SPEED);
}
 
Example 3
Source File: FramePropertiesPersister.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public static void saveFrameProperties(JFrame frame) {
    int extendedState = frame.getExtendedState();
    boolean extendedStateChanged = false;
    if (extendedState != Frame.NORMAL) {
        frame.setExtendedState(Frame.NORMAL);
        extendedStateChanged = true;
    }

    Preferences prefs = Gdx.app.getPreferences(PREF_NAME);
    prefs.putInteger("x", frame.getX());
    prefs.putInteger("y", frame.getY());
    prefs.putInteger("width", frame.getWidth());
    prefs.putInteger("height", frame.getHeight());
    prefs.putInteger("extendedState", extendedState != Frame.ICONIFIED ? extendedState : Frame.NORMAL); // Do not save Frame.ICONIFIED
    prefs.flush();

    if (extendedStateChanged) {
        frame.setExtendedState(extendedState);
    }
}
 
Example 4
Source File: WindowParamsPersistingApplicationWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
private void saveWindowParams() {
    int width = Display.getWidth();
    int height = Display.getHeight();
    int x = Display.getX();
    int y = Display.getY();

    //FIXME For some reason actual window position shifted by 6 pixels on Windows (by 12 at y when maximized).
    if (LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS) {
        x += 6;
        y += 6;
    }

    Preferences prefs = Gdx.app.getPreferences("window_params.xml");
    prefs.putInteger("x", x);
    prefs.putInteger("y", y);
    prefs.putInteger("width", width);
    prefs.putInteger("height", height);
    prefs.flush();
}
 
Example 5
Source File: GlobalConfiguration.java    From SIFTrain with MIT License 6 votes vote down vote up
public static void storeConfiguration() {
    Preferences prefs = Gdx.app.getPreferences("sif_train_config");
    prefs.putInteger("offset", offset);
    prefs.putInteger("input_offset", inputOffset);
    prefs.putInteger("song_vol", songVolume);
    prefs.putInteger("feedback_vol", feedbackVolume);
    prefs.putString("path_to_beatmaps", pathToBeatmaps);
    prefs.putBoolean("play_hint_sounds", playHintSounds);
    prefs.putInteger("note_speed", noteSpeed);
    prefs.putInteger("overall_difficulty", overallDifficulty);
    prefs.putInteger("sorting_mode", sortMode);
    prefs.putInteger("random_mode", randomMode);
    prefs.putInteger("sorting_order", sortOrder);
    prefs.putInteger("sync_mode", syncMode);
    prefs.flush();
}
 
Example 6
Source File: onScreenControls.java    From killingspree with MIT License 5 votes vote down vote up
public void resize() {
    Preferences prefs = Gdx.app.getPreferences("settings");
    int scaling = prefs.getInteger("scaling");
    if (scaling <= 30 || scaling >= 150) {
        scaling = 100;
        prefs.putInteger("scaling", 100);
        prefs.flush();
    }
    float buttonSize = (BUTTON_SIZE * (float) Gdx.graphics.getWidth() *
            scaling) / (1280f * 100f);
    shootButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            buttonSize, buttonSize, buttonSize);
    jumpButton.setBounds(Gdx.graphics.getWidth() - 2 * buttonSize, 10,
            buttonSize, buttonSize);
    throwBombButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            2f * buttonSize  * 1.1f, buttonSize, buttonSize);
    closeButton.setBounds(Gdx.graphics.getWidth() - buttonSize * 1.1f,
            Gdx.graphics.getHeight() - buttonSize * 1.1f, buttonSize,
            buttonSize);
    buttonSize *= 0.8f;
    leftButton.setBounds(buttonSize * 0.1f,
            buttonSize * 0.1f, buttonSize, buttonSize);
    upButton.setBounds(buttonSize * 1.6f / 2,
            buttonSize, buttonSize, buttonSize);
    rightButton.setBounds(buttonSize * 1.6f,
            buttonSize * 0.1f, buttonSize, buttonSize);
}
 
Example 7
Source File: GameManager.java    From martianrun with Apache License 2.0 5 votes vote down vote up
public void saveScore(int score) {
    Preferences preferences = getPreferences();
    int maxScore = preferences.getInteger(MAX_SCORE_PREFERENCE, 0);
    if (score > maxScore) {
        preferences.putInteger(MAX_SCORE_PREFERENCE, score);
        preferences.flush();
    }
}
 
Example 8
Source File: GameManager.java    From martianrun with Apache License 2.0 5 votes vote down vote up
public void incrementAchievementCount(String id, int steps) {
    Preferences preferences = getPreferences();
    int count = preferences.getInteger(getAchievementCountId(id), 0);
    count += steps;
    preferences.putInteger(getAchievementCountId(id), count);
    preferences.flush();
}
 
Example 9
Source File: MainMenu.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
@Override
public boolean keyDown(int keycode) {
	if(keycode == Input.Keys.BACK || keycode == Input.Keys.ESCAPE) {
		boolean exit = true;
		if(p1.picked) {
			p1.reset();
			exit = false;
		}
		if(p2.picked) {
			p2.reset();
			exit = false;
		}			
		if(p3.picked) {
			p3.reset();
			exit = false;
		}			
		if(p4.picked) {
			p4.reset();
			exit = false;
		}
		
		if(exit) {
			if(!(Gdx.app.getType() == ApplicationType.Applet)) {
				Gdx.app.exit();
			}
		}
	}
	
	if(keycode == Input.Keys.A) {
		if (!p1.picked) {
			p1.picked = true;
		} else {
			p1.playerSelect = true;
			p1.cpuSelect = false;
		}			
	}		
	if(keycode == Input.Keys.F) {
		if (!p2.picked) {
			p2.picked = true;
		}  else {
			p2.playerSelect = true;
			p2.cpuSelect = false;
		}	
	}		
	if(keycode == Input.Keys.H) {
		if (!p3.picked) {
			p3.picked = true;
		}  else {
			p3.playerSelect = true;
			p3.cpuSelect = false;
		}	
	}
	if(keycode == Input.Keys.L) {
		if (!p4.picked) {
			p4.picked = true;
		}  else {
			p4.playerSelect = true;
			p4.cpuSelect = false;
		}	
	}
	
	if(keycode == Input.Keys.M) {
		if (cnt >= 1)
			return false;
		Preferences prefs = Gdx.app.getPreferences("paxbritannica");
		prefs.putBoolean("music", !prefs.getBoolean("music"));
		prefs.flush();
		if(prefs.getBoolean("music")) {
			if(Resources.getInstance().music == null) Resources.getInstance().reInit();
			if(!Resources.getInstance().music.isPlaying()) { 
				Resources.getInstance().music.play();
				Resources.getInstance().music.setLooping(true);
			}
			musicOnOff.setColor(1,1,1,0.5f);				
		} else {
			Resources.getInstance().music.stop();
			musicOnOff.setColor(1,1,1,0.1f);
		}			
	}
	
	if(keycode == Input.Keys.F1) {
		if (cnt >= 1)
			return false;
		countdown.finished = true;
		changeToScreen = 0;
	}
	
	if(keycode == Input.Keys.S) {
		if (cnt >= 1)
			return false;
		countdown.finished = true;
		changeToScreen = 1;
	}
			

	return false;
}
 
Example 10
Source File: MainMenu.java    From libgdx-demo-pax-britannica with MIT License 4 votes vote down vote up
@Override
public boolean touchDown(int x, int y, int pointer, int button) {

	collisionRay = cam.getPickRay(x, y);
	
	if (cnt > 4 || countdown.finished)
		return false;	
	
	// check if ship is activated
	if (Intersector.intersectRayBoundsFast(collisionRay, p1.collision) && !p1.picked) {
		p1.picked = true;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p2.collision) && !p2.picked) {
		p2.picked = true;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p3.collision) && !p3.picked) {
		p3.picked = true;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p4.collision) && !p4.picked) {
		p4.picked = true;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p1.collisionPlayerSelect) && p1.picked && !p1.cpuSelect) {
		p1.playerSelect = true;
		p1.cpuSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p2.collisionPlayerSelect) && p2.picked && !p2.cpuSelect) {
		p2.playerSelect = true;
		p2.cpuSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p3.collisionPlayerSelect) && p3.picked && !p3.cpuSelect) {
		p3.playerSelect = true;
		p3.cpuSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p4.collisionPlayerSelect) && p4.picked && !p4.cpuSelect) {
		p4.playerSelect = true;
		p4.cpuSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p1.collisionCPUSelect) && p1.picked && !p1.playerSelect) {
		p1.cpuSelect = true;
		p1.playerSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p2.collisionCPUSelect) && p2.picked && !p2.playerSelect) {
		p2.cpuSelect = true;
		p2.playerSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p3.collisionCPUSelect) && p3.picked && !p3.playerSelect) {
		p3.cpuSelect = true;
		p3.playerSelect = false;
	} else if (Intersector.intersectRayBoundsFast(collisionRay, p4.collisionCPUSelect) && p4.picked && !p4.playerSelect) {
		p4.cpuSelect = true;
		p4.playerSelect = false;
	}
	
	if (Intersector.intersectRayBoundsFast(collisionRay, collisionMusic)) {
		if (cnt >= 1)
			return false;
		Preferences prefs = Gdx.app.getPreferences("paxbritannica");
		prefs.putBoolean("music", !prefs.getBoolean("music"));
		prefs.flush();
		if(prefs.getBoolean("music")) {
			if(Resources.getInstance().music == null) Resources.getInstance().reInit();
			if(!Resources.getInstance().music.isPlaying()) { 
				Resources.getInstance().music.play();
				Resources.getInstance().music.setLooping(true);
			}
			musicOnOff.setColor(1,1,1,0.5f);				
		} else {
			Resources.getInstance().music.stop();
			musicOnOff.setColor(1,1,1,0.1f);
		}			
	}
	
	if (Intersector.intersectRayBoundsFast(collisionRay, collisionHelp)) {
		if (cnt >= 1)
			return false;
		countdown.finished = true;
		changeToScreen = 0;
	}
	
	if (Intersector.intersectRayBoundsFast(collisionRay, collisionSettings)) {
		if (cnt >= 1)
			return false;
		countdown.finished = true;
		changeToScreen = 1;
	}
	
	return false;
}
 
Example 11
Source File: AudioUtils.java    From martianrun with Apache License 2.0 4 votes vote down vote up
private void saveBoolean(String key, boolean value) {
    Preferences preferences = getPreferences();
    preferences.putBoolean(key, value);
    preferences.flush();
}
 
Example 12
Source File: GameManager.java    From martianrun with Apache License 2.0 4 votes vote down vote up
public void submitSavedMaxScore() {
    Preferences preferences = getPreferences();
    submitScore(preferences.getInteger(MAX_SCORE_PREFERENCE, 0));
    preferences.remove(MAX_SCORE_PREFERENCE);
    preferences.flush();
}
 
Example 13
Source File: State.java    From FruitCatcher with Apache License 2.0 4 votes vote down vote up
public static void setSoundOn(boolean on) {
	Preferences prefs = Gdx.app.getPreferences(preferencesName);
	prefs.putBoolean("SoundOn", on);
	prefs.flush();
}
 
Example 14
Source File: State.java    From FruitCatcher with Apache License 2.0 4 votes vote down vote up
public static void unLockLevel(int level) {
	Preferences prefs = Gdx.app.getPreferences(preferencesName);
	prefs.putBoolean("Level" + (level + 1), true);
	prefs.flush();		
}
 
Example 15
Source File: Toggleable.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
public static void saveToPrefs() {
	Preferences p = getPrefs();
	p.putBoolean(DEBUG_DRAW, Toggleable.getValue(DEBUG_DRAW));
	p.putBoolean(PROFILE_GL, Toggleable.getValue(PROFILE_GL));
	p.flush();
}