author | Xeli |
Sun, 21 Aug 2011 18:14:49 +0200 | |
branch | hedgeroid |
changeset 5625 | 9add7b92c5f0 |
parent 5621 | ea796c83ea47 |
child 5627 | ce2d92589cbc |
permissions | -rw-r--r-- |
5621 | 1 |
/* |
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
||
5433 | 20 |
package org.hedgewars.mobile; |
21 |
||
5471 | 22 |
import org.hedgewars.mobile.EngineProtocol.FrontendDataUtils; |
23 |
import org.hedgewars.mobile.EngineProtocol.GameConfig; |
|
24 |
import org.hedgewars.mobile.EngineProtocol.Map; |
|
25 |
import org.hedgewars.mobile.EngineProtocol.Scheme; |
|
26 |
import org.hedgewars.mobile.EngineProtocol.Team; |
|
27 |
import org.hedgewars.mobile.EngineProtocol.Weapon; |
|
28 |
||
5433 | 29 |
import android.app.Activity; |
5471 | 30 |
import android.content.Intent; |
5433 | 31 |
import android.graphics.drawable.Drawable; |
32 |
import android.os.Bundle; |
|
5471 | 33 |
import android.os.Parcelable; |
5433 | 34 |
import android.view.View; |
5471 | 35 |
import android.view.View.OnClickListener; |
5433 | 36 |
import android.widget.AdapterView; |
37 |
import android.widget.AdapterView.OnItemSelectedListener; |
|
38 |
import android.widget.ArrayAdapter; |
|
5471 | 39 |
import android.widget.ImageButton; |
5433 | 40 |
import android.widget.ImageView; |
41 |
import android.widget.Spinner; |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
42 |
import android.widget.Toast; |
5433 | 43 |
|
44 |
public class StartGameActivity extends Activity { |
|
45 |
||
5471 | 46 |
public static final int ACTIVITY_TEAM_SELECTOR = 0; |
47 |
||
48 |
private GameConfig config = null; |
|
49 |
private ImageButton start, back, team; |
|
5433 | 50 |
private Spinner maps, gameplay, gamescheme, weapons, themes; |
5471 | 51 |
private ImageView themeIcon, mapPreview; |
52 |
||
5433 | 53 |
public void onCreate(Bundle savedInstanceState){ |
54 |
super.onCreate(savedInstanceState); |
|
5471 | 55 |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
56 |
//SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
57 |
//Copy all the xml files to the device TODO only do first time launch of the app... |
5471 | 58 |
Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); |
59 |
Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); |
|
60 |
Scheme.parseBasicFlags(this); |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
61 |
|
5471 | 62 |
config = new GameConfig(); |
63 |
||
5433 | 64 |
setContentView(R.layout.starting_game); |
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
65 |
|
5471 | 66 |
back = (ImageButton) findViewById(R.id.btnBack); |
67 |
team = (ImageButton) findViewById(R.id.btnTeams); |
|
68 |
start = (ImageButton) findViewById(R.id.btnStart); |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
69 |
|
5433 | 70 |
maps = (Spinner) findViewById(R.id.spinMaps); |
71 |
gameplay = (Spinner) findViewById(R.id.spinGameplay); |
|
72 |
gamescheme = (Spinner) findViewById(R.id.spinGamescheme); |
|
73 |
weapons = (Spinner) findViewById(R.id.spinweapons); |
|
74 |
themes = (Spinner) findViewById(R.id.spinTheme); |
|
5471 | 75 |
|
5433 | 76 |
themeIcon = (ImageView) findViewById(R.id.imgTheme); |
5471 | 77 |
mapPreview = (ImageView) findViewById(R.id.mapPreview); |
78 |
||
79 |
start.setOnClickListener(startClicker); |
|
80 |
back.setOnClickListener(backClicker); |
|
81 |
team.setOnClickListener(teamClicker); |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
82 |
|
5607 | 83 |
ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
5433 | 84 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
85 |
maps.setAdapter(adapter); |
|
5471 | 86 |
maps.setOnItemSelectedListener(mapsClicker); |
87 |
||
88 |
adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this)); |
|
5433 | 89 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
90 |
gameplay.setAdapter(adapter); |
|
5471 | 91 |
gameplay.setOnItemSelectedListener(gameplayClicker); |
5433 | 92 |
|
5471 | 93 |
adapter = new ArrayAdapter<Scheme>(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this)); |
5433 | 94 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
95 |
gamescheme.setAdapter(adapter); |
|
5471 | 96 |
gamescheme.setOnItemSelectedListener(schemeClicker); |
5433 | 97 |
|
5471 | 98 |
adapter = new ArrayAdapter<Weapon>(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this)); |
5433 | 99 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
100 |
weapons.setAdapter(adapter); |
|
5471 | 101 |
weapons.setOnItemSelectedListener(weaponClicker); |
102 |
||
103 |
adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getThemes(this)); |
|
5433 | 104 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
105 |
themes.setAdapter(adapter); |
|
106 |
themes.setOnItemSelectedListener(themesClicker); |
|
5471 | 107 |
|
5433 | 108 |
} |
5471 | 109 |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
110 |
private void startTeamsActivity(){ |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
111 |
Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
112 |
i.putParcelableArrayListExtra("teams", config.teams); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
113 |
startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
114 |
} |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
115 |
|
5471 | 116 |
public void onActivityResult(int requestCode, int resultCode, Intent data){ |
117 |
switch(requestCode){ |
|
118 |
case ACTIVITY_TEAM_SELECTOR: |
|
119 |
if(resultCode == Activity.RESULT_OK){ |
|
120 |
Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); |
|
121 |
config.teams.clear(); |
|
122 |
for(Parcelable t : parcelables){ |
|
123 |
config.teams.add((Team)t); |
|
124 |
} |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
125 |
|
5471 | 126 |
} |
127 |
break; |
|
128 |
} |
|
129 |
} |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
130 |
|
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
131 |
|
5433 | 132 |
private OnItemSelectedListener themesClicker = new OnItemSelectedListener(){ |
133 |
||
134 |
public void onItemSelected(AdapterView<?> arg0, View view, int position, long rowId) { |
|
135 |
String themeName = (String) arg0.getAdapter().getItem(position); |
|
5471 | 136 |
Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "Themes/" + themeName + "/icon@2X.png"); |
5433 | 137 |
themeIcon.setImageDrawable(themeIconDrawable); |
5471 | 138 |
config.theme = themeName; |
139 |
} |
|
140 |
||
141 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
142 |
} |
|
143 |
||
144 |
}; |
|
145 |
||
146 |
private OnItemSelectedListener mapsClicker = new OnItemSelectedListener(){ |
|
147 |
||
148 |
public void onItemSelected(AdapterView<?> arg0, View view, int position,long rowId) { |
|
149 |
Map map = (Map)arg0.getAdapter().getItem(position); |
|
150 |
mapPreview.setImageDrawable(map.getDrawable()); |
|
151 |
config.map = map; |
|
5433 | 152 |
} |
153 |
||
154 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
5471 | 155 |
} |
156 |
||
157 |
}; |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
158 |
|
5471 | 159 |
private OnItemSelectedListener weaponClicker = new OnItemSelectedListener(){ |
160 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
161 |
config.weapon = (Weapon)arg0.getAdapter().getItem(arg2); |
|
162 |
} |
|
163 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
164 |
|
5471 | 165 |
} |
166 |
}; |
|
167 |
private OnItemSelectedListener schemeClicker = new OnItemSelectedListener(){ |
|
168 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
169 |
config.scheme = (Scheme)arg0.getAdapter().getItem(arg2); |
|
170 |
} |
|
171 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
172 |
|
5433 | 173 |
} |
5471 | 174 |
}; |
175 |
private OnItemSelectedListener gameplayClicker = new OnItemSelectedListener(){ |
|
176 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
177 |
//config = ()arg0.getAdapter().getItem(arg2); |
|
178 |
} |
|
179 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
180 |
|
5471 | 181 |
} |
5433 | 182 |
}; |
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
183 |
|
5471 | 184 |
private OnClickListener startClicker = new OnClickListener(){ |
185 |
public void onClick(View v) { |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
186 |
if(config.teams.size() < 2){ |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
187 |
Toast.makeText(StartGameActivity.this, R.string.not_enough_teams, Toast.LENGTH_LONG).show(); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
188 |
startTeamsActivity(); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
189 |
} |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
190 |
else{ |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
191 |
Intent i = new Intent(StartGameActivity.this, SDLActivity.class); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
192 |
i.putExtra("config", config); |
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
193 |
startActivity(i);} |
5471 | 194 |
} |
195 |
}; |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
196 |
|
5471 | 197 |
private OnClickListener backClicker = new OnClickListener(){ |
198 |
public void onClick(View v) { |
|
199 |
finish(); |
|
200 |
} |
|
201 |
}; |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
202 |
|
5471 | 203 |
private OnClickListener teamClicker = new OnClickListener(){ |
204 |
public void onClick(View v) { |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
205 |
startTeamsActivity(); |
5471 | 206 |
} |
207 |
}; |
|
208 |
||
5433 | 209 |
} |