author | Xeli |
Sun, 21 Aug 2011 16:25:18 +0200 | |
branch | hedgeroid |
changeset 5621 | ea796c83ea47 |
parent 5603 | 4e4a579a60af |
child 5625 | 9add7b92c5f0 |
permissions | -rw-r--r-- |
5621 | 1 |
/* |
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2011 Richard Deurwaarder <xeli@xelification.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
||
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
20 |
package org.hedgewars.mobile; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
21 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
22 |
import java.io.File; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
23 |
import java.util.ArrayList; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
24 |
import java.util.HashMap; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
25 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
26 |
import org.hedgewars.mobile.EngineProtocol.FrontendDataUtils; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
27 |
import org.hedgewars.mobile.EngineProtocol.Team; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
28 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
29 |
import android.app.Activity; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
30 |
import android.content.Intent; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
31 |
import android.os.Bundle; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
32 |
import android.os.Parcelable; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
33 |
import android.view.ContextMenu; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
34 |
import android.view.MenuItem; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
35 |
import android.view.View; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
36 |
import android.view.View.OnClickListener; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
37 |
import android.widget.AdapterView; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
38 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
39 |
import android.widget.AdapterView.OnItemClickListener; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
40 |
import android.widget.ImageButton; |
5506 | 41 |
import android.widget.ImageView; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
42 |
import android.widget.ListView; |
5506 | 43 |
import android.widget.RelativeLayout; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
44 |
import android.widget.SimpleAdapter; |
5506 | 45 |
import android.widget.SimpleAdapter.ViewBinder; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
46 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
47 |
public class TeamSelectionActivity extends Activity{ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
48 |
|
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
49 |
private static final int ACTIVITY_TEAMCREATION = 0; |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
50 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
51 |
private ImageButton addTeam, back; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
52 |
private ListView availableTeams, selectedTeams; |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
53 |
private ArrayList<HashMap<String, Object>> availableTeamsList, selectedTeamsList; |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
54 |
private int minTeams = 2; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
55 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
56 |
public void onCreate(Bundle savedInstanceState){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
57 |
super.onCreate(savedInstanceState); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
58 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
59 |
setContentView(R.layout.team_selector); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
60 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
61 |
addTeam = (ImageButton) findViewById(R.id.btnAdd); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
62 |
back = (ImageButton) findViewById(R.id.btnBack); |
5506 | 63 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
64 |
addTeam.setOnClickListener(addTeamClicker); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
65 |
back.setOnClickListener(backClicker); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
66 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
67 |
availableTeams = (ListView) findViewById(R.id.availableTeams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
68 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
69 |
SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
70 |
availableTeams.setAdapter(adapter); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
71 |
registerForContextMenu(availableTeams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
72 |
availableTeams.setOnItemClickListener(availableClicker); |
5506 | 73 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
74 |
selectedTeams = (ListView) findViewById(R.id.selectedTeams); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
75 |
selectedTeamsList = new ArrayList<HashMap<String, Object>>(); |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
76 |
ArrayList<HashMap<String, ?>> toBeRemoved = new ArrayList<HashMap<String, ?>>(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
77 |
ArrayList<Team> teamsStartGame = getIntent().getParcelableArrayListExtra("teams"); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
78 |
for(HashMap<String, Object> hashmap : availableTeamsList){ |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
79 |
for(Team t : teamsStartGame){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
80 |
if(((Team)hashmap.get("team")).equals(t)){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
81 |
toBeRemoved.add(hashmap); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
82 |
selectedTeamsList.add(FrontendDataUtils.teamToHashMap(t));//create a new hashmap to ensure all variables are entered into the map |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
83 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
84 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
85 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
86 |
for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap); |
5506 | 87 |
|
88 |
adapter = new SimpleAdapter(this, selectedTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img", "color", "count"}, new int[]{R.id.txtName, R.id.imgDifficulty, R.id.teamColor, R.id.teamCount}); |
|
89 |
adapter.setViewBinder(viewBinder); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
90 |
selectedTeams.setAdapter(adapter); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
91 |
selectedTeams.setOnItemClickListener(selectedClicker); |
5506 | 92 |
|
93 |
} |
|
94 |
||
95 |
private ViewBinder viewBinder = new ViewBinder(){ |
|
96 |
public boolean setViewValue(View view, Object data, String textRepresentation) { |
|
97 |
switch(view.getId()){ |
|
98 |
case R.id.teamColor: |
|
99 |
setTeamColor(view, (Integer)data); |
|
100 |
return true; |
|
101 |
case R.id.teamCount: |
|
102 |
setTeamHogCount((ImageView)view, (Integer)data); |
|
103 |
return true; |
|
104 |
default: |
|
105 |
return false; |
|
106 |
} |
|
107 |
} |
|
108 |
}; |
|
109 |
||
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
110 |
public void onActivityResult(int requestCode, int resultCode, Intent data){ |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
111 |
if(requestCode == ACTIVITY_TEAMCREATION){ |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
112 |
if(resultCode == Activity.RESULT_OK){ |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
113 |
updateListViews(); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
114 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
115 |
}else{ |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
116 |
super.onActivityResult(requestCode, resultCode, data); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
117 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
118 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
119 |
|
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
120 |
private void updateListViews(){ |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
121 |
unregisterForContextMenu(availableTeams); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
122 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
123 |
ArrayList<HashMap<String, Object>> toBeRemoved = new ArrayList<HashMap<String, Object>>(); |
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
124 |
for(HashMap<String, Object> hashmap : selectedTeamsList){ |
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
125 |
String name = (String)hashmap.get("txt"); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
126 |
|
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
127 |
for(HashMap<String, Object> hash : availableTeamsList){ |
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
128 |
if(name.equals((String)hash.get("txt"))){ |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
129 |
toBeRemoved.add(hash); |
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
130 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
131 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
132 |
} |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
133 |
for(HashMap<String, Object> hash: toBeRemoved) availableTeamsList.remove(hash); |
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
134 |
|
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
135 |
SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
136 |
availableTeams.setAdapter(adapter); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
137 |
registerForContextMenu(availableTeams); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
138 |
availableTeams.setOnItemClickListener(availableClicker); |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
139 |
|
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
140 |
|
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
141 |
} |
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
142 |
|
5506 | 143 |
private void setTeamColor(int position, int color){ |
144 |
View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
145 |
setTeamColor(iv, color); |
|
146 |
} |
|
147 |
private void setTeamColor(View iv, int color){ |
|
5532
3d7ac2b3b703
Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents:
5506
diff
changeset
|
148 |
iv.setBackgroundColor(0xFF000000 + color); |
5506 | 149 |
} |
150 |
||
151 |
private void setTeamHogCount(int position, int count){ |
|
152 |
ImageView iv = (ImageView)((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
153 |
setTeamHogCount(iv, count); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
154 |
} |
5506 | 155 |
|
156 |
private void setTeamHogCount(ImageView iv, int count){ |
|
157 |
||
158 |
switch(count){ |
|
159 |
case 0: |
|
160 |
iv.setImageResource(R.drawable.teamcount0); |
|
161 |
break; |
|
162 |
case 1: |
|
163 |
iv.setImageResource(R.drawable.teamcount1); |
|
164 |
break; |
|
165 |
case 2: |
|
166 |
iv.setImageResource(R.drawable.teamcount2); |
|
167 |
break; |
|
168 |
case 3: |
|
169 |
iv.setImageResource(R.drawable.teamcount3); |
|
170 |
break; |
|
171 |
case 4: |
|
172 |
iv.setImageResource(R.drawable.teamcount4); |
|
173 |
break; |
|
174 |
case 5: |
|
175 |
iv.setImageResource(R.drawable.teamcount5); |
|
176 |
break; |
|
177 |
case 6: |
|
178 |
iv.setImageResource(R.drawable.teamcount6); |
|
179 |
break; |
|
180 |
case 7: |
|
181 |
iv.setImageResource(R.drawable.teamcount7); |
|
182 |
break; |
|
183 |
case 8: |
|
184 |
iv.setImageResource(R.drawable.teamcount8); |
|
185 |
break; |
|
186 |
case 9: |
|
187 |
iv.setImageResource(R.drawable.teamcount9); |
|
188 |
break; |
|
189 |
} |
|
190 |
} |
|
191 |
||
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
192 |
public void onBackPressed(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
193 |
returnTeams(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
194 |
super.onBackPressed(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
195 |
} |
5506 | 196 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
197 |
private OnClickListener addTeamClicker = new OnClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
198 |
public void onClick(View v) { |
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
199 |
startActivityForResult(new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class), ACTIVITY_TEAMCREATION); |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
200 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
201 |
}; |
5506 | 202 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
203 |
private OnClickListener backClicker = new OnClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
204 |
public void onClick(View v){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
205 |
returnTeams(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
206 |
finish(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
207 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
208 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
209 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
210 |
private OnItemClickListener availableClicker = new OnItemClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
211 |
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) { |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
212 |
selectAvailableTeamsItem(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
213 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
214 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
215 |
private OnItemClickListener selectedClicker = new OnItemClickListener(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
216 |
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) { |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
217 |
availableTeamsList.add((HashMap<String, Object>) selectedTeamsList.get(position)); |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
218 |
selectedTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
219 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
220 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
221 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
222 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
223 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
224 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
225 |
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuinfo){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
226 |
menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, R.string.select); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
227 |
menu.add(ContextMenu.NONE, 2, ContextMenu.NONE, R.string.edit); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
228 |
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete); |
5506 | 229 |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
230 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
231 |
public boolean onContextItemSelected(MenuItem item){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
232 |
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
233 |
int position = menuInfo.position; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
234 |
switch(item.getItemId()){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
235 |
case 0://select |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
236 |
selectAvailableTeamsItem(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
237 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
238 |
case 1://delete |
5532
3d7ac2b3b703
Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents:
5506
diff
changeset
|
239 |
File f = new File(String.format("%s/%s/%s.xml", TeamSelectionActivity.this.getFilesDir(), Team.DIRECTORY_TEAMS, availableTeamsList.get(position).get("txt"))); |
3d7ac2b3b703
Fixed team colors in the UI, delete and a nullpointer bug when no teams are created
Xeli
parents:
5506
diff
changeset
|
240 |
f.delete(); |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
241 |
availableTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
242 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
243 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
244 |
case 2://edit |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
245 |
Intent i = new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
246 |
Team t = (Team)availableTeamsList.get(position).get("team"); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
247 |
i.putExtra("team", t); |
5542
141c12a23787
start of implementation of the save button, check if there's something to save and update TeamSelectionActivity if a change has been made
Xeli
parents:
5532
diff
changeset
|
248 |
startActivityForResult(i, ACTIVITY_TEAMCREATION); |
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
249 |
return true; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
250 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
251 |
return false; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
252 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
253 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
254 |
private void selectAvailableTeamsItem(int position){ |
5506 | 255 |
HashMap<String, Object> hash = (HashMap<String, Object>) availableTeamsList.get(position); |
256 |
Team t = (Team)hash.get("team"); |
|
257 |
int[] illegalcolors = new int[selectedTeamsList.size()]; |
|
258 |
for(int i = 0; i < selectedTeamsList.size(); i++){ |
|
259 |
illegalcolors[i] = ((Team)selectedTeamsList.get(i).get("team")).color; |
|
260 |
} |
|
261 |
t.setRandomColor(illegalcolors); |
|
262 |
hash.put("color", t.color); |
|
263 |
hash.put("count", t.hogCount); |
|
264 |
||
265 |
selectedTeamsList.add(hash); |
|
5467
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
266 |
availableTeamsList.remove(position); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
267 |
((SimpleAdapter)availableTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
268 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
269 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
270 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
271 |
private void returnTeams(){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
272 |
int teamsCount = selectedTeamsList.size(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
273 |
if(teamsCount >= minTeams){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
274 |
Intent i = new Intent(); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
275 |
Parcelable[] teams = new Parcelable[teamsCount]; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
276 |
for(int x = 0 ; x < teamsCount; x++){ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
277 |
teams[x] = (Team)selectedTeamsList.get(x).get("team"); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
278 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
279 |
i.putExtra("teams", teams); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
280 |
setResult(Activity.RESULT_OK, i); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
281 |
}else{ |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
282 |
setResult(Activity.RESULT_CANCELED); |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
283 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
284 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
285 |
} |