project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
author koda
Mon, 04 Oct 2010 00:00:42 +0200
changeset 3924 2a9ace189288
child 3933 1a873262f5dd
permissions -rw-r--r--
WIP for an objc ammomenu implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     1
/*
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     4
 *
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     8
 *
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    13
 *
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    17
 *
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    18
 * File created on 03/10/2010.
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    19
 */
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    20
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    21
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    22
#import "AmmoMenuViewController.h"
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    23
#import <QuartzCore/QuartzCore.h>
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    24
#import "CommodityFunctions.h"
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    25
#import "UIImageExtra.h"
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    26
#import "PascalImports.h"
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    27
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    28
@implementation AmmoMenuViewController
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    29
@synthesize imagesArray;;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    30
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    31
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    32
-(void) viewDidLoad {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    33
    [super viewDidLoad];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    34
    self.view.frame = CGRectMake(0, 0, 480, 320);
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    35
    self.view.backgroundColor = [UIColor blackColor];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    36
    [self.view.layer setCornerRadius:10];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    37
    [self.view.layer setMasksToBounds:YES];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    38
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    39
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    40
    UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    41
    
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    42
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:CURRENT_AMMOSIZE];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    43
    for (int i = 0; i < CURRENT_AMMOSIZE; i++) {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    44
        int x_src = ((i*32)/(int)ammoStoreImage.size.height)*32;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    45
        int y_src = (i*32)%(int)ammoStoreImage.size.height;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    46
        int x_dst = 10+(i%10)*44;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    47
        int y_dst = 10+(i/10)*44;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    48
        
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    49
        if (i / 10 % 2 != 0)
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    50
            x_dst += 20;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    51
        UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, 32, 32)];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    52
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x_dst, y_dst, 40, 40)];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    53
        button.tag = i+1;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    54
        button.layer.borderWidth = 1;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    55
        button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    56
        [button.layer setCornerRadius:6];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    57
        [button.layer setMasksToBounds:YES];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    58
        [button setImage:img forState:UIControlStateNormal];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    59
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    60
        [self.view addSubview:button];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    61
        [array addObject:button];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    62
        [button release];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    63
    }
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    64
    self.imagesArray = array;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    65
    [array release];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    66
    [ammoStoreImage release];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    67
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    68
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    69
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    70
-(void) buttonPressed:(id) sender {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    71
    UIButton *theButton = (UIButton *)sender;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    72
    HW_setWeapon(theButton.tag);
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    73
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    74
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    75
-(void) didReceiveMemoryWarning {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    76
    // Releases the view if it doesn't have a superview.
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    77
    [super didReceiveMemoryWarning];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    78
    // Release any cached data, images, etc that aren't in use.
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    79
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    80
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    81
-(void) viewDidUnload {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    82
    [super viewDidUnload];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    83
    self.imagesArray = nil;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    84
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    85
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    86
-(void) dealloc {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    87
    [imagesArray release];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    88
    [super dealloc];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    89
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    90
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    91
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    92
@end