project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/MapFile.java
changeset 7508 763d3961400b
parent 7485 0481bd74267c
child 7584 7831c84cc644
equal deleted inserted replaced
7504:ed1d52c5aa94 7508:763d3961400b
     1 package org.hedgewars.hedgeroid.Datastructures;
     1 package org.hedgewars.hedgeroid.Datastructures;
     2 
     2 
     3 import java.io.File;
     3 import java.io.File;
     4 import java.io.FileNotFoundException;
     4 import java.io.FileNotFoundException;
       
     5 import java.util.ArrayList;
     5 import java.util.Comparator;
     6 import java.util.Comparator;
       
     7 import java.util.List;
     6 
     8 
     7 import org.hedgewars.hedgeroid.Utils;
     9 import org.hedgewars.hedgeroid.R;
       
    10 import org.hedgewars.hedgeroid.util.FileUtils;
     8 
    11 
     9 import android.content.Context;
    12 import android.content.Context;
    10 import android.widget.AdapterView.OnItemSelectedListener;
    13 import android.content.res.Resources;
    11 
    14 
    12 /**
    15 /**
    13  * Represents a map from the data directory
    16  * Represents a map from the data directory
    14  */
    17  */
    15 public final class MapFile {
    18 public final class MapFile {
    16 	public static final String MISSION_PREFIX = "Mission: "; // TODO move text generation to UI to allow translation
       
    17 	public static final String MAP_DIRECTORY = "Maps";
    19 	public static final String MAP_DIRECTORY = "Maps";
    18 	
    20 	
    19 	public final String name;
    21 	public final String name;
    20 	public final boolean isMission;
    22 	public final boolean isMission;
    21 	
    23 	
    26 	
    28 	
    27 	/**
    29 	/**
    28 	 * @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
    30 	 * @throws FileNotFoundException if the sdcard is not available. Does NOT throw if the requested map file does not exist.
    29 	 */
    31 	 */
    30 	public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
    32 	public static File getFileForMapname(Context ctx, String mapname) throws FileNotFoundException {
    31 		return new File(new File(Utils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
    33 		return new File(new File(FileUtils.getDataPathFile(ctx), MAP_DIRECTORY), mapname);
    32 	}
    34 	}
    33 	
    35 	
    34 	public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
    36 	public static final Comparator<MapFile> MISSIONS_FIRST_NAME_ORDER = new Comparator<MapFile>() {
    35 		public int compare(MapFile lhs, MapFile rhs) {
    37 		public int compare(MapFile lhs, MapFile rhs) {
    36 			if(lhs.isMission != rhs.isMission) {
    38 			if(lhs.isMission != rhs.isMission) {
    41 		}
    43 		}
    42 	};
    44 	};
    43 	
    45 	
    44 	@Override
    46 	@Override
    45 	public String toString() {
    47 	public String toString() {
    46 		return (isMission ? MISSION_PREFIX : "") + name;
    48 		return "MapFile [name=" + name + ", isMission=" + isMission + "]";
    47 	}
    49 	}
    48 
    50 
    49 	public File getPreviewFile(Context c) throws FileNotFoundException {
    51 	public File getPreviewFile(Context c) throws FileNotFoundException {
    50 		return new File(new File(new File(Utils.getDataPathFile(c), MAP_DIRECTORY), name), "preview.png");
    52 		return getPreviewFile(c, name);
    51 	};
    53 	}
       
    54 	
       
    55 	public static File getPreviewFile(Context c, String mapName) throws FileNotFoundException {
       
    56 		return new File(FileUtils.getDataPathFile(c), MAP_DIRECTORY + "/" + mapName + "/" + "preview.png");
       
    57 	}
       
    58 	
       
    59 	public static List<String> toDisplayNameList(List<MapFile> mapFiles, Resources res) {
       
    60 		String missionPrefix = res.getString(R.string.map_mission_prefix);
       
    61 		List<String> result = new ArrayList<String>();
       
    62 		for(MapFile mapFile : mapFiles) {
       
    63 			result.add((mapFile.isMission ? missionPrefix : "") + mapFile.name);
       
    64 		}
       
    65 		return result;
       
    66 	}
    52 }
    67 }