author | alfadur |
Tue, 04 Jun 2019 20:01:37 +0300 | |
changeset 15114 | a7841105493e |
parent 12872 | 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 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
27 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 28 |
return rotationManager(interfaceOrientation); |
29 |
} |
|
30 |
||
31 |
#pragma mark - |
|
32 |
#pragma mark View lifecycle |
|
33 |
// add an edit button |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
34 |
- (void)viewDidLoad { |
3547 | 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; |
|
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
|
42 |
|
11229
b49dfdf628f6
- Some strings localizations for Settings
antonc27 <antonc27@mail.ru>
parents:
11217
diff
changeset
|
43 |
self.navigationItem.title = NSLocalizedString(@"List of teams", nil); |
3547 | 44 |
} |
45 |
||
46 |
// load the list of teams in the teams directory |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
47 |
- (void)viewWillAppear:(BOOL)animated { |
3547 | 48 |
[super viewWillAppear:animated]; |
3697 | 49 |
|
3547 | 50 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
51 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
|
52 |
self.listOfTeams = array; |
|
3697 | 53 |
|
3547 | 54 |
[self.tableView reloadData]; |
55 |
} |
|
56 |
||
57 |
// modifies the navigation bar to add the "Add" and "Done" buttons |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
58 |
- (void)toggleEdit:(id)sender { |
3547 | 59 |
BOOL isEditing = self.tableView.editing; |
60 |
[self.tableView setEditing:!isEditing animated:YES]; |
|
3697 | 61 |
|
3547 | 62 |
if (isEditing) { |
63 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the team panel")]; |
|
64 |
[self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered]; |
|
65 |
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem; |
|
66 |
} else { |
|
67 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the team panel")]; |
|
68 |
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone]; |
|
69 |
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the team panel") |
|
70 |
style:UIBarButtonItemStyleBordered |
|
71 |
target:self |
|
72 |
action:@selector(addTeam:)]; |
|
73 |
self.navigationItem.leftBarButtonItem = addButton; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
// add a team file with default values and updates the table |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
78 |
- (void)addTeam:(id)sender { |
3547 | 79 |
NSString *fileName = [[NSString alloc] initWithFormat:@"Default Team %u.plist", [self.listOfTeams count]]; |
3697 | 80 |
|
6103 | 81 |
[CreationChamber createTeamNamed:[fileName stringByDeletingPathExtension]]; |
3697 | 82 |
|
3547 | 83 |
[self.listOfTeams addObject:fileName]; |
3697 | 84 |
|
3547 | 85 |
// order the array alphabetically, so teams will keep their position |
86 |
[self.listOfTeams sortUsingSelector:@selector(compare:)]; |
|
4287 | 87 |
[self.tableView reloadData]; |
3697 | 88 |
|
4287 | 89 |
NSInteger index = [self.listOfTeams indexOfObject:fileName]; |
90 |
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; |
|
3547 | 91 |
} |
92 |
||
93 |
#pragma mark - |
|
94 |
#pragma mark Table view data source |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
95 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3547 | 96 |
return 1; |
97 |
} |
|
98 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
99 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3547 | 100 |
return [self.listOfTeams count]; |
101 |
} |
|
102 |
||
103 |
// Customize the appearance of table view cells. |
|
104 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
105 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 106 |
|
3547 | 107 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
108 |
if (cell == nil) { |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
109 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
3547 | 110 |
} |
3697 | 111 |
|
112 |
NSUInteger row = [indexPath row]; |
|
113 |
NSString *rowString = [[self.listOfTeams objectAtIndex:row] stringByDeletingPathExtension]; |
|
114 |
cell.textLabel.text = rowString; |
|
3547 | 115 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
3697 | 116 |
|
3547 | 117 |
return cell; |
118 |
} |
|
119 |
||
120 |
// delete the row and the file |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
121 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 122 |
NSUInteger row = [indexPath row]; |
3697 | 123 |
|
3547 | 124 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@",TEAMS_DIRECTORY(),[self.listOfTeams objectAtIndex:row]]; |
125 |
[[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL]; |
|
3697 | 126 |
|
3547 | 127 |
[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
|
128 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
3547 | 129 |
} |
130 |
||
131 |
||
132 |
#pragma mark - |
|
133 |
#pragma mark Table view delegate |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
134 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
135 |
{ |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
136 |
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
|
137 |
|
3547 | 138 |
NSInteger row = [indexPath row]; |
139 |
NSString *selectedTeamFile = [listOfTeams objectAtIndex:row]; |
|
3697 | 140 |
|
3547 | 141 |
// this must be set so childController can load the correct plist |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
142 |
singleTeamViewController.teamName = [selectedTeamFile stringByDeletingPathExtension]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
143 |
[singleTeamViewController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
3547 | 144 |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
145 |
[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
|
146 |
|
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
|
147 |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; |
3547 | 148 |
} |
149 |
||
150 |
||
151 |
#pragma mark - |
|
152 |
#pragma mark Memory management |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
153 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
154 |
- (void)didReceiveMemoryWarning |
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
155 |
{ |
3547 | 156 |
// Releases the view if it doesn't have a superview. |
157 |
[super didReceiveMemoryWarning]; |
|
158 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
159 |
} |
|
160 |
||
161 |
@end |
|
162 |