cocoaTouch/otherSrc/HogButtonView.m
author koda
Wed, 21 Apr 2010 01:57:23 +0000
changeset 3361 cfc6cd502f85
child 3364 e5403e2bf02c
permissions -rw-r--r--
buttons for number of hogs in game config buttons for color of team in game config update and code cleanup fixed crashes at uitextfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     1
//
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     2
//  HogButtonView.m
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     3
//  HedgewarsMobile
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     4
//
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     5
//  Created by Vittorio on 20/04/10.
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     7
//
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     8
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
     9
#import "HogButtonView.h"
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    10
#import "CommodityFunctions.h"
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    11
#import "UIImageExtra.h"
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    12
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    13
@implementation HogButtonView
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    14
@synthesize singleHog;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    15
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    16
-(id) initWithFrame:(CGRect)frame {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    17
    if ((self = [super initWithFrame:frame])) {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    18
        numberOfHogs = 4;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    19
        self.backgroundColor = [UIColor clearColor];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    20
        
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    21
        NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    22
        UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    23
        [normalHogFile release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    24
        
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    25
        self.singleHog = normalHogSprite;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    26
        [normalHogSprite release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    27
        
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    28
        [self drawManyHogs];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    29
    }
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    30
    return self;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    31
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    32
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    33
-(void) drawManyHogs {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    34
    UIImage *teamHogs = [[UIImage alloc] init];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    35
    for (int i = 0; i < numberOfHogs; i++) {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    36
        teamHogs = [singleHog mergeWith:teamHogs
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    37
                                atPoint:CGPointMake(8, 0) 
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    38
                                 atSize:CGSizeMake(88, 32)];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    39
    }
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    40
    [self setImage:teamHogs forState:UIControlStateNormal];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    41
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    42
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    43
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    44
    UITouch *touch = [touches anyObject];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    45
    
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    46
	switch ([touch tapCount]) {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    47
		case 1:
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    48
            if (numberOfHogs < MAX_HOGS) {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    49
                numberOfHogs++;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    50
            } else {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    51
                numberOfHogs = 1;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    52
            }
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    53
			break;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    54
		case 2:
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    55
            if (numberOfHogs > 2) {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    56
                numberOfHogs--;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    57
                numberOfHogs--;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    58
            } else {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    59
                numberOfHogs = MAX_HOGS;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    60
            }
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    61
            break;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    62
		default:
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    63
			break;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    64
	}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    65
    NSLog(@"numberOfHogs: %d", numberOfHogs);
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    66
    [self drawManyHogs];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    67
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    68
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    69
-(void) dealloc {
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    70
    [singleHog release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    71
    [super dealloc];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    72
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    73
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    74
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    75
@end