author | koda |
Thu, 14 Oct 2010 22:01:33 +0200 | |
changeset 3976 | abaf741a4e21 |
parent 3952 | d6412423da45 |
child 3977 | 9df7b4812da9 |
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 |
||
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
28 |
#define BTNS_PER_ROW 9 |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
29 |
|
3924 | 30 |
@implementation AmmoMenuViewController |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
31 |
@synthesize weaponsImage, buttonsArray, isVisible; |
3924 | 32 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
33 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
34 |
return rotationManager(interfaceOrientation); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
35 |
} |
3924 | 36 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
37 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
38 |
#pragma mark view handling |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
39 |
-(void) viewDidLoad { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
40 |
[[NSNotificationCenter defaultCenter] addObserver:self |
3935 | 41 |
selector:@selector(updateAmmoVisuals) |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
42 |
name:@"updateAmmoVisuals" |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
43 |
object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
44 |
|
3924 | 45 |
self.view.frame = CGRectMake(0, 0, 480, 320); |
46 |
self.view.backgroundColor = [UIColor blackColor]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
47 |
self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
48 |
self.view.layer.borderWidth = 1.3f; |
3924 | 49 |
[self.view.layer setCornerRadius:10]; |
50 |
[self.view.layer setMasksToBounds:YES]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
51 |
self.view.autoresizingMask = UIViewAutoresizingNone; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
52 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
53 |
self.isVisible = NO; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
54 |
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
|
55 |
HW_getAmmoDelays(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
56 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
57 |
[super viewDidLoad]; |
3933
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 { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
61 |
[self updateAmmoVisuals]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
62 |
[super viewWillAppear:animated]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
63 |
} |
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 |
-(void) appearInView:(UIView *)container { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
66 |
[self viewWillAppear:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
67 |
[container addSubview:self.view]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
68 |
if (IS_DUALHEAD() == NO) |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
69 |
self.view.center = CGPointMake(container.center.y, container.center.x); |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
70 |
else { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
71 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
72 |
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
73 |
self.view.center = CGPointMake(container.center.y, container.center.x); |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
74 |
else |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
75 |
self.view.center = CGPointMake(container.center.x, container.center.y); |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
76 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
77 |
self.isVisible = YES; |
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) disappear { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
81 |
if (self.isVisible) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
82 |
[self.view removeFromSuperview]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
83 |
self.isVisible = NO; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
84 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
85 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
86 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
87 |
#pragma mark drawing |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
88 |
-(void) loadAmmoStuff:(id) object { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
89 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
90 |
|
3924 | 91 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
92 |
UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
93 |
[self performSelectorOnMainThread:@selector(setWeaponsImage:) withObject:ammoStoreImage waitUntilDone:NO]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
94 |
[ammoStoreImage release]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
95 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
96 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
97 |
int i, j, e; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
98 |
for (i = 0, j = 0, e = 0; i < HW_getNumberOfWeapons(); i++) { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
99 |
int x, y; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
100 |
float w, radius; |
3924 | 101 |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
102 |
// move utilities aside and make 'em rounded |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
103 |
if (HW_isWeaponAnEffect(i)) { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
104 |
x = 432; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
105 |
y = 20 + 48*e++; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
106 |
w = 1.5; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
107 |
radius = 22; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
108 |
} else { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
109 |
x = 10+(j%BTNS_PER_ROW)*44; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
110 |
y = 10+(j/BTNS_PER_ROW)*44; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
111 |
if (j / BTNS_PER_ROW % 2 != 0) |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
112 |
x += 20; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
113 |
w = 1; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
114 |
radius = 6; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
115 |
j++; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
116 |
} |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
117 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
118 |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
119 |
button.frame = CGRectMake(x, y, 40, 40); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
120 |
button.tag = i; |
3924 | 121 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
122 |
button.layer.borderWidth = w; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
123 |
[button.layer setCornerRadius:radius]; |
3924 | 124 |
[button.layer setMasksToBounds:YES]; |
3976 | 125 |
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown]; |
126 |
[button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
127 |
[button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
128 |
button.titleLabel.backgroundColor = [UIColor blackColor]; |
3935 | 129 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
130 |
[button.titleLabel.layer setCornerRadius:3]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
131 |
[button.titleLabel.layer setMasksToBounds:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
132 |
button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
133 |
button.titleLabel.layer.borderWidth = 1; |
3924 | 134 |
[self.view addSubview:button]; |
135 |
[array addObject:button]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
136 |
|
3924 | 137 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
138 |
[self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO]; |
3924 | 139 |
[array release]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
140 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
141 |
[self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:NO]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
142 |
UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
143 |
[spinner stopAnimating]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
144 |
[pool drain]; |
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 |
|
3935 | 147 |
-(void) updateAmmoVisuals { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
148 |
if (self.buttonsArray == nil || self.weaponsImage == nil) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
149 |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
150 |
spinner.hidesWhenStopped = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
151 |
spinner.center = self.view.center; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
152 |
[spinner startAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
153 |
[self.view addSubview:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
154 |
[NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
155 |
[spinner release]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
156 |
return; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
157 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
158 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
159 |
[NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
160 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
161 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
162 |
-(void) drawingThread { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
163 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
164 |
int *loadout = (int *)calloc(HW_getNumberOfWeapons(), sizeof(int)); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
165 |
int res = HW_getAmmoCounts(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
166 |
int turns = HW_getTurnsForCurrentTeam(); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
167 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
168 |
if (res == 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
169 |
self.view.userInteractionEnabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
170 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
171 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
172 |
UIButton *button = [self.buttonsArray objectAtIndex:i]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
173 |
if (loadout[i] > 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
174 |
if (delay[i]-turns >= 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
175 |
button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
176 |
[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
|
177 |
if (button.currentBackgroundImage == nil) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
[button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
182 |
button.imageView.tag = 10000; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
183 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
184 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
185 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
3976 | 186 |
[button setTitle:nil forState:UIControlStateNormal]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
187 |
if (button.currentBackgroundImage == nil || button.imageView.tag == 10000) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
192 |
button.imageView.tag = 0; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
193 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
194 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
195 |
button.enabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
196 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
197 |
if (button.enabled == YES) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
198 |
[button setBackgroundImage:nil forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
199 |
button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
200 |
button.enabled = NO; |
3935 | 201 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
202 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
203 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
204 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
205 |
self.view.userInteractionEnabled = NO; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
206 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
207 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
208 |
free(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
209 |
loadout = NULL; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
210 |
[pool drain]; |
3933
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 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
214 |
#pragma mark user interaction |
3976 | 215 |
-(void) buttonPressed:(id) sender { |
3924 | 216 |
UIButton *theButton = (UIButton *)sender; |
3976 | 217 |
if (theButton.currentTitle != nil) { |
218 |
DLog(@"eeee"); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
-(void) buttonReleased:(id) sender { |
|
223 |
UIButton *theButton = (UIButton *)sender; |
|
224 |
if (theButton.currentTitle == nil) { |
|
225 |
HW_setWeapon(theButton.tag); |
|
226 |
playSound(@"clickSound"); |
|
227 |
} |
|
3941 | 228 |
if (IS_DUALHEAD() == NO) |
229 |
[self disappear]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
230 |
} |
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 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
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 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
235 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
236 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
237 |
self.view.layer.borderWidth = 3.5; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
238 |
startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
239 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
240 |
*/ |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
241 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
242 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
243 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
244 |
//self.view.layer.borderWidth = 1.3; |
3924 | 245 |
} |
246 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
247 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
248 |
/* |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
249 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
250 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
251 |
if ([touches count] == 1) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
252 |
CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
253 |
CGFloat deltaX = touchedPoint.x - startingPoint.x; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
254 |
CGFloat deltaY = touchedPoint.y - startingPoint.y; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
255 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
256 |
//startingPoint = touchedPoint; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
260 |
*/ |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
261 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
262 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
263 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
264 |
//[self touchesEnded:touches withEvent:event]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
265 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
266 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
267 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
268 |
#pragma mark memory |
3924 | 269 |
-(void) didReceiveMemoryWarning { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
270 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
271 |
self.buttonsArray = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
272 |
MSG_MEMCLEAN(); |
3924 | 273 |
[super didReceiveMemoryWarning]; |
274 |
} |
|
275 |
||
276 |
-(void) viewDidUnload { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
277 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
278 |
self.weaponsImage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
279 |
self.buttonsArray = nil; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
280 |
free(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
281 |
delay = NULL; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
282 |
MSG_DIDUNLOAD(); |
3924 | 283 |
[super viewDidUnload]; |
284 |
} |
|
285 |
||
286 |
-(void) dealloc { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
287 |
[weaponsImage release]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
288 |
[buttonsArray release]; |
3924 | 289 |
[super dealloc]; |
290 |
} |
|
291 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
292 |
@end |
3924 | 293 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
294 |
void updateVisualsNewTurn (void) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
295 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateAmmoVisuals" object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
296 |
} |