project_files/HedgewarsMobile/Classes/WeaponCellView.m
changeset 3697 d5b30d6373fc
parent 3667 9359a70df013
child 3766 36b625111609
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    14             initialImg, probabImg, delayImg, crateImg, initialLab, probLab, delLab, craLab;
    14             initialImg, probabImg, delayImg, crateImg, initialLab, probLab, delLab, craLab;
    15 
    15 
    16 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    16 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    17     if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
    17     if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
    18         delegate = nil;
    18         delegate = nil;
    19         
    19 
    20         weaponName = [[UILabel alloc] init];
    20         weaponName = [[UILabel alloc] init];
    21         weaponName.backgroundColor = [UIColor clearColor];
    21         weaponName.backgroundColor = [UIColor clearColor];
    22         weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    22         weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    23         weaponIcon = [[UIImageView alloc] init];
    23         weaponIcon = [[UIImageView alloc] init];
    24     
    24 
    25         initialQt = [[UISlider alloc] init];
    25         initialQt = [[UISlider alloc] init];
    26         [initialQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    26         [initialQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    27         initialQt.maximumValue = 9;
    27         initialQt.maximumValue = 9;
    28         initialQt.minimumValue = 0;
    28         initialQt.minimumValue = 0;
    29         
    29 
    30         probabilityQt = [[UISlider alloc] init];
    30         probabilityQt = [[UISlider alloc] init];
    31         [probabilityQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    31         [probabilityQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    32         probabilityQt.maximumValue = 9;
    32         probabilityQt.maximumValue = 9;
    33         probabilityQt.minimumValue = 0;
    33         probabilityQt.minimumValue = 0;
    34         
    34 
    35         delayQt = [[UISlider alloc] init];
    35         delayQt = [[UISlider alloc] init];
    36         [delayQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    36         [delayQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    37         delayQt.maximumValue = 9;
    37         delayQt.maximumValue = 9;
    38         delayQt.minimumValue = 0;
    38         delayQt.minimumValue = 0;
    39         
    39 
    40         crateQt = [[UISlider alloc] init];
    40         crateQt = [[UISlider alloc] init];
    41         [crateQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    41         [crateQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    42         crateQt.maximumValue = 9;
    42         crateQt.maximumValue = 9;
    43         crateQt.minimumValue = 0;
    43         crateQt.minimumValue = 0;
    44     
    44 
    45         NSString *imgAmmoStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()];
    45         NSString *imgAmmoStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()];
    46         NSString *imgDamageStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()];
    46         NSString *imgDamageStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()];
    47         NSString *imgTimeStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()];
    47         NSString *imgTimeStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()];
    48         NSString *imgBoxStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()];
    48         NSString *imgBoxStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()];
    49 
    49 
    50         initialImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgAmmoStr]];
    50         initialImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgAmmoStr]];
    51         probabImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgDamageStr]];
    51         probabImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgDamageStr]];
    52         delayImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgTimeStr]];
    52         delayImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgTimeStr]];
    53         crateImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgBoxStr]];
    53         crateImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgBoxStr]];
    54         
    54 
    55         initialLab = [[UILabel alloc] init];
    55         initialLab = [[UILabel alloc] init];
    56         initialLab.backgroundColor = [UIColor clearColor];
    56         initialLab.backgroundColor = [UIColor clearColor];
    57         initialLab.textColor = [UIColor grayColor];
    57         initialLab.textColor = [UIColor grayColor];
    58         initialLab.textAlignment = UITextAlignmentCenter;
    58         initialLab.textAlignment = UITextAlignmentCenter;
    59         
    59 
    60         probLab = [[UILabel alloc] init];
    60         probLab = [[UILabel alloc] init];
    61         probLab.backgroundColor = [UIColor clearColor];
    61         probLab.backgroundColor = [UIColor clearColor];
    62         probLab.textColor = [UIColor grayColor];
    62         probLab.textColor = [UIColor grayColor];
    63         probLab.textAlignment = UITextAlignmentCenter;
    63         probLab.textAlignment = UITextAlignmentCenter;
    64         
    64 
    65         delLab = [[UILabel alloc] init];
    65         delLab = [[UILabel alloc] init];
    66         delLab.backgroundColor = [UIColor clearColor];
    66         delLab.backgroundColor = [UIColor clearColor];
    67         delLab.textColor = [UIColor grayColor];
    67         delLab.textColor = [UIColor grayColor];
    68         delLab.textAlignment = UITextAlignmentCenter;
    68         delLab.textAlignment = UITextAlignmentCenter;
    69         
    69 
    70         craLab = [[UILabel alloc] init];
    70         craLab = [[UILabel alloc] init];
    71         craLab.backgroundColor = [UIColor clearColor];
    71         craLab.backgroundColor = [UIColor clearColor];
    72         craLab.textColor = [UIColor grayColor];
    72         craLab.textColor = [UIColor grayColor];
    73         craLab.textAlignment = UITextAlignmentCenter;
    73         craLab.textAlignment = UITextAlignmentCenter;
    74         
    74 
    75         [self.contentView addSubview:weaponName]; // [weaponName release];
    75         [self.contentView addSubview:weaponName]; // [weaponName release];
    76         [self.contentView addSubview:weaponIcon]; // [weaponIcon release];
    76         [self.contentView addSubview:weaponIcon]; // [weaponIcon release];
    77         
    77 
    78         [self.contentView addSubview:initialQt];  // [initialQt release];
    78         [self.contentView addSubview:initialQt];  // [initialQt release];
    79         [self.contentView addSubview:probabilityQt]; // [probabilityQt release];
    79         [self.contentView addSubview:probabilityQt]; // [probabilityQt release];
    80         [self.contentView addSubview:delayQt];    // [delayQt release];
    80         [self.contentView addSubview:delayQt];    // [delayQt release];
    81         [self.contentView addSubview:crateQt];    // [crateQt release];
    81         [self.contentView addSubview:crateQt];    // [crateQt release];
    82         
    82 
    83         [self.contentView addSubview:initialImg]; // [initialImg release];
    83         [self.contentView addSubview:initialImg]; // [initialImg release];
    84         [self.contentView addSubview:probabImg];  // [probabImg release];
    84         [self.contentView addSubview:probabImg];  // [probabImg release];
    85         [self.contentView addSubview:delayImg];   // [delayImg release];
    85         [self.contentView addSubview:delayImg];   // [delayImg release];
    86         [self.contentView addSubview:crateImg];   // [crateImg release];
    86         [self.contentView addSubview:crateImg];   // [crateImg release];
    87 
    87 
    96 -(void) layoutSubviews {
    96 -(void) layoutSubviews {
    97     [super layoutSubviews];
    97     [super layoutSubviews];
    98 
    98 
    99     CGRect contentRect = self.contentView.bounds;
    99     CGRect contentRect = self.contentView.bounds;
   100     CGFloat boundsX = contentRect.origin.x;
   100     CGFloat boundsX = contentRect.origin.x;
   101     
   101 
   102     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   102     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   103         boundsX += 65;
   103         boundsX += 65;
   104     else
   104     else
   105         boundsX -= 9;
   105         boundsX -= 9;
   106 
   106 
   107     weaponIcon.frame = CGRectMake(5, 5, 32, 32);
   107     weaponIcon.frame = CGRectMake(5, 5, 32, 32);
   108     weaponName.frame = CGRectMake(45, 8, 200, 25);
   108     weaponName.frame = CGRectMake(45, 8, 200, 25);
   109     
   109 
   110     // second line
   110     // second line
   111     initialImg.frame = CGRectMake(boundsX+20, 40, 32, 32);
   111     initialImg.frame = CGRectMake(boundsX+20, 40, 32, 32);
   112     initialLab.frame = CGRectMake(boundsX+56, 40, 20, 32);
   112     initialLab.frame = CGRectMake(boundsX+56, 40, 20, 32);
   113     initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value];
   113     initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value];
   114     initialQt.frame = CGRectMake(boundsX+80, 40, 150, 32);
   114     initialQt.frame = CGRectMake(boundsX+80, 40, 150, 32);
   115     
   115 
   116     probabImg.frame = CGRectMake(boundsX+255, 40, 32, 32);
   116     probabImg.frame = CGRectMake(boundsX+255, 40, 32, 32);
   117     probLab.frame = CGRectMake(boundsX+291, 40, 20, 32);
   117     probLab.frame = CGRectMake(boundsX+291, 40, 20, 32);
   118     probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value];
   118     probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value];
   119     probabilityQt.frame = CGRectMake(boundsX+314, 40, 150, 32);
   119     probabilityQt.frame = CGRectMake(boundsX+314, 40, 150, 32);
   120     
   120 
   121     // third line
   121     // third line
   122     delayImg.frame = CGRectMake(boundsX+20, 80, 32, 32);
   122     delayImg.frame = CGRectMake(boundsX+20, 80, 32, 32);
   123     delLab.frame = CGRectMake(boundsX+56, 80, 20, 32);
   123     delLab.frame = CGRectMake(boundsX+56, 80, 20, 32);
   124     delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value];
   124     delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value];
   125     delayQt.frame = CGRectMake(boundsX+80, 80, 150, 32);
   125     delayQt.frame = CGRectMake(boundsX+80, 80, 150, 32);
   126     
   126 
   127     crateImg.frame = CGRectMake(boundsX+255, 80, 32, 32);
   127     crateImg.frame = CGRectMake(boundsX+255, 80, 32, 32);
   128     craLab.frame = CGRectMake(boundsX+291, 80, 20, 32);
   128     craLab.frame = CGRectMake(boundsX+291, 80, 20, 32);
   129     craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value];
   129     craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value];
   130     crateQt.frame = CGRectMake(boundsX+314, 80, 150, 32);
   130     crateQt.frame = CGRectMake(boundsX+314, 80, 150, 32);
   131 }
   131 }
   141     if (self.delegate != nil) {
   141     if (self.delegate != nil) {
   142         initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value];
   142         initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value];
   143         probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value];
   143         probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value];
   144         delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value];
   144         delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value];
   145         craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value];
   145         craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value];
   146         
   146 
   147         [delegate updateValues:[NSArray arrayWithObjects:
   147         [delegate updateValues:[NSArray arrayWithObjects:
   148                                 [NSNumber numberWithInt:(int)initialQt.value],
   148                                 [NSNumber numberWithInt:(int)initialQt.value],
   149                                 [NSNumber numberWithInt:(int)probabilityQt.value],
   149                                 [NSNumber numberWithInt:(int)probabilityQt.value],
   150                                 [NSNumber numberWithInt:(int)delayQt.value],
   150                                 [NSNumber numberWithInt:(int)delayQt.value],
   151                                 [NSNumber numberWithInt:(int)crateQt.value], nil] 
   151                                 [NSNumber numberWithInt:(int)crateQt.value], nil]
   152                        atIndex:self.tag];
   152                        atIndex:self.tag];
   153     } else
   153     } else
   154         DLog(@"error - delegate = nil!");
   154         DLog(@"error - delegate = nil!");
   155 }
   155 }
   156 
   156