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