cocoaTouch/OverlayViewController.m
author koda
Tue, 13 Apr 2010 14:39:05 +0000
changeset 3339 d558bc5a73c5
parent 3335 2520ee7a5484
child 3340 96dd168b080b
permissions -rw-r--r--
lots of untested stuff for the ifrontend
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"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    14
#import "PopoverMenuViewController.h"
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    15
#import "CommodityFunctions.h"
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    16
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    17
@implementation OverlayViewController
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    18
@synthesize dimTimer, popoverController, popupMenu;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    19
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    20
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    21
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    22
	return rotationManager(interfaceOrientation);
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    23
}
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    24
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3317
diff changeset
    25
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    26
-(void) didReceiveMemoryWarning {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    27
	// 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
    28
    [super didReceiveMemoryWarning];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    29
	// Release any cached data, images, etc that aren't in use.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    30
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    31
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    32
-(void) viewDidLoad {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    33
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    34
    self.view.alpha = 0;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    35
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    36
    // needed for rotation to work on os < 3.2
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    37
    self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    38
    self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0));
3317
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
    39
    self.view.frame = [[UIScreen mainScreen] applicationFrame];
198ec44b6d92 minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents: 3308
diff changeset
    40
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    41
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    42
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    43
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    44
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    45
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    46
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    47
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    48
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    49
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    50
    // listen for dismissal of the popover (see below)x
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    51
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    52
    // present the overlay after 2 seconds
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    53
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    54
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    55
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    56
-(void) viewDidUnload {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    57
	[dimTimer invalidate];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    58
	self.dimTimer = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    59
    self.popoverController = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    60
    self.popupMenu = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    61
    [super viewDidUnload];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    62
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    63
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    64
-(void) dealloc {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    65
    [popupMenu release];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    66
    [popoverController release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    67
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    68
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    70
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
// draws the controller overlay after the sdl window has taken control
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    72
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    74
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    75
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    76
	[UIView setAnimationDuration:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    77
	self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    78
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    79
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    80
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    81
// 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
    82
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    85
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    86
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    87
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    89
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    90
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    91
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    92
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    93
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    94
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    95
// 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
    96
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    97
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    98
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    99
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   100
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   101
// 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
   102
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   103
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   104
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   105
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   106
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   107
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   108
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   110
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   116
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   117
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   119
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   120
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   122
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   123
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   124
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   125
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   126
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   128
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   129
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   132
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   133
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   134
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   135
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   136
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   143
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   144
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   145
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   146
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   147
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   148
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   149
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   150
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   151
// 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
   152
// 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
   153
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   154
    isPopoverVisible = YES;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   155
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   156
    if (popoverControllerClass) {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   157
#ifdef __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   158
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   159
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   160
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   161
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   162
        
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   163
        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   164
                                           inView:self.view
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   165
                         permittedArrowDirections:UIPopoverArrowDirectionUp 
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   166
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   167
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   168
    } else {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   169
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   170
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   171
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   172
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   173
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   174
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   175
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   176
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   177
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   178
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   179
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   180
}
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   181
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   182
// on ipad just dismiss it, on iphone transtion on the right
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   183
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   184
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   185
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   186
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   187
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   188
#ifdef __IPHONE_3_2
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   189
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   190
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   191
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   192
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   193
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   194
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   195
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   196
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   197
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   198
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   199
            
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   200
            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   201
        }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   202
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   203
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   204
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   205
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   206
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   207
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   208
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   209
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   210
#define kMinimumPinchDelta      50
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   211
#define kMinimumGestureLength	10
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   212
#define kMaximumVariance        3
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   213
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   214
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   215
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   216
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   217
	int width = [[UIScreen mainScreen] bounds].size.width;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   218
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   219
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   220
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   221
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   222
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   223
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   224
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   225
			gestureStartPoint = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   226
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   228
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   229
					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   230
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   231
							      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
					HW_click();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   235
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   236
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   237
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   238
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   239
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   240
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   241
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   242
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   243
				HW_zoomReset();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   245
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
			// pinching
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   249
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   250
			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
   251
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   252
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   253
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   254
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   255
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   256
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   257
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   258
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   259
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   260
	gestureStartPoint.x = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   261
	gestureStartPoint.y = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   262
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   263
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   264
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   265
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   266
	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances.
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   267
	[self touchesEnded:touches withEvent:event];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   268
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   271
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   272
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   273
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   274
	int width = [[UIScreen mainScreen] bounds].size.width;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   275
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   276
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   277
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   278
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   279
			// panning
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   280
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   281
							(int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   282
			// remember that we have x and y inverted
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   283
			/* temporarily disabling hog movements for camera panning testing
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   284
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   285
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   286
			CGFloat deltaX = fabsf(vertDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   287
			CGFloat deltaY = fabsf(horizDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   288
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   289
			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   290
				NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   291
				if (horizDiff > 0) HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   292
				else HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   293
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   294
				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   295
				if (vertDiff < 0) HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   296
				else HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   297
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   298
			*/
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   299
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   300
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   301
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   302
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   303
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
			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
   305
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   307
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   308
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   309
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   310
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   311
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   312
				HW_zoomIn();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   313
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   314
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   315
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   316
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   317
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   318
	}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   319
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   320
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   321
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   322
@end