22 #import "AmmoMenuViewController.h" |
22 #import "AmmoMenuViewController.h" |
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 |
|
28 #define BTNS_PER_ROW 9 |
27 |
29 |
28 @implementation AmmoMenuViewController |
30 @implementation AmmoMenuViewController |
29 @synthesize weaponsImage, buttonsArray, isVisible; |
31 @synthesize weaponsImage, buttonsArray, isVisible; |
30 |
32 |
31 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
44 self.view.backgroundColor = [UIColor blackColor]; |
46 self.view.backgroundColor = [UIColor blackColor]; |
45 self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
47 self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
46 self.view.layer.borderWidth = 1.3f; |
48 self.view.layer.borderWidth = 1.3f; |
47 [self.view.layer setCornerRadius:10]; |
49 [self.view.layer setCornerRadius:10]; |
48 [self.view.layer setMasksToBounds:YES]; |
50 [self.view.layer setMasksToBounds:YES]; |
49 |
51 self.view.autoresizingMask = UIViewAutoresizingNone; |
|
52 |
50 self.isVisible = NO; |
53 self.isVisible = NO; |
51 delay = (uint8_t *) calloc(HW_getNumberOfWeapons(), sizeof(uint8_t)); |
54 delay = (uint8_t *) calloc(HW_getNumberOfWeapons(), sizeof(uint8_t)); |
52 HW_getAmmoDelays(delay); |
55 HW_getAmmoDelays(delay); |
53 |
56 |
54 [super viewDidLoad]; |
57 [super viewDidLoad]; |
60 } |
63 } |
61 |
64 |
62 -(void) appearInView:(UIView *)container { |
65 -(void) appearInView:(UIView *)container { |
63 [self viewWillAppear:YES]; |
66 [self viewWillAppear:YES]; |
64 [container addSubview:self.view]; |
67 [container addSubview:self.view]; |
65 self.view.center = CGPointMake(container.center.y, container.center.x); |
68 if (IS_DUALHEAD() == NO) |
|
69 self.view.center = CGPointMake(container.center.y, container.center.x); |
|
70 else { |
|
71 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
72 if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) |
|
73 self.view.center = CGPointMake(container.center.y, container.center.x); |
|
74 else |
|
75 self.view.center = CGPointMake(container.center.x, container.center.y); |
|
76 } |
66 self.isVisible = YES; |
77 self.isVisible = YES; |
67 } |
78 } |
68 |
79 |
69 -(void) disappear { |
80 -(void) disappear { |
70 if (self.isVisible) |
81 if (self.isVisible) |
81 UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
92 UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
82 [self performSelectorOnMainThread:@selector(setWeaponsImage:) withObject:ammoStoreImage waitUntilDone:NO]; |
93 [self performSelectorOnMainThread:@selector(setWeaponsImage:) withObject:ammoStoreImage waitUntilDone:NO]; |
83 [ammoStoreImage release]; |
94 [ammoStoreImage release]; |
84 |
95 |
85 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
96 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
86 for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
97 int i, j, e; |
87 int x_dst = 10+(i%10)*44; |
98 for (i = 0, j = 0, e = 0; i < HW_getNumberOfWeapons(); i++) { |
88 int y_dst = 10+(i/10)*44; |
99 int x, y; |
|
100 float w, radius; |
89 |
101 |
90 if (i / 10 % 2 != 0) |
102 // move utilities aside and make 'em rounded |
91 x_dst += 20; |
103 if (HW_isWeaponAnEffect(i)) { |
|
104 x = 432; |
|
105 y = 20 + 48*e++; |
|
106 w = 1.5; |
|
107 radius = 22; |
|
108 } else { |
|
109 x = 10+(j%BTNS_PER_ROW)*44; |
|
110 y = 10+(j/BTNS_PER_ROW)*44; |
|
111 if (j / BTNS_PER_ROW % 2 != 0) |
|
112 x += 20; |
|
113 w = 1; |
|
114 radius = 6; |
|
115 j++; |
|
116 } |
|
117 |
92 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
118 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
93 button.frame = CGRectMake(x_dst, y_dst, 40, 40); |
119 button.frame = CGRectMake(x, y, 40, 40); |
94 button.tag = i; |
120 button.tag = i; |
95 button.layer.borderWidth = 1; |
|
96 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
121 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
97 [button.layer setCornerRadius:6]; |
122 button.layer.borderWidth = w; |
|
123 [button.layer setCornerRadius:radius]; |
98 [button.layer setMasksToBounds:YES]; |
124 [button.layer setMasksToBounds:YES]; |
99 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
125 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
100 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
126 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
101 button.titleLabel.backgroundColor = [UIColor blackColor]; |
127 button.titleLabel.backgroundColor = [UIColor blackColor]; |
102 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
128 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
104 [button.titleLabel.layer setMasksToBounds:YES]; |
130 [button.titleLabel.layer setMasksToBounds:YES]; |
105 button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
131 button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
106 button.titleLabel.layer.borderWidth = 1; |
132 button.titleLabel.layer.borderWidth = 1; |
107 [self.view addSubview:button]; |
133 [self.view addSubview:button]; |
108 [array addObject:button]; |
134 [array addObject:button]; |
|
135 |
109 } |
136 } |
110 [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO]; |
137 [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO]; |
111 [array release]; |
138 [array release]; |
112 |
139 |
113 [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:NO]; |
140 [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:NO]; |