author | Xeli |
Thu, 01 Sep 2011 14:54:43 +0200 | |
branch | hedgeroid |
changeset 5669 | a806dbe25288 |
parent 5633 | 443b7c6543e5 |
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; |
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
46 |
import android.widget.TextView; |
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
|
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 |
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
|
49 |
|
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
|
50 |
private static final int ACTIVITY_TEAMCREATION = 0; |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
51 |
|
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
|
52 |
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
|
53 |
private ListView availableTeams, selectedTeams; |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
54 |
private ArrayList<HashMap<String, Object>> availableTeamsList, selectedTeamsList; |
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
55 |
private TextView txtInfo; |
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
|
56 |
|
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 |
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
|
58 |
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
|
59 |
|
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 |
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
|
61 |
|
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 |
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
|
63 |
back = (ImageButton) findViewById(R.id.btnBack); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
64 |
txtInfo = (TextView) findViewById(R.id.txtInfo); |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
65 |
|
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
|
66 |
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
|
67 |
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
|
68 |
|
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 |
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
|
70 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
5633 | 71 |
SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry_simple, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); |
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
|
72 |
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
|
73 |
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
|
74 |
availableTeams.setOnItemClickListener(availableClicker); |
5506 | 75 |
|
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 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
toBeRemoved.add(hashmap); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
84 |
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
|
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 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
87 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
88 |
for(HashMap<String, ?> hashmap : toBeRemoved) availableTeamsList.remove(hashmap); |
5506 | 89 |
|
90 |
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}); |
|
91 |
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
|
92 |
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
|
93 |
selectedTeams.setOnItemClickListener(selectedClicker); |
5506 | 94 |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
95 |
txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeams.getChildCount())); |
5506 | 96 |
} |
97 |
||
98 |
private ViewBinder viewBinder = new ViewBinder(){ |
|
99 |
public boolean setViewValue(View view, Object data, String textRepresentation) { |
|
100 |
switch(view.getId()){ |
|
101 |
case R.id.teamColor: |
|
102 |
setTeamColor(view, (Integer)data); |
|
103 |
return true; |
|
104 |
case R.id.teamCount: |
|
105 |
setTeamHogCount((ImageView)view, (Integer)data); |
|
106 |
return true; |
|
107 |
default: |
|
108 |
return false; |
|
109 |
} |
|
110 |
} |
|
111 |
}; |
|
112 |
||
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
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 |
}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
|
119 |
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
|
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 |
} |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
122 |
|
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
|
123 |
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
|
124 |
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
|
125 |
availableTeamsList = FrontendDataUtils.getTeams(this); |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
String name = (String)hashmap.get("txt"); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
129 |
|
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
} |
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
|
134 |
} |
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 |
} |
5603
4e4a579a60af
Fixed crash which occured when entering the teamselection menu for the second time
Xeli
parents:
5542
diff
changeset
|
136 |
for(HashMap<String, Object> hash: toBeRemoved) availableTeamsList.remove(hash); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
137 |
|
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
availableTeams.setOnItemClickListener(availableClicker); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
142 |
|
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
143 |
|
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
|
144 |
} |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
145 |
|
5506 | 146 |
private void setTeamColor(int position, int color){ |
147 |
View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
148 |
setTeamColor(iv, color); |
|
149 |
} |
|
150 |
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
|
151 |
iv.setBackgroundColor(0xFF000000 + color); |
5506 | 152 |
} |
153 |
||
154 |
private void setTeamHogCount(int position, int count){ |
|
155 |
ImageView iv = (ImageView)((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); |
|
156 |
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
|
157 |
} |
5506 | 158 |
|
159 |
private void setTeamHogCount(ImageView iv, int count){ |
|
160 |
||
161 |
switch(count){ |
|
162 |
case 0: |
|
163 |
iv.setImageResource(R.drawable.teamcount0); |
|
164 |
break; |
|
165 |
case 1: |
|
166 |
iv.setImageResource(R.drawable.teamcount1); |
|
167 |
break; |
|
168 |
case 2: |
|
169 |
iv.setImageResource(R.drawable.teamcount2); |
|
170 |
break; |
|
171 |
case 3: |
|
172 |
iv.setImageResource(R.drawable.teamcount3); |
|
173 |
break; |
|
174 |
case 4: |
|
175 |
iv.setImageResource(R.drawable.teamcount4); |
|
176 |
break; |
|
177 |
case 5: |
|
178 |
iv.setImageResource(R.drawable.teamcount5); |
|
179 |
break; |
|
180 |
case 6: |
|
181 |
iv.setImageResource(R.drawable.teamcount6); |
|
182 |
break; |
|
183 |
case 7: |
|
184 |
iv.setImageResource(R.drawable.teamcount7); |
|
185 |
break; |
|
186 |
case 8: |
|
187 |
iv.setImageResource(R.drawable.teamcount8); |
|
188 |
break; |
|
189 |
case 9: |
|
190 |
iv.setImageResource(R.drawable.teamcount9); |
|
191 |
break; |
|
192 |
} |
|
193 |
} |
|
194 |
||
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
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
} |
5506 | 199 |
|
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 |
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
|
201 |
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
|
202 |
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
|
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 |
}; |
5506 | 205 |
|
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
} |
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 |
|
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 |
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
|
214 |
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
|
215 |
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
|
216 |
} |
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 |
}; |
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 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
((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
|
223 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
224 |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
225 |
txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size())); |
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
|
226 |
} |
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 |
|
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 |
}; |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
229 |
|
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 |
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
|
231 |
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
|
232 |
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
|
233 |
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, R.string.delete); |
5506 | 234 |
|
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
|
235 |
} |
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 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
((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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
} |
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 |
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
|
257 |
} |
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 |
|
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 |
private void selectAvailableTeamsItem(int position){ |
5506 | 260 |
HashMap<String, Object> hash = (HashMap<String, Object>) availableTeamsList.get(position); |
261 |
Team t = (Team)hash.get("team"); |
|
262 |
int[] illegalcolors = new int[selectedTeamsList.size()]; |
|
263 |
for(int i = 0; i < selectedTeamsList.size(); i++){ |
|
264 |
illegalcolors[i] = ((Team)selectedTeamsList.get(i).get("team")).color; |
|
265 |
} |
|
266 |
t.setRandomColor(illegalcolors); |
|
267 |
hash.put("color", t.color); |
|
268 |
hash.put("count", t.hogCount); |
|
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
269 |
|
5506 | 270 |
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
|
271 |
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
|
272 |
((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
|
273 |
((SimpleAdapter)selectedTeams.getAdapter()).notifyDataSetChanged(); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
274 |
|
5625
9add7b92c5f0
Added a check for team count to prevent the engine from crashes when starting with <2 teams + changed the text in the Teams selection menu
Xeli
parents:
5621
diff
changeset
|
275 |
txtInfo.setText(String.format(getResources().getString(R.string.teams_info_template), selectedTeamsList.size())); |
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
|
276 |
} |
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 |
|
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 |
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
|
279 |
int teamsCount = selectedTeamsList.size(); |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
280 |
Intent i = new Intent(); |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
281 |
Parcelable[] teams = new Parcelable[teamsCount]; |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
282 |
for(int x = 0 ; x < teamsCount; x++){ |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
283 |
teams[x] = (Team)selectedTeamsList.get(x).get("team"); |
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
|
284 |
} |
5627
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
285 |
i.putExtra("teams", teams); |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
286 |
setResult(Activity.RESULT_OK, i); |
ce2d92589cbc
Added a visual imageview to show how many teams have been selected, plus feedback when creating a new team:
Xeli
parents:
5625
diff
changeset
|
287 |
|
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
|
288 |
} |
88e25840f532
Main activities for starting up the game, changing gameconfig, selecting and creating teams with their respective layouts and values
Xeli
parents:
diff
changeset
|
289 |
} |