cocoaTouch/otherSrc/HogButtonView.m
changeset 3514 59dbd31e9953
parent 3513 f589230fa21b
child 3515 3e8635f43972
equal deleted inserted replaced
3513:f589230fa21b 3514:59dbd31e9953
     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];
       
    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];
       
    26         [self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
       
    27     }
       
    28     return self;
       
    29 }
       
    30 
       
    31 -(void) addOne {
       
    32     self.highlighted = NO;
       
    33     NSInteger number = self.numberOfHogs;
       
    34     number++;
       
    35     [self drawManyHogs:number];
       
    36 }
       
    37 
       
    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)
       
    44                 numberOfHogs = 1;
       
    45             else
       
    46                 numberOfHogs = MAX_HOGS;
       
    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     }
       
    58 }
       
    59 
       
    60 -(void) dealloc {
       
    61     [ownerDictionary release];
       
    62     [singleHog release];
       
    63     [super dealloc];
       
    64 }
       
    65 
       
    66 
       
    67 @end