author | sheepluva |
Sat, 30 Oct 2010 23:25:41 +0200 | |
changeset 4026 | afae5a3b8424 |
parent 3983 | aa24192417a8 |
child 4082 | bfe14b38dad1 |
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" |
|
23 |
#import "CommodityFunctions.h" |
|
3971 | 24 |
#import "SDL_uikitappdelegate.h" |
3547 | 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 |
|
3971 | 41 |
self.selectedScheme = nil; |
42 |
self.selectedWeapon = nil; |
|
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 |
|
3971 | 56 |
if (self.selectedScheme == nil && [listOfSchemes containsObject:@"Default.plist"]) |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3917
diff
changeset
|
57 |
self.selectedScheme = @"Default.plist"; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3917
diff
changeset
|
58 |
|
3547 | 59 |
contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
60 |
self.listOfWeapons = contentsOfDir; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3917
diff
changeset
|
61 |
|
3971 | 62 |
if (self.selectedWeapon == nil && [listOfWeapons containsObject:@"Default.plist"]) |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3917
diff
changeset
|
63 |
self.selectedWeapon = @"Default.plist"; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3917
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 { |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
129 |
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
130 |
NSString *text; |
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) |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
132 |
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 |
3983
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
134 |
text = NSLocalizedString(@"Weapons",@""); |
aa24192417a8
use labels instead of images, should save ram and space
koda
parents:
3971
diff
changeset
|
135 |
UILabel *theLabel = createBlueLabel(text, frame); |
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
|
136 |
theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
137 |
|
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
|
138 |
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
|
139 |
[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
|
140 |
[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
|
141 |
return theView; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
142 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
143 |
|
3547 | 144 |
#pragma mark - |
145 |
#pragma mark Table view delegate |
|
146 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
147 |
NSIndexPath *lastIndexPath; |
|
148 |
if ([indexPath section] == 0) |
|
149 |
lastIndexPath = self.lastIndexPath_sc; |
|
150 |
else |
|
151 |
lastIndexPath = self.lastIndexPath_we; |
|
3697 | 152 |
|
3547 | 153 |
int newRow = [indexPath row]; |
154 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 155 |
|
3547 | 156 |
if (newRow != oldRow) { |
157 |
//TODO: this code works only for a single section table |
|
158 |
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
|
159 |
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
|
160 |
newCell.accessoryView = checkbox; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
161 |
[checkbox release]; |
3547 | 162 |
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
|
163 |
oldCell.accessoryView = nil; |
3697 | 164 |
|
3547 | 165 |
if ([indexPath section] == 0) { |
166 |
self.lastIndexPath_sc = indexPath; |
|
167 |
self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
168 |
} else { |
|
169 |
self.lastIndexPath_we = indexPath; |
|
170 |
self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
|
3697 | 171 |
} |
172 |
||
3547 | 173 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
174 |
} |
|
175 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
176 |
} |
|
177 |
||
178 |
#pragma mark - |
|
179 |
#pragma mark Memory management |
|
180 |
-(void) didReceiveMemoryWarning { |
|
3971 | 181 |
if ([[SDLUIKitDelegate sharedAppDelegate] isInGame]) { |
182 |
self.lastIndexPath_sc = nil; |
|
183 |
self.lastIndexPath_we = nil; |
|
184 |
self.listOfSchemes = nil; |
|
185 |
self.listOfWeapons = nil; |
|
186 |
MSG_MEMCLEAN(); |
|
187 |
} |
|
3547 | 188 |
[super didReceiveMemoryWarning]; |
189 |
} |
|
190 |
||
191 |
-(void) viewDidUnload { |
|
192 |
self.listOfSchemes = nil; |
|
193 |
self.listOfWeapons = nil; |
|
194 |
self.lastIndexPath_sc = nil; |
|
195 |
self.lastIndexPath_we = nil; |
|
196 |
self.selectedScheme = nil; |
|
197 |
self.selectedWeapon = nil; |
|
198 |
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
|
199 |
[super viewDidUnload]; |
3547 | 200 |
} |
201 |
||
202 |
||
203 |
-(void) dealloc { |
|
204 |
[listOfSchemes release]; |
|
205 |
[listOfWeapons release]; |
|
206 |
[lastIndexPath_sc release]; |
|
207 |
[lastIndexPath_we release]; |
|
208 |
[selectedScheme release]; |
|
209 |
[selectedWeapon release]; |
|
210 |
[super dealloc]; |
|
211 |
} |
|
212 |
||
213 |
||
214 |
@end |
|
215 |