103 [button.layer setMasksToBounds:YES]; |
103 [button.layer setMasksToBounds:YES]; |
104 [button setBackgroundImage:img forState:UIControlStateNormal]; |
104 [button setBackgroundImage:img forState:UIControlStateNormal]; |
105 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
105 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
106 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
106 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
107 button.titleLabel.backgroundColor = [UIColor blackColor]; |
107 button.titleLabel.backgroundColor = [UIColor blackColor]; |
108 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
108 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
109 [button.titleLabel.layer setCornerRadius:3]; |
109 [button.titleLabel.layer setCornerRadius:3]; |
110 [button.titleLabel.layer setMasksToBounds:YES]; |
110 [button.titleLabel.layer setMasksToBounds:YES]; |
111 button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
111 button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
112 button.titleLabel.layer.borderWidth = 1; |
112 button.titleLabel.layer.borderWidth = 1; |
113 [self.view addSubview:button]; |
113 [self.view addSubview:button]; |
125 -(void) ready:(id) object { |
125 -(void) ready:(id) object { |
126 NSDictionary *dict = (NSDictionary *)object; |
126 NSDictionary *dict = (NSDictionary *)object; |
127 [[dict objectForKey:@"spinner"] stopAnimating]; |
127 [[dict objectForKey:@"spinner"] stopAnimating]; |
128 self.weaponsImage = [dict objectForKey:@"image"]; |
128 self.weaponsImage = [dict objectForKey:@"image"]; |
129 self.buttonsArray = [dict objectForKey:@"array"]; |
129 self.buttonsArray = [dict objectForKey:@"array"]; |
130 [self updateVisuals:nil]; |
130 [self updateAmmoVisuals]; |
131 } |
131 } |
132 |
132 |
133 -(void) updateVisuals:(NSNotification *) object { |
133 -(void) updateAmmoVisuals { |
134 unsigned char *loadout = HW_getAmmoCounts(); |
134 unsigned char *loadout = HW_getAmmoCounts(); |
135 int turns = HW_getTurnsForCurrentTeam(); |
135 int turns = HW_getTurnsForCurrentTeam(); |
136 |
136 |
137 if (self.buttonsArray == nil) { |
137 if (self.buttonsArray == nil) { |
138 UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
138 UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
151 self.view.userInteractionEnabled = YES; |
151 self.view.userInteractionEnabled = YES; |
152 |
152 |
153 for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
153 for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
154 UIButton *button = [self.buttonsArray objectAtIndex:i]; |
154 UIButton *button = [self.buttonsArray objectAtIndex:i]; |
155 if (loadout[i] > 0) { |
155 if (loadout[i] > 0) { |
156 /*if (button.enabled == NO) { |
156 if (button.enabled == NO) { |
157 int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
157 int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
158 int y_src = (i*32)%(int)self.weaponsImage.size.height; |
158 int y_src = (i*32)%(int)self.weaponsImage.size.height; |
159 UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
159 UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
160 [button setBackgroundImage:img forState:UIControlStateNormal]; |
160 [button setBackgroundImage:img forState:UIControlStateNormal]; |
161 }*/ |
161 } |
162 button.enabled = YES; |
162 button.enabled = YES; |
163 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
163 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
164 } else { |
164 } else { |
165 /*if (button.enabled == YES) { |
165 if (button.enabled == YES) |
166 int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
166 [button setBackgroundImage:nil forState:UIControlStateNormal]; |
167 int y_src = (i*32)%(int)self.weaponsImage.size.height; |
|
168 UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
169 [button setBackgroundImage:img forState:UIControlStateNormal]; |
|
170 }*/ |
|
171 button.enabled = NO; |
167 button.enabled = NO; |
172 button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
168 button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
173 //NSLog(@"disabled: %d",button.tag); |
|
174 } |
169 } |
175 |
170 |
176 if (button.enabled == YES) { |
171 if (button.enabled == YES) { |
177 if (delay[i]-turns >= 0) { |
172 if (delay[i]-turns >= 0) { |
178 // NSLog(@"delayed(%d) %d",delay[i], button.tag); |
|
179 button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
173 button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
180 [button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal]; |
174 [button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal]; |
|
175 if (button.enabled == YES) { |
|
176 int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
|
177 int y_src = (i*32)%(int)self.weaponsImage.size.height; |
|
178 UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
179 [button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal]; |
|
180 } |
181 } else { |
181 } else { |
182 // NSLog(@"enabled %d",button.tag); |
|
183 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
182 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
184 [button setTitle:@"" forState:UIControlStateNormal]; |
183 [button setTitle:@"" forState:UIControlStateNormal]; |
|
184 if (button.enabled == YES) { |
|
185 int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
|
186 int y_src = (i*32)%(int)self.weaponsImage.size.height; |
|
187 UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
188 [button setBackgroundImage:img forState:UIControlStateNormal]; |
|
189 } |
185 } |
190 } |
186 } |
191 } |
187 } |
192 } |
188 } |
193 } |
189 |
194 |