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