cocoaTouch/otherSrc/HogButtonView.m
changeset 3361 cfc6cd502f85
child 3364 e5403e2bf02c
equal deleted inserted replaced
3360:717b4e46e855 3361:cfc6cd502f85
       
     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;
       
    15 
       
    16 -(id) initWithFrame:(CGRect)frame {
       
    17     if ((self = [super initWithFrame:frame])) {
       
    18         numberOfHogs = 4;
       
    19         self.backgroundColor = [UIColor clearColor];
       
    20         
       
    21         NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
       
    22         UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
       
    23         [normalHogFile release];
       
    24         
       
    25         self.singleHog = normalHogSprite;
       
    26         [normalHogSprite release];
       
    27         
       
    28         [self drawManyHogs];
       
    29     }
       
    30     return self;
       
    31 }
       
    32 
       
    33 -(void) drawManyHogs {
       
    34     UIImage *teamHogs = [[UIImage alloc] init];
       
    35     for (int i = 0; i < numberOfHogs; i++) {
       
    36         teamHogs = [singleHog mergeWith:teamHogs
       
    37                                 atPoint:CGPointMake(8, 0) 
       
    38                                  atSize:CGSizeMake(88, 32)];
       
    39     }
       
    40     [self setImage:teamHogs forState:UIControlStateNormal];
       
    41 }
       
    42 
       
    43 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       
    44     UITouch *touch = [touches anyObject];
       
    45     
       
    46 	switch ([touch tapCount]) {
       
    47 		case 1:
       
    48             if (numberOfHogs < MAX_HOGS) {
       
    49                 numberOfHogs++;
       
    50             } else {
       
    51                 numberOfHogs = 1;
       
    52             }
       
    53 			break;
       
    54 		case 2:
       
    55             if (numberOfHogs > 2) {
       
    56                 numberOfHogs--;
       
    57                 numberOfHogs--;
       
    58             } else {
       
    59                 numberOfHogs = MAX_HOGS;
       
    60             }
       
    61             break;
       
    62 		default:
       
    63 			break;
       
    64 	}
       
    65     NSLog(@"numberOfHogs: %d", numberOfHogs);
       
    66     [self drawManyHogs];
       
    67 }
       
    68 
       
    69 -(void) dealloc {
       
    70     [singleHog release];
       
    71     [super dealloc];
       
    72 }
       
    73 
       
    74 
       
    75 @end