android: startgamemenu now has some default values, plus the themes are ordered alphabetically
authorXeli
Sat, 03 Dec 2011 18:50:29 +0100
changeset 6486 2a3ee24764bb
parent 6485 7586c266b52e
child 6487 bd3c736c1eac
android: startgamemenu now has some default values, plus the themes are ordered alphabetically
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/FrontendDataUtils.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Scheme.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartGameActivity.java
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Utils.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/FrontendDataUtils.java	Sat Dec 03 18:49:17 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/FrontendDataUtils.java	Sat Dec 03 18:50:29 2011 +0100
@@ -61,14 +61,15 @@
 				ret.add(files[i].replace('_', ' ').substring(0, files[i].length()-4)); //replace _ by a space and removed the last four characters (.lua)
 			}
 		}
+		ret.add(0,"None");
 		Collections.sort(ret);
-
-		ret.add(0,"None");
 		return ret;	
 	}
 
-	public static String[] getThemes(Context c){
-		return Utils.getDirsWithFileSuffix(c, "Themes", "icon.png");
+	public static List<String> getThemes(Context c){
+		List<String> list = Utils.getDirsWithFileSuffix(c, "Themes", "icon.png");
+		Collections.sort(list);
+		return list;
 	}
 
 	public static List<Scheme> getSchemes(Context c){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Scheme.java	Sat Dec 03 18:49:17 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Scheme.java	Sat Dec 03 18:50:29 2011 +0100
@@ -44,13 +44,12 @@
 	//private ArrayList<Integer> basic;
 	private Integer gamemod;
 	private ArrayList<Integer> basic;;
-	private static ArrayList<LinkedHashMap<String, ?>> basicflags = new ArrayList<LinkedHashMap<String, ?>>();
+	private static ArrayList<LinkedHashMap<String, ?>> basicflags = new ArrayList<LinkedHashMap<String, ?>>();//TODO why is it static?
 	
 	public Scheme(String _name, ArrayList<Integer> _basic, int _gamemod){
 		name = _name;
 		gamemod = _gamemod;
 		basic = _basic;
-
 	}
 	
 	public Scheme(Parcel in){
@@ -329,7 +328,6 @@
 	}
 
 	public int describeContents() {
-		// TODO Auto-generated method stub
 		return 0;
 	}
 
@@ -337,7 +335,6 @@
 		dest.writeString(name);
 		dest.writeInt(gamemod);
 		dest.writeList(basic);
-		
 	}
 	
 	public void readFromParcel(Parcel src){
@@ -357,11 +354,6 @@
 	};
 
 	public int compareTo(Scheme another) {
-		boolean equalsDefault = name.toLowerCase().equals("default");
-		boolean otherEqualsDefault = another.name.toLowerCase().equals("default");
-		if(equalsDefault && otherEqualsDefault)	return 0;
-		else if(equalsDefault && !otherEqualsDefault) return -1;
-		else if((!equalsDefault) && otherEqualsDefault)	return 1;
-		else return name.compareTo(another.name);
+		return name.compareTo(another.name);
 	}
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java	Sat Dec 03 18:49:17 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java	Sat Dec 03 18:50:29 2011 +0100
@@ -210,12 +210,7 @@
 	};
 
 	public int compareTo(Weapon another) {
-		boolean equalsDefault = name.toLowerCase().equals("crazy");
-		boolean otherEqualsDefault = another.name.toLowerCase().equals("crazy");
-		if(equalsDefault && otherEqualsDefault)	return 0;
-		else if(equalsDefault && !otherEqualsDefault) return -1;
-		else if((!equalsDefault) && otherEqualsDefault)	return 1;
-		else return name.compareTo(another.name);
+		return name.compareTo(another.name);
 	}
 	
 	
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartGameActivity.java	Sat Dec 03 18:49:17 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/StartGameActivity.java	Sat Dec 03 18:50:29 2011 +0100
@@ -22,6 +22,7 @@
 import org.hedgewars.hedgeroid.EngineProtocol.FrontendDataUtils;
 import org.hedgewars.hedgeroid.EngineProtocol.GameConfig;
 import org.hedgewars.hedgeroid.EngineProtocol.Map;
+import org.hedgewars.hedgeroid.EngineProtocol.Map.MapType;
 import org.hedgewars.hedgeroid.EngineProtocol.Scheme;
 import org.hedgewars.hedgeroid.EngineProtocol.Team;
 import org.hedgewars.hedgeroid.EngineProtocol.Weapon;
@@ -93,27 +94,53 @@
 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 		maps.setAdapter(adapter);
 		maps.setOnItemSelectedListener(mapsClicker);
+		//set to first nonmap
+		for(int i = 0; i < adapter.getCount(); i++){
+			if(((Map)adapter.getItem(i)).getType() == MapType.TYPE_DEFAULT){
+				maps.setSelection(i, false);
+				break;
+			}
+		}
 
 		adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this));
 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 		gameplay.setAdapter(adapter);
 		gameplay.setOnItemSelectedListener(gameplayClicker);
+		//set to first nonmap
+		for(int i = 0; i < adapter.getCount(); i++){
+			if(((String)adapter.getItem(i)).equals("None")){
+				gameplay.setSelection(i, false);
+				break;
+			}
+		}
 
 		adapter = new ArrayAdapter<Scheme>(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this));
 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 		gamescheme.setAdapter(adapter);
 		gamescheme.setOnItemSelectedListener(schemeClicker);
-
+		//set to first nonmap
+		for(int i = 0; i < adapter.getCount(); i++){
+			if(((Scheme)adapter.getItem(i)).toString().equals("Default")){
+				gamescheme.setSelection(i, false);
+				break;
+			}
+		}
+		
+		
 		adapter = new ArrayAdapter<Weapon>(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this));
 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 		weapons.setAdapter(adapter);
 		weapons.setOnItemSelectedListener(weaponClicker);
-
+		for(int i = 0; i < adapter.getCount(); i++){
+			if(((Weapon)adapter.getItem(i)).toString().equals("Crazy")){
+				weapons.setSelection(i, false);
+				break;
+			}
+		}
 		adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getThemes(this));
 		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 		themes.setAdapter(adapter);
 		themes.setOnItemSelectedListener(themesClicker);
-
 	}
 
 	private void startTeamsActivity(){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Utils.java	Sat Dec 03 18:49:17 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Utils.java	Sat Dec 03 18:50:29 2011 +0100
@@ -25,14 +25,13 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.List;
 
-import android.app.Activity;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.os.Build;
 import android.os.Environment;
 import android.util.Log;
-import android.widget.Toast;
 
 public class Utils {
 
@@ -134,16 +133,13 @@
 	 * @param fileSuffix
 	 * @return
 	 */
-	public static String[] getDirsWithFileSuffix(Context c, String path, String fileSuffix){
+	public static List<String> getDirsWithFileSuffix(Context c, String path, String fileSuffix){
 		File[] files = getFilesFromRelativeDir(c,path);
-		String[] validFiles = new String[files.length];
-		int validCounter = 0;
+		ArrayList<String> ret = new ArrayList<String>();
 
 		for(File f : files){
-			if(hasFileWithSuffix(f, fileSuffix)) validFiles[validCounter++] = f.getName();
+			if(hasFileWithSuffix(f, fileSuffix)) ret.add(f.getName());
 		}
-		String[] ret = new String[validCounter];
-		System.arraycopy(validFiles, 0, ret, 0, validCounter);
 		return ret;
 	}