]> git.zerfleddert.de Git - FreeShisen/commitdiff
Allow selecting tileset.
authorgitknilch <gitknilch@cwde.de>
Tue, 2 Apr 2013 16:00:20 +0000 (18:00 +0200)
committergitknilch <gitknilch@cwde.de>
Tue, 2 Apr 2013 16:00:20 +0000 (18:00 +0200)
Change-Id: Ibe75ece1217aebfa31266db3c0e2acb05863667a
Signed-off-by: gitknilch <gitknilch@cwde.de>
res/drawable/classic.png [new file with mode: 0644]
res/drawable/jade.png [new file with mode: 0644]
res/drawable/pixel.png [new file with mode: 0644]
res/values/arrays.xml
res/values/strings.xml
res/xml/preferences.xml
src/de/cwde/freeshisen/SettingsActivity.java
src/de/cwde/freeshisen/ShisenSho.java
src/de/cwde/freeshisen/ShisenShoView.java

diff --git a/res/drawable/classic.png b/res/drawable/classic.png
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..f94d79d
Binary files /dev/null and b/res/drawable/pixel.png differ
index e7ded555952f3c5fd8acf2c2c1f267665d022f8d..221da23c5f0489f909f5eddde3e92333ddc258b9 100644 (file)
         <item>2</item>
         <item>3</item>
     </string-array>
         <item>2</item>
         <item>3</item>
     </string-array>
-</resources>
+    <string-array name="tilesets">
+        <item>classic</item>
+        <item>jade</item>
+        <item>traditional</item>
+        <item>pixel</item>
+    </string-array>
+</resources>
\ No newline at end of file
index 1b2152861b3e5140a35ae87587e24c89184c61e9..57d4646f3c0c9da176a239d746db24105e7ce9d3 100644 (file)
@@ -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/</string>
     <string name="size">Size</string>
 http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n
 Get the source code: https://code.google.com/p/freeshisen/</string>
     <string name="size">Size</string>
+    <string name="tileset">Tileset</string>
+    <string name="tileset_default">classic</string>
     <string name="difficulty">Difficulty</string>
     <string name="size_default">2</string>
     <string name="difficulty_default">1</string>
     <string name="difficulty">Difficulty</string>
     <string name="size_default">2</string>
     <string name="difficulty_default">1</string>
index ade0be718fcb744cc19c6cde4c043c5433ad4436..62eb65263aff290976da4e18202d0bac2d930d65 100644 (file)
@@ -1,23 +1,36 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-    <ListPreference 
-        android:title="@string/size" 
-        android:entryValues="@array/size_values" 
-        android:key="pref_size" 
-        android:dialogTitle="@string/size" 
-        android:entries="@array/sizes" android:defaultValue="@string/size_default"/>
-    <ListPreference 
-        android:title="@string/difficulty" 
-        android:entryValues="@array/difficulty_values" 
-        android:key="pref_diff" 
-        android:dialogTitle="@string/difficulty" 
-        android:entries="@array/difficulties" android:defaultValue="@string/difficulty_default"/>
-    <CheckBoxPreference 
-        android:defaultValue="true" 
-        android:title="@string/gravity"
-        android:key="pref_grav" android:summaryOn="@string/gravity_pref_on" android:summaryOff="@string/gravity_pref_off"/>
-    <CheckBoxPreference 
-        android:defaultValue="true" 
-        android:title="@string/time_counter"
-        android:key="pref_time" android:summaryOn="@string/time_pref_on" android:summaryOff="@string/time_pref_off"/>
+    <ListPreference
+        android:defaultValue="@string/size_default"
+        android:dialogTitle="@string/size"
+        android:entries="@array/sizes"
+        android:entryValues="@array/size_values"
+        android:key="pref_size"
+        android:title="@string/size" />
+    <ListPreference
+        android:defaultValue="@string/difficulty_default"
+        android:dialogTitle="@string/difficulty"
+        android:entries="@array/difficulties"
+        android:entryValues="@array/difficulty_values"
+        android:key="pref_diff"
+        android:title="@string/difficulty" />
+    <CheckBoxPreference
+        android:defaultValue="false"
+        android:key="pref_grav"
+        android:summaryOff="@string/gravity_pref_off"
+        android:summaryOn="@string/gravity_pref_on"
+        android:title="@string/gravity" />
+    <CheckBoxPreference
+        android:defaultValue="true"
+        android:key="pref_time"
+        android:summaryOff="@string/time_pref_off"
+        android:summaryOn="@string/time_pref_on"
+        android:title="@string/time_counter" />
+    <ListPreference
+        android:defaultValue="@string/tileset_default"
+        android:dialogTitle="@string/tileset"
+        android:entries="@array/tilesets"
+        android:entryValues="@array/tilesets"
+        android:key="pref_tile"
+        android:title="@string/tileset" />
 </PreferenceScreen>
\ No newline at end of file
 </PreferenceScreen>
\ No newline at end of file
index d055b2fed36ee62b4e5415cba9ed6a44080ec581..643c6d3533c4c93da9dc0e649291af18f338bda2 100644 (file)
@@ -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_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";
 
        //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);
                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
        }
 
        @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);
        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) {
        }
 
        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);
                }
                        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);
+               }
+       }
+
 }
 }
index d926ff9ed07e4df90fd62b05a862c1f5b851b8bb..9d5d1dd98a959583192a824cf4728da00eebc271 100644 (file)
@@ -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[] 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;
 
        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 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;
 
 
                boolean needsReset = false;
 
@@ -106,9 +108,29 @@ public class ShisenSho extends Application {
                        view.onTimeCounterActivate();
                }
 
                        view.onTimeCounterActivate();
                }
 
+               if ((tilesetid != this.tilesetid) && (view != null)) {
+                       this.tilesetid = tilesetid;
+                       view.loadTileset();
+               }
+
                if (needsReset && (view != null)) {
                        view.reset();
                }
                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;
+               }
+       }
 }
 }
index b802f0d59511e87a7b531c2a64a8fc87c6ce047e..9207d3d5358f0187b6cc004b488de870957d6ee6 100644 (file)
@@ -108,10 +108,10 @@ class ShisenShoView extends SurfaceView implements SurfaceHolder.Callback {
                this.cstate=cstate;
        }
 
                this.cstate=cstate;
        }
 
-       private void loadTileset() {
+       public void loadTileset() {
                BitmapFactory.Options ops = new BitmapFactory.Options();
                ops.inScaled = false;
                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
                tileset.setDensity(Bitmap.DENSITY_NONE);
 
                // The tile set has 4 rows x 9 columns
Impressum, Datenschutz