com.badlogic.gdx.Preferences Java Examples

The following examples show how to use com.badlogic.gdx.Preferences. 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: 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 #2
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 #3
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 #4
Source File: ClientDiscoveryScreen.java    From killingspree with MIT License 6 votes vote down vote up
private void joinGame (final String host) {
        // FIXME
//            LobbyScreen lobbyScreen = new LobbyScreen(game);
//            lobbyScreen.setHost(address);
//            lobbyScreen.setServer(false);
//            game.setScreen(lobbyScreen);
            GameScreen gameScreen = new GameScreen(game);
            final Preferences prefs = Gdx.app.getPreferences("profile");
            if (gameScreen.loadLevel("maps/retro-small.tmx", host, 
                    prefs.getString("name"))) {
                game.setScreen(gameScreen);
            } else {
                gameScreen.dispose();
            }
        
    }
 
Example #5
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 #6
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 #7
Source File: GameInstance.java    From libgdx-demo-pax-britannica with MIT License 6 votes vote down vote up
public void resetGame() {
	fighters.clear();
	factorys.clear();
	bombers.clear();
	frigates.clear();
	bullets.clear();
	
	bubbleParticles.dispose();
	bigBubbleParticles.dispose();
	sparkParticles.dispose();
	explosionParticles.dispose();

	bubbleParticles = new BubbleParticleEmitter();
	bigBubbleParticles = new BigBubbleParticleEmitter();

	sparkParticles = new SparkParticleEmitter();
	explosionParticles = new ExplosionParticleEmitter();
	
	Preferences prefs = Gdx.app.getPreferences("paxbritannica");
	GameInstance.getInstance().difficultyConfig  = prefs.getInteger("difficulty",0);
	GameInstance.getInstance().factoryHealthConfig  = prefs.getInteger("factoryHealth",0);
	GameInstance.getInstance().antiAliasConfig  = prefs.getInteger("antiAliasConfig",1);
}
 
Example #8
Source File: FramePropertiesPersister.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public static void loadFrameProperties(JFrame frame) {
    Preferences prefs = Gdx.app.getPreferences(PREF_NAME);

    DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
    int screenWidth = displayMode.getWidth();
    int screenHeight = displayMode.getHeight();

    int width = MathUtils.clamp(prefs.getInteger("width", frame.getSize().width), 320, screenWidth);
    int height = MathUtils.clamp(prefs.getInteger("height", frame.getSize().height), 320, screenHeight);
    int x = MathUtils.clamp(prefs.getInteger("x", frame.getLocation().x), 0, screenWidth - width);
    int y = MathUtils.clamp(prefs.getInteger("y", frame.getLocation().y), 0, screenHeight - height);
    int extendedState = prefs.getInteger("extendedState", frame.getExtendedState());

    frame.setSize(width, height);
    frame.setLocation(x, y);
    frame.setExtendedState(extendedState);
}
 
Example #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: DesktopMini2DxGame.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Override
public Preferences getPreferences(String name) {
	if (preferences.containsKey(name)) {
		return preferences.get(name);
	} else {
		Preferences prefs = new Lwjgl3Preferences(
				new Lwjgl3FileHandle(new File(config.preferencesDirectory, name), config.preferencesFileType));
		preferences.put(name, prefs);
		return prefs;
	}
}
 
Example #16
Source File: State.java    From FruitCatcher with Apache License 2.0 5 votes vote down vote up
public static boolean isLevelUnlocked(int level) {
	if (level == 0) {
		return true;
	}
	Preferences prefs = Gdx.app.getPreferences(preferencesName);
	return prefs.getBoolean("Level" + (level + 1));		
}
 
Example #17
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 #18
Source File: Toggleable.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private static void loadFromPrefs() {
	Preferences p = getPrefs();
	create(DEBUG_DRAW, p.getBoolean(DEBUG_DRAW, false));
	create(PROFILE_GL, p.getBoolean(PROFILE_GL, true));
	create(FREE_CAMERA, p.getBoolean(FREE_CAMERA, true));
	create(CONTROL_PLAYER, p.getBoolean(CONTROL_PLAYER, true));
	create(MOUSE_LOOK, p.getBoolean(MOUSE_LOOK, true));

	set(CONTROL_PLAYER, true);
	set(FREE_CAMERA, false);
	set(MOUSE_LOOK, true);
}
 
