author | nemo |
Thu, 12 Mar 2020 15:07:32 -0400 | |
changeset 15571 | 608b5de819a5 |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
/* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
* Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com> |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
4 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
* |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
6 |
* 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
|
7 |
* 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
|
8 |
* 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
|
9 |
* of the License, or (at your option) any later version. |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
* 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
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
* GNU General Public License for more details. |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
* |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
* 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
|
17 |
* along with this program; if not, write to the Free Software |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7582
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 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
package org.hedgewars.hedgeroid; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
import java.util.ArrayList; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
import java.util.Collections; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
import java.util.HashMap; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
import java.util.List; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
import java.util.Map; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
import org.hedgewars.hedgeroid.Datastructures.FrontendDataUtils; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
import org.hedgewars.hedgeroid.Datastructures.Team; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
import android.app.ListActivity; |
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.view.ContextMenu; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
import android.view.MenuItem; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
import android.view.View; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
import android.view.View.OnClickListener; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
import android.widget.AdapterView; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
import android.widget.AdapterView.OnItemClickListener; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
import android.widget.ImageButton; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
import android.widget.SimpleAdapter; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
|
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
public class TeamListActivity extends ListActivity implements OnItemClickListener { |
10017 | 46 |
private List<Team> teams; |
47 |
private ImageButton addButton; |
|
48 |
||
49 |
@Override |
|
50 |
protected void onCreate(Bundle savedInstanceState) { |
|
51 |
super.onCreate(savedInstanceState); |
|
52 |
setContentView(R.layout.activity_teamlist); |
|
53 |
addButton = (ImageButton)findViewById(R.id.btnAdd); |
|
54 |
addButton.setOnClickListener(new OnClickListener() { |
|
55 |
public void onClick(View v) { |
|
56 |
editTeam(null); |
|
57 |
} |
|
58 |
}); |
|
59 |
} |
|
60 |
||
61 |
@Override |
|
62 |
public void onResume() { |
|
63 |
super.onResume(); |
|
64 |
updateList(); |
|
65 |
getListView().setOnItemClickListener(this); |
|
66 |
registerForContextMenu(getListView()); |
|
67 |
} |
|
68 |
||
69 |
public void onItemClick(AdapterView<?> adapterView, View v, int position, long arg3) { |
|
70 |
editTeam(teams.get(position).name); |
|
71 |
} |
|
72 |
||
73 |
@Override |
|
74 |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){ |
|
75 |
menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.edit); |
|
76 |
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete); |
|
77 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
|
10017 | 79 |
@Override |
80 |
public boolean onContextItemSelected(MenuItem item){ |
|
81 |
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); |
|
82 |
int position = menuInfo.position; |
|
83 |
Team team = teams.get(position); |
|
84 |
switch(item.getItemId()){ |
|
85 |
case 0: |
|
86 |
editTeam(team.name); |
|
87 |
return true; |
|
88 |
case 1: |
|
89 |
Team.getTeamfileByName(getApplicationContext(), team.name).delete(); |
|
90 |
updateList(); |
|
91 |
return true; |
|
92 |
} |
|
93 |
return false; |
|
94 |
} |
|
95 |
||
96 |
private void updateList() { |
|
97 |
teams = FrontendDataUtils.getTeams(getApplicationContext()); |
|
98 |
Collections.sort(teams, Team.NAME_ORDER); |
|
99 |
SimpleAdapter adapter = new SimpleAdapter(this, teamsToMaps(teams), R.layout.team_selection_entry_simple, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); |
|
100 |
setListAdapter(adapter); |
|
101 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
102 |
|
10017 | 103 |
private void editTeam(String teamName) { |
104 |
Intent i = new Intent(this, TeamCreatorActivity.class); |
|
105 |
i.putExtra(TeamCreatorActivity.PARAMETER_EXISTING_TEAMNAME, teamName); |
|
106 |
startActivity(i); |
|
107 |
} |
|
108 |
||
109 |
private static final int[] botlevelDrawables = new int[] { |
|
110 |
R.drawable.human, R.drawable.bot5, R.drawable.bot4, R.drawable.bot3, R.drawable.bot2, R.drawable.bot1 |
|
111 |
}; |
|
112 |
||
113 |
private List<Map<String, ?>> teamsToMaps(List<Team> teams) { |
|
114 |
List<Map<String, ?>> result = new ArrayList<Map<String,?>>(); |
|
115 |
for(Team t : teams) { |
|
116 |
HashMap<String, Object> map = new HashMap<String, Object>(); |
|
117 |
map.put("team", t); |
|
118 |
map.put("txt", t.name); |
|
119 |
int botlevel = t.hogs.get(0).level; |
|
120 |
if(botlevel<0 || botlevel>=botlevelDrawables.length) { |
|
121 |
map.put("img", R.drawable.bot1); |
|
122 |
} else { |
|
123 |
map.put("img", botlevelDrawables[botlevel]); |
|
124 |
} |
|
125 |
result.add(map); |
|
126 |
} |
|
127 |
return result; |
|
128 |
} |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
129 |
} |