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 |
|
20 package org.hedgewars.mobile; |
|
21 |
|
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 |
|
29 import android.app.Activity; |
|
30 import android.content.Intent; |
|
31 import android.graphics.drawable.Drawable; |
|
32 import android.os.Bundle; |
|
33 import android.os.Parcelable; |
|
34 import android.view.View; |
|
35 import android.view.View.OnClickListener; |
|
36 import android.widget.AdapterView; |
|
37 import android.widget.AdapterView.OnItemSelectedListener; |
|
38 import android.widget.ArrayAdapter; |
|
39 import android.widget.ImageButton; |
|
40 import android.widget.ImageView; |
|
41 import android.widget.Spinner; |
|
42 import android.widget.Toast; |
|
43 |
|
44 public class StartGameActivity extends Activity { |
|
45 |
|
46 public static final int ACTIVITY_TEAM_SELECTOR = 0; |
|
47 |
|
48 private GameConfig config = null; |
|
49 private ImageButton start, back, team; |
|
50 private Spinner maps, gameplay, gamescheme, weapons, themes; |
|
51 private ImageView themeIcon, mapPreview, teamCount; |
|
52 |
|
53 public void onCreate(Bundle savedInstanceState){ |
|
54 super.onCreate(savedInstanceState); |
|
55 |
|
56 //SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
|
57 //Copy all the xml files to the device TODO only do first time launch of the app... |
|
58 Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); |
|
59 Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); |
|
60 Scheme.parseBasicFlags(this); |
|
61 |
|
62 config = new GameConfig(); |
|
63 |
|
64 setContentView(R.layout.starting_game); |
|
65 |
|
66 back = (ImageButton) findViewById(R.id.btnBack); |
|
67 team = (ImageButton) findViewById(R.id.btnTeams); |
|
68 start = (ImageButton) findViewById(R.id.btnStart); |
|
69 |
|
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); |
|
75 |
|
76 themeIcon = (ImageView) findViewById(R.id.imgTheme); |
|
77 mapPreview = (ImageView) findViewById(R.id.mapPreview); |
|
78 teamCount = (ImageView) findViewById(R.id.imgTeamsCount); |
|
79 |
|
80 start.setOnClickListener(startClicker); |
|
81 back.setOnClickListener(backClicker); |
|
82 team.setOnClickListener(teamClicker); |
|
83 |
|
84 ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
|
85 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
86 maps.setAdapter(adapter); |
|
87 maps.setOnItemSelectedListener(mapsClicker); |
|
88 |
|
89 adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this)); |
|
90 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
91 gameplay.setAdapter(adapter); |
|
92 gameplay.setOnItemSelectedListener(gameplayClicker); |
|
93 |
|
94 adapter = new ArrayAdapter<Scheme>(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this)); |
|
95 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
96 gamescheme.setAdapter(adapter); |
|
97 gamescheme.setOnItemSelectedListener(schemeClicker); |
|
98 |
|
99 adapter = new ArrayAdapter<Weapon>(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this)); |
|
100 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
101 weapons.setAdapter(adapter); |
|
102 weapons.setOnItemSelectedListener(weaponClicker); |
|
103 |
|
104 adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getThemes(this)); |
|
105 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
106 themes.setAdapter(adapter); |
|
107 themes.setOnItemSelectedListener(themesClicker); |
|
108 |
|
109 } |
|
110 |
|
111 private void startTeamsActivity(){ |
|
112 Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); |
|
113 i.putParcelableArrayListExtra("teams", config.teams); |
|
114 startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); |
|
115 } |
|
116 |
|
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 } |
|
126 teamCount.getDrawable().setLevel(config.teams.size()); |
|
127 } |
|
128 break; |
|
129 } |
|
130 } |
|
131 |
|
132 |
|
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); |
|
137 Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "Themes/" + themeName + "/icon@2X.png"); |
|
138 themeIcon.setImageDrawable(themeIconDrawable); |
|
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; |
|
153 } |
|
154 |
|
155 public void onNothingSelected(AdapterView<?> arg0) { |
|
156 } |
|
157 |
|
158 }; |
|
159 |
|
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) { |
|
165 |
|
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) { |
|
173 |
|
174 } |
|
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) { |
|
181 |
|
182 } |
|
183 }; |
|
184 |
|
185 private OnClickListener startClicker = new OnClickListener(){ |
|
186 public void onClick(View v) { |
|
187 if(config.teams.size() < 2){ |
|
188 Toast.makeText(StartGameActivity.this, R.string.not_enough_teams, Toast.LENGTH_LONG).show(); |
|
189 startTeamsActivity(); |
|
190 } |
|
191 else{ |
|
192 Intent i = new Intent(StartGameActivity.this, SDLActivity.class); |
|
193 i.putExtra("config", config); |
|
194 startActivity(i);} |
|
195 } |
|
196 }; |
|
197 |
|
198 private OnClickListener backClicker = new OnClickListener(){ |
|
199 public void onClick(View v) { |
|
200 finish(); |
|
201 } |
|
202 }; |
|
203 |
|
204 private OnClickListener teamClicker = new OnClickListener(){ |
|
205 public void onClick(View v) { |
|
206 startTeamsActivity(); |
|
207 } |
|
208 }; |
|
209 |
|
210 } |
|