project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
author koda
Thu, 22 Sep 2011 01:02:57 +0200
changeset 5984 6fd40d866342
parent 5976 306cedbeb213
child 6000 dbcebcd3d79f
permissions -rw-r--r--
create the ios schemes programmatically
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4946
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
3924
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
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
    28
#define BTNS_PER_ROW         9
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    29
#define DEFAULT_DESCRIPTION  IS_IPAD() ? \
4356
d1d26f8963a3 update some files for new graphics and new ios4.2
koda
parents: 4082
diff changeset
    30
                             NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen.",@"") : \
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    31
                             NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"")
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
    32
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    33
@implementation AmmoMenuViewController
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    34
@synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    35
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    36
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    37
    return rotationManager(interfaceOrientation);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    38
}
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
    39
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    40
#pragma mark -
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    41
#pragma mark view handling
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    42
-(void) viewDidLoad {    
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];
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
    49
    self.view.autoresizingMask = UIViewAutoresizingNone;
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    50
    placingPoint = CGPointMake(-1, -1);
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    51
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    52
    self.isVisible = NO;
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
    53
    delay = (uint8_t *)calloc(HW_getNumberOfWeapons(), sizeof(uint8_t));
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    54
    HW_getAmmoDelays(delay);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    55
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
    56
    shouldUpdateImage = (BOOL *)calloc(HW_getNumberOfWeapons(), sizeof(BOOL));
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
    57
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    58
    [super viewDidLoad];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    59
}
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
-(void) viewWillAppear:(BOOL)animated {
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    62
    [self updateAmmoVisuals];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    63
    [super viewWillAppear:animated];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    64
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    65
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    66
-(void) appearInView:(UIView *)container {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    67
    [self viewWillAppear:YES];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    68
    [container addSubview:self.view];
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    69
5195
1bfa81f0bc21 fix rotation and ammomenu on ios
koda
parents: 4976
diff changeset
    70
    if (placingPoint.x == -1 || placingPoint.y == -1)
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
    71
        placingPoint = container.center;
5662
99083392cd4f FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents: 5208
diff changeset
    72
    self.view.center = placingPoint;
5195
1bfa81f0bc21 fix rotation and ammomenu on ios
koda
parents: 4976
diff changeset
    73
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    74
    self.isVisible = YES;
4853
afe24c4491ef sheepluva suggested that game should pause when in weapon screen (iphone only)
koda
parents: 4362
diff changeset
    75
    if (IS_IPAD() == NO)
afe24c4491ef sheepluva suggested that game should pause when in weapon screen (iphone only)
koda
parents: 4362
diff changeset
    76
        HW_pause();
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    77
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    78
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    79
-(void) disappear {
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    80
    if (self.isVisible)
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    81
        [self.view removeFromSuperview];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    82
    self.isVisible = NO;
5662
99083392cd4f FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents: 5208
diff changeset
    83
    placingPoint = self.view.center;
4853
afe24c4491ef sheepluva suggested that game should pause when in weapon screen (iphone only)
koda
parents: 4362
diff changeset
    84
    if (IS_IPAD() == NO)
afe24c4491ef sheepluva suggested that game should pause when in weapon screen (iphone only)
koda
parents: 4362
diff changeset
    85
        HW_pauseToggle();
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    86
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
    87
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    88
#pragma mark -
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
    89
#pragma mark drawing
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
    90
-(void) loadLabels {
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    91
    int x = 12;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    92
    int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    93
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    94
    name.backgroundColor = [UIColor clearColor];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    95
    name.textColor = UICOLOR_HW_YELLOW_BODER;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    96
    name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    97
    self.nameLabel = name;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    98
    [self.view addSubview:self.nameLabel];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
    99
    [name release];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   100
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   101
    UILabel *caption = [[UILabel alloc] initWithFrame:CGRectMake(x+200, y, 220, 20)];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   102
    caption.backgroundColor = [UIColor clearColor];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   103
    caption.textColor = [UIColor whiteColor];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   104
    caption.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   105
    caption.adjustsFontSizeToFitWidth = YES;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   106
    caption.minimumFontSize = 8;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   107
    self.captionLabel = caption;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   108
    [self.view addSubview:self.captionLabel];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   109
    [caption release];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   110
5195
1bfa81f0bc21 fix rotation and ammomenu on ios
koda
parents: 4976
diff changeset
   111
    UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(x+2, self.view.frame.size.height-50, 415, 53)];
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   112
    description.backgroundColor = [UIColor clearColor];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   113
    description.textColor = [UIColor whiteColor];
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   114
    description.text = DEFAULT_DESCRIPTION;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   115
    description.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   116
    description.adjustsFontSizeToFitWidth = YES;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   117
    description.minimumFontSize = 8;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   118
    description.numberOfLines = 0;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   119
    self.extraLabel = description;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   120
    [self.view addSubview:self.extraLabel];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   121
    [description release];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   122
}
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   123
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   124
-(void) loadAmmoStuff:(id) object {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   125
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   126
    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   127
    UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   128
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   129
    NSMutableArray *imgs = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   130
    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:HW_getNumberOfWeapons()];
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   131
    int i, j, e;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   132
    for (i = 0, j = 0, e = 0; i < HW_getNumberOfWeapons(); i++) {
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   133
        int x, y;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   134
        float w, radius;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   135
        
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   136
        // move utilities aside and make 'em rounded
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   137
        if (HW_isWeaponAnEffect(i)) {
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   138
            x = 432;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   139
            y = 20 + 48*e++;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   140
            w = 1.5;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   141
            radius = 22;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   142
        } else {
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   143
            x = 10+(j%BTNS_PER_ROW)*44;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   144
            y = 10+(j/BTNS_PER_ROW)*44;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   145
            if (j / BTNS_PER_ROW % 2 != 0)
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   146
                x += 20;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   147
            w = 1;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   148
            radius = 6;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   149
            j++;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   150
        }
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   151
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   152
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   153
        button.frame = CGRectMake(x, y, 40, 40);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   154
        button.tag = i;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   155
        button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
3952
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   156
        button.layer.borderWidth = w;
d6412423da45 moved some utilities to a separate column with round buttons
koda
parents: 3941
diff changeset
   157
        [button.layer setCornerRadius:radius];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   158
        [button.layer setMasksToBounds:YES];
3976
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   159
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   160
        [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside];
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   161
        [button addTarget:self action:@selector(buttonCancelled:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   162
        [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   163
        button.titleLabel.backgroundColor = [UIColor blackColor];
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   164
        button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   165
        [button.titleLabel.layer setCornerRadius:3];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   166
        [button.titleLabel.layer setMasksToBounds:YES];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   167
        button.titleLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   168
        button.titleLabel.layer.borderWidth = 1;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   169
        [self.view addSubview:button];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   170
        [array addObject:button];
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   171
5976
306cedbeb213 fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents: 5662
diff changeset
   172
        int size = 32*getScreenScale();
306cedbeb213 fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents: 5662
diff changeset
   173
        int x_src = ((i*size)/(int)(ammoStoreImage.size.height*getScreenScale()))*size;
306cedbeb213 fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents: 5662
diff changeset
   174
        int y_src = (i*size)%(int)(ammoStoreImage.size.height*getScreenScale());
306cedbeb213 fixed several 'retina display' images and added a bunch more (though just from upscaling the normal ones; might be nice to have 'em redrawn at a real higher resolution)
koda
parents: 5662
diff changeset
   175
        UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, size, size)];
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   176
        [imgs addObject:img];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   177
    }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   178
    [self performSelectorOnMainThread:@selector(setButtonsArray:) withObject:array waitUntilDone:NO];
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   179
    [array release];
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   180
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   181
    [self performSelectorOnMainThread:@selector(setImagesArray:) withObject:imgs waitUntilDone:NO];
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   182
    [imgs release];
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   183
    [ammoStoreImage release];
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   184
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   185
    [self performSelectorOnMainThread:@selector(loadLabels) withObject:nil waitUntilDone:NO];
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   186
    
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   187
    [self performSelectorOnMainThread:@selector(updateAmmoVisuals) withObject:nil waitUntilDone:YES];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   188
    UIActivityIndicatorView *spinner = (UIActivityIndicatorView *)object;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   189
    [spinner stopAnimating];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   190
    [pool drain];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   191
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   192
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   193
-(void) updateAmmoVisuals {
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   194
    if (self.buttonsArray == nil || self.imagesArray == nil) {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   195
        UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   196
        spinner.hidesWhenStopped = YES;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   197
        spinner.center = self.view.center;
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   198
        [spinner startAnimating];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   199
        [self.view addSubview:spinner];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   200
        [NSThread detachNewThreadSelector:@selector(loadAmmoStuff:) toTarget:self withObject:spinner];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   201
        [spinner release];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   202
        return;
3933
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
    
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   205
    int *loadout = (int *)calloc(HW_getNumberOfWeapons(), sizeof(int));
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   206
    int res = HW_getAmmoCounts(loadout);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   207
    int turns = HW_getTurnsForCurrentTeam();
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   208
    
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   209
    if (res == 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   210
        self.view.userInteractionEnabled = YES;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   211
        
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   212
        for (int i = 0; i < HW_getNumberOfWeapons(); i++) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   213
            UIButton *button = [self.buttonsArray objectAtIndex:i];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   214
            if (loadout[i] > 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   215
                if (delay[i]-turns >= 0) {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   216
                    button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   217
                    [button setTitle:[NSString stringWithFormat:@" %d ",delay[i]-turns+1] forState:UIControlStateNormal];
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   218
                    if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == NO) {
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   219
                        UIImage *img = [self.imagesArray objectAtIndex:i];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   220
                        [button setBackgroundImage:[img convertToGrayScale] forState:UIControlStateNormal];
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   221
                        shouldUpdateImage[i] = YES;
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   222
                    }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   223
                } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   224
                    button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
3976
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   225
                    [button setTitle:nil forState:UIControlStateNormal];
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   226
                    if (button.currentBackgroundImage == nil || shouldUpdateImage[i] == YES) {
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   227
                        UIImage *img = [self.imagesArray objectAtIndex:i];
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   228
                        [button setBackgroundImage:img forState:UIControlStateNormal];
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   229
                        shouldUpdateImage[i] = NO;
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   230
                    }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   231
                }
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   232
                button.enabled = YES;
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   233
            } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   234
                if (button.enabled == YES)
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   235
                    [button setBackgroundImage:nil forState:UIControlStateNormal];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   236
                button.layer.borderColor = [[UIColor darkGrayColor] CGColor];
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   237
                button.enabled = NO;
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   238
                shouldUpdateImage[i] = NO;
3935
5ca27a0e9a63 made the new menu toggable
koda
parents: 3933
diff changeset
   239
            }
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   240
        }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   241
    } else {
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   242
        self.view.userInteractionEnabled = NO;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   243
    }
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   244
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   245
    free(loadout);
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   246
    loadout = NULL;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   247
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   248
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   249
#pragma mark -
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   250
#pragma mark user interaction
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   251
-(void) buttonPressed:(id) sender {
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   252
    UIButton *theButton = (UIButton *)sender;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   253
    if (self.nameLabel == nil || self.extraLabel == nil)
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   254
        [self loadLabels];
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   255
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   256
    self.nameLabel.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(theButton.tag)];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   257
    // description contains a lot of unnecessary stuff, we clean it by removing .|, !| and ?|
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   258
    NSString *description = [NSString stringWithUTF8String:HW_getWeaponDescriptionByIndex(theButton.tag)];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   259
    NSArray *elements = [description componentsSeparatedByString:@".|"];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   260
    NSArray *purgedElements = [[elements objectAtIndex:0] componentsSeparatedByString:@"!|"];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   261
    NSArray *morePurgedElements = [[purgedElements objectAtIndex:0] componentsSeparatedByString:@"?|"];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   262
    self.extraLabel.text = [[[morePurgedElements objectAtIndex:0] stringByReplacingOccurrencesOfString:@"|" withString:@" "] stringByAppendingString:@"."];
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   263
    if (theButton.currentTitle != nil)
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   264
        self.captionLabel.text = NSLocalizedString(@"This weapon is locked",@"");
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   265
    else
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   266
        self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)];
