author | Wuzzy <almikes@aol.com> |
Mon, 08 May 2017 03:42:51 +0200 | |
changeset 12414 | 7cdd8e113dc0 |
parent 11233 | b49dfdf628f6 |
child 12877 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6832
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 17 |
*/ |
18 |
||
3547 | 19 |
|
20 |
#import "TeamSettingsViewController.h" |
|
21 |
#import "SingleTeamViewController.h" |
|
22 |
||
6832 | 23 |
|
3547 | 24 |
@implementation TeamSettingsViewController |
25 |
@synthesize listOfTeams; |
|
26 |
||
27 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
28 |
return rotationManager(interfaceOrientation); |
|
29 |
} |
|
30 |
||
31 |
#pragma mark - |
|
32 |
#pragma mark View lifecycle |
|
33 |
// add an edit button |
|
34 |
-(void) viewDidLoad { |
|
35 |
[super viewDidLoad]; |
|
36 |
||
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
37 |
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"") |
3547 | 38 |
style:UIBarButtonItemStyleBordered |
39 |
target:self |
|
40 |
action:@selector(toggleEdit:)]; |
|
41 |
self.navigationItem.rightBarButtonItem = editButton; |
|
42 |
[editButton release]; |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
5208
diff
changeset
|
43 |
|
11233
b49dfdf628f6
- Some strings localizations for Settings
antonc27 <antonc27@mail.ru>
parents:
11221
diff
changeset
|
44 |
self.navigationItem.title = NSLocalizedString(@"List of teams", nil); |
3547 | 45 |
} |
46 |
||
47 |
// load the list of teams in the teams directory |
|
48 |
-(void) viewWillAppear:(BOOL)animated { |
|
49 |
[super viewWillAppear:animated]; |
|
3697 | 50 |
|
3547 | 51 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
52 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
|
53 |
self.listOfTeams = array; |
|
54 |
[array release]; |
|
3697 | 55 |
|
3547 | 56 |
[self.tableView reloadData]; |
57 |
} |
|
58 |
||
59 |
// modifies the navigation bar to add the "Add" and "Done" buttons |
|
60 |
-(void) toggleEdit:(id) sender { |
|
61 |
BOOL isEditing = self.tableView.editing; |
|
62 |
[self.tableView setEditing:!isEditing animated:YES]; |
|
3697 | 63 |
|
3547 | 64 |
if (isEditing) { |
65 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team panel")]; |
|
66 |
[self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered]; |
|
67 |
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem; |
|
68 |
} else { |
|
69 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the team panel")]; |
|
70 |
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone]; |
|
71 |
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the team panel") |
|
72 |
style:UIBarButtonItemStyleBordered |
|
73 |
target:self |
|
74 |
action:@selector(addTeam:)]; |
|
75 |
self.navigationItem.leftBarButtonItem = addButton; |
|
76 |
[addButton release]; |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
// add a team file with default values and updates the table |
|
81 |
-(void) addTeam:(id) sender { |
|
82 |
NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
|
3697 | 83 |
|
6103 | 84 |
[CreationChamber createTeamNamed:[fileName stringByDeletingPathExtension]]; |
3697 | 85 |
|
3547 | 86 |
[self.listOfTeams addObject:fileName]; |
3697 | 87 |
|
3547 | 88 |
// order the array alphabetically, so teams will keep their position |
89 |
[self.listOfTeams sortUsingSelector:@selector(compare:)]; |
|
4287 | 90 |
[self.tableView reloadData]; |
3697 | 91 |
|
4287 | 92 |
NSInteger index = [self.listOfTeams indexOfObject:fileName]; |
93 |
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; |
|
94 |
[fileName release]; |
|
3547 | 95 |
} |
96 |
||
97 |
#pragma mark - |
|
98 |
#pragma mark Table view data source |
|
99 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
100 |
return 1; |
|
101 |
} |
|
102 |
||
103 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
104 |
return [self.listOfTeams count]; |
|
105 |
} |
|
106 |
||
107 |
// Customize the appearance of table view cells. |
|
108 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
109 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 110 |
|
3547 | 111 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
112 |
if (cell == nil) { |
|
113 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
114 |
} |
|
3697 | 115 |
|
116 |
NSUInteger row = [indexPath row]; |
|
117 |
NSString *rowString = [[self.listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
|
118 |
cell.textLabel.text = rowString; |
|
3547 | 119 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
3697 | 120 |
|
3547 | 121 |
return cell; |
122 |
} |
|
123 |
||
124 |
// delete the row and the file |
|
125 |
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
126 |
NSUInteger row = [indexPath row]; |
|
3697 | 127 |
|
3547 | 128 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@",TEAMS_DIRECTORY(),[self.listOfTeams objectAtIndex:row]]; |
129 |
[[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL]; |
|
130 |
[teamFile release]; |
|
3697 | 131 |
|
3547 | 132 |
[self.listOfTeams removeObjectAtIndex:row]; |
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
5208
diff
changeset
|
133 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
3547 | 134 |
} |
135 |
||
136 |
||
137 |
#pragma mark - |
|
138 |
#pragma mark Table view delegate |
|
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
139 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
140 |
{ |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
141 |
SingleTeamViewController *singleTeamViewController = [[SingleTeamViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
142 |
|
3547 | 143 |
NSInteger row = [indexPath row]; |
144 |
NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
|
3697 | 145 |
|
3547 | 146 |
// this must be set so childController can load the correct plist |
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
147 |
singleTeamViewController.teamName = [selectedTeamFile stringByDeletingPathExtension]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
148 |
[singleTeamViewController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
3547 | 149 |
|
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
150 |
[self.navigationController pushViewController:singleTeamViewController animated:YES]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
151 |
[singleTeamViewController release]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
152 |
|
6074
047eaed35cbb
ios major refactoring for ios settings, now they are presented differently on iphone/ipad, code is simplified and optimized, and ui is a little refreshed (eg. no more stuck selected fields)
koda
parents:
5208
diff
changeset
|
153 |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; |
3547 | 154 |
} |
155 |
||
156 |
||
157 |
#pragma mark - |
|
158 |
#pragma mark Memory management |
|
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
159 |
-(void) didReceiveMemoryWarning |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
160 |
{ |
3547 | 161 |
// Releases the view if it doesn't have a superview. |
162 |
[super didReceiveMemoryWarning]; |
|
163 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
164 |
} |
|
165 |
||
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
166 |
-(void) viewDidUnload |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
167 |
{ |
3547 | 168 |
self.listOfTeams = nil; |
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
169 |
MSG_DIDUNLOAD(); |
3547 | 170 |
[super viewDidUnload]; |
171 |
} |
|
172 |
||
11221
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
173 |
-(void) dealloc |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
174 |
{ |
5208 | 175 |
releaseAndNil(listOfTeams); |
3547 | 176 |
[super dealloc]; |
177 |
} |
|
178 |
||
179 |
||
180 |
@end |
|
181 |