3829
|
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 20/04/2010.
|
|
19 |
*/
|
|
20 |
|
3547
|
21 |
|
|
22 |
#import "HogButtonView.h"
|
|
23 |
#import "CommodityFunctions.h"
|
|
24 |
#import "UIImageExtra.h"
|
|
25 |
|
|
26 |
@implementation HogButtonView
|
|
27 |
@synthesize singleHog, numberOfHogs, ownerDictionary;
|
|
28 |
|
|
29 |
-(id) initWithFrame:(CGRect)frame {
|
|
30 |
if ((self = [super initWithFrame:frame])) {
|
|
31 |
self.backgroundColor = [UIColor clearColor];
|
3697
|
32 |
|
3547
|
33 |
NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
|
|
34 |
UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
|
|
35 |
[normalHogFile release];
|
3697
|
36 |
|
3547
|
37 |
self.singleHog = normalHogSprite;
|
|
38 |
[normalHogSprite release];
|
|
39 |
[self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
|
|
40 |
}
|
|
41 |
return self;
|
|
42 |
}
|
|
43 |
|
|
44 |
-(void) addOne {
|
3783
|
45 |
playSound(@"clickSound");
|
3547
|
46 |
self.highlighted = NO;
|
|
47 |
NSInteger number = self.numberOfHogs;
|
|
48 |
number++;
|
|
49 |
[self drawManyHogs:number];
|
|
50 |
}
|
|
51 |
|
|
52 |
-(void) drawManyHogs:(NSInteger) hogs {
|
|
53 |
if (numberOfHogs != hogs) {
|
|
54 |
if (hogs <= MAX_HOGS && hogs >= 1)
|
|
55 |
numberOfHogs = hogs;
|
|
56 |
else {
|
|
57 |
if (hogs > MAX_HOGS)
|
|
58 |
numberOfHogs = 1;
|
|
59 |
else
|
|
60 |
numberOfHogs = MAX_HOGS;
|
|
61 |
}
|
|
62 |
[ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
|
3697
|
63 |
|
3547
|
64 |
UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
|
|
65 |
for (int i = 0; i < numberOfHogs; i++) {
|
|
66 |
teamHogs = [singleHog mergeWith:teamHogs
|
3697
|
67 |
atPoint:CGPointMake(8, 0)
|
3547
|
68 |
atSize:CGSizeMake(88, 32)];
|
|
69 |
}
|
|
70 |
[self setImage:teamHogs forState:UIControlStateNormal];
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
-(void) dealloc {
|
|
75 |
[ownerDictionary release];
|
|
76 |
[singleHog release];
|
|
77 |
[super dealloc];
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
@end
|