26 import org.hedgewars.hedgeroid.EngineProtocol.Team; |
26 import org.hedgewars.hedgeroid.EngineProtocol.Team; |
27 import org.hedgewars.hedgeroid.EngineProtocol.Weapon; |
27 import org.hedgewars.hedgeroid.EngineProtocol.Weapon; |
28 |
28 |
29 import android.app.Activity; |
29 import android.app.Activity; |
30 import android.content.Intent; |
30 import android.content.Intent; |
|
31 import android.content.SharedPreferences; |
31 import android.graphics.drawable.Drawable; |
32 import android.graphics.drawable.Drawable; |
32 import android.os.Bundle; |
33 import android.os.Bundle; |
33 import android.os.Parcelable; |
34 import android.os.Parcelable; |
|
35 import android.preference.PreferenceManager; |
34 import android.view.View; |
36 import android.view.View; |
35 import android.view.View.OnClickListener; |
37 import android.view.View.OnClickListener; |
36 import android.widget.AdapterView; |
38 import android.widget.AdapterView; |
37 import android.widget.AdapterView.OnItemSelectedListener; |
39 import android.widget.AdapterView.OnItemSelectedListener; |
38 import android.widget.ArrayAdapter; |
40 import android.widget.ArrayAdapter; |
51 private ImageView themeIcon, mapPreview, teamCount; |
53 private ImageView themeIcon, mapPreview, teamCount; |
52 |
54 |
53 public void onCreate(Bundle savedInstanceState){ |
55 public void onCreate(Bundle savedInstanceState){ |
54 super.onCreate(savedInstanceState); |
56 super.onCreate(savedInstanceState); |
55 |
57 |
56 //SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
58 SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); |
|
59 boolean firstTime = sharedPref.getBoolean("firstTime", true); |
57 //Copy all the xml files to the device TODO only do first time launch of the app... |
60 //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); |
61 if(firstTime){ |
59 Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); |
62 sharedPref.edit().putBoolean("firstTime", false).commit(); |
60 Scheme.parseBasicFlags(this); |
63 |
|
64 Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); |
|
65 Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); |
|
66 Utils.resRawToFilesDir(this, R.array.teams, Team.DIRECTORY_TEAMS); |
|
67 Scheme.parseBasicFlags(this); |
|
68 } |
61 |
69 |
62 config = new GameConfig(); |
70 config = new GameConfig(); |
63 |
71 |
64 setContentView(R.layout.starting_game); |
72 setContentView(R.layout.starting_game); |
65 |
73 |
74 themes = (Spinner) findViewById(R.id.spinTheme); |
82 themes = (Spinner) findViewById(R.id.spinTheme); |
75 |
83 |
76 themeIcon = (ImageView) findViewById(R.id.imgTheme); |
84 themeIcon = (ImageView) findViewById(R.id.imgTheme); |
77 mapPreview = (ImageView) findViewById(R.id.mapPreview); |
85 mapPreview = (ImageView) findViewById(R.id.mapPreview); |
78 teamCount = (ImageView) findViewById(R.id.imgTeamsCount); |
86 teamCount = (ImageView) findViewById(R.id.imgTeamsCount); |
79 |
87 |
80 start.setOnClickListener(startClicker); |
88 start.setOnClickListener(startClicker); |
81 back.setOnClickListener(backClicker); |
89 back.setOnClickListener(backClicker); |
82 team.setOnClickListener(teamClicker); |
90 team.setOnClickListener(teamClicker); |
83 |
91 |
84 ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
92 ArrayAdapter<?> adapter = new ArrayAdapter<Map>(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); |
111 private void startTeamsActivity(){ |
119 private void startTeamsActivity(){ |
112 Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); |
120 Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); |
113 i.putParcelableArrayListExtra("teams", config.teams); |
121 i.putParcelableArrayListExtra("teams", config.teams); |
114 startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); |
122 startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); |
115 } |
123 } |
116 |
124 |
117 public void onActivityResult(int requestCode, int resultCode, Intent data){ |
125 public void onActivityResult(int requestCode, int resultCode, Intent data){ |
118 switch(requestCode){ |
126 switch(requestCode){ |
119 case ACTIVITY_TEAM_SELECTOR: |
127 case ACTIVITY_TEAM_SELECTOR: |
120 if(resultCode == Activity.RESULT_OK){ |
128 if(resultCode == Activity.RESULT_OK){ |
121 Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); |
129 Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); |
122 config.teams.clear(); |
130 config.teams.clear(); |
123 for(Parcelable t : parcelables){ |
131 for(Parcelable t : parcelables){ |
124 config.teams.add((Team)t); |
132 config.teams.add((Team)t); |
125 } |
133 } |
126 teamCount.getDrawable().setLevel(config.teams.size()); |
134 teamCount.getDrawable().setLevel(config.teams.size()); |
127 } |
135 } |
128 break; |
136 break; |
129 } |
137 } |
130 } |
138 } |
131 |
139 |