29 |
29 |
30 #pragma mark - |
30 #pragma mark - |
31 #pragma mark View lifecycle |
31 #pragma mark View lifecycle |
32 -(void) viewDidLoad { |
32 -(void) viewDidLoad { |
33 [super viewDidLoad]; |
33 [super viewDidLoad]; |
34 |
34 |
35 NSString *trFilePath = [NSString stringWithFormat:@"%@/%@.txt",LOCALE_DIRECTORY(),[[NSLocale preferredLanguages] objectAtIndex:0]]; |
35 NSString *trFilePath = [NSString stringWithFormat:@"%@/%@.txt",LOCALE_DIRECTORY(),[[NSLocale preferredLanguages] objectAtIndex:0]]; |
36 // fill the data structure that we are going to read |
36 // fill the data structure that we are going to read |
37 LoadLocaleWrapper([trFilePath UTF8String]); |
37 LoadLocaleWrapper([trFilePath UTF8String]); |
38 |
38 |
39 quantity = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
39 quantity = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
40 probability = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
40 probability = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
41 delay = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
41 delay = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
42 crateness = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
42 crateness = (char *)malloc(sizeof(char)*(HW_getNumberOfWeapons()+1)); |
43 |
43 |
44 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
44 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
45 UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; |
45 UIImage *img = [[UIImage alloc] initWithContentsOfFile:str]; |
46 self.ammoStoreImage = img; |
46 self.ammoStoreImage = img; |
47 [img release]; |
47 [img release]; |
48 |
48 |
49 self.title = NSLocalizedString(@"Edit weapons preferences",@""); |
49 self.title = NSLocalizedString(@"Edit weapons preferences",@""); |
50 } |
50 } |
51 |
51 |
52 -(void) viewWillAppear:(BOOL) animated { |
52 -(void) viewWillAppear:(BOOL) animated { |
53 [super viewWillAppear:animated]; |
53 [super viewWillAppear:animated]; |
54 |
54 |
55 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
55 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
56 NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; |
56 NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile]; |
57 [ammoFile release]; |
57 [ammoFile release]; |
58 |
58 |
59 self.description = [weapon objectForKey:@"description"]; |
59 self.description = [weapon objectForKey:@"description"]; |
60 const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; |
60 const char *tmp1 = [[weapon objectForKey:@"ammostore_initialqt"] UTF8String]; |
61 const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; |
61 const char *tmp2 = [[weapon objectForKey:@"ammostore_probability"] UTF8String]; |
62 const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String]; |
62 const char *tmp3 = [[weapon objectForKey:@"ammostore_delay"] UTF8String]; |
63 const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String]; |
63 const char *tmp4 = [[weapon objectForKey:@"ammostore_crate"] UTF8String]; |
64 [weapon release]; |
64 [weapon release]; |
65 |
65 |
66 // if the new weaponset is diffrent from the older we need to update it replacing |
66 // if the new weaponset is diffrent from the older we need to update it replacing |
67 // the missing ammos with 0 quantity |
67 // the missing ammos with 0 quantity |
68 int oldlen = strlen(tmp1); |
68 int oldlen = strlen(tmp1); |
69 for (int i = 0; i < oldlen; i++) { |
69 for (int i = 0; i < oldlen; i++) { |
70 quantity[i] = tmp1[i]; |
70 quantity[i] = tmp1[i]; |
90 -(void) saveAmmos { |
90 -(void) saveAmmos { |
91 quantity[HW_getNumberOfWeapons()] = '\0'; |
91 quantity[HW_getNumberOfWeapons()] = '\0'; |
92 probability[HW_getNumberOfWeapons()] = '\0'; |
92 probability[HW_getNumberOfWeapons()] = '\0'; |
93 delay[HW_getNumberOfWeapons()] = '\0'; |
93 delay[HW_getNumberOfWeapons()] = '\0'; |
94 crateness[HW_getNumberOfWeapons()] = '\0'; |
94 crateness[HW_getNumberOfWeapons()] = '\0'; |
95 |
95 |
96 NSString *quantityStr = [NSString stringWithUTF8String:quantity]; |
96 NSString *quantityStr = [NSString stringWithUTF8String:quantity]; |
97 NSString *probabilityStr = [NSString stringWithUTF8String:probability]; |
97 NSString *probabilityStr = [NSString stringWithUTF8String:probability]; |
98 NSString *delayStr = [NSString stringWithUTF8String:delay]; |
98 NSString *delayStr = [NSString stringWithUTF8String:delay]; |
99 NSString *cratenessStr = [NSString stringWithUTF8String:crateness]; |
99 NSString *cratenessStr = [NSString stringWithUTF8String:crateness]; |
100 |
100 |
101 NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys: |
101 NSDictionary *weapon = [[NSDictionary alloc] initWithObjectsAndKeys: |
102 quantityStr,@"ammostore_initialqt", |
102 quantityStr,@"ammostore_initialqt", |
103 probabilityStr,@"ammostore_probability", |
103 probabilityStr,@"ammostore_probability", |
104 delayStr,@"ammostore_delay", |
104 delayStr,@"ammostore_delay", |
105 cratenessStr,@"ammostore_crate", |
105 cratenessStr,@"ammostore_crate", |
106 self.description,@"description", |
106 self.description,@"description", |
107 nil]; |
107 nil]; |
108 |
108 |
109 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
109 NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName]; |
110 [weapon writeToFile:ammoFile atomically:YES]; |
110 [weapon writeToFile:ammoFile atomically:YES]; |
111 [ammoFile release]; |
111 [ammoFile release]; |
112 [weapon release]; |
112 [weapon release]; |
113 } |
113 } |
129 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
129 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
130 static NSString *CellIdentifier0 = @"Cell0"; |
130 static NSString *CellIdentifier0 = @"Cell0"; |
131 static NSString *CellIdentifier1 = @"Cell1"; |
131 static NSString *CellIdentifier1 = @"Cell1"; |
132 NSInteger row = [indexPath row]; |
132 NSInteger row = [indexPath row]; |
133 UITableViewCell *cell = nil; |
133 UITableViewCell *cell = nil; |
134 |
134 |
135 if (0 == [indexPath section]) { |
135 if (0 == [indexPath section]) { |
136 EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
136 EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
137 if (editableCell == nil) { |
137 if (editableCell == nil) { |
138 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
138 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault |
139 reuseIdentifier:CellIdentifier0] autorelease]; |
139 reuseIdentifier:CellIdentifier0] autorelease]; |
141 } |
141 } |
142 editableCell.tag = row; |
142 editableCell.tag = row; |
143 editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
143 editableCell.selectionStyle = UITableViewCellSelectionStyleNone; |
144 editableCell.imageView.image = nil; |
144 editableCell.imageView.image = nil; |
145 editableCell.detailTextLabel.text = nil; |
145 editableCell.detailTextLabel.text = nil; |
146 |
146 |
147 if (row == 0) { |
147 if (row == 0) { |
148 editableCell.textField.text = self.weaponName; |
148 editableCell.textField.text = self.weaponName; |
149 editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
149 editableCell.textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
150 } else { |
150 } else { |
151 editableCell.minimumCharacters = 0; |
151 editableCell.minimumCharacters = 0; |