author | Medo <smaxein@googlemail.com> |
Thu, 23 Aug 2012 18:28:33 +0200 | |
changeset 7588 | 27e5857da6af |
parent 7584 | 7831c84cc644 |
child 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.R; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
import org.hedgewars.hedgeroid.Datastructures.Player; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
import org.hedgewars.hedgeroid.netplay.Netplay; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
import android.os.Bundle; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
import android.support.v4.app.ListFragment; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
import android.view.ContextMenu; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
import android.view.ContextMenu.ContextMenuInfo; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
import android.view.LayoutInflater; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
import android.view.MenuInflater; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
import android.view.MenuItem; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
import android.view.View; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
import android.view.ViewGroup; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
37 |
/** |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
38 |
* Shows the list of players in the lobby and allows some interactions with them |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
39 |
* over the context menu. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
40 |
*/ |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
public class LobbyPlayerlistFragment extends ListFragment { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
private Netplay netplay; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
private LobbyPlayerlistAdapter adapter; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
public void onCreate(Bundle savedInstanceState) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
super.onCreate(savedInstanceState); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
adapter = new LobbyPlayerlistAdapter(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
adapter.setSource(netplay.lobbyPlayerlist); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
setListAdapter(adapter); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
public void onDestroy() { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
super.onDestroy(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
adapter.invalidate(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
public void onActivityCreated(Bundle savedInstanceState) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
super.onActivityCreated(savedInstanceState); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
registerForContextMenu(getListView()); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
public void onCreateContextMenu(ContextMenu menu, View v, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
ContextMenuInfo menuInfo) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
super.onCreateContextMenu(menu, v, menuInfo); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
MenuInflater inflater = getActivity().getMenuInflater(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
inflater.inflate(R.menu.lobby_playerlist_context, menu); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
menu.setHeaderIcon(R.drawable.human); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
menu.setHeaderTitle(adapter.getItem(info.position).name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
public boolean onContextItemSelected(MenuItem item) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
Player player = adapter.getItem(info.position); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
switch(item.getItemId()) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
case R.id.player_info: |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
netplay.sendPlayerInfoQuery(player.name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
return true; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
case R.id.player_follow: |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
86 |
netplay.sendFollowPlayer(player.name); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
87 |
return true; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
88 |
default: |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
89 |
return super.onContextItemSelected(item); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
92 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
93 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
95 |
Bundle savedInstanceState) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
96 |
return inflater.inflate(R.layout.fragment_playerlist, container, false); |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
} |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
} |