author | koda |
Mon, 08 Nov 2010 23:46:34 +0100 | |
changeset 4211 | 7dcbd236ca59 |
parent 3948 | 24daa33a3114 |
permissions | -rw-r--r-- |
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" |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3829
diff
changeset
|
25 |
#import "PascalImports.h" |
3547 | 26 |
|
27 |
@implementation HogButtonView |
|
28 |
@synthesize singleHog, numberOfHogs, ownerDictionary; |
|
29 |
||
30 |
-(id) initWithFrame:(CGRect)frame { |
|
31 |
if ((self = [super initWithFrame:frame])) { |
|
32 |
self.backgroundColor = [UIColor clearColor]; |
|
3697 | 33 |
|
3547 | 34 |
NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; |
35 |
UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)]; |
|
36 |
[normalHogFile release]; |
|
3697 | 37 |
|
3547 | 38 |
self.singleHog = normalHogSprite; |
39 |
[normalHogSprite release]; |
|
40 |
[self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside]; |
|
41 |
} |
|
42 |
return self; |
|
43 |
} |
|
44 |
||
45 |
-(void) addOne { |
|
3783 | 46 |
playSound(@"clickSound"); |
3547 | 47 |
self.highlighted = NO; |
48 |
NSInteger number = self.numberOfHogs; |
|
49 |
number++; |
|
50 |
[self drawManyHogs:number]; |
|
51 |
} |
|
52 |
||
53 |
-(void) drawManyHogs:(NSInteger) hogs { |
|
54 |
if (numberOfHogs != hogs) { |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3829
diff
changeset
|
55 |
if (hogs <= HW_getMaxNumberOfHogs() && hogs >= 1) |
3547 | 56 |
numberOfHogs = hogs; |
57 |
else { |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3829
diff
changeset
|
58 |
if (hogs > HW_getMaxNumberOfHogs()) |
3547 | 59 |
numberOfHogs = 1; |
60 |
else |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3829
diff
changeset
|
61 |
numberOfHogs = HW_getMaxNumberOfHogs(); |
3547 | 62 |
} |
63 |
[ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"]; |
|
3697 | 64 |
|
3547 | 65 |
UIImage *teamHogs = [[[UIImage alloc] init] autorelease]; |
66 |
for (int i = 0; i < numberOfHogs; i++) { |
|
67 |
teamHogs = [singleHog mergeWith:teamHogs |
|
3697 | 68 |
atPoint:CGPointMake(8, 0) |
3948
24daa33a3114
some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents:
3926
diff
changeset
|
69 |
ofSize:CGSizeMake(88, 32)]; |
3547 | 70 |
} |
71 |
[self setImage:teamHogs forState:UIControlStateNormal]; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
-(void) dealloc { |
|
76 |
[ownerDictionary release]; |
|
77 |
[singleHog release]; |
|
78 |
[super dealloc]; |
|
79 |
} |
|
80 |
||
81 |
||
82 |
@end |