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