project_files/HedgewarsMobile/Classes/HogButtonView.m
author koda
Sun, 19 Sep 2010 13:54:38 +0200
changeset 3883 5934ddf9ed5d
parent 3829 81db3c85784b
child 3926 668b71f31e51
permissions -rw-r--r--
fixed the voice selection where you couldn't hear a preview sound
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    18
 * File created on 20/04/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3783
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "HogButtonView.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
#import "UIImageExtra.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
@implementation HogButtonView
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@synthesize singleHog, numberOfHogs, ownerDictionary;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
-(id) initWithFrame:(CGRect)frame {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
    if ((self = [super initWithFrame:frame])) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
        self.backgroundColor = [UIColor clearColor];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    32
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
        NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
        UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
        [normalHogFile release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    36
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
        self.singleHog = normalHogSprite;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
        [normalHogSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
        [self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    return self;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
-(void) addOne {
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3697
diff changeset
    45
    playSound(@"clickSound");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
    self.highlighted = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
    NSInteger number = self.numberOfHogs;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    number++;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    [self drawManyHogs:number];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
-(void) drawManyHogs:(NSInteger) hogs {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
    if (numberOfHogs != hogs) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
        if (hogs <= MAX_HOGS && hogs >= 1)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
            numberOfHogs = hogs;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
        else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
            if (hogs > MAX_HOGS)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
                numberOfHogs = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
            else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
                numberOfHogs = MAX_HOGS;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
        [ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    63
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
        UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
        for (int i = 0; i < numberOfHogs; i++) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
            teamHogs = [singleHog mergeWith:teamHogs
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    67
                                    atPoint:CGPointMake(8, 0)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
                                     atSize:CGSizeMake(88, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
        [self setImage:teamHogs forState:UIControlStateNormal];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
    [ownerDictionary release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
    [singleHog release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
@end