project_files/HedgewarsMobile/Classes/WeaponCellView.m
changeset 3624 304c6d32383a
parent 3621 a8ddf681ba7d
child 3643 858b20bafb6e
equal deleted inserted replaced
3623:f14db208f2fa 3624:304c6d32383a
     8 
     8 
     9 #import "WeaponCellView.h"
     9 #import "WeaponCellView.h"
    10 #import "CommodityFunctions.h"
    10 #import "CommodityFunctions.h"
    11 
    11 
    12 @implementation WeaponCellView
    12 @implementation WeaponCellView
    13 @synthesize weaponName, weaponIcon, initialQt, probability, delay, crateQt;
    13 @synthesize delegate, weaponName, weaponIcon, initialQt, probability, delay, crateQt;
    14 
    14 
    15 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    15 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    16     if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
    16     if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
    17         // Initialization code
    17         delegate = nil;
       
    18         
    18         weaponName = [[UILabel alloc] init];
    19         weaponName = [[UILabel alloc] init];
    19         weaponName.backgroundColor = [UIColor clearColor];
    20         weaponName.backgroundColor = [UIColor clearColor];
    20         weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    21         weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    21         weaponIcon = [[UIImageView alloc] init];
    22         weaponIcon = [[UIImageView alloc] init];
    22     
    23     
    23         NSString *imgStr;
    24         NSString *imgStr;
    24         initialQt = [[UIButton alloc] init];
    25         initialQt = [[UIButton alloc] init];
    25         imgStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()];
    26         imgStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()];
       
    27         [initialQt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    26         [initialQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    28         [initialQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
       
    29         [initialQt addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    27         
    30         
    28         probability = [[UIButton alloc] init];
    31         probability = [[UIButton alloc] init];
    29         imgStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()];
    32         imgStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()];
    30         [probability setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    33         [probability setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    31         
    34         [probability addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
       
    35 
    32         delay = [[UIButton alloc] init];
    36         delay = [[UIButton alloc] init];
    33         imgStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()];
    37         imgStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()];
    34         [delay setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    38         [delay setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    35         
    39         [delay addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
       
    40 
    36         crateQt = [[UIButton alloc] init];
    41         crateQt = [[UIButton alloc] init];
    37         imgStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()];
    42         imgStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()];
    38         [crateQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    43         [crateQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal];
    39         
    44         [crateQt addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
       
    45 
    40         [self.contentView addSubview:weaponName];
    46         [self.contentView addSubview:weaponName];
    41         [self.contentView addSubview:weaponIcon];
    47         [self.contentView addSubview:weaponIcon];
    42         [self.contentView addSubview:initialQt];
    48         [self.contentView addSubview:initialQt];
    43         [self.contentView addSubview:probability];
    49         [self.contentView addSubview:probability];
    44         [self.contentView addSubview:delay];
    50         [self.contentView addSubview:delay];
    52 
    58 
    53     CGRect contentRect = self.contentView.bounds;
    59     CGRect contentRect = self.contentView.bounds;
    54     CGFloat boundsX = contentRect.origin.x;
    60     CGFloat boundsX = contentRect.origin.x;
    55     CGRect frame;
    61     CGRect frame;
    56     
    62     
    57     frame = CGRectMake(boundsX+10, 5, 32, 32);
    63     frame = CGRectMake(boundsX+5, 5, 32, 32);
    58     weaponIcon.frame = frame;
    64     weaponIcon.frame = frame;
    59 
    65 
    60     frame = CGRectMake(boundsX+50, 9, 200, 25);
    66     frame = CGRectMake(boundsX+45, 8, 200, 25);
    61     weaponName.frame = frame;
    67     weaponName.frame = frame;
    62     
    68     
    63     // second line
    69     // second line
    64     frame = CGRectMake(boundsX+20, 40, 32, 32);
    70     frame = CGRectMake(boundsX+20, 40, 32, 32);
    65     initialQt.frame = frame;
    71     initialQt.frame = frame;
    79     [super setSelected:selected animated:animated];
    85     [super setSelected:selected animated:animated];
    80     // Configure the view for the selected state
    86     // Configure the view for the selected state
    81 }
    87 }
    82 */
    88 */
    83 
    89 
       
    90 -(void) buttonPressed:(id) sender {
       
    91     if (self.delegate != nil) {
       
    92         [(UIButton *)sender setTag:self.tag];
       
    93         [delegate buttonPressed:sender];
       
    94     } else
       
    95         DLog(@"error - delegate = nil!");
       
    96 }
       
    97 
    84 -(void) dealloc {
    98 -(void) dealloc {
    85     [weaponName release];
    99     [weaponName release];
    86     [weaponIcon release];
   100     [weaponIcon release];
    87     [initialQt release];
   101     [initialQt release];
    88     [probability release];
   102     [probability release];