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 |
|
3621
|
77 |
ammoSize = [self.ammoNames count];
|
|
78 |
quantity = (char *)malloc(sizeof(char)*ammoSize);
|
|
79 |
probability = (char *)malloc(sizeof(char)*ammoSize);
|
|
80 |
delay = (char *)malloc(sizeof(char)*ammoSize);
|
|
81 |
crateness = (char *)malloc(sizeof(char)*ammoSize);
|
|
82 |
|
|
83 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
|
|
84 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:str];
|
|
85 |
self.ammoStoreImage = img;
|
|
86 |
[img release];
|
|
87 |
|
|
88 |
self.tableView.rowHeight = 75;
|
3547
|
89 |
}
|
3621
|
90 |
|
|
91 |
-(void) viewWillAppear:(BOOL) animated {
|
|
92 |
[super viewWillAppear:animated];
|
|
93 |
|
|
94 |
NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title];
|
|
95 |
NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile];
|
|
96 |
[ammoFile release];
|
|
97 |
|
|
98 |
const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String];
|
|
99 |
const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String];
|
|
100 |
const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String];
|
|
101 |
const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String];
|
|
102 |
[weapon release];
|
|
103 |
|
|
104 |
// if the new weaponset is diffrent from the older we need to update it replacing
|
|
105 |
// the missing ammos with 0 quantity
|
|
106 |
int oldlen = strlen(tmp1);
|
|
107 |
for (int i = 0; i < oldlen; i++) {
|
|
108 |
quantity[i] = tmp1[i];
|
|
109 |
probability[i] = tmp2[i];
|
|
110 |
delay[i] = tmp3[i];
|
|
111 |
crateness[i] = tmp4[i];
|
|
112 |
}
|
|
113 |
for (int i = oldlen; i < ammoSize; i++) {
|
|
114 |
quantity[i] = '0';
|
|
115 |
probability[i] = '0';
|
|
116 |
delay[i] = '0';
|
|
117 |
crateness[i] = '0';
|
|
118 |
}
|
|
119 |
|
|
120 |
[self.tableView reloadData];
|
3547
|
121 |
}
|
3621
|
122 |
|
|
123 |
-(void) viewWillDisappear:(BOOL) animated {
|
|
124 |
[super viewWillDisappear:animated];
|
|
125 |
|
|
126 |
NSString *quantityStr = [NSString stringWithUTF8String:quantity];
|
|
127 |
NSString *probabilityStr = [NSString stringWithUTF8String:probability];
|
|
128 |
NSString *delayStr = [NSString stringWithUTF8String:delay];
|
|
129 |
NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
|
|
130 |
|
|
131 |
NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
132 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
|
|
133 |
quantityStr,@"ammostore_initialqt",
|
|
134 |
probabilityStr,@"ammostore_probability",
|
|
135 |
delayStr,@"ammostore_delay",
|
|
136 |
cratenessStr,@"ammostore_crate", nil];
|
|
137 |
|
|
138 |
NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title];
|
|
139 |
[weapon writeToFile:ammoFile atomically:YES];
|
|
140 |
[ammoFile release];
|
|
141 |
[weapon release];
|
3547
|
142 |
}
|
|
143 |
|
|
144 |
#pragma mark -
|
|
145 |
#pragma mark Table view data source
|
3621
|
146 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
147 |
return 1;
|
3547
|
148 |
}
|
|
149 |
|
|
150 |
|
3621
|
151 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
152 |
return ammoSize;
|
3547
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
// Customize the appearance of table view cells.
|
3621
|
157 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
3547
|
158 |
static NSString *CellIdentifier = @"Cell";
|
3621
|
159 |
NSInteger row = [indexPath row];
|
3547
|
160 |
|
3621
|
161 |
WeaponCellView *cell = (WeaponCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
3547
|
162 |
if (cell == nil) {
|
3621
|
163 |
cell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
3547
|
164 |
}
|
|
165 |
|
3621
|
166 |
int x = ((row*32)/1024)*32;
|
|
167 |
int y = (row*32)%1024;
|
|
168 |
|
|
169 |
UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
|
|
170 |
cell.weaponIcon.image = img;
|
|
171 |
cell.weaponName.text = [ammoNames objectAtIndex:row];
|
|
172 |
|
|
173 |
cell.initialQt.titleLabel.text = [NSString stringWithFormat:@"%c",quantity[row]];
|
|
174 |
cell.probability.titleLabel.text = [NSString stringWithFormat:@"%c",probability[row]];
|
|
175 |
cell.delay.titleLabel.text = [NSString stringWithFormat:@"%c",delay[row]];
|
|
176 |
cell.initialQt.titleLabel.text = [NSString stringWithFormat:@"%c",crateness[row]];
|
3547
|
177 |
return cell;
|
|
178 |
}
|
|
179 |
|
|
180 |
|
|
181 |
#pragma mark -
|
|
182 |
#pragma mark Table view delegate
|
3621
|
183 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
3547
|
184 |
// Navigation logic may go here. Create and push another view controller.
|
|
185 |
/*
|
|
186 |
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
|
|
187 |
// ...
|
|
188 |
// Pass the selected object to the new view controller.
|
|
189 |
[self.navigationController pushViewController:detailViewController animated:YES];
|
|
190 |
[detailViewController release];
|
|
191 |
*/
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
#pragma mark -
|
|
196 |
#pragma mark Memory management
|
3621
|
197 |
-(void) didReceiveMemoryWarning {
|
3547
|
198 |
// Releases the view if it doesn't have a superview.
|
|
199 |
[super didReceiveMemoryWarning];
|
|
200 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
201 |
}
|
|
202 |
|
3621
|
203 |
-(void) viewDidUnload {
|
|
204 |
free(quantity);
|
|
205 |
free(probability);
|
|
206 |
free(delay);
|
|
207 |
free(crateness);
|
|
208 |
[super viewDidUnload];
|
|
209 |
MSG_DIDUNLOAD();
|
3547
|
210 |
}
|
|
211 |
|
|
212 |
|
3621
|
213 |
-(void) dealloc {
|
3547
|
214 |
[super dealloc];
|
|
215 |
}
|
|
216 |
|
|
217 |
|
|
218 |
@end
|
|
219 |
|