project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomActivity.java
changeset 10017 de822cd3df3a
parent 7586 33924ff4af50
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
    42 
    42 
    43 /**
    43 /**
    44  * This activity is used to set up and start a local game.
    44  * This activity is used to set up and start a local game.
    45  */
    45  */
    46 public class LocalRoomActivity extends FragmentActivity implements RoomStateManager.Provider, TeamAddDialog.Listener {
    46 public class LocalRoomActivity extends FragmentActivity implements RoomStateManager.Provider, TeamAddDialog.Listener {
    47 	private TabHost tabHost;
    47     private TabHost tabHost;
    48 	private RoomStateManager stateManager;
    48     private RoomStateManager stateManager;
    49 	private Button startButton;
    49     private Button startButton;
    50 	
    50 
    51     @Override
    51     @Override
    52     protected void onCreate(Bundle icicle) {
    52     protected void onCreate(Bundle icicle) {
    53         super.onCreate(icicle);
    53         super.onCreate(icicle);
    54         // TODO find a better central location / way to set up the default scheme and weaponset
    54         // TODO find a better central location / way to set up the default scheme and weaponset
    55         Netplay netplay = Netplay.getAppInstance(getApplicationContext());
    55         Netplay netplay = Netplay.getAppInstance(getApplicationContext());
    56         stateManager = new LocalRoomStateManager(netplay.defaultScheme, netplay.defaultWeaponset);
    56         stateManager = new LocalRoomStateManager(netplay.defaultScheme, netplay.defaultWeaponset);
    57         
    57 
    58         setContentView(R.layout.activity_localroom);
    58         setContentView(R.layout.activity_localroom);
    59         startButton = (Button)findViewById(R.id.startGame);
    59         startButton = (Button)findViewById(R.id.startGame);
    60         
    60 
    61         startButton.setOnClickListener(startButtonClickListener);
    61         startButton.setOnClickListener(startButtonClickListener);
    62         
    62 
    63         // Set up a tabbed UI for medium and small screens
    63         // Set up a tabbed UI for medium and small screens
    64         tabHost = (TabHost)findViewById(android.R.id.tabhost);
    64         tabHost = (TabHost)findViewById(android.R.id.tabhost);
    65         if(tabHost != null) {
    65         if(tabHost != null) {
    66 	        tabHost.setup();
    66             tabHost.setup();
    67 	        tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
    67             tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL);
    68 
    68 
    69 	        tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
    69             tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment));
    70 	        tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
    70             tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment));
    71 	        tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
    71             tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer));
    72 	        
    72 
    73 	        if (icicle != null) {
    73             if (icicle != null) {
    74 	            tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
    74                 tabHost.setCurrentTabByTag(icicle.getString("currentTab"));
    75 	        }
    75             }
    76         }
    76         }
    77     }
    77     }
    78     
    78 
    79     @Override
    79     @Override
    80     protected void onSaveInstanceState(Bundle icicle) {
    80     protected void onSaveInstanceState(Bundle icicle) {
    81         super.onSaveInstanceState(icicle);
    81         super.onSaveInstanceState(icicle);
    82         if(tabHost != null) {
    82         if(tabHost != null) {
    83         	icicle.putString("currentTab", tabHost.getCurrentTabTag());
    83             icicle.putString("currentTab", tabHost.getCurrentTabTag());
    84         }
    84         }
    85     }
    85     }
    86     
       
    87 	public void onTeamAddDialogSubmitted(Team newTeam) {
       
    88 		stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
       
    89 	}
       
    90 	
       
    91 	public RoomStateManager getRoomStateManager() {
       
    92 		return stateManager;
       
    93 	}
       
    94 
    86 
    95 	private final OnClickListener startButtonClickListener = new OnClickListener() {
    87     public void onTeamAddDialogSubmitted(Team newTeam) {
    96 		public void onClick(View v) {
    88         stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values()));
    97 			Map<String, TeamInGame> teams = stateManager.getTeams();
    89     }
    98 			Set<Integer> clanColors = new TreeSet<Integer>();
    90 
    99 			for(TeamInGame t : teams.values()) {
    91     public RoomStateManager getRoomStateManager() {
   100 				clanColors.add(t.ingameAttribs.colorIndex);
    92         return stateManager;
   101 			}
    93     }
   102 			if(clanColors.size()<2) {
    94 
   103 				if(tabHost != null) {
    95     private final OnClickListener startButtonClickListener = new OnClickListener() {
   104 					tabHost.setCurrentTabByTag("teams");
    96         public void onClick(View v) {
   105 				}
    97             Map<String, TeamInGame> teams = stateManager.getTeams();
   106 				int errortext = teams.size()<2 ? R.string.not_enough_teams : R.string.not_enough_clans;
    98             Set<Integer> clanColors = new TreeSet<Integer>();
   107 				Toast.makeText(getApplicationContext(), errortext, Toast.LENGTH_SHORT).show();
    99             for(TeamInGame t : teams.values()) {
   108 				return;
   100                 clanColors.add(t.ingameAttribs.colorIndex);
   109 			}
   101             }
   110 			
   102             if(clanColors.size()<2) {
   111 			SDLActivity.startNetgame = false;
   103                 if(tabHost != null) {
   112 			SDLActivity.startConfig = new GameConfig(
   104                     tabHost.setCurrentTabByTag("teams");
   113 					stateManager.getGameStyle(),
   105                 }
   114 					stateManager.getScheme(),
   106                 int errortext = teams.size()<2 ? R.string.not_enough_teams : R.string.not_enough_clans;
   115 					stateManager.getMapRecipe(),
   107                 Toast.makeText(getApplicationContext(), errortext, Toast.LENGTH_SHORT).show();
   116 					new ArrayList<TeamInGame>(stateManager.getTeams().values()),
   108                 return;
   117 					stateManager.getWeaponset());
   109             }
   118 			startActivity(new Intent(LocalRoomActivity.this, SDLActivity.class));
   110 
   119 		}
   111             SDLActivity.startNetgame = false;
   120 	};
   112             SDLActivity.startConfig = new GameConfig(
       
   113                     stateManager.getGameStyle(),
       
   114                     stateManager.getScheme(),
       
   115                     stateManager.getMapRecipe(),
       
   116                     new ArrayList<TeamInGame>(stateManager.getTeams().values()),
       
   117                     stateManager.getWeaponset());
       
   118             startActivity(new Intent(LocalRoomActivity.this, SDLActivity.class));
       
   119         }
       
   120     };
   121 }
   121 }