Skip to content
Snippets Groups Projects
Commit 886d13e3 authored by Frantisek Simon's avatar Frantisek Simon Committed by Matyáš Latner
Browse files

#282 Every user has own settings of default difficulty for each game

parent ac6b2c50
No related branches found
No related tags found
No related merge requests found
......@@ -216,16 +216,16 @@ public class TablexiaSettings {
}
public void setGameDifficulty(GameDefinition gameDefinition, GameDifficulty gameDifficulty) {
preferences.putString(getGameDifficultyPreferncesKey(gameDefinition), gameDifficulty.name());
preferences.putString(getGameDifficultyPreferencesKey(gameDefinition), gameDifficulty.name());
preferences.flush();
}
public GameDifficulty getGameDifficulty(GameDefinition gameDefinition) {
return GameDifficulty.valueOf(GameDifficulty.class, preferences.getString(getGameDifficultyPreferncesKey(gameDefinition), GameDifficulty.DEFAULT_DIFFICULTY.name()));
return GameDifficulty.valueOf(GameDifficulty.class, preferences.getString(getGameDifficultyPreferencesKey(gameDefinition), GameDifficulty.DEFAULT_DIFFICULTY.name()));
}
private String getGameDifficultyPreferncesKey(GameDefinition gameDefinition) {
return "GAME_DIFFICULTY_" + gameDefinition.name();
private String getGameDifficultyPreferencesKey(GameDefinition gameDefinition) {
return "GAME_DIFFICULTY_" + gameDefinition.name() + "_" + getSelectedUser().getId();
}
public static Color getDefaultBackgroundColor() {
......
package cz.nic.tablexia.screen.gamemenu.pages;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
......@@ -15,6 +16,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import net.engio.mbassy.listener.Handler;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
......@@ -134,7 +137,10 @@ public class GameMenuPage extends MenuPage {
prepareTitle();
prepareStartButton();
prepareDifficulty();
}
// init event bus handlers
ApplicationBus.getInstance().subscribe(this);
}
private void prepareBackground() {
background = getScreen().getScreenTextureRegion( GameMenuScreen.GameMenuPageDefinition.getResourcePath(game, GameMenuAssets.AssetType.BACK));
......@@ -569,4 +575,17 @@ public class GameMenuPage extends MenuPage {
public void setIsFirstLogin(boolean isFirstLogin) {
this.isFirstLogin = isFirstLogin;
}
}
\ No newline at end of file
@Handler
public void handleSelectedUserEvent(final TablexiaSettings.SelectedUserEvent selectedUserEvent) {
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
if (selectedUserEvent.isUserSelected()) {
gameDifficulty = TablexiaSettings.getInstance().getGameDifficulty(game);
dragSwitchListener.switchToStep(gameDifficulty.getDifficultyNumber() - 1);
}
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment