cocoaTouch/OverlayViewController.m
author koda
Tue, 13 Apr 2010 22:45:46 +0000
changeset 3340 96dd168b080b
parent 3335 2520ee7a5484
child 3347 5d0ac8197eb7
permissions -rw-r--r--
fix all of what was committed before
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
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    32
/*
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    33
- (void)didRotate:(NSNotification *)notification {	
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    34
	if (orientation == UIDeviceOrientationLandscapeLeft) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    35
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    36
    if (orientation == UIDeviceOrientationLandscapeRight) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    37
    }
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    38
	if (orientation == UIDeviceOrientationPortrait) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    39
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    40
    if (orientation == UIDeviceOrientationPortrait) {
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    41
	}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    42
}
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    43
*/
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    44
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    45
-(void) viewDidLoad {
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    46
    /*
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    47
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];	
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    48
    [[NSNotificationCenter defaultCenter] addObserver:self
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    49
							selector:@selector(didRotate:)
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    50
							name:UIDeviceOrientationDidChangeNotification
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    51
							object:nil];
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    52
    */
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    53
    isPopoverVisible = NO;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    54
    self.view.alpha = 0;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    55
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    56
    // needed for rotation to work on os < 3.2
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    57
    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
    58
    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
    59
    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
    60
    
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    61
    dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    62
                                        interval:1000
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    63
                                          target:self
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    64
                                        selector:@selector(dimOverlay)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    65
                                        userInfo:nil
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    66
                                         repeats:YES];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    67
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    68
    // add timer too runloop, otherwise it doesn't work
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    69
    [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    70
    // listen for dismissal of the popover (see below)x
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    71
    [[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
    72
    // present the overlay after 2 seconds
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    73
    [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
    74
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    75
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    76
-(void) viewDidUnload {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    77
	[dimTimer invalidate];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    78
	self.dimTimer = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    79
    self.popoverController = nil;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    80
    self.popupMenu = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
    81
    [super viewDidUnload];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    82
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    83
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    84
-(void) dealloc {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    85
    [popupMenu release];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    86
    [popoverController release];
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    87
    // dimTimer is autoreleased
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    88
    [super dealloc];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    89
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    90
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    91
// 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
    92
-(void) showMenuAfterwards {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    93
    [[SDLUIKitDelegate sharedAppDelegate].uiwindow bringSubviewToFront:self.view];
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
	[UIView beginAnimations:@"showing overlay" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
    96
	[UIView setAnimationDuration:1];
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
	[UIView commitAnimations];
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
// 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
   102
-(IBAction) buttonReleased:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   103
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   104
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   105
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   106
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   107
// nice transition for dimming
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   108
-(void) dimOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   109
    [UIView beginAnimations:@"overlay dim" context:NULL];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   110
   	[UIView setAnimationDuration:0.6];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   111
    self.view.alpha = 0.2;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   112
	[UIView commitAnimations];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   113
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   114
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   115
// 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
   116
-(void) activateOverlay {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   117
    self.view.alpha = 1;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   118
    [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   119
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   120
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   121
// 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
   122
-(IBAction) buttonPressed:(id) sender {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   123
    [self activateOverlay];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   124
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   125
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   126
    }
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   127
    UIButton *theButton = (UIButton *)sender;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   128
    
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   129
    switch (theButton.tag) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   130
        case 0:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   131
            HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   132
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   133
        case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   134
            HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   135
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   136
        case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   137
            HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   138
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   139
        case 3:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   140
            HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   141
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   142
        case 4:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   143
            HW_shoot();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   144
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   145
        case 5:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   146
            HW_jump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   147
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   148
        case 6:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   149
            HW_backjump();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   150
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   151
        case 7:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   152
            HW_tab();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   153
            break;
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   154
        case 10:
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   155
            [self showPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   156
            break;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   157
        default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   158
            NSLog(@"Nope");
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   159
            break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   160
    }
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   161
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   162
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   163
// present a further check before closing game
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   164
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   165
	if ([actionSheet cancelButtonIndex] != buttonIndex)
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   166
	    HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   167
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   168
        HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   169
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   170
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   171
// 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
   172
// 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
   173
-(IBAction) showPopover{
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   174
    isPopoverVisible = YES;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   175
    Class popoverControllerClass = NSClassFromString(@"UIPopoverController");
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   176
    if (popoverControllerClass) {
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   177
#ifdef __IPHONE_3_2
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   178
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   179
        popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   180
        [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   181
        [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   182
        
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   183
        [popoverController presentPopoverFromRect:CGRectMake(960, 0, 220, 32)
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   184
                                           inView:self.view
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   185
                         permittedArrowDirections:UIPopoverArrowDirectionUp 
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   186
                                         animated:YES];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   187
#endif
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   188
    } else {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   189
        popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   190
        popupMenu.view.backgroundColor = [UIColor clearColor];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   191
        popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   192
        [self.view addSubview:popupMenu.view];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   193
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   194
        [UIView beginAnimations:@"showing popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   195
        [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   196
        popupMenu.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   197
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   198
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   199
    popupMenu.tableView.scrollEnabled = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   200
}
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
// on ipad just dismiss it, on iphone transtion on the right
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   203
-(void) dismissPopover {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   204
    if (YES == isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   205
        isPopoverVisible = NO;
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   206
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   207
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   208
#ifdef __IPHONE_3_2
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   209
            [popoverController dismissPopoverAnimated:YES];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   210
#endif
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   211
        } else {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   212
            [UIView beginAnimations:@"hiding popover" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   213
            [UIView setAnimationDuration:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   214
            popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   215
            [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   216
        
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   217
            [popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   218
            [popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   219
            
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   220
            //[dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
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
        [self buttonReleased:nil];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   223
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   224
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   225
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   226
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   227
#pragma mark -
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   228
#pragma mark Custom touch event handling
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   229
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   230
#define kMinimumPinchDelta      50
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   231
#define kMinimumGestureLength	10
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   232
#define kMaximumVariance        3
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   233
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   234
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   235
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   236
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   237
	int width = [[UIScreen mainScreen] bounds].size.width;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   238
    
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   239
    if (isPopoverVisible) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   240
        [self dismissPopover];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   241
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   242
        
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   243
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   244
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   245
			gestureStartPoint = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   246
			initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   247
			switch ([touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   248
				case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   249
					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
   250
					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   251
							      (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   252
					HW_click();
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
				case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   255
					HW_ammoMenu();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   256
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   257
				default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   258
					break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   259
			}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   260
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   261
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   262
			if (2 == [touch tapCount]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   263
				HW_zoomReset();
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
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   266
			// pinching
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   267
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   268
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   269
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   270
			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
   271
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   272
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   273
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   274
	}
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
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   277
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   278
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   279
	initialDistanceForPinching = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   280
	gestureStartPoint.x = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   281
	gestureStartPoint.y = 0;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   282
	HW_allKeysUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   283
}
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   284
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   285
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   286
	// 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
   287
	[self touchesEnded:touches withEvent:event];
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   290
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   291
	NSArray *twoTouches;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   292
	CGPoint currentPosition;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   293
	UITouch *touch = [touches anyObject];
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   294
	int width = [[UIScreen mainScreen] bounds].size.width;
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   295
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   296
	switch ([touches count]) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   297
		case 1:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   298
			currentPosition = [touch locationInView:self.view];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   299
			// panning
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   300
			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents: 3117
diff changeset
   301
							(int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
3117
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   302
			// remember that we have x and y inverted
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   303
			/* temporarily disabling hog movements for camera panning testing
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   304
			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   305
			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   306
			CGFloat deltaX = fabsf(vertDiff);
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   307
			CGFloat deltaY = fabsf(horizDiff);
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 (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   310
				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
   311
				if (horizDiff > 0) HW_walkLeft();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   312
				else HW_walkRight();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   313
			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   314
				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
   315
				if (vertDiff < 0) HW_aimUp();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   316
				else HW_aimDown();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   317
			}
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
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   320
		case 2:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   321
			twoTouches = [touches allObjects];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   322
			UITouch *first = [twoTouches objectAtIndex:0];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   323
			UITouch *second = [twoTouches objectAtIndex:1];
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   324
			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
   325
			
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   326
			if (0 == initialDistanceForPinching) 
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   327
				initialDistanceForPinching = currentDistanceOfPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   328
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   329
			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   330
				HW_zoomOut();
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   331
			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   332
				HW_zoomIn();
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
			currentDistanceOfPinching = initialDistanceForPinching;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   335
			break;
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   336
		default:
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   337
			break;
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
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   341
f3e363a9b7db complete previous commit (which broken my local copy as well)
koda
parents:
diff changeset
   342
@end