author | koda |
Sat, 09 Oct 2010 18:00:53 +0200 | |
changeset 3935 | 5ca27a0e9a63 |
parent 3933 | 1a873262f5dd |
child 3940 | cc29628976cc |
permissions | -rw-r--r-- |
3924 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 03/10/2010. |
|
19 |
*/ |
|
20 |
||
21 |
||
22 |
#import "AmmoMenuViewController.h" |
|
23 |
#import <QuartzCore/QuartzCore.h> |
|
24 |
#import "CommodityFunctions.h" |
|
25 |
#import "UIImageExtra.h" |
|
26 |
#import "PascalImports.h" |
|
27 |
||
28 |
@implementation AmmoMenuViewController |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
29 |
@synthesize weaponsImage, buttonsArray, isVisible; |
3924 | 30 |
|
31 |
||
32 |
-(void) viewDidLoad { |
|
33 |
[super viewDidLoad]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
34 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
35 |
[[NSNotificationCenter defaultCenter] addObserver:self |
3935 | 36 |
selector:@selector(updateAmmoVisuals) |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
37 |
name:@"updateAmmoVisuals" |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
38 |
object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
39 |
|
3924 | 40 |
self.view.frame = CGRectMake(0, 0, 480, 320); |
41 |
self.view.backgroundColor = [UIColor blackColor]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
42 |
self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
43 |
self.view.layer.borderWidth = 1.3f; |
3924 | 44 |
[self.view.layer setCornerRadius:10]; |
45 |
[self.view.layer setMasksToBounds:YES]; |
|
46 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
47 |
self.isVisible = NO; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
48 |
delay = HW_getAmmoDelays(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
49 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
50 |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
51 |
spinner.hidesWhenStopped = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
52 |
spinner.center = self.view.center; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
53 |
[spinner startAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
54 |
[self.view addSubview:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
55 |
if (self.buttonsArray == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
56 |
[NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
57 |
[spinner release]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
58 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
59 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
60 |
-(void) viewWillAppear:(BOOL)animated { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
61 |
if (self.buttonsArray != nil) |
3935 | 62 |
[self updateAmmoVisuals]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
63 |
[super viewWillAppear:animated]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
64 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
65 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
66 |
-(void) appearInView:(UIView *)container { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
67 |
[self viewWillAppear:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
68 |
[container addSubview:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
69 |
self.view.center = CGPointMake(container.center.y, container.center.x); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
70 |
self.isVisible = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
71 |
[self viewDidAppear:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
72 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
73 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
74 |
-(void) disappear { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
75 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
76 |
[self.view removeFromSuperview]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
77 |
self.isVisible = NO; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
78 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
79 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
80 |
-(void) loadAmmoStuff:(id) object { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
81 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
82 |
UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
83 |
|
3924 | 84 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
85 |
UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
|
86 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
87 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
88 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
3924 | 89 |
int x_src = ((i*32)/(int)ammoStoreImage.size.height)*32; |
90 |
int y_src = (i*32)%(int)ammoStoreImage.size.height; |
|
91 |
int x_dst = 10+(i%10)*44; |
|
92 |
int y_dst = 10+(i/10)*44; |
|
93 |
||
94 |
if (i / 10 % 2 != 0) |
|
95 |
x_dst += 20; |
|
96 |
UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
97 |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
98 |
button.frame = CGRectMake(x_dst, y_dst, 40, 40); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
99 |
button.tag = i; |
3924 | 100 |
button.layer.borderWidth = 1; |
101 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
|
102 |
[button.layer setCornerRadius:6]; |
|
103 |
[button.layer setMasksToBounds:YES]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
104 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
3924 | 105 |
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
106 |
[button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
107 |
button.titleLabel.backgroundColor = [UIColor blackColor]; |
3935 | 108 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
109 |
[button.titleLabel.layer setCornerRadius:3]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
110 |
[button.titleLabel.layer setMasksToBounds:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
111 |
button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
112 |
button.titleLabel.layer.borderWidth = 1; |
3924 | 113 |
[self.view addSubview:button]; |
114 |
[array addObject:button]; |
|
115 |
} |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
116 |
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:array,@"array",ammoStoreImage,@"image",spinner,@"spinner",nil]; |
3924 | 117 |
[array release]; |
118 |
[ammoStoreImage release]; |
|
119 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
120 |
[self performSelectorOnMainThread:@selector(ready:) withObject:dict waitUntilDone:NO]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
121 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
122 |
[pool drain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
123 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
124 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
125 |
-(void) ready:(id) object { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
126 |
NSDictionary *dict = (NSDictionary *)object; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
127 |
[[dict objectForKey:@"spinner"] stopAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
128 |
self.weaponsImage = [dict objectForKey:@"image"]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
129 |
self.buttonsArray = [dict objectForKey:@"array"]; |
3935 | 130 |
[self updateAmmoVisuals]; |
3924 | 131 |
} |
132 |
||
3935 | 133 |
-(void) updateAmmoVisuals { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
134 |
unsigned char *loadout = HW_getAmmoCounts(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
135 |
int turns = HW_getTurnsForCurrentTeam(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
136 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
137 |
if (self.buttonsArray == nil) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
138 |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
139 |
spinner.hidesWhenStopped = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
140 |
spinner.center = self.view.center; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
141 |
[spinner startAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
142 |
[self.view addSubview:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
143 |
[NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
144 |
[spinner release]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
145 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
146 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
147 |
if (loadout == NULL) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
148 |
self.view.userInteractionEnabled = NO; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
149 |
return; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
150 |
} else |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
151 |
self.view.userInteractionEnabled = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
152 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
153 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
154 |
UIButton *button = [self.buttonsArray objectAtIndex:i]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
155 |
if (loadout[i] > 0) { |
3935 | 156 |
if (button.enabled == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
157 |
int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
158 |
int y_src = (i*32)%(int)self.weaponsImage.size.height; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
159 |
UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
160 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
3935 | 161 |
} |
162 |
button.enabled = YES; |
|
163 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
|
164 |
} else { |
|
165 |
if (button.enabled == YES) |
|
166 |
[button setBackgroundImage:nil forState:UIControlStateNormal]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
167 |
button.enabled = NO; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
168 |
button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
169 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
170 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
171 |
if (button.enabled == YES) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
172 |
if (delay[i]-turns >= 0) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
173 |
button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
174 |
[button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal]; |
3935 | 175 |
if (button.enabled == YES) { |
176 |
int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
|
177 |
int y_src = (i*32)%(int)self.weaponsImage.size.height; |
|
178 |
UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
179 |
[button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal]; |
|
180 |
} |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
181 |
} else { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
182 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
183 |
[button setTitle:@"" forState:UIControlStateNormal]; |
3935 | 184 |
if (button.enabled == YES) { |
185 |
int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
|
186 |
int y_src = (i*32)%(int)self.weaponsImage.size.height; |
|
187 |
UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
188 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
|
189 |
} |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
190 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
191 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
192 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
193 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
194 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
195 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
196 |
#pragma mark user interaction |
3924 | 197 |
-(void) buttonPressed:(id) sender { |
198 |
UIButton *theButton = (UIButton *)sender; |
|
199 |
HW_setWeapon(theButton.tag); |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
200 |
playSound(@"clickSound"); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
201 |
[self disappear]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
202 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
203 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
204 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
205 |
/* |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
206 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
207 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
208 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
209 |
self.view.layer.borderWidth = 3.5; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
210 |
startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
211 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
212 |
*/ |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
213 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
214 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
215 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
216 |
//self.view.layer.borderWidth = 1.3; |
3924 | 217 |
} |
218 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
219 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
220 |
/* |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
221 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
222 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
223 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
224 |
CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
225 |
CGFloat deltaX = touchedPoint.x - startingPoint.x; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
226 |
CGFloat deltaY = touchedPoint.y - startingPoint.y; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
227 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
228 |
//startingPoint = touchedPoint; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
229 |
self.view.frame = CGRectMake(self.view.frame.origin.x + deltaX, self.view.frame.origin.y + deltaY, |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
230 |
self.view.frame.size.width, self.view.frame.size.height); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
231 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
232 |
*/ |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
233 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
234 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
235 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
236 |
//[self touchesEnded:touches withEvent:event]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
237 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
238 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
239 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
240 |
#pragma mark memory |
3924 | 241 |
-(void) didReceiveMemoryWarning { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
242 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
243 |
self.buttonsArray = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
244 |
MSG_MEMCLEAN(); |
3924 | 245 |
[super didReceiveMemoryWarning]; |
246 |
} |
|
247 |
||
248 |
-(void) viewDidUnload { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
249 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
250 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
251 |
self.buttonsArray = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
252 |
delay = NULL; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
253 |
MSG_DIDUNLOAD(); |
3924 | 254 |
[super viewDidUnload]; |
255 |
} |
|
256 |
||
257 |
-(void) dealloc { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
258 |
[weaponsImage release]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
259 |
[buttonsArray release]; |
3924 | 260 |
[super dealloc]; |
261 |
} |
|
262 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
263 |
@end |
3924 | 264 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
265 |
void updateVisualsNewTurn (void) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
266 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateAmmoVisuals" object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
267 |
} |