project_files/HedgewarsMobile/Classes/HogButtonView.m
author koda
Sun, 07 Nov 2010 19:00:41 +0100
changeset 4187 adb144a907aa
parent 3948 24daa33a3114
permissions -rw-r--r--
remove last warnings from xcodeproj update credits
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"
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3829
diff changeset
    25
#import "PascalImports.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
@implementation HogButtonView
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
@synthesize singleHog, numberOfHogs, ownerDictionary;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
-(id) initWithFrame:(CGRect)frame {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    if ((self = [super initWithFrame:frame])) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
        self.backgroundColor = [UIColor clearColor];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    33
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
        NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
        UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
        [normalHogFile release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    37
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
        self.singleHog = normalHogSprite;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
        [normalHogSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
        [self addTarget:self action:@selector(addOne) forControlEvents:UIControlEventTouchUpInside];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
    return self;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
-(void) addOne {
3783
8e9daf967406 X&Y buttons, sounds for some buttons, cleanup
koda
parents: 3697
diff changeset
    46
    playSound(@"clickSound");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
    self.highlighted = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    NSInteger number = self.numberOfHogs;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    number++;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    [self drawManyHogs:number];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
-(void) drawManyHogs:(NSInteger) hogs {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
    if (numberOfHogs != hogs) {
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3829
diff changeset
    55
        if (hogs <= HW_getMaxNumberOfHogs() && hogs >= 1)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
            numberOfHogs = hogs;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
        else {
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3829
diff changeset
    58
            if (hogs > HW_getMaxNumberOfHogs())
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
                numberOfHogs = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
            else
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3829
diff changeset
    61
                numberOfHogs = HW_getMaxNumberOfHogs();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
        [ownerDictionary setObject:[NSNumber numberWithInt:numberOfHogs] forKey:@"number"];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    64
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
        UIImage *teamHogs = [[[UIImage alloc] init] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
        for (int i = 0; i < numberOfHogs; i++) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
            teamHogs = [singleHog mergeWith:teamHogs
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3547
diff changeset
    68
                                    atPoint:CGPointMake(8, 0)
3948
24daa33a3114 some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents: 3926
diff changeset
    69
                                     ofSize:CGSizeMake(88, 32)];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
        [self setImage:teamHogs forState:UIControlStateNormal];
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
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
    [ownerDictionary release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    [singleHog release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    [super dealloc];
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
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
@end