author | Xeli |
Sun, 21 Aug 2011 19:57:06 +0200 | |
branch | hedgeroid |
changeset 5630 | a5a338628633 |
parent 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; |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
51 |
private ImageView themeIcon, mapPreview, teamCount; |
5471 | 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); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
78 |
teamCount = (ImageView) findViewById(R.id.imgTeamsCount); |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
79 |
|
5471 | 80 |
start.setOnClickListener(startClicker); |
81 |
back.setOnClickListener(backClicker); |
|
82 |
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
|
83 |
|
5607 | 84 |
ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
5433 | 85 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
86 |
maps.setAdapter(adapter); |
|
5471 | 87 |
maps.setOnItemSelectedListener(mapsClicker); |
88 |
||
89 |
adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this)); |
|
5433 | 90 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
91 |
gameplay.setAdapter(adapter); |
|
5471 | 92 |
gameplay.setOnItemSelectedListener(gameplayClicker); |
5433 | 93 |
|
5471 | 94 |
adapter = new ArrayAdapter<Scheme>(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this)); |
5433 | 95 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
96 |
gamescheme.setAdapter(adapter); |
|
5471 | 97 |
gamescheme.setOnItemSelectedListener(schemeClicker); |
5433 | 98 |
|
5471 | 99 |
adapter = new ArrayAdapter<Weapon>(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this)); |
5433 | 100 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
101 |
weapons.setAdapter(adapter); |
|
5471 | 102 |
weapons.setOnItemSelectedListener(weaponClicker); |
103 |
||
104 |
adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getThemes(this)); |
|
5433 | 105 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
106 |
themes.setAdapter(adapter); |
|
107 |
themes.setOnItemSelectedListener(themesClicker); |
|
5471 | 108 |
|
5433 | 109 |
} |
5471 | 110 |
|
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
} |
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
|
116 |
|
5471 | 117 |
public void onActivityResult(int requestCode, int resultCode, Intent data){ |
118 |
switch(requestCode){ |
|
119 |
case ACTIVITY_TEAM_SELECTOR: |
|
120 |
if(resultCode == Activity.RESULT_OK){ |
|
121 |
Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); |
|
122 |
config.teams.clear(); |
|
123 |
for(Parcelable t : parcelables){ |
|
124 |
config.teams.add((Team)t); |
|
125 |
} |
|
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
126 |
teamCount.getDrawable().setLevel(config.teams.size()); |
5471 | 127 |
} |
128 |
break; |
|
129 |
} |
|
130 |
} |
|
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
|
131 |
|
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
|
132 |
|
5433 | 133 |
private OnItemSelectedListener themesClicker = new OnItemSelectedListener(){ |
134 |
||
135 |
public void onItemSelected(AdapterView<?> arg0, View view, int position, long rowId) { |
|
136 |
String themeName = (String) arg0.getAdapter().getItem(position); |
|
5471 | 137 |
Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "Themes/" + themeName + "/icon@2X.png"); |
5433 | 138 |
themeIcon.setImageDrawable(themeIconDrawable); |
5471 | 139 |
config.theme = themeName; |
140 |
} |
|
141 |
||
142 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
143 |
} |
|
144 |
||
145 |
}; |
|
146 |
||
147 |
private OnItemSelectedListener mapsClicker = new OnItemSelectedListener(){ |
|
148 |
||
149 |
public void onItemSelected(AdapterView<?> arg0, View view, int position,long rowId) { |
|
150 |
Map map = (Map)arg0.getAdapter().getItem(position); |
|
151 |
mapPreview.setImageDrawable(map.getDrawable()); |
|
152 |
config.map = map; |
|
5433 | 153 |
} |
154 |
||
155 |
public void onNothingSelected(AdapterView<?> arg0) { |
|
5471 | 156 |
} |
157 |
||
158 |
}; |
|
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
|
159 |
|
5471 | 160 |
private OnItemSelectedListener weaponClicker = new OnItemSelectedListener(){ |
161 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
162 |
config.weapon = (Weapon)arg0.getAdapter().getItem(arg2); |
|
163 |
} |
|
164 |
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
|
165 |
|
5471 | 166 |
} |
167 |
}; |
|
168 |
private OnItemSelectedListener schemeClicker = new OnItemSelectedListener(){ |
|
169 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
170 |
config.scheme = (Scheme)arg0.getAdapter().getItem(arg2); |
|
171 |
} |
|
172 |
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
|
173 |
|
5433 | 174 |
} |
5471 | 175 |
}; |
176 |
private OnItemSelectedListener gameplayClicker = new OnItemSelectedListener(){ |
|
177 |
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
178 |
//config = ()arg0.getAdapter().getItem(arg2); |
|
179 |
} |
|
180 |
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
|
181 |
|
5471 | 182 |
} |
5433 | 183 |
}; |
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
|
184 |
|
5471 | 185 |
private OnClickListener startClicker = new OnClickListener(){ |
186 |
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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
} |
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 |
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
|
192 |
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
|
193 |
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
|
194 |
startActivity(i);} |
5471 | 195 |
} |
196 |
}; |
|
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
|
197 |
|
5471 | 198 |
private OnClickListener backClicker = new OnClickListener(){ |
199 |
public void onClick(View v) { |
|
200 |
finish(); |
|
201 |
} |
|
202 |
}; |
|
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
|
203 |
|
5471 | 204 |
private OnClickListener teamClicker = new OnClickListener(){ |
205 |
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
|
206 |
startTeamsActivity(); |
5471 | 207 |
} |
208 |
}; |
|
209 |
||
5433 | 210 |
} |