|
1 /* |
|
2 * Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 * |
|
18 * File created on 03/10/2010. |
|
19 */ |
|
20 |
|
21 |
|
22 #import "AmmoMenuViewController.h" |
|
23 #import <QuartzCore/QuartzCore.h> |
|
24 #import "CommodityFunctions.h" |
|
25 #import "UIImageExtra.h" |
|
26 #import "PascalImports.h" |
|
27 |
|
28 @implementation AmmoMenuViewController |
|
29 @synthesize imagesArray;; |
|
30 |
|
31 |
|
32 -(void) viewDidLoad { |
|
33 [super viewDidLoad]; |
|
34 self.view.frame = CGRectMake(0, 0, 480, 320); |
|
35 self.view.backgroundColor = [UIColor blackColor]; |
|
36 [self.view.layer setCornerRadius:10]; |
|
37 [self.view.layer setMasksToBounds:YES]; |
|
38 |
|
39 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
|
40 UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
|
41 |
|
42 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:CURRENT_AMMOSIZE]; |
|
43 for (int i = 0; i < CURRENT_AMMOSIZE; i++) { |
|
44 int x_src = ((i*32)/(int)ammoStoreImage.size.height)*32; |
|
45 int y_src = (i*32)%(int)ammoStoreImage.size.height; |
|
46 int x_dst = 10+(i%10)*44; |
|
47 int y_dst = 10+(i/10)*44; |
|
48 |
|
49 if (i / 10 % 2 != 0) |
|
50 x_dst += 20; |
|
51 UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, 32, 32)]; |
|
52 UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x_dst, y_dst, 40, 40)]; |
|
53 button.tag = i+1; |
|
54 button.layer.borderWidth = 1; |
|
55 button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor]; |
|
56 [button.layer setCornerRadius:6]; |
|
57 [button.layer setMasksToBounds:YES]; |
|
58 [button setImage:img forState:UIControlStateNormal]; |
|
59 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; |
|
60 [self.view addSubview:button]; |
|
61 [array addObject:button]; |
|
62 [button release]; |
|
63 } |
|
64 self.imagesArray = array; |
|
65 [array release]; |
|
66 [ammoStoreImage release]; |
|
67 |
|
68 } |
|
69 |
|
70 -(void) buttonPressed:(id) sender { |
|
71 UIButton *theButton = (UIButton *)sender; |
|
72 HW_setWeapon(theButton.tag); |
|
73 } |
|
74 |
|
75 -(void) didReceiveMemoryWarning { |
|
76 // Releases the view if it doesn't have a superview. |
|
77 [super didReceiveMemoryWarning]; |
|
78 // Release any cached data, images, etc that aren't in use. |
|
79 } |
|
80 |
|
81 -(void) viewDidUnload { |
|
82 [super viewDidUnload]; |
|
83 self.imagesArray = nil; |
|
84 } |
|
85 |
|
86 -(void) dealloc { |
|
87 [imagesArray release]; |
|
88 [super dealloc]; |
|
89 } |
|
90 |
|
91 |
|
92 @end |