author | Xeli |
Fri, 19 Aug 2011 03:33:25 +0200 | |
branch | hedgeroid |
changeset 5607 | d3a3e80ad1da |
parent 5603 | 4e4a579a60af |
child 5621 | ea796c83ea47 |
permissions | -rw-r--r-- |
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
|
1 |
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
|
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
|
3 |
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
|
4 |
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
|
5 |
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
|
6 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
7 |
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
|
8 |
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
|
9 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
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
|
14 |
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
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
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
|
21 |
import android.widget.ImageButton; |
5506 | 22 |
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
|
23 |
import android.widget.ListView; |
5506 | 24 |
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
|
25 |
import android.widget.SimpleAdapter; |
5506 | 26 |
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
|
27 |
|
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 |
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
|
29 |
|
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
|
30 |
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
|
31 |
|
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
|
32 |
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
|
33 |
private ListView availableTeams, selectedTeams; |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
|
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 |
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
|
38 |
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
|
39 |
|
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 |
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
|
41 |
|
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 |
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
|
43 |
back = (ImageButton) findViewById(R.id.btnBack); |
5506 | 44 |
|
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
|
45 |
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
|
46 |
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
|
47 |
|
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 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
availableTeams.setOnItemClickListener(availableClicker); |
5506 | 54 |
|
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
toBeRemoved.add(hashmap); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
63 |
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
|
64 |
} |
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 |
} |
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 |
for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap); |
5506 | 68 |
|
69 |
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}); |
|
70 |
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
|
71 |
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
|
72 |
selectedTeams.setOnItemClickListener(selectedClicker); |
5506 | 73 |
|
74 |
} |
|
75 |
||
76 |
private ViewBinder viewBinder = new ViewBinder(){ |
|
77 |
public boolean setViewValue(View view, Object data, String textRepresentation) { |
|
78 |
switch(view.getId()){ |
|
79 |
case R.id.teamColor: |
|
80 |
setTeamColor(view, (Integer)data); |
|
81 |
return true; |
|
82 |
case R.id.teamCount: |
|
83 |
setTeamHogCount((ImageView)view, (Integer)data); |
|
84 |
return true; |
|
85 |
default: |
|
86 |
return false; |
|
87 |
} |
|
88 |
} |
|
89 |
}; |
|
90 |
||
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
} |
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
|
96 |
}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
|
97 |
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
|
98 |
} |
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
|
99 |
} |
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
|
100 |
|
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
|
101 |
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
|
102 |
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
|
103 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
|
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
} |
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 |
} |
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 |
} |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
114 |
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
|
115 |
|
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
|
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 |
|
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 |
} |
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
|
123 |
|
5506 | 124 |
private void setTeamColor(int position, int color){ |
125 |
View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
126 |
setTeamColor(iv, color); |
|
127 |
} |
|
128 |
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
|
129 |
iv.setBackgroundColor(0xFF000000 + color); |
5506 | 130 |
} |
131 |
||
132 |
private void setTeamHogCount(int position, int count){ |
|
133 |
ImageView iv = (ImageView)((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
134 |
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
|
135 |
} |
5506 | 136 |
|
137 |
private void setTeamHogCount(ImageView iv, int count){ |
|
138 |
||
139 |
switch(count){ |
|
140 |
case 0: |
|
141 |
iv.setImageResource(R.drawable.teamcount0); |
|
142 |
break; |
|
143 |
case 1: |
|
144 |
iv.setImageResource(R.drawable.teamcount1); |
|
145 |
break; |
|
146 |
case 2: |
|
147 |
iv.setImageResource(R.drawable.teamcount2); |
|
148 |
break; |
|
149 |
case 3: |
|
150 |
iv.setImageResource(R.drawable.teamcount3); |
|
151 |
break; |
|
152 |
case 4: |
|
153 |
iv.setImageResource(R.drawable.teamcount4); |
|
154 |
break; |
|
155 |
case 5: |
|
156 |
iv.setImageResource(R.drawable.teamcount5); |
|
157 |
break; |
|
158 |
case 6: |
|
159 |
iv.setImageResource(R.drawable.teamcount6); |
|
160 |
break; |
|
161 |
case 7: |
|
162 |
iv.setImageResource(R.drawable.teamcount7); |
|
163 |
break; |
|
164 |
case 8: |
|
165 |
iv.setImageResource(R.drawable.teamcount8); |
|
166 |
break; |
|
167 |
case 9: |
|
168 |
iv.setImageResource(R.drawable.teamcount9); |
|
169 |
break; |
|
170 |
} |
|
171 |
} |
|
172 |
||
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
} |
5506 | 177 |
|
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
182 |
}; |
5506 | 183 |
|
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
|
184 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
189 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
190 |
|
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
} |
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 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
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
|
200 |
((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
|
201 |
((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
|
202 |
} |
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 |
|
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 |
}; |
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 |
|
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 |
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
|
207 |
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
|
208 |
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
|
209 |
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete); |
5506 | 210 |
|
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
|
211 |
} |
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 |
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
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
|
223 |
((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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
} |
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 |
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
|
233 |
} |
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 |
|
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 |
private void selectAvailableTeamsItem(int position){ |
5506 | 236 |
HashMap<String, Object> hash = (HashMap<String, Object>) availableTeamsList.get(position); |
237 |
Team t = (Team)hash.get("team"); |
|
238 |
int[] illegalcolors = new int[selectedTeamsList.size()]; |
|
239 |
for(int i = 0; i < selectedTeamsList.size(); i++){ |
|
240 |
illegalcolors[i] = ((Team)selectedTeamsList.get(i).get("team")).color; |
|
241 |
} |
|
242 |
t.setRandomColor(illegalcolors); |
|
243 |
hash.put("color", t.color); |
|
244 |
hash.put("count", t.hogCount); |
|
245 |
||
246 |
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
|
247 |
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
|
248 |
((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
|
249 |
((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
|
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 |
|
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 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
}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
|
263 |
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
|
264 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
265 |
} |
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 |
} |