author | szczur |
Sun, 31 Oct 2010 21:17:17 -0400 | |
changeset 4074 | b73fd6ca06dd |
parent 4034 | 634a8c8682de |
child 4082 | bfe14b38dad1 |
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 |
||
3989 | 28 |
#define BTNS_PER_ROW 9 |
4032 | 29 |
#define DEFAULT_DESCRIPTION IS_IPAD() ? \ |
30 |
NSLocalizedString(@"Hold your finger on a weapon to see what it does...",@"") : \ |
|
31 |
NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"") |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
32 |
|
3924 | 33 |
@implementation AmmoMenuViewController |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
34 |
@synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible; |
3924 | 35 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
36 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
37 |
return rotationManager(interfaceOrientation); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
38 |
} |
3924 | 39 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
40 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
41 |
#pragma mark view handling |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
42 |
-(void) viewDidLoad { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
43 |
[[NSNotificationCenter defaultCenter] addObserver:self |
3935 | 44 |
selector:@selector(updateAmmoVisuals) |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
45 |
name:@"updateAmmoVisuals" |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
46 |
object:nil]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
47 |
|
3924 | 48 |
self.view.frame = CGRectMake(0, 0, 480, 320); |
49 |
self.view.backgroundColor = [UIColor blackColor]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
50 |
self.view.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
51 |
self.view.layer.borderWidth = 1.3f; |
3924 | 52 |
[self.view.layer setCornerRadius:10]; |
53 |
[self.view.layer setMasksToBounds:YES]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
54 |
self.view.autoresizingMask = UIViewAutoresizingNone; |
4032 | 55 |
placingPoint = CGPointMake(-1, -1); |
56 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
57 |
self.isVisible = NO; |
3978 | 58 |
delay = (uint8_t *)calloc(HW_getNumberOfWeapons(), sizeof(uint8_t)); |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
59 |
HW_getAmmoDelays(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
60 |
|
3978 | 61 |
shouldUpdateImage = (BOOL *)calloc(HW_getNumberOfWeapons(), sizeof(BOOL)); |
62 |
||
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
63 |
[super viewDidLoad]; |
3933
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) viewWillAppear:(BOOL)animated { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
67 |
[self updateAmmoVisuals]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
68 |
[super viewWillAppear:animated]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
69 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
70 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
71 |
-(void) appearInView:(UIView *)container { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
72 |
[self viewWillAppear:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
73 |
[container addSubview:self.view]; |
4032 | 74 |
|
75 |
if (placingPoint.x == -1 && placingPoint.y == -1) |
|
76 |
placingPoint = container.center; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
77 |
if (IS_DUALHEAD() == NO) |
4032 | 78 |
self.view.center = CGPointMake(placingPoint.y, placingPoint.x); |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
79 |
else { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
80 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
81 |
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) |
4032 | 82 |
self.view.center = CGPointMake(placingPoint.y, placingPoint.x); |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
83 |
else |
4032 | 84 |
self.view.center = CGPointMake(placingPoint.x, placingPoint.y); |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
85 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
86 |
self.isVisible = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
87 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
88 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
89 |
-(void) disappear { |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
90 |
if (self.isVisible) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
91 |
[self.view removeFromSuperview]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
92 |
self.isVisible = NO; |
4032 | 93 |
placingPoint.x = self.view.center.y; |
94 |
placingPoint.y = self.view.center.x; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
95 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
96 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
97 |
#pragma mark - |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
98 |
#pragma mark drawing |
3989 | 99 |
-(void) loadLabels { |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
100 |
int x = 12; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
101 |
int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
102 |
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
103 |
name.backgroundColor = [UIColor clearColor]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
104 |
name.textColor = UICOLOR_HW_YELLOW_BODER; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
105 |
name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
106 |
self.nameLabel = name; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
107 |
[self.view addSubview:self.nameLabel]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
108 |
[name release]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
109 |
|
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
110 |
UILabel *caption = [[UILabel alloc] initWithFrame:CGRectMake(x+200, y, 220, 20)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
111 |
caption.backgroundColor = [UIColor clearColor]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
112 |
caption.textColor = [UIColor whiteColor]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
113 |
caption.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
114 |
caption.adjustsFontSizeToFitWidth = YES; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
115 |
caption.minimumFontSize = 8; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
116 |
self.captionLabel = caption; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
117 |
[self.view addSubview:self.captionLabel]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
118 |
[caption release]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
119 |
|
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
120 |
UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(x+2, y+20, 410, 53)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
121 |
description.backgroundColor = [UIColor clearColor]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
122 |
description.textColor = [UIColor whiteColor]; |
3989 | 123 |
description.text = DEFAULT_DESCRIPTION; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
124 |
description.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
125 |
description.adjustsFontSizeToFitWidth = YES; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
126 |
description.minimumFontSize = 8; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
127 |
description.numberOfLines = 0; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
128 |
self.extraLabel = description; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
129 |
[self.view addSubview:self.extraLabel]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
130 |
[description release]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
131 |
} |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
132 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
133 |
-(void) loadAmmoStuff:(id) object { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
134 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
3924 | 135 |
NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
136 |
UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
137 |
|
3977 | 138 |
NSMutableArray *imgs = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
139 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
140 |
int i, j, e; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
141 |
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
|
142 |
int x, y; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
143 |
float w, radius; |
3924 | 144 |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
145 |
// move utilities aside and make 'em rounded |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
146 |
if (HW_isWeaponAnEffect(i)) { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
147 |
x = 432; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
148 |
y = 20 + 48*e++; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
149 |
w = 1.5; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
150 |
radius = 22; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
151 |
} else { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
152 |
x = 10+(j%BTNS_PER_ROW)*44; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
153 |
y = 10+(j/BTNS_PER_ROW)*44; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
154 |
if (j / BTNS_PER_ROW % 2 != 0) |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
155 |
x += 20; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
156 |
w = 1; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
157 |
radius = 6; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
158 |
j++; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
159 |
} |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
160 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
161 |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
162 |
button.frame = CGRectMake(x, y, 40, 40); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
163 |
button.tag = i; |
3924 | 164 |
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
|
165 |
button.layer.borderWidth = w; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3941
diff
changeset
|
166 |
[button.layer setCornerRadius:radius]; |
3924 | 167 |
[button.layer setMasksToBounds:YES]; |
3976 | 168 |
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown]; |
169 |
[button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside]; |
|
3989 | 170 |
[button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
171 |
[button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
172 |
button.titleLabel.backgroundColor = [UIColor blackColor]; |
3935 | 173 |
button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
174 |
[button.titleLabel.layer setCornerRadius:3]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
175 |
[button.titleLabel.layer setMasksToBounds:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
176 |
button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
177 |
button.titleLabel.layer.borderWidth = 1; |
3924 | 178 |
[self.view addSubview:button]; |
179 |
[array addObject:button]; |
|
3977 | 180 |
|
181 |
int x_src = ((i*32)/(int)ammoStoreImage.size.height)*32; |
|
182 |
int y_src = (i*32)%(int)ammoStoreImage.size.height; |
|
183 |
UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
184 |
[imgs addObject:img]; |
|
3924 | 185 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
186 |
[self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO]; |
3924 | 187 |
[array release]; |
3977 | 188 |
|
189 |
[self performSelectorOnMainThread:@selector(setImagesArray:) withObject:imgs waitUntilDone:NO]; |
|
190 |
[imgs release]; |
|
191 |
[ammoStoreImage release]; |
|
192 |
||
3989 | 193 |
[self performSelectorOnMainThread:@selector(loadLabels) withObject:nil waitUntilDone:NO]; |
194 |
||
3977 | 195 |
[self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:YES]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
196 |
UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
197 |
[spinner stopAnimating]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
198 |
[pool drain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
199 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
200 |
|
3935 | 201 |
-(void) updateAmmoVisuals { |
3977 | 202 |
if (self.buttonsArray == nil || self.imagesArray == nil) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
203 |
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
204 |
spinner.hidesWhenStopped = YES; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
205 |
spinner.center = self.view.center; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
206 |
[spinner startAnimating]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
207 |
[self.view addSubview:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
208 |
[NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
209 |
[spinner release]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
210 |
return; |
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 |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
213 |
int *loadout = (int *)calloc(HW_getNumberOfWeapons(), sizeof(int)); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
214 |
int res = HW_getAmmoCounts(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
215 |
int turns = HW_getTurnsForCurrentTeam(); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
216 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
217 |
if (res == 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
218 |
self.view.userInteractionEnabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
219 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
220 |
for (int i = 0; i < HW_getNumberOfWeapons(); i++) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
221 |
UIButton *button = [self.buttonsArray objectAtIndex:i]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
222 |
if (loadout[i] > 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
223 |
if (delay[i]-turns >= 0) { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
224 |
button.layer.borderColor = [[UIColor lightGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
225 |
[button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal]; |
3978 | 226 |
if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == NO) { |
3977 | 227 |
UIImage *img = [self.imagesArray objectAtIndex:i]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
228 |
[button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal]; |
3978 | 229 |
shouldUpdateImage[i] = YES; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
230 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
231 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
232 |
button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
3976 | 233 |
[button setTitle:nil forState:UIControlStateNormal]; |
3978 | 234 |
if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == YES) { |
3977 | 235 |
UIImage *img = [self.imagesArray objectAtIndex:i]; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
236 |
[button setBackgroundImage:img forState:UIControlStateNormal]; |
3978 | 237 |
shouldUpdateImage[i] = NO; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
238 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
239 |
} |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
240 |
button.enabled = YES; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
241 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
242 |
if (button.enabled == YES) |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
243 |
[button setBackgroundImage:nil forState:UIControlStateNormal]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
244 |
button.layer.borderColor = [[UIColor darkGrayColor] CGColor]; |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
245 |
button.enabled = NO; |
3978 | 246 |
shouldUpdateImage[i] = NO; |
3935 | 247 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
248 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
249 |
} else { |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
250 |
self.view.userInteractionEnabled = NO; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
251 |
} |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
252 |
|
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
253 |
free(loadout); |
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
254 |
loadout = NULL; |
3933
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 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
257 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
258 |
#pragma mark user interaction |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
259 |
-(void) buttonPressed:(id) sender { |
3924 | 260 |
UIButton *theButton = (UIButton *)sender; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
261 |
if (self.nameLabel == nil || self.extraLabel == nil) |
3989 | 262 |
[self loadLabels]; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
263 |
|
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
264 |
self.nameLabel.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(theButton.tag)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
265 |
// description contains a lot of unnecessary stuff, we clean it by removing .|, !| and ?| |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
266 |
NSString *description = [NSString stringWithUTF8String:HW_getWeaponDescriptionByIndex(theButton.tag)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
267 |
NSArray *elements = [description componentsSeparatedByString:@".|"]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
268 |
NSArray *purgedElements = [[elements objectAtIndex:0] componentsSeparatedByString:@"!|"]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
269 |
NSArray *morePurgedElements = [[purgedElements objectAtIndex:0] componentsSeparatedByString:@"?|"]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
270 |
self.extraLabel.text = [[[morePurgedElements objectAtIndex:0] stringByReplacingOccurrencesOfString:@"|" withString:@" "] stringByAppendingString:@"."]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
271 |
if (theButton.currentTitle != nil) |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
272 |
self.captionLabel.text = NSLocalizedString(@"This weapon is locked",@""); |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
273 |
else |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
274 |
self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
275 |
} |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
276 |
|
3989 | 277 |
-(void) buttonCancelled:(id) sender { |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
278 |
self.nameLabel.text = nil; |
4032 | 279 |
self.extraLabel.text = nil; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
280 |
self.captionLabel.text = nil; |
3976 | 281 |
} |
282 |
||
283 |
-(void) buttonReleased:(id) sender { |
|
284 |
UIButton *theButton = (UIButton *)sender; |
|
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
285 |
if (self.nameLabel == nil || self.extraLabel == nil) |
3989 | 286 |
[self loadLabels]; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
287 |
|
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
288 |
self.nameLabel.text = nil; |
4032 | 289 |
self.extraLabel.text = nil; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
290 |
self.captionLabel.text = nil; |
3976 | 291 |
if (theButton.currentTitle == nil) { |
292 |
HW_setWeapon(theButton.tag); |
|
293 |
playSound(@"clickSound"); |
|
3984 | 294 |
if (IS_DUALHEAD() == NO) |
295 |
[self disappear]; |
|
3976 | 296 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
297 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
298 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
299 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
300 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
301 |
|
4032 | 302 |
if (IS_IPAD() && [touches count] == 1) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
303 |
self.view.layer.borderWidth = 3.5; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
304 |
startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
305 |
} |
4032 | 306 |
|
3996 | 307 |
if (IS_IPAD() == NO) |
308 |
[self disappear]; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
309 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
310 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
311 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
4032 | 312 |
self.view.layer.borderWidth = 1.3; |
3924 | 313 |
} |
314 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
315 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
316 |
NSSet *allTouches = [event allTouches]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
317 |
|
4032 | 318 |
if (IS_IPAD() && [touches count] == 1) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
319 |
CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
320 |
CGFloat deltaX = touchedPoint.x - startingPoint.x; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
321 |
CGFloat deltaY = touchedPoint.y - startingPoint.y; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
322 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
323 |
//startingPoint = touchedPoint; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
324 |
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
|
325 |
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
|
326 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
327 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
328 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
329 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
4032 | 330 |
[self touchesEnded:touches withEvent:event]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
331 |
} |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
332 |
|
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
333 |
#pragma mark - |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
334 |
#pragma mark memory |
3924 | 335 |
-(void) didReceiveMemoryWarning { |
3977 | 336 |
self.imagesArray = nil; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
337 |
self.buttonsArray = nil; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
338 |
self.nameLabel = nil; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
339 |
self.extraLabel = nil; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
340 |
self.captionLabel = nil; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
341 |
MSG_MEMCLEAN(); |
3924 | 342 |
[super didReceiveMemoryWarning]; |
343 |
} |
|
344 |
||
345 |
-(void) viewDidUnload { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
346 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
3977 | 347 |
self.imagesArray = nil; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
348 |
self.buttonsArray = nil; |
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
349 |
self.nameLabel = nil; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
350 |
self.extraLabel = nil; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
351 |
self.captionLabel = nil; |
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
352 |
free(delay); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
353 |
delay = NULL; |
3978 | 354 |
free(shouldUpdateImage); |
355 |
shouldUpdateImage = NULL; |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
356 |
MSG_DIDUNLOAD(); |
3924 | 357 |
[super viewDidUnload]; |
358 |
} |
|
359 |
||
360 |
-(void) dealloc { |
|
3981
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
361 |
[nameLabel release]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
362 |
[extraLabel release]; |
928e2040d34f
add name, caption and description to the new ammomenu
koda
parents:
3978
diff
changeset
|
363 |
[captionLabel release]; |
3977 | 364 |
[imagesArray release]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
365 |
[buttonsArray release]; |
3924 | 366 |
[super dealloc]; |
367 |
} |
|
368 |
||
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3924
diff
changeset
|
369 |
@end |