project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/EngineProtocol/FrontendDataUtils.java
author Xeli
Sun, 21 Aug 2011 16:25:18 +0200
branchhedgeroid
changeset 5621 ea796c83ea47
parent 5603 4e4a579a60af
permissions -rw-r--r--
added licenses
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5621
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     1
/*
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     3
 * Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com>
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     4
 *
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     8
 *
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    12
 * GNU General Public License for more details.
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    13
 *
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    14
 * You should have received a copy of the GNU General Public License
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    15
 * along with this program; if not, write to the Free Software
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    17
 */
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    18
ea796c83ea47 added licenses
Xeli
parents: 5603
diff changeset
    19
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    20
package org.hedgewars.mobile.EngineProtocol;
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    21
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    22
import java.io.File;
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    23
import java.util.ArrayList;
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    24
import java.util.Arrays;
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    25
import java.util.Collections;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    26
import java.util.HashMap;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    27
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    28
import org.hedgewars.mobile.R;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    29
import org.hedgewars.mobile.Utils;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    30
import org.hedgewars.mobile.EngineProtocol.Map.MapType;
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    31
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    32
import android.content.Context;
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    33
import android.graphics.Bitmap;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    34
import android.graphics.BitmapFactory;
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    35
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    36
public class FrontendDataUtils {
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    37
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    38
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    39
	public static ArrayList<Map> getMaps(Context c){
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    40
		File[] files = Utils.getFilesFromRelativeDir(c,"Maps");
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    41
		ArrayList<Map> ret = new ArrayList<Map>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    42
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    43
		for(File f : files){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    44
			if(Utils.hasFileWithSuffix(f, ".lua")){
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    45
				ret.add(new Map(f,MapType.TYPE_MISSION, c));
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    46
			}else{
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    47
				ret.add(new Map(f, MapType.TYPE_DEFAULT,c));
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    48
			}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    49
		}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    50
		Collections.sort(ret);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    51
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    52
		return ret;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    53
	}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    54
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    55
	public static String[] getGameplay(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    56
		String[] files = Utils.getFileNamesFromRelativeDir(c, "Scripts/Multiplayer");
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    57
		int retCounter = 0;
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    58
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    59
		for(int i = 0; i < files.length; i++){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    60
			if(files[i].endsWith(".lua")){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    61
				files[i] = files[i].replace('_', ' ').substring(0, files[i].length()-4); //replace _ by a space and removed the last four characters (.lua)
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    62
				retCounter++;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    63
			}else files[i] = null;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    64
		}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    65
		String[] ret = new String[retCounter];
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    66
		retCounter = 0;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    67
		for(String s : files){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    68
			if(s != null) ret[retCounter++] = s;
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    69
		}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    70
		Arrays.sort(ret);
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    71
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    72
		return ret;	
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    73
	}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    74
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    75
	public static String[] getThemes(Context c){
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    76
		return Utils.getDirsWithFileSuffix(c, "Themes", "icon.png");
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    77
	}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    78
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    79
	public static ArrayList<Scheme> getSchemes(Context c){
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    80
		return Scheme.getSchemes(c);
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
    81
	}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    82
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    83
	public static ArrayList<Weapon> getWeapons(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    84
		return Weapon.getWeapons(c);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    85
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    86
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    87
	public static ArrayList<HashMap<String, ?>> getGraves(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    88
		String pathPrefix = Utils.getDownloadPath(c) + "Graphics/Graves/";
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    89
		ArrayList<String> names = Utils.getFilesFromDirWithSuffix(c, "Graphics/Graves", ".png", true);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    90
		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size());
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    91
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    92
		for(String s : names){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    93
			HashMap<String, Object> map = new HashMap<String, Object>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    94
			map.put("txt", s);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    95
			Bitmap b = BitmapFactory.decodeFile(pathPrefix + s + ".png");//create a full path - decode to to a bitmap
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    96
			int width = b.getWidth();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    97
			if(b.getHeight() > width){//some pictures contain more 'frames' underneath each other, if so we only use the first frame
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    98
				Bitmap tmp = Bitmap.createBitmap(b, 0, 0, width, width);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
    99
				b.recycle();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   100
				b = tmp;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   101
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   102
			map.put("img", b);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   103
			data.add(map);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   104
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   105
		return data;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   106
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   107
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   108
	public static ArrayList<HashMap<String, ?>> getFlags(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   109
		String pathPrefix = Utils.getDownloadPath(c) + "Graphics/Flags/";
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   110
		ArrayList<String> names = Utils.getFilesFromDirWithSuffix(c, "Graphics/Flags", ".png", true);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   111
		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(names.size());
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   112
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   113
		for(String s : names){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   114
			HashMap<String, Object> map = new HashMap<String, Object>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   115
			map.put("txt", s);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   116
			Bitmap b = BitmapFactory.decodeFile(pathPrefix + s + ".png");//create a full path - decode to to a bitmap
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   117
			map.put("img", b);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   118
			data.add(map);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   119
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   120
		return data;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   121
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   122
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   123
	public static ArrayList<String> getVoices(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   124
		File[] files = Utils.getFilesFromRelativeDir(c, "Sounds/voices");
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   125
		ArrayList<String> ret = new ArrayList<String>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   126
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   127
		for(File f : files){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   128
			if(f.isDirectory()) ret.add(f.getName());
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   129
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   130
		return ret;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   131
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   132
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   133
	public static ArrayList<String> getForts(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   134
		return Utils.getFilesFromDirWithSuffix(c, "Forts", "L.png", true);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   135
	}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   136
	public static ArrayList<HashMap<String, ?>> getTypes(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   137
		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(6);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   138
		String[] levels = {c.getString(R.string.human), c.getString(R.string.bot5), c.getString(R.string.bot4), c.getString(R.string.bot3), c.getString(R.string.bot2), c.getString(R.string.bot1)};
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   139
		int[] images = {R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1};
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   140
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   141
		for(int i = 0; i < levels.length; i++){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   142
			HashMap<String, Object> map = new HashMap<String, Object>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   143
			map.put("txt", levels[i]);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   144
			map.put("img", images[i]);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   145
			data.add(map);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   146
		}
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   147
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   148
		return data;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   149
	}
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   150
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   151
	public static ArrayList<HashMap<String, ?>> getHats(Context c){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   152
		ArrayList<String> files = Utils.getFilesFromDirWithSuffix(c, "Graphics/Hats", ".png", true);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   153
		String pathPrefix = Utils.getDownloadPath(c) + "Graphics/Hats/";
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   154
		int size = files.size();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   155
		ArrayList<HashMap<String, ?>> data = new ArrayList<HashMap<String, ?>>(size);
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   156
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   157
		HashMap<String, Object> hashmap; 
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   158
		for(String s : files){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   159
			hashmap = new HashMap<String, Object>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   160
			hashmap.put("txt", s);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   161
			Bitmap b = BitmapFactory.decodeFile(pathPrefix + s + ".png");//create a full path - decode to to a bitmap
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   162
			b = Bitmap.createBitmap(b, 0,0,b.getWidth()/2, b.getWidth()/2);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   163
			hashmap.put("img", b);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   164
			data.add(hashmap);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   165
		}
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   166
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   167
		return data;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   168
	}
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   169
5603
4e4a579a60af Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents: 5534
diff changeset
   170
	public static ArrayList<HashMap<String, Object>> getTeams(Context c){
4e4a579a60af Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents: 5534
diff changeset
   171
		ArrayList<HashMap<String, Object>> ret = new ArrayList<HashMap<String, Object>>();
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   172
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   173
		File teamsDir = new File(c.getFilesDir().getAbsolutePath() + '/' + Team.DIRECTORY_TEAMS);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   174
		File[] teamFileNames = teamsDir.listFiles();
5534
7f3a391a66fb typo on the nullpointer check
Xeli
parents: 5532
diff changeset
   175
		if(teamFileNames != null){
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   176
			for(File s : teamFileNames){
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   177
				Team t = Team.getTeamFromXml(s.getAbsolutePath());
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   178
				if(t != null){
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   179
					ret.add(teamToHashMap(t));
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   180
				}
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   181
			}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   182
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   183
		return ret;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   184
	}
5532
3d7ac2b3b703 Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents: 5467
diff changeset
   185
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   186
	public static HashMap<String, Object> teamToHashMap(Team t){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   187
		HashMap<String, Object> hashmap = new HashMap<String, Object>();
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   188
		hashmap.put("team", t);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   189
		hashmap.put("txt", t.name);
5603
4e4a579a60af Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents: 5534
diff changeset
   190
		hashmap.put("color", t.color);
4e4a579a60af Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents: 5534
diff changeset
   191
		hashmap.put("count", t.hogCount);
5467
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   192
		switch(t.levels[0]){
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   193
		case 0:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   194
			hashmap.put("img", R.drawable.human);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   195
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   196
		case 1:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   197
			hashmap.put("img", R.drawable.bot5);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   198
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   199
		case 2:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   200
			hashmap.put("img", R.drawable.bot4);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   201
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   202
		case 3:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   203
			hashmap.put("img", R.drawable.bot3);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   204
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   205
		case 4:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   206
			hashmap.put("img", R.drawable.bot2);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   207
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   208
		default:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   209
		case 5:
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   210
			hashmap.put("img", R.drawable.bot1);
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   211
			break;
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   212
		}
88e25840f532 Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents: 5433
diff changeset
   213
		return hashmap;
5433
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
   214
	}
8f82045953c1 Main class files for the start-local-game screen
Xeli
parents:
diff changeset
   215
}