author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 20 Feb 2018 14:03:46 +0100 | |
changeset 13036 | 434bcdd9562c |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
1 |
/* |
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 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
4 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
9 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
13 |
* GNU General Public License for more details. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
14 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
18 |
*/ |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
19 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
20 |
package org.hedgewars.hedgeroid; |
7449 | 21 |
|
22 |
import org.hedgewars.hedgeroid.R; |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
23 |
import org.hedgewars.hedgeroid.Datastructures.GameConfig; |
7485 | 24 |
import org.hedgewars.hedgeroid.Datastructures.Team; |
7568 | 25 |
import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
26 |
import org.hedgewars.hedgeroid.NetplayStateFragment.NetplayStateListener; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7485
diff
changeset
|
27 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.netplay.RunGameListener; |
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.netplay.Netplay.State; |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.util.UiUtils; |
7449 | 31 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
32 |
import android.content.Intent; |
7449 | 33 |
import android.os.Bundle; |
34 |
import android.support.v4.app.FragmentActivity; |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
35 |
import android.support.v4.app.FragmentTransaction; |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
36 |
import android.view.View; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
37 |
import android.view.View.OnClickListener; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
38 |
import android.widget.Button; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
39 |
import android.widget.LinearLayout; |
7449 | 40 |
import android.widget.TabHost; |
41 |
||
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
42 |
/** |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
43 |
* This activity is used to set up and start a game on the server. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
44 |
*/ |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
45 |
public class NetRoomActivity extends FragmentActivity implements NetplayStateListener, TeamAddDialog.Listener, RoomStateManager.Provider, RunGameListener { |
10017 | 46 |
private TabHost tabHost; |
47 |
private Netplay netplay; |
|
48 |
private RoomStateManager stateManager; |
|
49 |
private Button startButton; |
|
50 |
||
7449 | 51 |
@Override |
52 |
protected void onCreate(Bundle icicle) { |
|
53 |
super.onCreate(icicle); |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
54 |
netplay = Netplay.getAppInstance(getApplicationContext()); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
55 |
netplay.registerRunGameListener(this); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
56 |
stateManager = netplay.getRoomStateManager(); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
57 |
stateManager.addListener(roomStateChangeListener); |
10017 | 58 |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
59 |
setContentView(R.layout.activity_netroom); |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
60 |
startButton = (Button)findViewById(R.id.startGame); |
10017 | 61 |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
62 |
ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
63 |
chatFragment.setInRoom(true); |
10017 | 64 |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
65 |
FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
66 |
trans.add(new NetplayStateFragment(), "netplayFragment"); |
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
67 |
trans.commit(); |
10017 | 68 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
69 |
startButton.setVisibility(netplay.isChief() ? View.VISIBLE : View.GONE); |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
70 |
startButton.setOnClickListener(startButtonClickListener); |
10017 | 71 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
72 |
// Set up a tabbed UI for medium and small screens |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
73 |
tabHost = (TabHost)findViewById(android.R.id.tabhost); |
7449 | 74 |
if(tabHost != null) { |
10017 | 75 |
tabHost.setup(); |
76 |
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
|
7449 | 77 |
|
10017 | 78 |
tabHost.addTab(tabHost.newTabSpec("map").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_map, 0)).setContent(R.id.mapFragment)); |
79 |
tabHost.addTab(tabHost.newTabSpec("settings").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_settings, 0)).setContent(R.id.settingsFragment)); |
|
80 |
tabHost.addTab(tabHost.newTabSpec("teams").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_teams, 0)).setContent(R.id.teamlistFragment)); |
|
81 |
tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_chat, 0)).setContent(R.id.chatFragment)); |
|
82 |
tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.room_tab_players, 0)).setContent(R.id.playerListContainer)); |
|
83 |
||
84 |
if (icicle != null) { |
|
85 |
tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
|
86 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
87 |
} |
7449 | 88 |
} |
89 |
||
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
90 |
@Override |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
91 |
protected void onDestroy() { |
10017 | 92 |
super.onDestroy(); |
93 |
stateManager.removeListener(roomStateChangeListener); |
|
94 |
netplay.unregisterRunGameListener(this); |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
95 |
} |
10017 | 96 |
|
97 |
@Override |
|
98 |
public void onBackPressed() { |
|
99 |
netplay.sendLeaveRoom(null); |
|
100 |
} |
|
101 |
||
7449 | 102 |
@Override |
103 |
protected void onSaveInstanceState(Bundle icicle) { |
|
104 |
super.onSaveInstanceState(icicle); |
|
105 |
if(tabHost != null) { |
|
10017 | 106 |
icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
107 |
} |
|
108 |
} |
|
109 |
||
110 |
public void onNetplayStateChanged(State newState) { |
|
111 |
switch(newState) { |
|
112 |
case NOT_CONNECTED: |
|
113 |
case CONNECTING: |
|
114 |
case LOBBY: |
|
115 |
finish(); |
|
116 |
break; |
|
117 |
case ROOM: |
|
118 |
// Do nothing |
|
119 |
break; |
|
120 |
default: |
|
121 |
throw new IllegalStateException("Unknown connection state: "+newState); |
|
7449 | 122 |
} |
123 |
} |
|
10017 | 124 |
|
125 |
public void onTeamAddDialogSubmitted(Team newTeam) { |
|
126 |
stateManager.requestAddTeam(newTeam, TeamInGame.getUnusedOrRandomColorIndex(stateManager.getTeams().values())); |
|
127 |
} |
|
128 |
||
129 |
public RoomStateManager getRoomStateManager() { |
|
130 |
return stateManager; |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7449
diff
changeset
|
131 |
} |
10017 | 132 |
|
133 |
private final OnClickListener startButtonClickListener = new OnClickListener() { |
|
134 |
public void onClick(View v) { |
|
135 |
netplay.sendStartGame(); |
|
136 |
} |
|
137 |
}; |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7568
diff
changeset
|
138 |
|
10017 | 139 |
private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.ListenerAdapter() { |
140 |
@Override |
|
141 |
public void onChiefStatusChanged(boolean isChief) { |
|
142 |
startButton.setVisibility(isChief ? View.VISIBLE : View.GONE); |
|
143 |
} |
|
144 |
}; |
|
145 |
||
146 |
public void runGame(GameConfig config) { |
|
147 |
SDLActivity.startConfig = config; |
|
148 |
SDLActivity.startNetgame = true; |
|
149 |
startActivity(new Intent(this, SDLActivity.class)); |
|
150 |
} |
|
7449 | 151 |
} |