Sort the weapons/schemes/styles and give make give them a default value
authorXeli
Sat, 26 Nov 2011 16:18:44 +0100
changeset 6436 f1a42ba9cab2
parent 6435 356fbb672f84
child 6437 4ed58839b13b
child 6438 b3a8718ac2a0
Sort the weapons/schemes/styles and give make give them a default value
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/GameConfig.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
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/FrontendDataUtils.java	Sat Nov 26 11:47:31 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/FrontendDataUtils.java	Sat Nov 26 16:18:44 2011 +0100
@@ -24,6 +24,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 
 import org.hedgewars.hedgeroid.R;
 import org.hedgewars.hedgeroid.Utils;
@@ -52,23 +53,18 @@
 		return ret;
 	}
 
-	public static String[] getGameplay(Context c){
+	public static List<String> getGameplay(Context c){
 		String[] files = Utils.getFileNamesFromRelativeDir(c, "Scripts/Multiplayer");
-		int retCounter = 0;
-
+		ArrayList<String> ret = new ArrayList<String>();
+		
 		for(int i = 0; i < files.length; i++){
 			if(files[i].endsWith(".lua")){
-				files[i] = files[i].replace('_', ' ').substring(0, files[i].length()-4); //replace _ by a space and removed the last four characters (.lua)
-				retCounter++;
-			}else files[i] = null;
+				ret.add(files[i].replace('_', ' ').substring(0, files[i].length()-4)); //replace _ by a space and removed the last four characters (.lua)
+			}
 		}
-		String[] ret = new String[retCounter];
-		retCounter = 0;
-		for(String s : files){
-			if(s != null) ret[retCounter++] = s;
-		}
-		Arrays.sort(ret);
+		Collections.sort(ret);
 
+		ret.add(0,"None");
 		return ret;	
 	}
 
@@ -76,12 +72,16 @@
 		return Utils.getDirsWithFileSuffix(c, "Themes", "icon.png");
 	}
 
-	public static ArrayList<Scheme> getSchemes(Context c){
-		return Scheme.getSchemes(c);
+	public static List<Scheme> getSchemes(Context c){
+		List<Scheme> list = Scheme.getSchemes(c);
+		Collections.sort(list);
+		return list;
 	}
 
-	public static ArrayList<Weapon> getWeapons(Context c){
-		return Weapon.getWeapons(c);
+	public static List<Weapon> getWeapons(Context c){
+		List<Weapon> list = Weapon.getWeapons(c);
+		Collections.sort(list);
+		return list;
 	}
 
 	public static ArrayList<HashMap<String, ?>> getGraves(Context c){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/GameConfig.java	Sat Nov 26 11:47:31 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/GameConfig.java	Sat Nov 26 16:18:44 2011 +0100
@@ -34,7 +34,8 @@
 	public Scheme scheme = null;
 	public Weapon weapon = null;
 	
-	public String mission = null;
+	public String style = null;
+	public String training = null;
 	public String seed = null;
 	
 	public ArrayList<Team> teams = new ArrayList<Team>();
@@ -53,7 +54,8 @@
 		Log.d("HW_Frontend", "Sending Gameconfig...");
 		int teamCount = 4;
 		epn.sendToEngine("TL"); //Write game mode
-		if(mission != null) epn.sendToEngine(mission);
+		if(training != null) epn.sendToEngine(String.format("escript Scripts/Training/%s.lua", training));
+		else if(style != null) epn.sendToEngine(String.format("escript Scripts/Multiplayer/%s.lua", style));
 		
 		//seed info
 		epn.sendToEngine(String.format("eseed {%s}", UUID.randomUUID().toString()));
@@ -85,7 +87,8 @@
 		dest.writeString(theme);
 		dest.writeParcelable(scheme, flags);
 		dest.writeParcelable(weapon, flags);
-		dest.writeString(mission);
+		dest.writeString(style);
+		dest.writeString(training);
 		dest.writeString(seed);
 		dest.writeParcelableArray((Team[])teams.toArray(new Team[1]), 0);
 	}
@@ -96,7 +99,8 @@
 		theme = src.readString();
 		scheme = src.readParcelable(Scheme.class.getClassLoader());
 		weapon = src.readParcelable(Weapon.class.getClassLoader());
-		mission = src.readString();
+		style = src.readString();
+		training = src.readString();
 		seed = src.readString();
 		Parcelable[] parcelables = src.readParcelableArray(Team[].class.getClassLoader());
 		for(Parcelable team : parcelables){
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Scheme.java	Sat Nov 26 11:47:31 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Scheme.java	Sat Nov 26 16:18:44 2011 +0100
@@ -36,7 +36,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 
-public class Scheme implements Parcelable{
+public class Scheme implements Parcelable, Comparable<Scheme>{
 
 	public static final String DIRECTORY_SCHEME = "schemes";
 
@@ -355,4 +355,13 @@
 		}
 		
 	};
+
+	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);
+	}
 }
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java	Sat Nov 26 11:47:31 2011 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/EngineProtocol/Weapon.java	Sat Nov 26 16:18:44 2011 +0100
@@ -24,7 +24,6 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -33,8 +32,9 @@
 import android.content.Context;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.util.Log;
 
-public class Weapon implements Parcelable{
+public class Weapon implements Parcelable, Comparable<Weapon>{
 
 	public static final String DIRECTORY_WEAPON = "weapons";
 	
@@ -95,7 +95,6 @@
 		String dir = c.getFilesDir().getAbsolutePath() + '/' + DIRECTORY_WEAPON + '/';
 		String[] files = new File(dir).list();
 		if(files == null) files = new String[]{};
-		Arrays.sort(files);
 		
 		ArrayList<Weapon> weapons = new ArrayList<Weapon>();
 
@@ -209,4 +208,15 @@
 		}
 		
 	};
+
+	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);
+	}
+	
+	
 }