# HG changeset patch # User Xeli # Date 1312472142 -7200 # Node ID 081bc0170623697e4be3b21acd1741af78a446c3 # Parent 2ad2a4261b56b16c7f5b3306a82e6b9a3fced3aa Main activity for starting a local game diff -r 2ad2a4261b56 -r 081bc0170623 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 Thu Aug 04 17:34:57 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/StartGameActivity.java Thu Aug 04 17:35:42 2011 +0200 @@ -1,77 +1,184 @@ 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; +import org.hedgewars.mobile.EngineProtocol.Scheme; +import org.hedgewars.mobile.EngineProtocol.Team; +import org.hedgewars.mobile.EngineProtocol.Weapon; + 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; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.Spinner; public class StartGameActivity extends Activity { + public static final int ACTIVITY_TEAM_SELECTOR = 0; + + private GameConfig config = null; + private ImageButton start, back, team; private Spinner maps, gameplay, gamescheme, weapons, themes; - private ImageView themeIcon; - + private ImageView themeIcon, mapPreview; + public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); - + + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + + 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); weapons = (Spinner) findViewById(R.id.spinweapons); themes = (Spinner) findViewById(R.id.spinTheme); - + themeIcon = (ImageView) findViewById(R.id.imgTheme); + mapPreview = (ImageView) findViewById(R.id.mapPreview); + + start.setOnClickListener(startClicker); + back.setOnClickListener(backClicker); + team.setOnClickListener(teamClicker); - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, FrontendDataUtil.getMaps(this)); + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, FrontendDataUtils.getMaps(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); maps.setAdapter(adapter); - - adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtil.getGameplay(this)); + maps.setOnItemSelectedListener(mapsClicker); + + adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtils.getGameplay(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); gameplay.setAdapter(adapter); + gameplay.setOnItemSelectedListener(gameplayClicker); - adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtil.getSchemes(this)); + adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtils.getSchemes(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); gamescheme.setAdapter(adapter); + gamescheme.setOnItemSelectedListener(schemeClicker); - adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtil.getWeapons(this)); + adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtils.getWeapons(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); weapons.setAdapter(adapter); - - adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtil.getThemes(this)); + weapons.setOnItemSelectedListener(weaponClicker); + + adapter = new ArrayAdapter(this, R.layout.listview_item, FrontendDataUtils.getThemes(this)); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); themes.setAdapter(adapter); - - themes.setOnItemSelectedListener(themesClicker); - - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - - Utils.resRawToFilesDir(this,R.array.schemes, Scheme.DIRECTORY_SCHEME); - Utils.resRawToFilesDir(this, R.array.weapons, Weapon.DIRECTORY_WEAPON); + } + + public void onActivityResult(int requestCode, int resultCode, Intent data){ + switch(requestCode){ + case ACTIVITY_TEAM_SELECTOR: + if(resultCode == Activity.RESULT_OK){ + Parcelable[] parcelables = (Parcelable[])data.getParcelableArrayExtra("teams"); + config.teams.clear(); + 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) { String themeName = (String) arg0.getAdapter().getItem(position); - Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "/Data/Themes/" + themeName + "/icon@2X.png"); + Drawable themeIconDrawable = Drawable.createFromPath(Utils.getDownloadPath(StartGameActivity.this) + "Themes/" + themeName + "/icon@2X.png"); themeIcon.setImageDrawable(themeIconDrawable); + config.theme = themeName; + } + + public void onNothingSelected(AdapterView arg0) { + } + + }; + + private OnItemSelectedListener mapsClicker = new OnItemSelectedListener(){ + + public void onItemSelected(AdapterView arg0, View view, int position,long rowId) { + Map map = (Map)arg0.getAdapter().getItem(position); + mapPreview.setImageDrawable(map.getDrawable()); + config.map = map; } public void onNothingSelected(AdapterView arg0) { - // TODO Auto-generated method stub + } + + }; + + 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(){ + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + config.scheme = (Scheme)arg0.getAdapter().getItem(arg2); + } + public void onNothingSelected(AdapterView arg0) { } - + }; + private OnItemSelectedListener gameplayClicker = new OnItemSelectedListener(){ + public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { + //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); + } + }; + + 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); + } + }; + }