X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/blobdiff_plain/1065ae67bcab7e10507617a2189026b63a180103..a8ebc47081a14b3af3e22e3e6123a81e938e79ab:/src/de/cwde/freeshisen/ShisenSho.java diff --git a/src/de/cwde/freeshisen/ShisenSho.java b/src/de/cwde/freeshisen/ShisenSho.java index 99327bd..f24f0c0 100644 --- a/src/de/cwde/freeshisen/ShisenSho.java +++ b/src/de/cwde/freeshisen/ShisenSho.java @@ -14,36 +14,32 @@ public class ShisenSho extends Application { public int[] boardSize=new int[2]; public int difficulty=1; // 1=Easy, 2=Hard public int size=3; // 1=Small, 2=Medium, 3=Big - public int tilesetid = R.drawable.classic; + public String tilesetid = "classic"; public boolean gravity=true; public boolean timeCounter=true; - public static void log(String msg) { - Log.w("ShisenSho", msg); - } - public void newPlay() { + loadOptions(); board = new Board(); board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity); } public void setSize(int s) { + size = s; + switch (s) { case 1: - size=1; - boardSize[0]=6+2; - boardSize[1]=8+2; + boardSize[0] = 6 + 2; + boardSize[1] = 8 + 2; break; case 2: - size=2; - boardSize[0]=6+2; - boardSize[1]=12+2; + boardSize[0] = 6 + 2; + boardSize[1] = 12 + 2; break; case 3: default: - size=3; - boardSize[0]=6+2; - boardSize[1]=16+2; + boardSize[0] = 6 + 2; + boardSize[1] = 16 + 2; break; } } @@ -73,70 +69,62 @@ public class ShisenSho extends Application { public void onCreate() { super.onCreate(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); - setOptions(); + Log.d("ShisenSho", "starting up..."); + loadOptions(); } - public void setOptions() { - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + private void loadOptions() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); // FIXME: handle NumberFormatException here? - int size = Integer.parseInt(sharedPref.getString("pref_size", "1")); - int difficulty = Integer.parseInt(sharedPref.getString("pref_diff", "1")); - boolean gravity = sharedPref.getBoolean("pref_grav", true); - boolean timeCounter = sharedPref.getBoolean("pref_time", true); - int tilesetid = tilesetStringToRes(sharedPref.getString("pref_tile", "")); + setSize(Integer.parseInt(sp.getString("pref_size", "1"))); + difficulty = Integer.parseInt(sp.getString("pref_diff", "1")); + gravity = sp.getBoolean("pref_grav", true); + timeCounter = sp.getBoolean("pref_time", true); + tilesetid = sp.getString("pref_tile", ""); + } + + public void checkForChangedOptions() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + + // FIXME: handle NumberFormatException here? + int size = Integer.parseInt(sp.getString("pref_size", "1")); + int difficulty = Integer.parseInt(sp.getString("pref_diff", "1")); + boolean gravity = sp.getBoolean("pref_grav", true); + boolean timeCounter = sp.getBoolean("pref_time", true); + String tilesetid = sp.getString("pref_tile", ""); boolean needsReset = false; if (size != this.size) { - setSize(size); needsReset = true; } if (difficulty != this.difficulty) { - this.difficulty = difficulty; needsReset = true; } if (gravity != this.gravity) { - this.gravity = gravity; needsReset = true; } - if ((timeCounter != this.timeCounter) && (view != null)) { - this.timeCounter = timeCounter; - view.onTimeCounterActivate(); + if (timeCounter != this.timeCounter) { + needsReset = true; } if ((tilesetid != this.tilesetid) && (view != null)) { + // tileset can be changed without a reset this.tilesetid = tilesetid; view.loadTileset(); } - if (needsReset && (view != null)) { - view.reset(); + if (needsReset) { + if ((view != null) && (activity != null)) { + activity.onOptionsChanged(); + } else { + Log.d("ShisenSho", "Preferences changed, but no view or activity online - huh?"); + } } } - - private int tilesetStringToRes(String s) - { - if (s.equals("classic")) { - return R.drawable.classic; - } else if (s.equals("jade")) { - return R.drawable.jade; - } else if (s.equals("traditional")) { - return R.drawable.traditional; - } else if (s.equals("pixel")) { - return R.drawable.pixel; - } else if (s.equals("original")) { - return R.drawable.original; - } else if (s.equals("veit")) { - return R.drawable.veit; - } else { - // shouldn't be reached... - Log.e("ShisenSho", "somebody managed to set an invalid tileset string"); - return R.drawable.classic; - } - } }