author | unc0rr |
Sat, 14 Nov 2015 22:19:05 +0300 | |
changeset 11381 | 437a60995fe1 |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
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:
7508
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
4 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
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:
7508
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:
7508
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:
7508
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:
7508
diff
changeset
|
9 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
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:
7508
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:
7508
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
13 |
* GNU General Public License for more details. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
14 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
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:
7508
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:
7508
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:
7508
diff
changeset
|
18 |
*/ |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
19 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
package org.hedgewars.hedgeroid; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
import org.hedgewars.hedgeroid.NetplayStateFragment.NetplayStateListener; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
import org.hedgewars.hedgeroid.netplay.Netplay.State; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
import org.hedgewars.hedgeroid.util.TextInputDialog; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
import org.hedgewars.hedgeroid.util.TextInputDialog.TextInputDialogListener; |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
27 |
import org.hedgewars.hedgeroid.util.UiUtils; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
import android.content.Intent; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
import android.os.Bundle; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
import android.support.v4.app.FragmentActivity; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
import android.support.v4.app.FragmentTransaction; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
import android.view.Menu; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
import android.view.MenuItem; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
import android.widget.LinearLayout; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
import android.widget.TabHost; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
38 |
/** |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
39 |
* Activity for the server lobby of a hedgewars server. Allows you to chat, join |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
40 |
* and create rooms and interact with a list of players. |
10017 | 41 |
* |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
42 |
* Most of the functionality is handled by various fragments. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
43 |
*/ |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
public class LobbyActivity extends FragmentActivity implements TextInputDialogListener, NetplayStateListener { |
10017 | 45 |
private static final int DIALOG_CREATE_ROOM = 0; |
46 |
||
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
private TabHost tabHost; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
private Netplay netplay; |
10017 | 49 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
protected void onCreate(Bundle icicle) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
super.onCreate(icicle); |
10017 | 53 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
setContentView(R.layout.activity_lobby); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
ChatFragment chatFragment = (ChatFragment)getSupportFragmentManager().findFragmentById(R.id.chatFragment); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
chatFragment.setInRoom(false); |
10017 | 57 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
trans.add(new NetplayStateFragment(), "netplayFragment"); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
trans.commit(); |
10017 | 61 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
netplay = Netplay.getAppInstance(getApplicationContext()); |
10017 | 63 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
64 |
// Set up a tabbed UI for medium and small screens |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
tabHost = (TabHost)findViewById(android.R.id.tabhost); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
if(tabHost != null) { |
10017 | 67 |
tabHost.setup(); |
68 |
tabHost.getTabWidget().setOrientation(LinearLayout.VERTICAL); |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
|
10017 | 70 |
tabHost.addTab(tabHost.newTabSpec("rooms").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_rooms, R.drawable.roomlist_ingame)).setContent(R.id.roomListFragment)); |
71 |
tabHost.addTab(tabHost.newTabSpec("chat").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_chat, R.drawable.edit)).setContent(R.id.chatFragment)); |
|
72 |
tabHost.addTab(tabHost.newTabSpec("players").setIndicator(UiUtils.createVerticalTabIndicator(tabHost, R.string.lobby_tab_players, R.drawable.human)).setContent(R.id.playerListFragment)); |
|
73 |
||
74 |
if (icicle != null) { |
|
75 |
tabHost.setCurrentTabByTag(icicle.getString("currentTab")); |
|
76 |
} |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
} |
10017 | 79 |
|
80 |
@Override |
|
81 |
public boolean onCreateOptionsMenu(Menu menu) { |
|
82 |
super.onCreateOptionsMenu(menu); |
|
83 |
getMenuInflater().inflate(R.menu.lobby_options, menu); |
|
84 |
return true; |
|
85 |
} |
|
86 |
||
87 |
@Override |
|
88 |
public boolean onOptionsItemSelected(MenuItem item) { |
|
89 |
switch(item.getItemId()) { |
|
90 |
case R.id.room_create: |
|
91 |
TextInputDialog dialog = new TextInputDialog(DIALOG_CREATE_ROOM, R.string.dialog_create_room_title, 0, R.string.dialog_create_room_hint); |
|
92 |
dialog.show(getSupportFragmentManager(), "create_room_dialog"); |
|
93 |
return true; |
|
94 |
case R.id.disconnect: |
|
95 |
netplay.disconnect(); |
|
96 |
return true; |
|
97 |
default: |
|
98 |
return super.onOptionsItemSelected(item); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
@Override |
|
103 |
public void onBackPressed() { |
|
104 |
netplay.disconnect(); |
|
105 |
} |
|
106 |
||
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
108 |
protected void onSaveInstanceState(Bundle icicle) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
109 |
super.onSaveInstanceState(icicle); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
if(tabHost != null) { |
10017 | 111 |
icicle.putString("currentTab", tabHost.getCurrentTabTag()); |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
112 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
113 |
} |
10017 | 114 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
115 |
public void onTextInputDialogSubmitted(int dialogId, String text) { |
10017 | 116 |
if(text != null && text.length()>0) { |
117 |
netplay.sendCreateRoom(text); |
|
118 |
} |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
119 |
} |
10017 | 120 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
121 |
public void onTextInputDialogCancelled(int dialogId) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
122 |
} |
10017 | 123 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
124 |
public void onNetplayStateChanged(State newState) { |
10017 | 125 |
switch(newState) { |
126 |
case CONNECTING: |
|
127 |
case NOT_CONNECTED: |
|
128 |
finish(); |
|
129 |
break; |
|
130 |
case ROOM: |
|
131 |
startActivity(new Intent(getApplicationContext(), NetRoomActivity.class)); |
|
132 |
break; |
|
133 |
case LOBBY: |
|
134 |
// Do nothing |
|
135 |
break; |
|
136 |
default: |
|
137 |
throw new IllegalStateException("Unknown connection state: "+newState); |
|
138 |
} |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
139 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
140 |
} |