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 delegate, weaponName, weaponIcon, initialQt, probability, delay, crateQt; |
13 @synthesize delegate, weaponName, weaponIcon, initialQt, probabilityQt, delayQt, crateQt, |
|
14 initialImg, probabImg, delayImg, crateImg, initialLab, probLab, delLab, craLab; |
14 |
15 |
15 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { |
16 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { |
16 if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { |
17 if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { |
17 delegate = nil; |
18 delegate = nil; |
18 |
19 |
19 weaponName = [[UILabel alloc] init]; |
20 weaponName = [[UILabel alloc] init]; |
20 weaponName.backgroundColor = [UIColor clearColor]; |
21 weaponName.backgroundColor = [UIColor clearColor]; |
21 weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
22 weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
22 weaponIcon = [[UIImageView alloc] init]; |
23 weaponIcon = [[UIImageView alloc] init]; |
23 |
24 |
24 NSString *imgStr; |
25 initialQt = [[UISlider alloc] init]; |
25 initialQt = [[UIButton alloc] init]; |
26 [initialQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
26 imgStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()]; |
27 initialQt.maximumValue = 9; |
27 [initialQt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; |
28 initialQt.minimumValue = 0; |
28 [initialQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal]; |
|
29 [initialQt addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
|
30 |
29 |
31 probability = [[UIButton alloc] init]; |
30 probabilityQt = [[UISlider alloc] init]; |
32 imgStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()]; |
31 [probabilityQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
33 [probability setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal]; |
32 probabilityQt.maximumValue = 9; |
34 [probability addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
33 probabilityQt.minimumValue = 0; |
|
34 |
|
35 delayQt = [[UISlider alloc] init]; |
|
36 [delayQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
|
37 delayQt.maximumValue = 9; |
|
38 delayQt.minimumValue = 0; |
|
39 |
|
40 crateQt = [[UISlider alloc] init]; |
|
41 [crateQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
|
42 crateQt.maximumValue = 9; |
|
43 crateQt.minimumValue = 0; |
|
44 |
|
45 NSString *imgAmmoStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()]; |
|
46 NSString *imgDamageStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()]; |
|
47 NSString *imgTimeStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()]; |
|
48 NSString *imgBoxStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()]; |
35 |
49 |
36 delay = [[UIButton alloc] init]; |
50 initialImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgAmmoStr]]; |
37 imgStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()]; |
51 probabImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgDamageStr]]; |
38 [delay setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal]; |
52 delayImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgTimeStr]]; |
39 [delay addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
53 crateImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgBoxStr]]; |
|
54 |
|
55 initialLab = [[UILabel alloc] init]; |
|
56 initialLab.backgroundColor = [UIColor clearColor]; |
|
57 initialLab.textColor = [UIColor grayColor]; |
|
58 initialLab.textAlignment = UITextAlignmentCenter; |
|
59 |
|
60 probLab = [[UILabel alloc] init]; |
|
61 probLab.backgroundColor = [UIColor clearColor]; |
|
62 probLab.textColor = [UIColor grayColor]; |
|
63 probLab.textAlignment = UITextAlignmentCenter; |
|
64 |
|
65 delLab = [[UILabel alloc] init]; |
|
66 delLab.backgroundColor = [UIColor clearColor]; |
|
67 delLab.textColor = [UIColor grayColor]; |
|
68 delLab.textAlignment = UITextAlignmentCenter; |
|
69 |
|
70 craLab = [[UILabel alloc] init]; |
|
71 craLab.backgroundColor = [UIColor clearColor]; |
|
72 craLab.textColor = [UIColor grayColor]; |
|
73 craLab.textAlignment = UITextAlignmentCenter; |
|
74 |
|
75 [self.contentView addSubview:weaponName]; [weaponName release]; |
|
76 [self.contentView addSubview:weaponIcon]; [weaponIcon release]; |
|
77 |
|
78 [self.contentView addSubview:initialQt]; [initialQt release]; |
|
79 [self.contentView addSubview:probabilityQt]; [probabilityQt release]; |
|
80 [self.contentView addSubview:delayQt]; [delayQt release]; |
|
81 [self.contentView addSubview:crateQt]; [crateQt release]; |
|
82 |
|
83 [self.contentView addSubview:initialImg]; [initialImg release]; |
|
84 [self.contentView addSubview:probabImg]; [probabImg release]; |
|
85 [self.contentView addSubview:delayImg]; [delayImg release]; |
|
86 [self.contentView addSubview:crateImg]; [crateImg release]; |
40 |
87 |
41 crateQt = [[UIButton alloc] init]; |
88 [self.contentView addSubview:initialLab]; [initialLab release]; |
42 imgStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()]; |
89 [self.contentView addSubview:probLab]; [probLab release]; |
43 [crateQt setBackgroundImage:[UIImage imageWithContentsOfFile:imgStr] forState:UIControlStateNormal]; |
90 [self.contentView addSubview:delLab]; [delLab release]; |
44 [crateQt addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
91 [self.contentView addSubview:craLab]; [craLab release]; |
45 |
|
46 [self.contentView addSubview:weaponName]; |
|
47 [self.contentView addSubview:weaponIcon]; |
|
48 [self.contentView addSubview:initialQt]; |
|
49 [self.contentView addSubview:probability]; |
|
50 [self.contentView addSubview:delay]; |
|
51 [self.contentView addSubview:crateQt]; |
|
52 } |
92 } |
53 return self; |
93 return self; |
54 } |
94 } |
55 |
95 |
56 -(void) layoutSubviews { |
96 -(void) layoutSubviews { |
57 [super layoutSubviews]; |
97 [super layoutSubviews]; |
58 |
98 |
59 CGRect contentRect = self.contentView.bounds; |
99 CGRect contentRect = self.contentView.bounds; |
60 CGFloat boundsX = contentRect.origin.x; |
100 CGFloat boundsX = contentRect.origin.x; |
61 CGRect frame; |
|
62 |
101 |
63 frame = CGRectMake(boundsX+5, 5, 32, 32); |
102 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
64 weaponIcon.frame = frame; |
103 boundsX += 65; |
|
104 else |
|
105 boundsX -= 9; |
65 |
106 |
66 frame = CGRectMake(boundsX+45, 8, 200, 25); |
107 weaponIcon.frame = CGRectMake(5, 5, 32, 32); |
67 weaponName.frame = frame; |
108 weaponName.frame = CGRectMake(45, 8, 200, 25); |
68 |
109 |
69 // second line |
110 // second line |
70 frame = CGRectMake(boundsX+20, 40, 32, 32); |
111 initialImg.frame = CGRectMake(boundsX+20, 40, 32, 32); |
71 initialQt.frame = frame; |
112 initialLab.frame = CGRectMake(boundsX+56, 40, 20, 32); |
|
113 initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value]; |
|
114 initialQt.frame = CGRectMake(boundsX+80, 40, 150, 32); |
72 |
115 |
73 frame = CGRectMake(boundsX+60, 40, 32, 32); |
116 probabImg.frame = CGRectMake(boundsX+255, 40, 32, 32); |
74 probability.frame = frame; |
117 probLab.frame = CGRectMake(boundsX+291, 40, 20, 32); |
|
118 probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value]; |
|
119 probabilityQt.frame = CGRectMake(boundsX+314, 40, 150, 32); |
75 |
120 |
76 frame = CGRectMake(boundsX+100, 40, 32, 32); |
121 // third line |
77 delay.frame = frame; |
122 delayImg.frame = CGRectMake(boundsX+20, 80, 32, 32); |
|
123 delLab.frame = CGRectMake(boundsX+56, 80, 20, 32); |
|
124 delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value]; |
|
125 delayQt.frame = CGRectMake(boundsX+80, 80, 150, 32); |
78 |
126 |
79 frame = CGRectMake(boundsX+140, 40, 32, 32); |
127 crateImg.frame = CGRectMake(boundsX+255, 80, 32, 32); |
80 crateQt.frame = frame; |
128 craLab.frame = CGRectMake(boundsX+291, 80, 20, 32); |
|
129 craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value]; |
|
130 crateQt.frame = CGRectMake(boundsX+314, 80, 150, 32); |
81 } |
131 } |
82 |
132 |
83 /* |
133 /* |
84 -(void) setSelected:(BOOL)selected animated:(BOOL)animated { |
134 -(void) setSelected:(BOOL)selected animated:(BOOL)animated { |
85 [super setSelected:selected animated:animated]; |
135 [super setSelected:selected animated:animated]; |
86 // Configure the view for the selected state |
136 // Configure the view for the selected state |
87 } |
137 } |
88 */ |
138 */ |
89 |
139 |
90 -(void) buttonPressed:(id) sender { |
140 -(void) valueChanged:(id) sender { |
91 if (self.delegate != nil) { |
141 if (self.delegate != nil) { |
92 [(UIButton *)sender setTag:self.tag]; |
142 initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value]; |
93 [delegate buttonPressed:sender]; |
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]; |
|
145 craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value]; |
|
146 |
|
147 [(UISlider *)sender setTag:self.tag]; |
|
148 [delegate valueChanged:sender]; |
94 } else |
149 } else |
95 DLog(@"error - delegate = nil!"); |
150 DLog(@"error - delegate = nil!"); |
96 } |
151 } |
97 |
152 |
98 -(void) dealloc { |
153 -(void) dealloc { |
99 [weaponName release]; |
154 [weaponName release]; |
100 [weaponIcon release]; |
155 [weaponIcon release]; |
101 [initialQt release]; |
156 [initialQt release]; |
102 [probability release]; |
157 [probabilityQt release]; |
103 [delay release]; |
158 [delayQt release]; |
104 [crateQt release]; |
159 [crateQt release]; |
105 [super dealloc]; |
160 [super dealloc]; |
106 } |
161 } |
107 |
162 |
108 |
163 |