cocoaTouch/otherSrc/HogButtonView.m
author convert-repo
Wed, 16 Jun 2010 04:10:50 +0000
changeset 3504 6a28efdec1f5
parent 3364 e5403e2bf02c
permissions -rw-r--r--
update tags
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
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    14
@synthesize singleHog, numberOfHogs, ownerDictionary;
3361
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
        self.backgroundColor = [UIColor clearColor];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    19
        
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    20
        NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    21
        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
    22
        [normalHogFile release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    23
        
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    24
        self.singleHog = normalHogSprite;
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    25
        [normalHogSprite release];
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    26
        [self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
3361
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
    return self;
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
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    31
-(void) addOne {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    32
    self.highlighted = NO;
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    33
    NSInteger number = self.numberOfHogs;
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    34
    number++;
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    35
    [self drawManyHogs:number];
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    36
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    37
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    38
-(void) drawManyHogs:(NSInteger) hogs {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    39
    if (numberOfHogs != hogs) {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    40
        if (hogs <= MAX_HOGS && hogs >= 1)
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    41
            numberOfHogs = hogs;
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    42
        else {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    43
            if (hogs > MAX_HOGS)
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    44
                numberOfHogs = 1;
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    45
            else
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    46
                numberOfHogs = MAX_HOGS;
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    47
        }
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    48
        [ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    49
        
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    50
        UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    51
        for (int i = 0; i < numberOfHogs; i++) {
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    52
            teamHogs = [singleHog mergeWith:teamHogs
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    53
                                    atPoint:CGPointMake(8, 0) 
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    54
                                     atSize:CGSizeMake(88, 32)];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    55
        }
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    56
        [self setImage:teamHogs forState:UIControlStateNormal];
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    57
    }
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    58
}
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    59
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    60
-(void) dealloc {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3361
diff changeset
    61
    [ownerDictionary release];
3361
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    62
    [singleHog release];
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    63
    [super dealloc];
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
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    66
cfc6cd502f85 buttons for number of hogs in game config
koda
parents:
diff changeset
    67
@end