3361
|
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
|
3364
|
14 |
@synthesize singleHog, numberOfHogs, ownerDictionary;
|
3361
|
15 |
|
|
16 |
-(id) initWithFrame:(CGRect)frame {
|
|
17 |
if ((self = [super initWithFrame:frame])) {
|
|
18 |
self.backgroundColor = [UIColor clearColor];
|
|
19 |
|
|
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];
|
|
23 |
|
|
24 |
self.singleHog = normalHogSprite;
|
|
25 |
[normalHogSprite release];
|
3364
|
26 |
[self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
|
3361
|
27 |
}
|
|
28 |
return self;
|
|
29 |
}
|
|
30 |
|
3364
|
31 |
-(void) addOne {
|
|
32 |
self.highlighted = NO;
|
|
33 |
NSInteger number = self.numberOfHogs;
|
|
34 |
number++;
|
|
35 |
[self drawManyHogs:number];
|
3361
|
36 |
}
|
|
37 |
|
3364
|
38 |
-(void) drawManyHogs:(NSInteger) hogs {
|
|
39 |
if (numberOfHogs != hogs) {
|
|
40 |
if (hogs <= MAX_HOGS && hogs >= 1)
|
|
41 |
numberOfHogs = hogs;
|
|
42 |
else {
|
|
43 |
if (hogs > MAX_HOGS)
|
3361
|
44 |
numberOfHogs = 1;
|
3364
|
45 |
else
|
3361
|
46 |
numberOfHogs = MAX_HOGS;
|
3364
|
47 |
}
|
|
48 |
[ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
|
|
49 |
|
|
50 |
UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
|
|
51 |
for (int i = 0; i < numberOfHogs; i++) {
|
|
52 |
teamHogs = [singleHog mergeWith:teamHogs
|
|
53 |
atPoint:CGPointMake(8, 0)
|
|
54 |
atSize:CGSizeMake(88, 32)];
|
|
55 |
}
|
|
56 |
[self setImage:teamHogs forState:UIControlStateNormal];
|
|
57 |
}
|
3361
|
58 |
}
|
|
59 |
|
|
60 |
-(void) dealloc {
|
3364
|
61 |
[ownerDictionary release];
|
3361
|
62 |
[singleHog release];
|
|
63 |
[super dealloc];
|
|
64 |
}
|
|
65 |
|
|
66 |
|
|
67 |
@end
|