author | unc0rr |
Tue, 11 Apr 2023 09:30:56 +0200 | |
changeset 15951 | 5aed6c0b63e2 |
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 "WeaponSettingsViewController.h" |
|
21 |
#import "SingleWeaponViewController.h" |
|
22 |
||
6832 | 23 |
|
3547 | 24 |
@implementation WeaponSettingsViewController |
25 |
@synthesize listOfWeapons; |
|
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 |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
33 |
- (void)viewDidLoad { |
3547 | 34 |
[super viewDidLoad]; |
3697 | 35 |
|
3916
e7d665a4ef42
implemented endless turns support and added Timeless scheme (also fixed a crasher)
koda
parents:
3829
diff
changeset
|
36 |
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Edit",@"") |
3547 | 37 |
style:UIBarButtonItemStyleBordered |
38 |
target:self |
|
39 |
action:@selector(toggleEdit:)]; |
|
40 |
self.navigationItem.rightBarButtonItem = editButton; |
|
3697 | 41 |
|
11229
b49dfdf628f6
- Some strings localizations for Settings
antonc27 <antonc27@mail.ru>
parents:
11217
diff
changeset
|
42 |
self.navigationItem.title = NSLocalizedString(@"List of weapons", nil); |
3547 | 43 |
} |
44 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
45 |
- (void)viewWillAppear:(BOOL) animated { |
3547 | 46 |
[super viewWillAppear:animated]; |
3697 | 47 |
|
3547 | 48 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
49 |
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
|
50 |
self.listOfWeapons = array; |
|
3697 | 51 |
|
3547 | 52 |
[self.tableView reloadData]; |
53 |
} |
|
54 |
||
55 |
// 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
|
56 |
- (void)toggleEdit:(id)sender { |
3547 | 57 |
BOOL isEditing = self.tableView.editing; |
58 |
[self.tableView setEditing:!isEditing animated:YES]; |
|
3697 | 59 |
|
3547 | 60 |
if (isEditing) { |
61 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Edit",@"from the scheme panel")]; |
|
62 |
[self.navigationItem.rightBarButtonItem setStyle: UIBarButtonItemStyleBordered]; |
|
63 |
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem; |
|
64 |
} else { |
|
65 |
[self.navigationItem.rightBarButtonItem setTitle:NSLocalizedString(@"Done",@"from the scheme panel")]; |
|
66 |
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone]; |
|
67 |
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Add",@"from the scheme panel") |
|
68 |
style:UIBarButtonItemStyleBordered |
|
69 |
target:self |
|
70 |
action:@selector(addWeapon:)]; |
|
71 |
self.navigationItem.leftBarButtonItem = addButton; |
|
72 |
} |
|
73 |
} |
|
74 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
75 |
- (void)addWeapon:(id)sender { |
3547 | 76 |
NSString *fileName = [[NSString alloc] initWithFormat:@"Weapon %u.plist", [self.listOfWeapons count]]; |
3697 | 77 |
|
6103 | 78 |
[CreationChamber createWeaponNamed:[fileName stringByDeletingPathExtension]]; |
3697 | 79 |
|
3547 | 80 |
[self.listOfWeapons addObject:fileName]; |
3697 | 81 |
|
3547 | 82 |
// order the array alphabetically, so schemes will keep their position |
83 |
[self.listOfWeapons sortUsingSelector:@selector(compare:)]; |
|
4287 | 84 |
[self.tableView reloadData]; |
3697 | 85 |
|
4287 | 86 |
NSInteger index = [self.listOfWeapons indexOfObject:fileName]; |
87 |
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; |
|
3547 | 88 |
} |
89 |
||
90 |
#pragma mark - |
|
91 |
#pragma mark Table view data source |
|
92 |
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
|
93 |
return 1; |
|
94 |
} |
|
95 |
||
96 |
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
97 |
return [self.listOfWeapons count]; |
|
98 |
} |
|
99 |
||
100 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
101 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 102 |
|
3547 | 103 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
104 |
if (cell == nil) { |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
105 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
3547 | 106 |
} |
3697 | 107 |
|
108 |
NSUInteger row = [indexPath row]; |
|
109 |
NSString *rowString = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
|
110 |
cell.textLabel.text = rowString; |
|
3547 | 111 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
3697 | 112 |
|
3547 | 113 |
return cell; |
114 |
} |
|
115 |
||
116 |
// delete the row and the file |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
117 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 118 |
NSUInteger row = [indexPath row]; |
3697 | 119 |
|
3547 | 120 |
NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; |
121 |
[[NSFileManager defaultManager] removeItemAtPath:schemeFile error:NULL]; |
|
3697 | 122 |
|
3547 | 123 |
[self.listOfWeapons 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
|
124 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; |
3547 | 125 |
} |
126 |
||
127 |
#pragma mark - |
|
128 |
#pragma mark Table view delegate |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
129 |
- (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
|
130 |
{ |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
131 |
SingleWeaponViewController *singleWeaponViewController = [[SingleWeaponViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 132 |
|
3547 | 133 |
NSInteger row = [indexPath row]; |
134 |
NSString *selectedWeaponFile = [self.listOfWeapons objectAtIndex:row]; |
|
3697 | 135 |
|
3547 | 136 |
// 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
|
137 |
singleWeaponViewController.weaponName = [selectedWeaponFile stringByDeletingPathExtension]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
138 |
[singleWeaponViewController.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
3547 | 139 |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
140 |
[self.navigationController pushViewController:singleWeaponViewController animated:YES]; |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
141 |
|
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
|
142 |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; |
3547 | 143 |
} |
144 |
||
145 |
||
146 |
#pragma mark - |
|
147 |
#pragma mark Memory management |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
148 |
|
11217
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
149 |
-(void)didReceiveMemoryWarning |
e68b3e392091
- Big refactoring of front-end Settings for both iPhone and iPad:
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
150 |
{ |
3547 | 151 |
[super didReceiveMemoryWarning]; |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11229
diff
changeset
|
152 |
MSG_MEMCLEAN(); |
3547 | 153 |
} |
154 |
||
155 |
@end |
|
156 |