4945
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   267
    
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   268
    self.nameLabel.backgroundColor = [UIColor blackColor];
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   269
    self.captionLabel.backgroundColor = [UIColor blackColor];
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   270
    self.extraLabel.backgroundColor = [UIColor blackColor];
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   271
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   272
    int y, x = 8;
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   273
    // display labels on top for lower buttons
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   274
    if (theButton.tag > 41)
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   275
        y = 5;
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   276
    else
5195
1bfa81f0bc21 fix rotation and ammomenu on ios
koda
parents: 4976
diff changeset
   277
        y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*40;
4945
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   278
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   279
    self.nameLabel.frame = CGRectMake(x, y, 200, 20);
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   280
    self.captionLabel.frame = CGRectMake(x+200, y, 220, 20);
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   281
    self.extraLabel.frame = CGRectMake(x+2, y+20, 415, 53);
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   282
}
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   283
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   284
-(void) buttonCancelled:(id) sender {
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   285
    self.nameLabel.text = nil;
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   286
    self.extraLabel.text = nil;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   287
    self.captionLabel.text = nil;
4945
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   288
    self.extraLabel.backgroundColor = [UIColor clearColor];
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   289
    self.captionLabel.backgroundColor = [UIColor clearColor];
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   290
    self.nameLabel.backgroundColor = [UIColor clearColor];
3976
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   291
}
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   292
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   293
-(void) buttonReleased:(id) sender {
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   294
    UIButton *theButton = (UIButton *)sender;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   295
    if (self.nameLabel == nil || self.extraLabel == nil)
3989
adffb668f06e add a default description to the new ammomenu
koda
parents: 3984
diff changeset
   296
        [self loadLabels];
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   297
3976
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   298
    if (theButton.currentTitle == nil) {
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   299
        HW_setWeapon(theButton.tag);
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   300
        playSound(@"clickSound");
3984
d92509c2f255 some more memory opt
koda
parents: 3981
diff changeset
   301
        if (IS_DUALHEAD() == NO)
d92509c2f255 some more memory opt
koda
parents: 3981
diff changeset
   302
            [self disappear];
3976
abaf741a4e21 less warning, no rotation glitch, more comments
koda
parents: 3952
diff changeset
   303
    }
4945
541d35d1f2e8 in the cocoa ammomenu show descriptions properly for lower weapons
koda
parents: 4853
diff changeset
   304
    [self buttonCancelled:sender];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   305
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   306
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   307
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   308
    NSSet *allTouches = [event allTouches];
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   309
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   310
    if (IS_IPAD() && [touches count] == 1) {
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   311
        self.view.layer.borderWidth = 3.5;
4946
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   312
        currentPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   313
    }
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   314
3996
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3989
diff changeset
   315
    if (IS_IPAD() == NO)
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3989
diff changeset
   316
        [self disappear];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   317
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   318
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   319
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   320
    self.view.layer.borderWidth = 1.3;
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   321
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   322
4946
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   323
// better window dragging implementation by
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   324
// http://iphonedevelopertips.com/graphics/drag-an-image-within-the-bounds-of-superview.html
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   325
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   326
    if (IS_IPAD() && [touches count] == 1) {
4946
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   327
        // Get active location upon move
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   328
        CGPoint activePoint = [[touches anyObject] locationInView:self.view];
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   329
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   330
        // Determine new point based on where the touch is now located
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   331
        CGPoint newPoint = CGPointMake(self.view.center.x + (activePoint.x - currentPoint.x),
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   332
                                       self.view.center.y + (activePoint.y - currentPoint.y));
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   333
4946
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   334
        // Make sure we stay within the bounds of the parent view
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   335
        float midPointX = CGRectGetMidX(self.view.bounds);
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   336
        if (newPoint.x > self.view.superview.bounds.size.width  - midPointX)
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   337
            newPoint.x = self.view.superview.bounds.size.width - midPointX;
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   338
        else if (newPoint.x < midPointX)
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   339
            newPoint.x = midPointX;
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   340
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   341
        float midPointY = CGRectGetMidY(self.view.bounds);
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   342
        if (newPoint.y > self.view.superview.bounds.size.height  - midPointY)
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   343
            newPoint.y = self.view.superview.bounds.size.height - midPointY;
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   344
        else if (newPoint.y < midPointY)
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   345
            newPoint.y = midPointY;
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   346
076767e86f2b better ammomenu window dragging algorithm (as suggested by iphonedevelopertips)
koda
parents: 4945
diff changeset
   347
        self.view.center = newPoint;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   348
    }
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   349
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   350
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   351
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
4032
4aeab704d006 can move the new ammo menu freely
koda
parents: 3996
diff changeset
   352
    [self touchesEnded:touches withEvent:event];
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   353
}
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   354
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   355
#pragma mark -
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   356
#pragma mark memory
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   357
-(void) didReceiveMemoryWarning {
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   358
    self.imagesArray = nil;
4082
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 4034
diff changeset
   359
    if (self.isVisible == NO)
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 4034
diff changeset
   360
        self.buttonsArray = nil;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   361
    self.nameLabel = nil;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   362
    self.extraLabel = nil;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   363
    self.captionLabel = nil;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   364
    MSG_MEMCLEAN();
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   365
    [super didReceiveMemoryWarning];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   366
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   367
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   368
-(void) viewDidUnload {
3977
9df7b4812da9 optimizations to new ammomenu and overlay
koda
parents: 3976
diff changeset
   369
    self.imagesArray = nil;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   370
    self.buttonsArray = nil;
3981
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   371
    self.nameLabel = nil;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   372
    self.extraLabel = nil;
928e2040d34f add name, caption and description to the new ammomenu
koda
parents: 3978
diff changeset
   373
    self.captionLabel = nil;
3940
cc29628976cc some optimizations to drawing and fetching data of new ammomenu
koda
parents: 3935
diff changeset
   374
    free(delay);
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   375
    delay = NULL;
3978
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   376
    free(shouldUpdateImage);
9660600e43cb fix some glitches
koda
parents: 3977
diff changeset
   377
    shouldUpdateImage = NULL;
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   378
    MSG_DIDUNLOAD();
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   379
    [super viewDidUnload];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   380
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   381
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   382
-(void) dealloc {
5208
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5195
diff changeset
   383
    releaseAndNil(nameLabel);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5195
diff changeset
   384
    releaseAndNil(extraLabel);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5195
diff changeset
   385
    releaseAndNil(captionLabel);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5195
diff changeset
   386
    releaseAndNil(imagesArray);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5195
diff changeset
   387
    releaseAndNil(buttonsArray);
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   388
    [super dealloc];
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   389
}
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents:
diff changeset
   390
3933
1a873262f5dd polishing the cocoa ammomenu a little, still requires work
koda
parents: 3924
diff changeset
   391
@end