# HG changeset patch # User Xeli # Date 1313943289 -7200 # Node ID 9add7b92c5f08ceb76bb93763061f35672f943fc # Parent df23b477609dcd07601073c2fc064ece61b4b926 Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu diff -r df23b477609d -r 9add7b92c5f0 project_files/Android-build/SDL-android-project/res/layout/team_selector.xml --- a/project_files/Android-build/SDL-android-project/res/layout/team_selector.xml Sun Aug 21 18:13:11 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/res/layout/team_selector.xml Sun Aug 21 18:14:49 2011 +0200 @@ -28,8 +28,7 @@ android:layout_alignTop="@id/btnBack" android:layout_margin="3dp" android:gravity="center" - android:background="@drawable/box" - android:text="bla"/> + android:background="@drawable/box"/> diff -r df23b477609d -r 9add7b92c5f0 project_files/Android-build/SDL-android-project/res/values/strings.xml --- a/project_files/Android-build/SDL-android-project/res/values/strings.xml Sun Aug 21 18:13:11 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/res/values/strings.xml Sun Aug 21 18:14:49 2011 +0200 @@ -29,6 +29,11 @@ Filter Themes + + + + Not enough teams + Selected teams = %d Name Unnamed diff -r df23b477609d -r 9add7b92c5f0 project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java Sun Aug 21 18:13:11 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java Sun Aug 21 18:14:49 2011 +0200 @@ -19,8 +19,6 @@ package org.hedgewars.mobile; -import java.util.ArrayList; - import org.hedgewars.mobile.EngineProtocol.FrontendDataUtils; import org.hedgewars.mobile.EngineProtocol.GameConfig; import org.hedgewars.mobile.EngineProtocol.Map; @@ -30,12 +28,9 @@ import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Parcelable; -import android.preference.PreferenceManager; -import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; @@ -44,6 +39,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.Spinner; +import android.widget.Toast; public class StartGameActivity extends Activity { @@ -57,19 +53,20 @@ public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - + //SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + //Copy all the xml files to the device TODO only do first time launch of the app... Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); Scheme.parseBasicFlags(this); + config = new GameConfig(); setContentView(R.layout.starting_game); - + back = (ImageButton) findViewById(R.id.btnBack); team = (ImageButton) findViewById(R.id.btnTeams); start = (ImageButton) findViewById(R.id.btnStart); - + maps = (Spinner) findViewById(R.id.spinMaps); gameplay = (Spinner) findViewById(R.id.spinGameplay); gamescheme = (Spinner) findViewById(R.id.spinGamescheme); @@ -82,7 +79,7 @@ start.setOnClickListener(startClicker); back.setOnClickListener(backClicker); team.setOnClickListener(teamClicker); - + ArrayAdapter adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtils.getMaps(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); maps.setAdapter(adapter); @@ -110,6 +107,12 @@ } + private void startTeamsActivity(){ + Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); + i.putParcelableArrayListExtra("teams", config.teams); + startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); + } + public void onActivityResult(int requestCode, int resultCode, Intent data){ switch(requestCode){ case ACTIVITY_TEAM_SELECTOR: @@ -119,13 +122,13 @@ for(Parcelable t : parcelables){ config.teams.add((Team)t); } - + } break; } } - - + + private OnItemSelectedListener themesClicker = new OnItemSelectedListener(){ public void onItemSelected(AdapterView arg0, View view, int position, long rowId) { @@ -152,13 +155,13 @@ } }; - + private OnItemSelectedListener weaponClicker = new OnItemSelectedListener(){ public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { config.weapon = (Weapon)arg0.getAdapter().getItem(arg2); } public void onNothingSelected(AdapterView arg0) { - + } }; private OnItemSelectedListener schemeClicker = new OnItemSelectedListener(){ @@ -166,7 +169,7 @@ config.scheme = (Scheme)arg0.getAdapter().getItem(arg2); } public void onNothingSelected(AdapterView arg0) { - + } }; private OnItemSelectedListener gameplayClicker = new OnItemSelectedListener(){ @@ -174,29 +177,32 @@ //config = ()arg0.getAdapter().getItem(arg2); } public void onNothingSelected(AdapterView arg0) { - + } }; - + private OnClickListener startClicker = new OnClickListener(){ public void onClick(View v) { - Intent i = new Intent(StartGameActivity.this, SDLActivity.class); - i.putExtra("config", config); - startActivity(i); + if(config.teams.size() < 2){ + Toast.makeText(StartGameActivity.this, R.string.not_enough_teams, Toast.LENGTH_LONG).show(); + startTeamsActivity(); + } + else{ + Intent i = new Intent(StartGameActivity.this, SDLActivity.class); + i.putExtra("config", config); + startActivity(i);} } }; - + private OnClickListener backClicker = new OnClickListener(){ public void onClick(View v) { finish(); } }; - + private OnClickListener teamClicker = new OnClickListener(){ public void onClick(View v) { - Intent i = new Intent(StartGameActivity.this, TeamSelectionActivity.class); - i.putParcelableArrayListExtra("teams", config.teams); - startActivityForResult(i, ACTIVITY_TEAM_SELECTOR); + startTeamsActivity(); } }; diff -r df23b477609d -r 9add7b92c5f0 project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java Sun Aug 21 18:13:11 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java Sun Aug 21 18:14:49 2011 +0200 @@ -43,6 +43,7 @@ import android.widget.RelativeLayout; import android.widget.SimpleAdapter; import android.widget.SimpleAdapter.ViewBinder; +import android.widget.TextView; public class TeamSelectionActivity extends Activity{ @@ -51,6 +52,7 @@ private ImageButton addTeam, back; private ListView availableTeams, selectedTeams; private ArrayList> availableTeamsList, selectedTeamsList; + private TextView txtInfo; private int minTeams = 2; public void onCreate(Bundle savedInstanceState){ @@ -60,7 +62,8 @@ addTeam = (ImageButton) findViewById(R.id.btnAdd); back = (ImageButton) findViewById(R.id.btnBack); - + txtInfo = (TextView) findViewById(R.id.txtInfo); + addTeam.setOnClickListener(addTeamClicker); back.setOnClickListener(backClicker); @@ -90,6 +93,7 @@ selectedTeams.setAdapter(adapter); selectedTeams.setOnItemClickListener(selectedClicker); + txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeams.getChildCount())); } private ViewBinder viewBinder = new ViewBinder(){ @@ -218,6 +222,8 @@ selectedTeamsList.remove(position); ((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); ((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); + + txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size())); } }; @@ -266,6 +272,8 @@ availableTeamsList.remove(position); ((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); ((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); + + txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size())); } private void returnTeams(){