cocoaTouch/OverlayViewController.m
author koda
Thu, 17 Jun 2010 19:57:51 +0200
changeset 3513 f589230fa21b
parent 3490 016b3172b645
permissions -rw-r--r--
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive) add rotation for iphone build too make the ifrontend work again with 3.0 sdk reworked openalbridge following most of an old implementation by Smaxx and making it more modular -- now sources are limited but the memory extension and cleanup is todo nil'd many variables in engine that were causing intialization problems
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     1
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     2
//  overlayViewController.m
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     3
//  HedgewarsMobile
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     4
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     5
//  Created by Vittorio on 16/03/10.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     7
//
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     8
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
     9
#import "OverlayViewController.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    10
#import "SDL_uikitappdelegate.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    11
#import "PascalImports.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    12
#import "CGPointUtils.h"
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    13
#import "SDL_mouse.h"
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    14
#import "SDL_config_iphoneos.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    15
#import "PopoverMenuViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    16
#import "CommodityFunctions.h"
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    17
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    18
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    19
#define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    20
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    21
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    22
@implementation OverlayViewController
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    23
@synthesize popoverController, popupMenu, writeChatTextField;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    24
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    25
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    26
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    27
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    28
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    29
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    30
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
-(void) didReceiveMemoryWarning {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    32
	// Releases the view if it doesn't have a superview.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    33
    [super didReceiveMemoryWarning];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    34
	// Release any cached data, images, etc that aren't in use.
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    35
    if (popupMenu.view.superview == nil) 
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
    36
        popupMenu = nil;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    37
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    38
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    39
-(void) didRotate:(NSNotification *)notification {	
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    40
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    41
    CGRect rect = [[UIScreen mainScreen] bounds];
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    42
    CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height);
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    43
    UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345];
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    44
    
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    45
    [UIView beginAnimations:@"rotation" context:NULL];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    46
    [UIView setAnimationDuration:0.8f];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    47
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    48
	switch (orientation) {
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    49
        case UIDeviceOrientationLandscapeLeft:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    50
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    51
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    52
            [self chatDisappear];
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    53
            HW_setLandscape(YES);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    54
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    55
        case UIDeviceOrientationLandscapeRight:
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    56
            sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    57
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    58
            [self chatDisappear];
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    59
            HW_setLandscape(YES);
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    60
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    61
        case UIDeviceOrientationPortrait:
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    62
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    63
                sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270));
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    64
                self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    65
                [self chatAppear];
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    66
                HW_setLandscape(NO);
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    67
            }
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    68
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    69
        case UIDeviceOrientationPortraitUpsideDown:
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    70
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    71
                sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    72
                self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    73
                [self chatAppear];
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    74
                HW_setLandscape(NO);
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    75
            }
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    76
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    77
        default:
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    78
            DLog(@"Unknown rotation status");
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    79
            break;
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    80
    }
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    81
    self.view.frame = usefulRect;
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    82
    //sdlView.frame = usefulRect;
