|
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.hedgeroid; |
|
21 |
|
22 import org.hedgewars.hedgeroid.EngineProtocol.FrontendDataUtils; |
|
23 import org.hedgewars.hedgeroid.EngineProtocol.GameConfig; |
|
24 import org.hedgewars.hedgeroid.EngineProtocol.Map; |
|
25 import org.hedgewars.hedgeroid.EngineProtocol.Scheme; |
|
26 import org.hedgewars.hedgeroid.EngineProtocol.Team; |
|
27 import org.hedgewars.hedgeroid.EngineProtocol.Weapon; |
|
28 import org.hedgewars.mobile.R; |
|
29 |
|
30 import android.app.Activity; |
|
31 import android.content.Intent; |
|
32 import android.graphics.drawable.Drawable; |
|
33 import android.os.Bundle; |
|
34 import android.os.Parcelable; |
|
35 import android.view.View; |
|
36 import android.view.View.OnClickListener; |
|
37 import android.widget.AdapterView; |
|
38 import android.widget.AdapterView.OnItemSelectedListener; |
|
39 import android.widget.ArrayAdapter; |
|
40 import android.widget.ImageButton; |
|
41 import android.widget.ImageView; |
|
42 import android.widget.Spinner; |
|
43 import android.widget.Toast; |
|
44 |
|
45 public class StartGameActivity extends Activity { |
|
46 |
|
47 public static final int ACTIVITY_TEAM_SELECTOR = 0; |
|
48 |
|
49 private GameConfig config = null; |
|
50 private ImageButton start, back, team; |
|
51 private Spinner maps, gameplay, gamescheme, weapons, themes; |
|
52 private ImageView themeIcon, mapPreview, teamCount; |
|
53 |
|
54 public void onCreate(Bundle savedInstanceState){ |
|
55 super.onCreate(savedInstanceState); |
|
56 |
|
57 //SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
|
58 //Copy all the xml files to the device TODO only do first time launch of the app... |
|
59 Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); |
|
60 Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); |
|
61 Scheme.parseBasicFlags(this); |
|
62 |
|
63 config = new GameConfig(); |
|
64 |
|
65 setContentView(R.layout.starting_game); |
|
66 |
|
67 back = (ImageButton) findViewById(R.id.btnBack); |
|
68 team = (ImageButton) findViewById(R.id.btnTeams); |
|
69 start = (ImageButton) findViewById(R.id.btnStart); |
|
70 |
|
71 maps = (Spinner) findViewById(R.id.spinMaps); |
|
72 gameplay = (Spinner) findViewById(R.id.spinGameplay); |
|
73 gamescheme = (Spinner) findViewById(R.id.spinGamescheme); |
|
74 weapons = (Spinner) findViewById(R.id.spinweapons); |
|
75 themes = (Spinner) findViewById(R.id.spinTheme); |
|
76 |
|
77 themeIcon = (ImageView) findViewById(R.id.imgTheme); |
|
78 mapPreview = (ImageView) findViewById(R.id.mapPreview); |
|
79 teamCount = (ImageView) findViewById(R.id.imgTeamsCount); |
|
80 |
|
81 start.setOnClickListener(startClicker); |
|
82 back.setOnClickListener(backClicker); |
|
83 team.setOnClickListener(teamClicker); |
|
84 |
|
85 ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
|
86 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
87 maps.setAdapter(adapter); |
|
88 maps.setOnItemSelectedListener(mapsClicker); |
|
89 |
|
90 adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this)); |
|
91 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
92 gameplay.setAdapter(adapter); |
|
93 gameplay.setOnItemSelectedListener(gameplayClicker); |
|
94 |
|
95 adapter = new ArrayAdapter<Scheme>(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this)); |
|
96 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
97 gamescheme.setAdapter(adapter); |
|
98 gamescheme.setOnItemSelectedListener(schemeClicker); |
|
99 |
|
100 adapter = new ArrayAdapter<Weapon>(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this)); |
|
101 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
102 weapons.setAdapter(adapter); |
|
103 weapons.setOnItemSelectedListener(weaponClicker); |
|
104 |
|
105 adapter = new ArrayAdapter<String>(this, R.layout.listview_item, FrontendDataUtils.getThemes(this)); |
|
106 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
107 themes.setAdapter(adapter); |
|
108 themes.setOnItemSelectedListener(themesClicker); |
|
109 |
|
110 } |
|
111 |
|
112 private void startTeamsActivity(){ |
|
113 Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); |
|
114 i.putParcelableArrayListExtra("teams", config.teams); |
|
115 startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); |
|
116 } |
|
117 |
|
118 public void onActivityResult(int requestCode, int resultCode, Intent data){ |
|
119 switch(requestCode){ |
|
120 case ACTIVITY_TEAM_SELECTOR: |
|
121 if(resultCode == Activity.RESULT_OK){ |
|
122 Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); |
|
123 config.teams.clear(); |
|
124 for(Parcelable t : parcelables){ |
|
125 config.teams.add((Team)t); |
|
126 } |
|
127 teamCount.getDrawable().setLevel(config.teams.size()); |
|
128 } |
|
129 break; |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 private OnItemSelectedListener themesClicker = new OnItemSelectedListener(){ |
|
135 |
|
136 public void onItemSelected(AdapterView<?> arg0, View view, int position, long rowId) { |
|
137 String themeName = (String) arg0.getAdapter().getItem(position); |
|
138 Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "Themes/" + themeName + "/icon@2X.png"); |
|
139 themeIcon.setImageDrawable(themeIconDrawable); |
|
140 config.theme = themeName; |
|
141 } |
|
142 |
|
143 public void onNothingSelected(AdapterView<?> arg0) { |
|
144 } |
|
145 |
|
146 }; |
|
147 |
|
148 private OnItemSelectedListener mapsClicker = new OnItemSelectedListener(){ |
|
149 |
|
150 public void onItemSelected(AdapterView<?> arg0, View view, int position,long rowId) { |
|
151 Map map = (Map)arg0.getAdapter().getItem(position); |
|
152 mapPreview.setImageDrawable(map.getDrawable()); |
|
153 config.map = map; |
|
154 } |
|
155 |
|
156 public void onNothingSelected(AdapterView<?> arg0) { |
|
157 } |
|
158 |
|
159 }; |
|
160 |
|
161 private OnItemSelectedListener weaponClicker = new OnItemSelectedListener(){ |
|
162 public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
163 config.weapon = (Weapon)arg0.getAdapter().getItem(arg2); |
|
164 } |
|
165 public void onNothingSelected(AdapterView<?> arg0) { |
|
166 |
|
167 } |
|
168 }; |
|
169 private OnItemSelectedListener schemeClicker = new OnItemSelectedListener(){ |
|
170 public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
171 config.scheme = (Scheme)arg0.getAdapter().getItem(arg2); |
|
172 } |
|
173 public void onNothingSelected(AdapterView<?> arg0) { |
|
174 |
|
175 } |
|
176 }; |
|
177 private OnItemSelectedListener gameplayClicker = new OnItemSelectedListener(){ |
|
178 public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { |
|
179 //config = ()arg0.getAdapter().getItem(arg2); |
|
180 } |
|
181 public void onNothingSelected(AdapterView<?> arg0) { |
|
182 |
|
183 } |
|
184 }; |
|
185 |
|
186 private OnClickListener startClicker = new OnClickListener(){ |
|
187 public void onClick(View v) { |
|
188 if(config.teams.size() < 2){ |
|
189 Toast.makeText(StartGameActivity.this, R.string.not_enough_teams, Toast.LENGTH_LONG).show(); |
|
190 startTeamsActivity(); |
|
191 } |
|
192 else{ |
|
193 Intent i = new Intent(StartGameActivity.this, SDLActivity.class); |
|
194 i.putExtra("config", config); |
|
195 startActivity(i);} |
|
196 } |
|
197 }; |
|
198 |
|
199 private OnClickListener backClicker = new OnClickListener(){ |
|
200 public void onClick(View v) { |
|
201 finish(); |
|
202 } |
|
203 }; |
|
204 |
|
205 private OnClickListener teamClicker = new OnClickListener(){ |
|
206 public void onClick(View v) { |
|
207 startTeamsActivity(); |
|
208 } |
|
209 }; |
|
210 |
|
211 } |