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 |
|
3623
|
77 |
quantity = (char *)malloc(sizeof(char)*CURRENT_AMMOSIZE);
|
|
78 |
probability = (char *)malloc(sizeof(char)*CURRENT_AMMOSIZE);
|
|
79 |
delay = (char *)malloc(sizeof(char)*CURRENT_AMMOSIZE);
|
|
80 |
crateness = (char *)malloc(sizeof(char)*CURRENT_AMMOSIZE);
|
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 |
|
|
87 |
self.tableView.rowHeight = 75;
|
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 |
|
|
125 |
NSString *quantityStr = [NSString stringWithUTF8String:quantity];
|
|
126 |
NSString *probabilityStr = [NSString stringWithUTF8String:probability];
|
|
127 |
NSString *delayStr = [NSString stringWithUTF8String:delay];
|
|
128 |
NSString *cratenessStr = [NSString stringWithUTF8String:crateness];
|
|
129 |
|
|
130 |
NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
131 |
[NSNumber numberWithInt:CURRENT_AMMOSIZE],@"version",
|
|
132 |
quantityStr,@"ammostore_initialqt",
|
|
133 |
probabilityStr,@"ammostore_probability",
|
|
134 |
delayStr,@"ammostore_delay",
|
|
135 |
cratenessStr,@"ammostore_crate", nil];
|
|
136 |
|
|
137 |
NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title];
|
|
138 |
[weapon writeToFile:ammoFile atomically:YES];
|
|
139 |
[ammoFile release];
|
|
140 |
[weapon release];
|
3547
|
141 |
}
|
|
142 |
|
|
143 |
#pragma mark -
|
|
144 |
#pragma mark Table view data source
|
3621
|
145 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
146 |
return 1;
|
3547
|
147 |
}
|
|
148 |
|
|
149 |
|
3621
|
150 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3623
|
151 |
return CURRENT_AMMOSIZE;
|
3547
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
// Customize the appearance of table view cells.
|
3621
|
156 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
3547
|
157 |
static NSString *CellIdentifier = @"Cell";
|
3621
|
158 |
NSInteger row = [indexPath row];
|
3547
|
159 |
|
3621
|
160 |
WeaponCellView *cell = (WeaponCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
3547
|
161 |
if (cell == nil) {
|
3621
|
162 |
cell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
3624
|
163 |
cell.delegate = self;
|
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];
|
3624
|
172 |
cell.tag = row;
|
|
173 |
|
|
174 |
[cell.initialQt setTitle:[NSString stringWithFormat:@"%c",quantity[row]] forState:UIControlStateNormal];
|
3621
|
175 |
cell.probability.titleLabel.text = [NSString stringWithFormat:@"%c",probability[row]];
|
|
176 |
cell.delay.titleLabel.text = [NSString stringWithFormat:@"%c",delay[row]];
|
3624
|
177 |
cell.crateQt.titleLabel.text = [NSString stringWithFormat:@"%c",crateness[row]];
|
3547
|
178 |
return cell;
|
|
179 |
}
|
|
180 |
|
|
181 |
|
|
182 |
#pragma mark -
|
|
183 |
#pragma mark Table view delegate
|
3621
|
184 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
3547
|
185 |
// Navigation logic may go here. Create and push another view controller.
|
|
186 |
/*
|
|
187 |
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
|
|
188 |
// ...
|
|
189 |
// Pass the selected object to the new view controller.
|
|
190 |
[self.navigationController pushViewController:detailViewController animated:YES];
|
|
191 |
[detailViewController release];
|
|
192 |
*/
|
|
193 |
}
|
|
194 |
|
3624
|
195 |
#pragma mark -
|
|
196 |
#pragma mark WeaponButtonControllerDelegate
|
|
197 |
-(void) buttonPressed:(id) sender {
|
|
198 |
UIButton *button = (UIButton *)sender;
|
|
199 |
DLog(@"%@ %d", button.titleLabel.text, button.tag);
|
|
200 |
}
|
3547
|
201 |
|
|
202 |
#pragma mark -
|
|
203 |
#pragma mark Memory management
|
3621
|
204 |
-(void) didReceiveMemoryWarning {
|
3547
|
205 |
// Releases the view if it doesn't have a superview.
|
|
206 |
[super didReceiveMemoryWarning];
|
|
207 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
208 |
}
|
|
209 |
|
3621
|
210 |
-(void) viewDidUnload {
|
|
211 |
free(quantity);
|
|
212 |
free(probability);
|
|
213 |
free(delay);
|
|
214 |
free(crateness);
|
|
215 |
[super viewDidUnload];
|
|
216 |
MSG_DIDUNLOAD();
|
3547
|
217 |
}
|
|
218 |
|
|
219 |
|
3621
|
220 |
-(void) dealloc {
|
3547
|
221 |
[super dealloc];
|
|
222 |
}
|
|
223 |
|
|
224 |
|
|
225 |
@end
|
|
226 |
|