author | nemo |
Sun, 10 Oct 2010 20:16:17 -0400 | |
changeset 3951 | c9a63db3e603 |
parent 3917 | 4c243b1eac97 |
child 3952 | d6412423da45 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.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 |
* File created on 13/06/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "SchemeWeaponConfigViewController.h" |
|
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
23 |
#import <QuartzCore/QuartzCore.h> |
3547 | 24 |
#import "CommodityFunctions.h" |
25 |
||
26 |
@implementation SchemeWeaponConfigViewController |
|
27 |
@synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon; |
|
28 |
||
29 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
30 |
return rotationManager(interfaceOrientation); |
|
31 |
} |
|
32 |
||
33 |
#pragma mark - |
|
34 |
#pragma mark View lifecycle |
|
35 |
-(void) viewDidLoad { |
|
36 |
[super viewDidLoad]; |
|
37 |
||
38 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
|
39 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3697 | 40 |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
41 |
self.selectedScheme = @""; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
42 |
self.selectedWeapon = @""; |
3697 | 43 |
|
3917 | 44 |
[self.tableView setBackgroundView:nil]; |
45 |
self.view.backgroundColor = [UIColor clearColor]; |
|
46 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
|
3659 | 47 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 48 |
} |
49 |
||
50 |
-(void) viewWillAppear:(BOOL) animated { |
|
51 |
[super viewWillAppear:animated]; |
|
52 |
||
53 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL]; |
|
54 |
self.listOfSchemes = contentsOfDir; |
|
3697 | 55 |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
56 |
if ([listOfSchemes containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
57 |
self.selectedScheme = @"Default.plist"; |
3697 | 58 |
|
3547 | 59 |
contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
60 |
self.listOfWeapons = contentsOfDir; |
|
3697 | 61 |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
62 |
if ([listOfWeapons containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
63 |
self.selectedWeapon = @"Default.plist"; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
64 |
|
3547 | 65 |
[self.tableView reloadData]; |
66 |
} |
|
67 |
||
68 |
||
69 |
#pragma mark - |
|
70 |
#pragma mark Table view data source |
|
71 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
72 |
return 2; |
|
73 |
} |
|
74 |
||
75 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
3697 | 76 |
if (section == 0) |
3547 | 77 |
return [self.listOfSchemes count]; |
78 |
else |
|
79 |
return [self.listOfWeapons count]; |
|
80 |
} |
|
81 |
||
82 |
// Customize the appearance of table view cells. |
|
83 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
84 |
static NSString *CellIdentifier = @"Cell"; |
|
85 |
NSInteger row = [indexPath row]; |
|
3697 | 86 |
|
3547 | 87 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
88 |
if (cell == nil) |
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
89 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
3697 | 90 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
91 |
cell.accessoryView = nil; |
3547 | 92 |
if ([indexPath section] == 0) { |
93 |
cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
|
3782 | 94 |
NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]]; |
95 |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
|
96 |
cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
|
97 |
[dict release]; |
|
3547 | 98 |
if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) { |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
99 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
100 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
101 |
[checkbox release]; |
3547 | 102 |
self.lastIndexPath_sc = indexPath; |
103 |
} |
|
104 |
} else { |
|
105 |
cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
|
3782 | 106 |
NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; |
107 |
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
|
108 |
cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
|
109 |
[dict release]; |
|
3547 | 110 |
if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) { |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
111 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
112 |
cell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
113 |
[checkbox release]; |
3547 | 114 |
self.lastIndexPath_we = indexPath; |
115 |
} |
|
116 |
} |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
117 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
118 |
cell.backgroundColor = [UIColor blackColor]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
119 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
3781
2bfda544ae48
modified file format for schemes files (which is going to introduce a lot of pre-release bugs, i'm sure)
koda
parents:
3780
diff
changeset
|
120 |
cell.detailTextLabel.textColor = [UIColor whiteColor]; |
3547 | 121 |
return cell; |
122 |
} |
|
123 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
124 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
125 |
return 40.0; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
126 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
127 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
128 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
129 |
UILabel *theLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30)]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
130 |
theLabel.backgroundColor = [UIColor blueColor]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
131 |
if (section == 0) |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
132 |
theLabel.text = NSLocalizedString(@"Schemes",@""); |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
133 |
else |
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
134 |
theLabel.text = NSLocalizedString(@"Weapons",@""); |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
135 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
136 |
theLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
137 |
theLabel.textAlignment = UITextAlignmentCenter; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
138 |
theLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]*80/100]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
139 |
theLabel.backgroundColor = UICOLOR_HW_DARKBLUE; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
140 |
|
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
141 |
[theLabel.layer setBorderWidth:1.5f]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
142 |
[theLabel.layer setBorderColor:[UICOLOR_HW_YELLOW_BODER CGColor]]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
143 |
[theLabel.layer setCornerRadius:8.0f]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
144 |
[theLabel.layer setMasksToBounds:YES]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
145 |
|
3780
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
146 |
UIView *theView = [[[UIView alloc] init] autorelease]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
147 |
[theView addSubview:theLabel]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
148 |
[theLabel release]; |
7c704e69242e
fade in when returning from game, labels rewritten so that they are drawn at runtime (more flexibility with i18n and iphone support)
koda
parents:
3703
diff
changeset
|
149 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
150 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
151 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
152 |
/* |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
153 |
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
154 |
if (section == 0) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
155 |
return NSLocalizedString(@"Schemes",@""); |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
156 |
} else { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
157 |
return NSLocalizedString(@"Weapons",@"");; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
158 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
159 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
160 |
*/ |
3547 | 161 |
|
162 |
#pragma mark - |
|
163 |
#pragma mark Table view delegate |
|
164 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
165 |
NSIndexPath *lastIndexPath; |
|
166 |
if ([indexPath section] == 0) |
|
167 |
lastIndexPath = self.lastIndexPath_sc; |
|
168 |
else |
|
169 |
lastIndexPath = self.lastIndexPath_we; |
|
3697 | 170 |
|
3547 | 171 |
int newRow = [indexPath row]; |
172 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 173 |
|
3547 | 174 |
if (newRow != oldRow) { |
175 |
//TODO: this code works only for a single section table |
|
176 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
177 |
UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
178 |
newCell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
179 |
[checkbox release]; |
3547 | 180 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
181 |
oldCell.accessoryView = nil; |
3697 | 182 |
|
3547 | 183 |
if ([indexPath section] == 0) { |
184 |
self.lastIndexPath_sc = indexPath; |
|
185 |
self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
186 |
} else { |
|
187 |
self.lastIndexPath_we = indexPath; |
|
188 |
self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
|
3697 | 189 |
} |
190 |
||
3547 | 191 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
192 |
} |
|
193 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
194 |
} |
|
195 |
||
196 |
#pragma mark - |
|
197 |
#pragma mark Memory management |
|
198 |
-(void) didReceiveMemoryWarning { |
|
199 |
// Releases the view if it doesn't have a superview. |
|
200 |
[super didReceiveMemoryWarning]; |
|
201 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
202 |
} |
|
203 |
||
204 |
-(void) viewDidUnload { |
|
205 |
self.listOfSchemes = nil; |
|
206 |
self.listOfWeapons = nil; |
|
207 |
self.lastIndexPath_sc = nil; |
|
208 |
self.lastIndexPath_we = nil; |
|
209 |
self.selectedScheme = nil; |
|
210 |
self.selectedWeapon = nil; |
|
211 |
MSG_DIDUNLOAD(); |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3659
diff
changeset
|
212 |
[super viewDidUnload]; |
3547 | 213 |
} |
214 |
||
215 |
||
216 |
-(void) dealloc { |
|
217 |
[listOfSchemes release]; |
|
218 |
[listOfWeapons release]; |
|
219 |
[lastIndexPath_sc release]; |
|
220 |
[lastIndexPath_we release]; |
|
221 |
[selectedScheme release]; |
|
222 |
[selectedWeapon release]; |
|
223 |
[super dealloc]; |
|
224 |
} |
|
225 |
||
226 |
||
227 |
@end |
|
228 |