From: gitknilch Date: Tue, 2 Apr 2013 16:00:20 +0000 (+0200) Subject: Allow selecting tileset. X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/FreeShisen/commitdiff_plain/07fd4c9f7cc4b5ba98994f9c153213adf7c01a44 Allow selecting tileset. Change-Id: Ibe75ece1217aebfa31266db3c0e2acb05863667a Signed-off-by: gitknilch --- diff --git a/res/drawable/classic.png b/res/drawable/classic.png new file mode 100644 index 0000000..cc4129b Binary files /dev/null and b/res/drawable/classic.png differ diff --git a/res/drawable/jade.png b/res/drawable/jade.png new file mode 100644 index 0000000..c9ce6a4 Binary files /dev/null and b/res/drawable/jade.png differ diff --git a/res/drawable/pixel.png b/res/drawable/pixel.png new file mode 100644 index 0000000..f94d79d Binary files /dev/null and b/res/drawable/pixel.png differ diff --git a/res/values/arrays.xml b/res/values/arrays.xml index e7ded55..221da23 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -18,4 +18,10 @@ 2 3 - + + classic + jade + traditional + pixel + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 1b21528..57d4646 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -16,6 +16,8 @@ Distributed under GPL v2:\n http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n Get the source code: https://code.google.com/p/freeshisen/ Size + Tileset + classic Difficulty 2 1 diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index ade0be7..62eb652 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -1,23 +1,36 @@ - - - - + + + + + \ No newline at end of file diff --git a/src/de/cwde/freeshisen/SettingsActivity.java b/src/de/cwde/freeshisen/SettingsActivity.java index d055b2f..643c6d3 100644 --- a/src/de/cwde/freeshisen/SettingsActivity.java +++ b/src/de/cwde/freeshisen/SettingsActivity.java @@ -13,6 +13,7 @@ implements OnSharedPreferenceChangeListener { private static final String KEY_PREF_DIFF = "pref_diff"; private static final String KEY_PREF_SIZE = "pref_size"; + private static final String KEY_PREF_TILE = "pref_tile"; //private static final String KEY_PREF_GRAV = "pref_grav"; //private static final String KEY_PREF_TIME = "pref_time"; @@ -27,6 +28,7 @@ implements OnSharedPreferenceChangeListener { sharedPreferences.registerOnSharedPreferenceChangeListener(this); updateSummary(sharedPreferences, KEY_PREF_DIFF, KEY_PREF_DIFF, R.array.difficulties); updateSummary(sharedPreferences, KEY_PREF_SIZE, KEY_PREF_SIZE, R.array.sizes); + updateTileSummary(sharedPreferences, KEY_PREF_TILE); } @Override @@ -54,6 +56,7 @@ implements OnSharedPreferenceChangeListener { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { updateSummary(sharedPreferences, key, KEY_PREF_DIFF, R.array.difficulties); updateSummary(sharedPreferences, key, KEY_PREF_SIZE, R.array.sizes); + updateTileSummary(sharedPreferences, key); } private void updateSummary(SharedPreferences sharedPreferences, String changedkey, String mykey, int myresource) { @@ -69,5 +72,16 @@ implements OnSharedPreferenceChangeListener { Preference myPref = findPreference(changedkey); myPref.setSummary("Currently: " + name); } - } + } + + private void updateTileSummary(SharedPreferences sharedPreferences, String changedkey) { + if (changedkey.equals(KEY_PREF_TILE)) { + String name = sharedPreferences.getString(KEY_PREF_TILE, "classic"); + + @SuppressWarnings("deprecation") + Preference myPref = findPreference(KEY_PREF_TILE); + myPref.setSummary("Current Tileset: " + name); + } + } + } diff --git a/src/de/cwde/freeshisen/ShisenSho.java b/src/de/cwde/freeshisen/ShisenSho.java index d926ff9..9d5d1dd 100644 --- a/src/de/cwde/freeshisen/ShisenSho.java +++ b/src/de/cwde/freeshisen/ShisenSho.java @@ -14,6 +14,7 @@ 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 boolean gravity=true; public boolean timeCounter=true; @@ -83,6 +84,7 @@ public class ShisenSho extends Application { 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", "")); boolean needsReset = false; @@ -106,9 +108,29 @@ public class ShisenSho extends Application { view.onTimeCounterActivate(); } + if ((tilesetid != this.tilesetid) && (view != null)) { + this.tilesetid = tilesetid; + view.loadTileset(); + } + if (needsReset && (view != null)) { view.reset(); } + } + 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 { + return R.drawable.classic; + } + } } diff --git a/src/de/cwde/freeshisen/ShisenShoView.java b/src/de/cwde/freeshisen/ShisenShoView.java index b802f0d..9207d3d 100644 --- a/src/de/cwde/freeshisen/ShisenShoView.java +++ b/src/de/cwde/freeshisen/ShisenShoView.java @@ -108,10 +108,10 @@ class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback { this.cstate=cstate; } - private void loadTileset() { + public void loadTileset() { BitmapFactory.Options ops = new BitmapFactory.Options(); ops.inScaled = false; - Bitmap tileset = BitmapFactory.decodeResource(getResources(), R.drawable.traditional, ops); + Bitmap tileset = BitmapFactory.decodeResource(getResources(), app.tilesetid, ops); tileset.setDensity(Bitmap.DENSITY_NONE); // The tile set has 4 rows x 9 columns