Example #19
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 #20
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 #21
Source File: CustomLwjglCanvas.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public Preferences getPreferences(String name) {
    if (preferences.containsKey(name)) {
        return preferences.get(name);
    } else {
        Preferences prefs = new LwjglPreferences(new LwjglFileHandle(new File(prefersDir, name), prefsFileType));
        preferences.put(name, prefs);
        return prefs;
    }
}
 
Example #22
Source File: UserPreferences.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public static void load () {
	prefs = Gdx.app.getPreferences(Storage.Preferences);

	boolean isDifferent = false;
	for (Preference p : Preference.values()) {
		if (!prefs.contains(p.name())) {
			isDifferent = true;
			break;
		}
	}

	if (isDifferent || (prefs.get().size() == 0)) {
		toDefaults();
	}
}
 
Example #23
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 #24
Source File: WindowParamsPersistingApplicationWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
private void loadWindowParams(LwjglApplicationConfiguration configuration) {
    FileHandle file = new FileHandle(LwjglFiles.externalPath + configuration.preferencesDirectory + "/window_params.xml");
    if (!file.exists()) return;

    DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
    int screenWidth = displayMode.getWidth();
    int screenHeight = displayMode.getHeight();

    Preferences prefs = new LwjglPreferences(file);
    configuration.width = MathUtils.clamp(prefs.getInteger("width", configuration.width), 320, screenWidth);
    configuration.height = MathUtils.clamp(prefs.getInteger("height", configuration.height), 320, screenHeight);
    configuration.x = MathUtils.clamp(prefs.getInteger("x", configuration.x), 0, screenWidth - configuration.width);
    configuration.y = MathUtils.clamp(prefs.getInteger("y", configuration.y), 0, screenHeight - configuration.height);
}
 
Example #25
Source File: KTXProcessor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
protected void saveTempFilePath(File file) {
    try {
        Preferences preferences = Gdx.app.getPreferences(PREFERENCES_FILE);
        preferences
                .putString(prefKeyFilePath, file.getAbsolutePath())
                .putInteger(prefKeyFileRevision, fileRevision)
                .flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: KtxEtc2Processor.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
protected void saveTempFilePath(File file) {
    try {
        Preferences preferences = Gdx.app.getPreferences(PREFERENCES_FILE);
        preferences
                .putString(prefKeyFilePath, file.getAbsolutePath())
                .putInteger(prefKeyFileRevision, fileRevision)
                .flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: MainController.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Destroy
void destroy() {
    if (viewShown) {
        // Save pack list split value
        float packListSplitValue = packListSplitPane.getSplit();
        Preferences prefs = Gdx.app.getPreferences(AppConstants.PREF_NAME_COMMON);
        prefs.putFloat(PREF_KEY_PACK_LIST_SPLIT, packListSplitValue).flush();
    }
}
 
Example #28
Source File: GameSettings.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void set( Preferences prefs ){
	GameSettings.prefs = prefs;
}
 
Example #29
Source File: GlobalActions.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public FileChooserHistory(Preferences prefs) {
    this.prefs = prefs;
}
 
Example #30
Source File: MenuScreen.java    From Cardshifter with Apache License 2.0 4 votes vote down vote up
public MenuScreen(final CardshifterGame game) {
    final Preferences prefs = Gdx.app.getPreferences("cardshifter");
    this.table = new Table();
    this.game = game;
    this.table.setFillParent(true);
    
    Image imageObject = new Image(new Texture(Gdx.files.internal("bg2.png")));
    this.table.add(imageObject);
    this.table.row();

    Table inner = new Table();

    final TextField username = new TextField("", game.skin);
    String[] servers = isGWT() ? availableWSServers : availableServers;
    inner.add(username).expand().fill().colspan(servers.length).row();
    username.setText(prefs.getString("username", "YourUserName"));

    HorizontalGroup serverView = new HorizontalGroup();
    for (final String server : servers) {
        final String[] serverData = server.split(":");
        TextButton button = new TextButton(serverData[0], game.skin);
        button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                prefs.putString("username", username.getText());
                prefs.flush();
                String hostname = isGWT() ? "ws://" + serverData[0] : serverData[0];
                try {
                    ClientScreen clientScreen = new ClientScreen(game, hostname, Integer.parseInt(serverData[1]), username.getText());
                    game.setScreen(clientScreen);
                } catch (GdxRuntimeException e) {
                	MenuScreen.this.connectionLabel.setText("Connection Failed!");
                }
            }
        });
        serverView.addActor(button);
    }
    inner.add(serverView).expand().fill();
    table.add(inner);
    table.row();
    
    this.connectionLabel = new Label(" ", game.skin);
    this.table.add(this.connectionLabel);
    
}