3395
095273ad0e08 adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents: 3385
diff changeset
    83
    [UIView commitAnimations];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    84
}
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
    85
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    86
-(void) chatAppear {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    87
    if (writeChatTextField == nil) {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    88
        writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    89
        writeChatTextField.textColor = [UIColor whiteColor];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    90
        writeChatTextField.backgroundColor = [UIColor blueColor];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    91
        writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    92
        writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    93
        writeChatTextField.enablesReturnKeyAutomatically = NO;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    94
        writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    95
        writeChatTextField.keyboardType = UIKeyboardTypeDefault;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    96
        writeChatTextField.returnKeyType = UIReturnKeyDefault;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    97
        writeChatTextField.secureTextEntry = NO;	
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    98
        [self.view addSubview:writeChatTextField];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
    99
    }
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   100
    writeChatTextField.alpha = 1;
3479
972ae3ec178a initial support for game modifiers (schemes)
koda
parents: 3463
diff changeset
   101
    [self activateOverlay];
972ae3ec178a initial support for game modifiers (schemes)
koda
parents: 3463
diff changeset
   102
    [dimTimer setFireDate:HIDING_TIME_NEVER];
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   103
}
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   104
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   105
-(void) chatDisappear {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   106
    writeChatTextField.alpha = 0;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   107
    [writeChatTextField resignFirstResponder];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   108
    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   109
}
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   110
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
-(void) viewDidLoad {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   112
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
    self.view.alpha = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   115
    
3317
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
   116
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   117
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   119
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   120
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   122
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   123
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   124
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   125
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   126
    
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   127
    // listen for dismissal of the popover (see below)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   128
    [[NSNotificationCenter defaultCenter] addObserver:self
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   129
                                             selector:@selector(dismissPopover)
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   130
                                                 name:@"dismissPopover"
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3356
diff changeset
   131
                                               object:nil];
3385
361bd29293f4 add automatic rotation in ipad (landscape only)
koda
parents: 3364
diff changeset
   132
    
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   133
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];	
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   134
    [[NSNotificationCenter defaultCenter] addObserver:self
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   135
                                             selector:@selector(didRotate:)
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   136
                                                 name:@"UIDeviceOrientationDidChangeNotification"
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   137
                                               object:nil];
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   138
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   139
    //self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); 
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   143
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   144
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   145
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   146
-(void) viewDidUnload {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   147
    self.writeChatTextField = nil;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   148
    self.popoverController = nil;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   149
    self.popupMenu = nil;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   150
    [super viewDidUnload];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   151
    MSG_DIDUNLOAD();
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   152
}
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   153
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   154
-(void) dealloc {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   155
	[dimTimer invalidate];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   156
    [writeChatTextField release];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   157
    [popupMenu release];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   158
    [popoverController release];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   159
    // dimTimer is autoreleased
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   160
    [super dealloc];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   161
}
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   162
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   163
// dim the overlay when there's no more input for a certain amount of time
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   164
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   165
	HW_allKeysUp();
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   166
    [dimTimer setFireDate:HIDING_TIME_DEFAULT];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   167
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   168
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   169
// nice transition for dimming, should be called only by the timer himself
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   170
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   171
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   172
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   173
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   174
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   175
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   176
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   177
// set the overlay visible and put off the timer for enough time
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   178
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   179
    self.view.alpha = 1;
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   180
    [dimTimer setFireDate:HIDING_TIME_NEVER];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   181
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   182
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   183
// issue certain action based on the tag of the button 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   184
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   185
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   186
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   187
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   188
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   189
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   190
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   191
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   192
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   193
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   194
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   195
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   196
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   197
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   198
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   199
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   200
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   201
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   202
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   203
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   204
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   205
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   206
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   207
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   208
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   209
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   210
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   211
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   212
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   213
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   214
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   215
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   216
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   217
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   218
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   219
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   220
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   221
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   222
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   223
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   224
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   225
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   226
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   227
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   228
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   229
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   230
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   231
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   232
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   233
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   234
// on iphone instead just use the tableViewController directly (and implement manually all animations)
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   235
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   236
    isPopoverVisible = YES;
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   237
    CGRect anchorForPopover;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   238
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   239
    if (popoverControllerClass) {
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
   240
#if __IPHONE_3_2
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   241
        if (popupMenu == nil) 
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   242
            popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   243
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   244
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   245
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   246
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   247
        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   248
            anchorForPopover = CGRectMake(960, 0, 220, 32);
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   249
        else
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   250
            anchorForPopover = CGRectMake(736, 0, 220, 32);
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   251
        
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   252
        [popoverController presentPopoverFromRect:anchorForPopover
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   253
                                           inView:self.view
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   254
                         permittedArrowDirections:UIPopoverArrowDirectionUp
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   255
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   256
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   257
    } else {
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   258
        if (popupMenu == nil) 
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   259
            popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   260
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   261
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   262
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   263
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   264
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   265
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   266
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   267
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   268
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   269
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   270
}
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   271
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   272
// on ipad just dismiss it, on iphone transtion to the right
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   273
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   274
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   275
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   276
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   277
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3479
diff changeset
   278
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   279
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   280
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   281
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   282
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   283
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   284
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   285
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   286
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   287
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   288
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   289
        }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   290
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   291
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   292
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   293
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   294
-(void) textFieldDoneEditing:(id) sender{
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   295
    [sender resignFirstResponder];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   296
}
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   297
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   298
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   299
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   300
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   301
#define kMinimumPinchDelta      50
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   302
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   303
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   305
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   307
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   308
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   309
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   310
    }
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   311
    if (writeChatTextField) {
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   312
        [self.writeChatTextField resignFirstResponder];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   313
        [dimTimer setFireDate:HIDING_TIME_DEFAULT];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3405
diff changeset
   314
    }
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   315
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   316
    gestureStartPoint = [touch locationInView:self.view];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   317
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   318
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   319
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   320
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   321
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   322
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   323
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   324
					//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   325
					//		      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   326
					//HW_click();
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   327
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   328
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   329
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   330
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   331
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   332
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   333
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   334
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   335
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   336
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   337
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   338
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   339
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   340
			// pinching
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   341
            gestureStartPoint.x = 0;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   342
            gestureStartPoint.y = 0;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   343
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   344
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   345
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   346
			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   347
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   348
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   349
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   350
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   351
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   352
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   353
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   354
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   355
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   356
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   357
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   358
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   359
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   360
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   361
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   362
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   363
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   364
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   365
    CGFloat minimumGestureLength;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   366
    int logCoeff;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   367
    
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   368
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   369
        minimumGestureLength = 5.0f;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   370
        logCoeff = 19;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   371
    } else {
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   372
        minimumGestureLength = 3.0f;
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   373
        logCoeff = 3;
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   374
    }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   375
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   376
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   377
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   378
	UITouch *touch = [touches anyObject];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   379
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   380
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   381
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   382
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   383
			// panning
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   384
			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   385
			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   386
			
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   387
            if (deltaX >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   388
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   389
                if (currentPosition.x > gestureStartPoint.x) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   390
                    HW_cursorLeft(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   391
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   392
                    HW_cursorRight(logCoeff*log(deltaX));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   393
                }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   394
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   395
            } 
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   396
            if (deltaY >= minimumGestureLength) {
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   397
                NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3357
diff changeset
   398
                if (currentPosition.y < gestureStartPoint.y) {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   399
                    HW_cursorDown(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   400
                } else {
3356
3ae3fccb439e add missing controller stubs
koda
parents: 3347
diff changeset
   401
                    HW_cursorUp(logCoeff*log(deltaY));
3347
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   402
                }            
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   403
            }
5d0ac8197eb7 camera panning ftw
koda
parents: 3340
diff changeset
   404
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   405
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   406
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   407
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   408
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   409
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   410
			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   411
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   412
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   413
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   414
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   415
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   416
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   417
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   418
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   419
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   420
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   421
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   422
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   423
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   424
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   425
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   426
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   427
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   428
@end