author | koda |
Sat, 17 Jul 2010 03:59:10 +0200 | |
changeset 3647 | 0d0df215fb52 |
parent 3644 | 42c5684289ae |
child 3659 | f8d5ac50e307 |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// SingleWeaponViewController.m |
|
3 |
// Hedgewars |
|
4 |
// |
|
5 |
// Created by Vittorio on 19/06/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "SingleWeaponViewController.h" |
|
3621 | 10 |
#import "WeaponCellView.h" |
11 |
#import "CommodityFunctions.h" |
|
12 |
#import "UIImageExtra.h" |
|
3547 | 13 |
|
14 |
@implementation SingleWeaponViewController |
|
3621 | 15 |
@synthesize ammoStoreImage, ammoNames; |
3547 | 16 |
|
3621 | 17 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
18 |
return rotationManager(interfaceOrientation); |
|
3547 | 19 |
} |
20 |
||
21 |
#pragma mark - |
|
22 |
#pragma mark View lifecycle |
|
3621 | 23 |
-(void) viewDidLoad { |
3547 | 24 |
[super viewDidLoad]; |
3621 | 25 |
|
26 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
27 |
NSLocalizedString(@"Grenade",@""), |
|
28 |
NSLocalizedString(@"Cluster Bomb",@""), |
|
29 |
NSLocalizedString(@"Bazooka",@""), |
|
30 |
NSLocalizedString(@"Homing Bee",@""), |
|
31 |
NSLocalizedString(@"Shotgun",@""), |
|
32 |
NSLocalizedString(@"Pick Hammer",@""), |
|
33 |
NSLocalizedString(@"Skip",@""), |
|
34 |
NSLocalizedString(@"Rope",@""), |
|
35 |
NSLocalizedString(@"Mine",@""), |
|
36 |
NSLocalizedString(@"Deagle",@""), |
|
37 |
NSLocalizedString(@"Dynamite",@""), |
|
38 |
NSLocalizedString(@"Fire Punch",@""), |
|
39 |
NSLocalizedString(@"Slash",@""), |
|
40 |
NSLocalizedString(@"Baseball bat",@""), |
|
41 |
NSLocalizedString(@"Parachute",@""), |
|
42 |
NSLocalizedString(@"Air Attack",@""), |
|
43 |
NSLocalizedString(@"Mines Attack",@""), |
|
44 |
NSLocalizedString(@"Blow Torch",@""), |
|
45 |
NSLocalizedString(@"Construction",@""), |
|
46 |
NSLocalizedString(@"Teleport",@""), |
|
47 |
NSLocalizedString(@"Switch Hedgehog",@""), |
|
48 |
NSLocalizedString(@"Mortar",@""), |
|
49 |
NSLocalizedString(@"Kamikaze",@""), |
|
50 |
NSLocalizedString(@"Cake",@""), |
|
51 |
NSLocalizedString(@"Seduction",@""), |
|
52 |
NSLocalizedString(@"Watermelon Bomb",@""), |
|
53 |
NSLocalizedString(@"Hellish Hand Grenade",@""), |
|
54 |
NSLocalizedString(@"Napalm Attack",@""), |
|
55 |
NSLocalizedString(@"Drill Rocket",@""), |
|
56 |
NSLocalizedString(@"Ballgun",@""), |
|
57 |
NSLocalizedString(@"RC Plane",@""), |
|
58 |
NSLocalizedString(@"Low Gravity",@""), |
|
59 |
NSLocalizedString(@"Extra Damage",@""), |
|
60 |
NSLocalizedString(@"Invulnerable",@""), |
|
61 |
NSLocalizedString(@"Extra Time",@""), |
|
62 |
NSLocalizedString(@"Laser Sight",@""), |
|
63 |
NSLocalizedString(@"Vampirism",@""), |
|
64 |
NSLocalizedString(@"Sniper Rifle",@""), |
|
65 |
NSLocalizedString(@"Flying Saucer",@""), |
|
66 |
NSLocalizedString(@"Molotov Cocktail",@""), |
|
67 |
NSLocalizedString(@"Birdy",@""), |
|
68 |
NSLocalizedString(@"Portable Portal Device",@""), |
|
69 |
NSLocalizedString(@"Piano Attack",@""), |
|
70 |
NSLocalizedString(@"Old Limburger",@""), |
|
71 |
NSLocalizedString(@"Sine Gun",@""), |
|
72 |
NSLocalizedString(@"Flamethrower",@""), |
|
73 |
nil]; |
|
74 |
self.ammoNames = array; |
|
75 |
[array release]; |
|
3547 | 76 |
|
3644
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
77 |
quantity = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
78 |
probability = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
79 |
delay = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
80 |
crateness = (char *)malloc(sizeof(char)*(CURRENT_AMMOSIZE+1)); |
3621 | 81 |
|
82 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
|
83 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; |
|
84 |
self.ammoStoreImage = img; |
|
85 |
[img release]; |
|
86 |
||
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
87 |
self.tableView.rowHeight = 120; |
3547 | 88 |
} |
3621 | 89 |
|
90 |
-(void) viewWillAppear:(BOOL) animated { |
|
91 |
[super viewWillAppear:animated]; |
|
92 |
||
93 |
NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title]; |
|
94 |
NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; |
|
95 |
[ammoFile release]; |
|
96 |
||
97 |
const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; |
|
98 |
const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; |
|
99 |
const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String]; |
|
100 |
const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String]; |
|
101 |
[weapon release]; |
|
102 |
||
103 |
// if the new weaponset is diffrent from the older we need to update it replacing |
|
104 |
// the missing ammos with 0 quantity |
|
105 |
int oldlen = strlen(tmp1); |
|
106 |
for (int i = 0; i < oldlen; i++) { |
|
107 |
quantity[i] = tmp1[i]; |
|
108 |
probability[i] = tmp2[i]; |
|
109 |
delay[i] = tmp3[i]; |
|
110 |
crateness[i] = tmp4[i]; |
|
111 |
} |
|
3623 | 112 |
for (int i = oldlen; i < CURRENT_AMMOSIZE; i++) { |
3621 | 113 |
quantity[i] = '0'; |
114 |
probability[i] = '0'; |
|
115 |
delay[i] = '0'; |
|
116 |
crateness[i] = '0'; |
|
117 |
} |
|
118 |
||
119 |
[self.tableView reloadData]; |
|
3547 | 120 |
} |
3621 | 121 |
|
122 |
-(void) viewWillDisappear:(BOOL) animated { |
|
123 |
[super viewWillDisappear:animated]; |
|
124 |
||
3644
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
125 |
quantity[CURRENT_AMMOSIZE] = '\0'; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
126 |
probability[CURRENT_AMMOSIZE] = '\0'; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
127 |
delay[CURRENT_AMMOSIZE] = '\0'; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
128 |
crateness[CURRENT_AMMOSIZE] = '\0'; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
129 |
|
3621 | 130 |
NSString *quantityStr = [NSString stringWithUTF8String:quantity]; |
131 |
NSString *probabilityStr = [NSString stringWithUTF8String:probability]; |
|
132 |
NSString *delayStr = [NSString stringWithUTF8String:delay]; |
|
133 |
NSString *cratenessStr = [NSString stringWithUTF8String:crateness]; |
|
134 |
||
135 |
NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys: |
|
136 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version", |
|
137 |
quantityStr,@"ammostore_initialqt", |
|
138 |
probabilityStr,@"ammostore_probability", |
|
139 |
delayStr,@"ammostore_delay", |
|
140 |
cratenessStr,@"ammostore_crate", nil]; |
|
141 |
||
142 |
NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title]; |
|
143 |
[weapon writeToFile:ammoFile atomically:YES]; |
|
144 |
[ammoFile release]; |
|
145 |
[weapon release]; |
|
3547 | 146 |
} |
147 |
||
148 |
#pragma mark - |
|
149 |
#pragma mark Table view data source |
|
3621 | 150 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
151 |
return 1; |
|
3547 | 152 |
} |
153 |
||
3621 | 154 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3623 | 155 |
return CURRENT_AMMOSIZE; |
3547 | 156 |
} |
157 |
||
158 |
// Customize the appearance of table view cells. |
|
3621 | 159 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 160 |
static NSString *CellIdentifier = @"Cell"; |
3621 | 161 |
NSInteger row = [indexPath row]; |
3547 | 162 |
|
3621 | 163 |
WeaponCellView *cell = (WeaponCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
3547 | 164 |
if (cell == nil) { |
3621 | 165 |
cell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
3624 | 166 |
cell.delegate = self; |
3547 | 167 |
} |
168 |
||
3621 | 169 |
int x = ((row*32)/1024)*32; |
170 |
int y = (row*32)%1024; |
|
171 |
||
172 |
UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)]; |
|
173 |
cell.weaponIcon.image = img; |
|
174 |
cell.weaponName.text = [ammoNames objectAtIndex:row]; |
|
3624 | 175 |
cell.tag = row; |
176 |
||
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
177 |
[cell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO]; |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
178 |
[cell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO]; |
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
179 |
[cell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO]; |
3644
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
180 |
[cell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO]; |
3643
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
181 |
|
858b20bafb6e
reworked the ammunition configuration page (visually)
koda
parents:
3624
diff
changeset
|
182 |
cell.selectionStyle = UITableViewCellSelectionStyleNone; |
3547 | 183 |
return cell; |
184 |
} |
|
185 |
||
186 |
||
187 |
#pragma mark - |
|
188 |
#pragma mark Table view delegate |
|
3621 | 189 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3547 | 190 |
// Navigation logic may go here. Create and push another view controller. |
191 |
/* |
|
192 |
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; |
|
193 |
// ... |
|
194 |
// Pass the selected object to the new view controller. |
|
195 |
[self.navigationController pushViewController:detailViewController animated:YES]; |
|
196 |
[detailViewController release]; |
|
197 |
*/ |
|
198 |
} |
|
199 |
||
3624 | 200 |
#pragma mark - |
201 |
#pragma mark WeaponButtonControllerDelegate |
|
3644
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
202 |
-(void) updateValues:(NSArray *)withArray atIndex:(NSInteger) index { |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
203 |
quantity[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:0] intValue]] characterAtIndex:0]; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
204 |
probability[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:1] intValue]] characterAtIndex:0]; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
205 |
delay[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:2] intValue]] characterAtIndex:0]; |
42c5684289ae
finished ammo configuration (which is the last page missing in config \o/)
koda
parents:
3643
diff
changeset
|
206 |
crateness[index] = [[NSString stringWithFormat:@"%d",[[withArray objectAtIndex:3] intValue]] characterAtIndex:0]; |
3624 | 207 |
} |
3547 | 208 |
|
209 |
#pragma mark - |
|
210 |
#pragma mark Memory management |
|
3621 | 211 |
-(void) didReceiveMemoryWarning { |
3547 | 212 |
// Releases the view if it doesn't have a superview. |
213 |
[super didReceiveMemoryWarning]; |
|
214 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
215 |
} |
|
216 |
||
3621 | 217 |
-(void) viewDidUnload { |
218 |
free(quantity); |
|
219 |
free(probability); |
|
220 |
free(delay); |
|
221 |
free(crateness); |
|
222 |
[super viewDidUnload]; |
|
223 |
MSG_DIDUNLOAD(); |
|
3547 | 224 |
} |
225 |
||
226 |
||
3621 | 227 |
-(void) dealloc { |
3547 | 228 |
[super dealloc]; |
229 |
} |
|
230 |
||
231 |
||
232 |
@end |
|
233 |