3547
|
1 |
//
|
|
2 |
// HogButtonView.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 20/04/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "HogButtonView.h"
|
|
10 |
#import "CommodityFunctions.h"
|
|
11 |
#import "UIImageExtra.h"
|
|
12 |
|
|
13 |
@implementation HogButtonView
|
|
14 |
@synthesize singleHog, numberOfHogs, ownerDictionary;
|
|
15 |
|
|
16 |
-(id) initWithFrame:(CGRect)frame {
|
|
17 |
if ((self = [super initWithFrame:frame])) {
|
|
18 |
self.backgroundColor = [UIColor clearColor];
|
3697
|
19 |
|
3547
|
20 |
NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
|
|
21 |
UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
|
|
22 |
[normalHogFile release];
|
3697
|
23 |
|
3547
|
24 |
self.singleHog = normalHogSprite;
|
|
25 |
[normalHogSprite release];
|
|
26 |
[self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
|
|
27 |
}
|
|
28 |
return self;
|
|
29 |
}
|
|
30 |
|
|
31 |
-(void) addOne {
|
3783
|
32 |
playSound(@"clickSound");
|
3547
|
33 |
self.highlighted = NO;
|
|
34 |
NSInteger number = self.numberOfHogs;
|
|
35 |
number++;
|
|
36 |
[self drawManyHogs:number];
|
|
37 |
}
|
|
38 |
|
|
39 |
-(void) drawManyHogs:(NSInteger) hogs {
|
|
40 |
if (numberOfHogs != hogs) {
|
|
41 |
if (hogs <= MAX_HOGS && hogs >= 1)
|
|
42 |
numberOfHogs = hogs;
|
|
43 |
else {
|
|
44 |
if (hogs > MAX_HOGS)
|
|
45 |
numberOfHogs = 1;
|
|
46 |
else
|
|
47 |
numberOfHogs = MAX_HOGS;
|
|
48 |
}
|
|
49 |
[ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
|
3697
|
50 |
|
3547
|
51 |
UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
|
|
52 |
for (int i = 0; i < numberOfHogs; i++) {
|
|
53 |
teamHogs = [singleHog mergeWith:teamHogs
|
3697
|
54 |
atPoint:CGPointMake(8, 0)
|
3547
|
55 |
atSize:CGSizeMake(88, 32)];
|
|
56 |
}
|
|
57 |
[self setImage:teamHogs forState:UIControlStateNormal];
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
-(void) dealloc {
|
|
62 |
[ownerDictionary release];
|
|
63 |
[singleHog release];
|
|
64 |
[super dealloc];
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
@end
|