author | unc0rr |
Thu, 20 Feb 2014 01:32:37 +0400 | |
changeset 10148 | a599593e1dc2 |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
/* |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
*/ |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
package org.hedgewars.hedgeroid; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
import java.util.ArrayList; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
import java.util.Map; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
import java.util.Set; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
import java.util.TreeSet; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
import org.hedgewars.hedgeroid.Datastructures.GameConfig; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.Datastructures.Team; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
import org.hedgewars.hedgeroid.util.UiUtils; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
import android.content.Intent; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
import android.os.Bundle; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
import android.support.v4.app.FragmentActivity; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
import android.view.View; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
import android.view.View.OnClickListener; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
import android.widget.Button; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
import android.widget.LinearLayout; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
import android.widget.TabHost; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
import android.widget.Toast; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
/** |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
44 |
* This activity is used to set up and start a local game. |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
*/ |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
public class LocalRoomActivity extends FragmentActivity implements RoomStateManager.Provider, TeamAddDialog.Listener { |
10017 | 47 |
private TabHost tabHost; |
48 |
private RoomStateManager stateManager; |
|
49 |
private Button startButton; |
|
50 |
||
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
@Override |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
protected void onCreate(Bundle icicle) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
super.onCreate(icicle); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
// TODO find a better central location / way to set up the default scheme and weaponset |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
Netplay netplay = Netplay.getAppInstance(getApplicationContext()); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
stateManager = new LocalRoomStateManager(netplay.defaultScheme, netplay.defaultWeaponset); |
10017 | 57 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
setContentView(R.layout.activity_localroom); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
startButton = (Button)findViewById(R.id.startGame); |
10017 | 60 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
startButton.setOnClickListener(startButtonClickListener); |
10017 | 62 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
// Set up a tabbed UI for medium and small screens |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
tabHost = (TabHost)findViewById(android.R.id.tabhost); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
if(tabHost != null) { |
10017 | 66 |
tabHost.setup(); |
67 |
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
|
10017 | 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)); |
|
71 |
tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistContainer)); |
|
72 |
||
73 |
if (icicle != null) { |
|
74 |
tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
|
75 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
} |
10017 | 78 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
@Override |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
protected void onSaveInstanceState(Bundle icicle) { |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
super.onSaveInstanceState(icicle); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
if(tabHost != null) { |
10017 | 83 |
icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
} |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
} |
10017 | 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 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
|
10017 | 95 |
private final OnClickListener startButtonClickListener = new OnClickListener() { |
96 |
public void onClick(View v) { |
|
97 |
Map<String, TeamInGame> teams = stateManager.getTeams(); |
|
98 |
Set<Integer> clanColors = new TreeSet<Integer>(); |
|
99 |
for(TeamInGame t : teams.values()) { |
|
100 |
clanColors.add(t.ingameAttribs.colorIndex); |
|
101 |
} |
|
102 |
if(clanColors.size()<2) { |
|
103 |
if(tabHost != null) { |
|
104 |
tabHost.setCurrentTabByTag("teams"); |
|
105 |
} |
|
106 |
int errortext = teams.size()<2 ? R.string.not_enough_teams : R.string.not_enough_clans; |
|
107 |
Toast.makeText(getApplicationContext(), errortext, Toast.LENGTH_SHORT).show(); |
|
108 |
return; |
|
109 |
} |
|
110 |
||
111 |
SDLActivity.startNetgame = false; |
|
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 |
}; |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
} |