project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
author koda
Sun, 10 Oct 2010 02:06:42 +0200
changeset 3940 cc29628976cc
parent 3935 5ca27a0e9a63
child 3941 017b2b31e1c6
permissions -rw-r--r--
some optimizations to drawing and fetching data of new ammomenu
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
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    29
@synthesize weaponsImage, buttonsArray, isVisible;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    30
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    31
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    32
    return rotationManager(interfaceOrientation);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    33
}
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    34
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    35
#pragma mark -
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    36
#pragma mark view handling
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    37
-(void) viewDidLoad {    
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    38
    [[NSNotificationCenter defaultCenter] addObserver:self
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
    39
                                             selector:@selector(updateAmmoVisuals)
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    40
                                                 name:@"updateAmmoVisuals"
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    41
                                               object:nil];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    42
     
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    43
    self.view.frame = CGRectMake(0, 0, 480, 320);
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    44
    self.view.backgroundColor = [UIColor blackColor];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    45
    self.view.layer.borderColor = [[UIColor whiteColor] CGColor];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    46
    self.view.layer.borderWidth = 1.3f;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    47
    [self.view.layer setCornerRadius:10];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    48
    [self.view.layer setMasksToBounds:YES];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    49
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    50
    self.isVisible = NO;
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    51
    delay = (uint8_t *) calloc(HW_getNumberOfWeapons(), sizeof(uint8_t));
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    52
    HW_getAmmoDelays(delay);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    53
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    54
    [super viewDidLoad];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    55
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    56
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    57
-(void) viewWillAppear:(BOOL)animated {
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    58
    [self updateAmmoVisuals];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    59
    [super viewWillAppear:animated];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    60
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    61
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    62
-(void) appearInView:(UIView *)container {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    63
    [self viewWillAppear:YES];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    64
    [container addSubview:self.view];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    65
    self.view.center = CGPointMake(container.center.y, container.center.x);
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    66
    self.isVisible = YES;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    67
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    68
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    69
-(void) disappear {
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    70
    if (self.isVisible)
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    71
        [self.view removeFromSuperview];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    72
    self.isVisible = NO;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    73
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    74
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    75
#pragma mark -
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    76
#pragma mark drawing
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    77
-(void) loadAmmoStuff:(id) object {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    78
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    79
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    80
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    81
    UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    82
    [self performSelectorOnMainThread:@selector(setWeaponsImage:) withObject:ammoStoreImage waitUntilDone:NO];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    83
    [ammoStoreImage release];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    84
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    85
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    86
    for (int i = 0; i < HW_getNumberOfWeapons(); i++) {
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    87
        int x_dst = 10+(i%10)*44;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    88
        int y_dst = 10+(i/10)*44;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    89
        
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    90
        if (i / 10 % 2 != 0)
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    91
            x_dst += 20;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    92
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    93
        button.frame = CGRectMake(x_dst, y_dst, 40, 40);
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    94
        button.tag = i;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    95
        button.layer.borderWidth = 1;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    96
        button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    97
        [button.layer setCornerRadius:6];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    98
        [button.layer setMasksToBounds:YES];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    99
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   100
        [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   101
        button.titleLabel.backgroundColor = [UIColor blackColor];
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   102
        button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   103
        [button.titleLabel.layer setCornerRadius:3];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   104
        [button.titleLabel.layer setMasksToBounds:YES];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   105
        button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   106
        button.titleLabel.layer.borderWidth = 1;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   107
        [self.view addSubview:button];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   108
        [array addObject:button];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   109
    }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   110
    [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   111
    [array release];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   112
    
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   113
    [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:NO];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   114
    UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   115
    [spinner stopAnimating];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   116
    [pool drain];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   117
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   118
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   119
-(void) updateAmmoVisuals {
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   120
    if (self.buttonsArray == nil || self.weaponsImage == nil) {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   121
        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   122
        spinner.hidesWhenStopped = YES;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   123
        spinner.center = self.view.center;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   124
        [spinner startAnimating];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   125
        [self.view addSubview:spinner];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   126
        [NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   127
        [spinner release];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   128
        return;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   129
    }
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   130
    
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   131
    [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   132
}
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   133
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   134
-(void) drawingThread {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   135
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   136
    int *loadout = (int *)calloc(HW_getNumberOfWeapons(), sizeof(int));
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   137
    int res = HW_getAmmoCounts(loadout);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   138
    int turns = HW_getTurnsForCurrentTeam();
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   139
    
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   140
    if (res == 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   141
        self.view.userInteractionEnabled = YES;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   142
        
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   143
        for (int i = 0; i < HW_getNumberOfWeapons(); i++) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   144
            UIButton *button = [self.buttonsArray objectAtIndex:i];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   145
            if (loadout[i] > 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   146
                if (delay[i]-turns >= 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   147
                    button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   148
                    [button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   149
                    if (button.currentBackgroundImage == nil) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   150
                        int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   151
                        int y_src = (i*32)%(int)self.weaponsImage.size.height;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   152
                        UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   153
                        [button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   154
                        button.imageView.tag = 10000;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   155
                    }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   156
                } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   157
                    button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   158
                    [button setTitle:@"" forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   159
                    if (button.currentBackgroundImage == nil || button.imageView.tag == 10000) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   160
                        int x_src = ((i*32)/(int)self.weaponsImage.size.height)*32;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   161
                        int y_src = (i*32)%(int)self.weaponsImage.size.height;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   162
                        UIImage *img = [self.weaponsImage cutAt:CGRectMake(x_src, y_src, 32, 32)];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   163
                        [button setBackgroundImage:img forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   164
                        button.imageView.tag = 0;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   165
                    }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   166
                }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   167
                button.enabled = YES;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   168
            } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   169
                if (button.enabled == YES)
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   170
                    [button setBackgroundImage:nil forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   171
                button.layer.borderColor = [[UIColor darkGrayColor] CGColor];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   172
                button.enabled = NO;
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   173
            }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   174
            
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   175
        }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   176
    } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   177
        self.view.userInteractionEnabled = NO;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   178
    }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   179
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   180
    free(loadout);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   181
    loadout = NULL;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   182
    [pool drain];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   183
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   184
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   185
#pragma mark -
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   186
#pragma mark user interaction
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   187
-(void) buttonPressed:(id) sender {
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   188
    UIButton *theButton = (UIButton *)sender;
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   189
    HW_setWeapon(theButton.tag);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   190
    playSound(@"clickSound");
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   191
    [self disappear];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   192
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   193
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   194
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   195
    /*
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   196
    NSSet *allTouches = [event allTouches];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   197
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   198
    if ([touches count] == 1) {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   199
        self.view.layer.borderWidth = 3.5;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   200
        startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   201
    }
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   202
    */
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   203
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   204
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   205
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   206
    //self.view.layer.borderWidth = 1.3;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   207
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   208
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   209
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   210
    /*
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   211
    NSSet *allTouches = [event allTouches];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   212
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   213
    if ([touches count] == 1) {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   214
        CGPoint touchedPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   215
        CGFloat deltaX = touchedPoint.x - startingPoint.x;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   216
        CGFloat deltaY = touchedPoint.y - startingPoint.y;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   217
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   218
        //startingPoint = touchedPoint;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   219
        self.view.frame = CGRectMake(self.view.frame.origin.x + deltaX, self.view.frame.origin.y + deltaY,
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   220
                                     self.view.frame.size.width, self.view.frame.size.height);
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   221
    }
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   222
    */
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   223
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   224
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   225
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   226
    //[self touchesEnded:touches withEvent:event];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   227
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   228
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   229
#pragma mark -
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   230
#pragma mark memory
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   231
-(void) didReceiveMemoryWarning {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   232
    self.weaponsImage = nil;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   233
    self.buttonsArray = nil;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   234
    MSG_MEMCLEAN();
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   235
    [super didReceiveMemoryWarning];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   236
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   237
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   238
-(void) viewDidUnload {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   239
    [[NSNotificationCenter defaultCenter] removeObserver:self];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   240
    self.weaponsImage = nil;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   241
    self.buttonsArray = nil;
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   242
    free(delay);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   243
    delay = NULL;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   244
    MSG_DIDUNLOAD();
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   245
    [super viewDidUnload];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   246
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   247
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   248
-(void) dealloc {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   249
    [weaponsImage release];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   250
    [buttonsArray release];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   251
    [super dealloc];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   252
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   253
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   254
@end
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   255
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   256
void updateVisualsNewTurn (void) {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   257
    [[NSNotificationCenter defaultCenter] postNotificationName:@"updateAmmoVisuals" object:nil];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   258
}