author | nemo |
Sun, 10 Oct 2010 20:16:17 -0400 | |
changeset 3951 | c9a63db3e603 |
parent 3941 | 017b2b31e1c6 |
child 3952 | d6412423da45 |
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 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
31 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
32 |
return rotationManager(interfaceOrientation); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
33 |
} |
3924 | 34 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
35 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
36 |
#pragma mark view handling |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
37 |
-(void) viewDidLoad { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
38 |
[[NSNotificationCenter defaultCenter] addObserver:self |
3935 | 39 |
selector:@selector(updateAmmoVisuals) |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
40 |
name:@"updateAmmoVisuals" |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
41 |
object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
42 |
|
3924 | 43 |
self.view.frame = CGRectMake(0, 0, 480, 320); |
44 |
self.view.backgroundColor = [UIColor blackColor]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
45 |
self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
46 |
self.view.layer.borderWidth = 1.3f; |
3924 | 47 |
[self.view.layer setCornerRadius:10]; |
48 |
[self.view.layer setMasksToBounds:YES]; |
|
49 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
50 |
self.isVisible = NO; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
51 |
delay = (uint8_t *) calloc(HW_getNumberOfWeapons(), sizeof(uint8_t)); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
52 |
HW_getAmmoDelays(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
53 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
54 |
[super viewDidLoad]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
55 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
56 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
57 |
-(void) viewWillAppear:(BOOL)animated { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
58 |
[self updateAmmoVisuals]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
59 |
[super viewWillAppear:animated]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
60 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
61 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
62 |
-(void) appearInView:(UIView *)container { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
63 |
[self viewWillAppear:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
64 |
[container addSubview:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
65 |
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
|
66 |
self.isVisible = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
67 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
68 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
69 |
-(void) disappear { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
70 |
if (self.isVisible) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
71 |
[self.view removeFromSuperview]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
72 |
self.isVisible = NO; |
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 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
75 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
76 |
#pragma mark drawing |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
77 |
-(void) loadAmmoStuff:(id) object { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
78 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
79 |
|
3924 | 80 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
81 |
UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
82 |
[self performSelectorOnMainThread:@selector(setWeaponsImage:) withObject:ammoStoreImage waitUntilDone:NO]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
83 |
[ammoStoreImage release]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
84 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
85 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
86 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
3924 | 87 |
int x_dst = 10+(i%10)*44; |
88 |
int y_dst = 10+(i/10)*44; |
|
89 |
||
90 |
if (i / 10 % 2 != 0) |
|
91 |
x_dst += 20; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
92 |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
93 |
button.frame = CGRectMake(x_dst, y_dst, 40, 40); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
94 |
button.tag = i; |
3924 | 95 |
button.layer.borderWidth = 1; |
96 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
|
97 |
[button.layer setCornerRadius:6]; |
|
98 |
[button.layer setMasksToBounds:YES]; |
|
99 |
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
100 |
[button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
101 |
button.titleLabel.backgroundColor = [UIColor blackColor]; |
3935 | 102 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
103 |
[button.titleLabel.layer setCornerRadius:3]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
104 |
[button.titleLabel.layer setMasksToBounds:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
105 |
button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
106 |
button.titleLabel.layer.borderWidth = 1; |
3924 | 107 |
[self.view addSubview:button]; |
108 |
[array addObject:button]; |
|
109 |
} |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
110 |
[self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO]; |
3924 | 111 |
[array release]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
112 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
113 |
[self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:NO]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
114 |
UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
115 |
[spinner stopAnimating]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
116 |
[pool drain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
117 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
118 |
|
3935 | 119 |
-(void) updateAmmoVisuals { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
120 |
if (self.buttonsArray == nil || self.weaponsImage == nil) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
121 |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
122 |
spinner.hidesWhenStopped = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
123 |
spinner.center = self.view.center; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
124 |
[spinner startAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
125 |
[self.view addSubview:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
126 |
[NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
127 |
[spinner release]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
128 |
return; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
129 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
130 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
131 |
[NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
132 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
133 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
134 |
-(void) drawingThread { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
135 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
136 |
int *loadout = (int *)calloc(HW_getNumberOfWeapons(), sizeof(int)); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
137 |
int res = HW_getAmmoCounts(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
138 |
int turns = HW_getTurnsForCurrentTeam(); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
139 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
140 |
if (res == 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
141 |
self.view.userInteractionEnabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
142 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
143 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
144 |
UIButton *button = [self.buttonsArray objectAtIndex:i]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
145 |
if (loadout[i] > 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
146 |
if (delay[i]-turns >= 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
147 |
button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
148 |
[button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
149 |
if (button.currentBackgroundImage == nil) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
150 |
int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
151 |
int y_src = (i*32)%(int)self.weaponsImage.size.height; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
152 |
UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
153 |
[button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
154 |
button.imageView.tag = 10000; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
155 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
156 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
157 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
158 |
[button setTitle:@"" forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
159 |
if (button.currentBackgroundImage == nil || button.imageView.tag == 10000) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
160 |
int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
161 |
int y_src = (i*32)%(int)self.weaponsImage.size.height; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
162 |
UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
163 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
164 |
button.imageView.tag = 0; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
165 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
166 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
167 |
button.enabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
168 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
169 |
if (button.enabled == YES) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
170 |
[button setBackgroundImage:nil forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
171 |
button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
172 |
button.enabled = NO; |
3935 | 173 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
174 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
175 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
176 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
177 |
self.view.userInteractionEnabled = NO; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
178 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
179 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
180 |
free(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
181 |
loadout = NULL; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
182 |
[pool drain]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
183 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
184 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
185 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
186 |
#pragma mark user interaction |
3924 | 187 |
-(void) buttonPressed:(id) sender { |
188 |
UIButton *theButton = (UIButton *)sender; |
|
189 |
HW_setWeapon(theButton.tag); |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
190 |
playSound(@"clickSound"); |
3941 | 191 |
if (IS_DUALHEAD() == NO) |
192 |
[self disappear]; |
|
3933
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 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
196 |
/* |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
197 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
198 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
199 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
200 |
self.view.layer.borderWidth = 3.5; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
201 |
startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
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 |
} |
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 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
207 |
//self.view.layer.borderWidth = 1.3; |
3924 | 208 |
} |
209 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
210 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
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 |
NSSet *allTouches = [event allTouches]; |
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 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
215 |
CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
216 |
CGFloat deltaX = touchedPoint.x - startingPoint.x; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
217 |
CGFloat deltaY = touchedPoint.y - startingPoint.y; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
218 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
219 |
//startingPoint = touchedPoint; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
220 |
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
|
221 |
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
|
222 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
223 |
*/ |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
224 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
225 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
226 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
227 |
//[self touchesEnded:touches withEvent:event]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
228 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
229 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
230 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
231 |
#pragma mark memory |
3924 | 232 |
-(void) didReceiveMemoryWarning { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
233 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
234 |
self.buttonsArray = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
235 |
MSG_MEMCLEAN(); |
3924 | 236 |
[super didReceiveMemoryWarning]; |
237 |
} |
|
238 |
||
239 |
-(void) viewDidUnload { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
240 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
241 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
242 |
self.buttonsArray = nil; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
243 |
free(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
244 |
delay = NULL; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
245 |
MSG_DIDUNLOAD(); |
3924 | 246 |
[super viewDidUnload]; |
247 |
} |
|
248 |
||
249 |
-(void) dealloc { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
250 |
[weaponsImage release]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
251 |
[buttonsArray release]; |
3924 | 252 |
[super dealloc]; |
253 |
} |
|
254 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
255 |
@end |
3924 | 256 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
257 |
void updateVisualsNewTurn (void) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
258 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateAmmoVisuals" object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
259 |
} |