project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
changeset 3989 adffb668f06e
parent 3984 d92509c2f255
child 3996 eb549fd864a5
equal deleted inserted replaced
3988:044cc945b2f8 3989:adffb668f06e
    23 #import <QuartzCore/QuartzCore.h>
    23 #import <QuartzCore/QuartzCore.h>
    24 #import "CommodityFunctions.h"
    24 #import "CommodityFunctions.h"
    25 #import "UIImageExtra.h"
    25 #import "UIImageExtra.h"
    26 #import "PascalImports.h"
    26 #import "PascalImports.h"
    27 
    27 
    28 #define BTNS_PER_ROW 9
    28 #define BTNS_PER_ROW         9
       
    29 #define DEFAULT_DESCRIPTION  NSLocalizedString(@"Hold your finger on a weapon to see what it does",@"")
    29 
    30 
    30 @implementation AmmoMenuViewController
    31 @implementation AmmoMenuViewController
    31 @synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible;
    32 @synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible;
    32 
    33 
    33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    85     self.isVisible = NO;
    86     self.isVisible = NO;
    86 }
    87 }
    87 
    88 
    88 #pragma mark -
    89 #pragma mark -
    89 #pragma mark drawing
    90 #pragma mark drawing
    90 -(void) prepareLabels {
    91 -(void) loadLabels {
    91     int x = 12;
    92     int x = 12;
    92     int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
    93     int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
    93     UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
    94     UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
    94     name.backgroundColor = [UIColor clearColor];
    95     name.backgroundColor = [UIColor clearColor];
    95     name.textColor = UICOLOR_HW_YELLOW_BODER;
    96     name.textColor = UICOLOR_HW_YELLOW_BODER;
   109     [caption release];
   110     [caption release];
   110 
   111 
   111     UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(x+2, y+20, 410, 53)];
   112     UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(x+2, y+20, 410, 53)];
   112     description.backgroundColor = [UIColor clearColor];
   113     description.backgroundColor = [UIColor clearColor];
   113     description.textColor = [UIColor whiteColor];
   114     description.textColor = [UIColor whiteColor];
       
   115     description.text = DEFAULT_DESCRIPTION;
   114     description.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
   116     description.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
   115     description.adjustsFontSizeToFitWidth = YES;
   117     description.adjustsFontSizeToFitWidth = YES;
   116     description.minimumFontSize = 8;
   118     description.minimumFontSize = 8;
   117     description.numberOfLines = 0;
   119     description.numberOfLines = 0;
   118     self.extraLabel = description;
   120     self.extraLabel = description;
   155         button.layer.borderWidth = w;
   157         button.layer.borderWidth = w;
   156         [button.layer setCornerRadius:radius];
   158         [button.layer setCornerRadius:radius];
   157         [button.layer setMasksToBounds:YES];
   159         [button.layer setMasksToBounds:YES];
   158         [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
   160         [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
   159         [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
   161         [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
   160         [button addTarget:self action:@selector(buttonCancel:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
   162         [button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
   161         [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
   163         [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
   162         button.titleLabel.backgroundColor = [UIColor blackColor];
   164         button.titleLabel.backgroundColor = [UIColor blackColor];
   163         button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
   165         button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
   164         [button.titleLabel.layer setCornerRadius:3];
   166         [button.titleLabel.layer setCornerRadius:3];
   165         [button.titleLabel.layer setMasksToBounds:YES];
   167         [button.titleLabel.layer setMasksToBounds:YES];
   178 
   180 
   179     [self performSelectorOnMainThread:@selector(setImagesArray:) withObject:imgs waitUntilDone:NO];
   181     [self performSelectorOnMainThread:@selector(setImagesArray:) withObject:imgs waitUntilDone:NO];
   180     [imgs release];
   182     [imgs release];
   181     [ammoStoreImage release];
   183     [ammoStoreImage release];
   182 
   184 
       
   185     [self performSelectorOnMainThread:@selector(loadLabels) withObject:nil waitUntilDone:NO];
       
   186     
   183     [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:YES];
   187     [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:YES];
   184     UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object;
   188     UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object;
   185     [spinner stopAnimating];
   189     [spinner stopAnimating];
   186     [pool drain];
   190     [pool drain];
   187 }
   191 }
   245 #pragma mark -
   249 #pragma mark -
   246 #pragma mark user interaction
   250 #pragma mark user interaction
   247 -(void) buttonPressed:(id) sender {
   251 -(void) buttonPressed:(id) sender {
   248     UIButton *theButton = (UIButton *)sender;
   252     UIButton *theButton = (UIButton *)sender;
   249     if (self.nameLabel == nil || self.extraLabel == nil)
   253     if (self.nameLabel == nil || self.extraLabel == nil)
   250         [self prepareLabels];
   254         [self loadLabels];
   251 
   255 
   252     self.nameLabel.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(theButton.tag)];
   256     self.nameLabel.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(theButton.tag)];
   253     // description contains a lot of unnecessary stuff, we clean it by removing .|, !| and ?|
   257     // description contains a lot of unnecessary stuff, we clean it by removing .|, !| and ?|
   254     NSString *description = [NSString stringWithUTF8String:HW_getWeaponDescriptionByIndex(theButton.tag)];
   258     NSString *description = [NSString stringWithUTF8String:HW_getWeaponDescriptionByIndex(theButton.tag)];
   255     NSArray *elements = [description componentsSeparatedByString:@".|"];
   259     NSArray *elements = [description componentsSeparatedByString:@".|"];
   260         self.captionLabel.text = NSLocalizedString(@"This weapon is locked",@"");
   264         self.captionLabel.text = NSLocalizedString(@"This weapon is locked",@"");
   261     else
   265     else
   262         self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)];
   266         self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)];
   263 }
   267 }
   264 
   268 
   265 -(void) buttonCancel:(id) sender {
   269 -(void) buttonCancelled:(id) sender {
   266     self.nameLabel.text = nil;
   270     self.nameLabel.text = nil;
   267     self.extraLabel.text = nil;
   271     self.extraLabel.text = DEFAULT_DESCRIPTION;
   268     self.captionLabel.text = nil;
   272     self.captionLabel.text = nil;
   269 }
   273 }
   270 
   274 
   271 -(void) buttonReleased:(id) sender {
   275 -(void) buttonReleased:(id) sender {
   272     UIButton *theButton = (UIButton *)sender;
   276     UIButton *theButton = (UIButton *)sender;
   273     if (self.nameLabel == nil || self.extraLabel == nil)
   277     if (self.nameLabel == nil || self.extraLabel == nil)
   274         [self prepareLabels];
   278         [self loadLabels];
   275 
   279 
   276     self.nameLabel.text = nil;
   280     self.nameLabel.text = nil;
   277     self.extraLabel.text = nil;
   281     self.extraLabel.text = DEFAULT_DESCRIPTION;
   278     self.captionLabel.text = nil;
   282     self.captionLabel.text = nil;
   279     if (theButton.currentTitle == nil) {
   283     if (theButton.currentTitle == nil) {
   280         HW_setWeapon(theButton.tag);
   284         HW_setWeapon(theButton.tag);
   281         playSound(@"clickSound");
   285         playSound(@"clickSound");
   282         if (IS_DUALHEAD() == NO)
   286         if (IS_DUALHEAD() == NO)