project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
changeset 6078 8c0cc07731e5
parent 6000 dbcebcd3d79f
child 6209 074ab6ebcb3e
equal deleted inserted replaced
6077:d8fa5a85d24f 6078:8c0cc07731e5
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "AmmoMenuViewController.h"
    22 #import "AmmoMenuViewController.h"
    23 #import <QuartzCore/QuartzCore.h>
    23 #import <QuartzCore/QuartzCore.h>
    24 #import "CommodityFunctions.h"
    24 
    25 #import "UIImageExtra.h"
       
    26 #import "PascalImports.h"
       
    27 
    25 
    28 #define BTNS_PER_ROW         9
    26 #define BTNS_PER_ROW         9
    29 #define DEFAULT_DESCRIPTION  IS_IPAD() ? \
    27 #define DEFAULT_DESCRIPTION  IS_IPAD() ? \
    30                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen.",@"") : \
    28                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen.",@"") : \
    31                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"")
    29                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"")
    90 -(void) loadLabels {
    88 -(void) loadLabels {
    91     int x = 12;
    89     int x = 12;
    92     int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
    90     int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
    93     UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
    91     UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
    94     name.backgroundColor = [UIColor clearColor];
    92     name.backgroundColor = [UIColor clearColor];
    95     name.textColor = UICOLOR_HW_YELLOW_BODER;
    93     name.textColor = [UIColor darkYellowColor];
    96     name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    94     name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    97     self.nameLabel = name;
    95     self.nameLabel = name;
    98     [self.view addSubview:self.nameLabel];
    96     [self.view addSubview:self.nameLabel];
    99     [name release];
    97     [name release];
   100 
    98 
   150         }
   148         }
   151 
   149 
   152         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
   150         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
   153         button.frame = CGRectMake(x, y, 40, 40);
   151         button.frame = CGRectMake(x, y, 40, 40);
   154         button.tag = i;
   152         button.tag = i;
   155         button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
   153         button.layer.borderColor = [[UIColor lightYellowColor] CGColor];
   156         button.layer.borderWidth = w;
   154         button.layer.borderWidth = w;
   157         [button.layer setCornerRadius:radius];
   155         [button.layer setCornerRadius:radius];
   158         [button.layer setMasksToBounds:YES];
   156         [button.layer setMasksToBounds:YES];
   159         [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
   157         [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
   160         [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
   158         [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
   161         [button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
   159         [button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
   162         [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
   160         [button setTitleColor:[UIColor lightYellowColor] forState:UIControlStateNormal];
   163         button.titleLabel.backgroundColor = [UIColor blackColor];
   161         button.titleLabel.backgroundColor = [UIColor blackColor];
   164         button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
   162         button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
   165         [button.titleLabel.layer setCornerRadius:3];
   163         [button.titleLabel.layer setCornerRadius:3];
   166         [button.titleLabel.layer setMasksToBounds:YES];
   164         [button.titleLabel.layer setMasksToBounds:YES];
   167         button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
   165         button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
   168         button.titleLabel.layer.borderWidth = 1;
   166         button.titleLabel.layer.borderWidth = 1;
   169         [self.view addSubview:button];
   167         [self.view addSubview:button];
   170         [array addObject:button];
   168         [array addObject:button];
   171 
   169 
   172         int size = 32*getScreenScale();
   170         int size = 32 * [[UIScreen mainScreen] scale];
   173         int x_src = ((i*size)/(int)(ammoStoreImage.size.height*getScreenScale()))*size;
   171         int x_src = ((i*size)/(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]))*size;
   174         int y_src = (i*size)%(int)(ammoStoreImage.size.height*getScreenScale());
   172         int y_src = (i*size)%(int)(ammoStoreImage.size.height * [[UIScreen mainScreen] scale]);
   175         UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, size, size)];
   173         UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, size, size)];
   176         [imgs addObject:img];
   174         [imgs addObject:img];
   177     }
   175     }
   178     [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO];
   176     [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO];
   179     [array release];
   177     [array release];
   219                         UIImage *img = [self.imagesArray objectAtIndex:i];
   217                         UIImage *img = [self.imagesArray objectAtIndex:i];
   220                         [button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal];
   218                         [button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal];
   221                         shouldUpdateImage[i] = YES;
   219                         shouldUpdateImage[i] = YES;
   222                     }
   220                     }
   223                 } else {
   221                 } else {
   224                     button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
   222                     button.layer.borderColor = [[UIColor lightYellowColor] CGColor];
   225                     [button setTitle:nil forState:UIControlStateNormal];
   223                     [button setTitle:nil forState:UIControlStateNormal];
   226                     if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == YES) {
   224                     if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == YES) {
   227                         UIImage *img = [self.imagesArray objectAtIndex:i];
   225                         UIImage *img = [self.imagesArray objectAtIndex:i];
   228                         [button setBackgroundImage:img forState:UIControlStateNormal];
   226                         [button setBackgroundImage:img forState:UIControlStateNormal];
   229                         shouldUpdateImage[i] = NO;
   227                         shouldUpdateImage[i] = NO;