cocoaTouch/overlayViewController.m
changeset 3015 20a9c8160e82
parent 3006 da6023c2745b
child 3025 01682ec58eb0
equal deleted inserted replaced
3013:dfc1f16aeb53 3015:20a9c8160e82
     8 
     8 
     9 #import "overlayViewController.h"
     9 #import "overlayViewController.h"
    10 #import "PascalImports.h"
    10 #import "PascalImports.h"
    11 
    11 
    12 @implementation overlayViewController
    12 @implementation overlayViewController
       
    13 @synthesize dimTimer;
       
    14 
    13 
    15 
    14 -(void) didReceiveMemoryWarning {
    16 -(void) didReceiveMemoryWarning {
    15 	// Releases the view if it doesn't have a superview.
    17 	// Releases the view if it doesn't have a superview.
    16     [super didReceiveMemoryWarning];
    18     [super didReceiveMemoryWarning];
    17 	
    19 	
    18 	// Release any cached data, images, etc that aren't in use.
    20 	// Release any cached data, images, etc that aren't in use.
    19 }
    21 }
    20 
    22 
       
    23 -(void) viewDidLoad {
       
    24     dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
       
    25                                         interval:1000
       
    26                                           target:self
       
    27                                         selector:@selector(dimOverlay)
       
    28                                         userInfo:nil
       
    29                                          repeats:YES];
       
    30     
       
    31     [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
       
    32 }
       
    33 
    21 -(void) viewDidUnload {
    34 -(void) viewDidUnload {
    22 	// Release any retained subviews of the main view.
    35 	[dimTimer invalidate];
    23 	// e.g. self.myOutlet = nil;
       
    24 }
    36 }
    25 
    37 
    26 -(void) dealloc {
    38 -(void) dealloc {
       
    39     [dimTimer release];
    27     [super dealloc];
    40     [super dealloc];
    28 }
    41 }
    29 
    42 
    30 
    43 
    31 // dim the overlay when there's no more input for a certain amount of time
    44 // dim the overlay when there's no more input for a certain amount of time
    32 -(IBAction) buttonReleased:(id) sender {
    45 -(IBAction) buttonReleased:(id) sender {
    33 	HW_allKeysUp();
    46 	HW_allKeysUp();
    34     [NSTimer scheduledTimerWithTimeInterval:2.8 target:self selector:@selector(dimOverlay) userInfo:nil repeats:NO];
    47     [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:2.7]];
    35 }
    48 }
    36 
    49 
       
    50 // nice transition for dimming
    37 -(void) dimOverlay {
    51 -(void) dimOverlay {
    38     [UIView beginAnimations:@"overlay dim" context:NULL];
    52     [UIView beginAnimations:@"overlay dim" context:NULL];
    39    	[UIView setAnimationDuration:0.6];
    53    	[UIView setAnimationDuration:0.6];
    40     self.view.alpha = 0.2;
    54     self.view.alpha = 0.2;
    41 	[UIView commitAnimations];
    55 	[UIView commitAnimations];
    42 }
    56 }
    43 
    57 
       
    58 // set the overlay visible and put off the timer for enough time
    44 -(void) activateOverlay {
    59 -(void) activateOverlay {
    45     self.view.alpha = 1;
    60     self.view.alpha = 1;
       
    61     [dimTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1000]];
    46 }
    62 }
    47 
    63 
    48 // issue certain action based on the tag of the button 
    64 // issue certain action based on the tag of the button 
    49 -(IBAction) buttonPressed:(id) sender {
    65 -(IBAction) buttonPressed:(id) sender {
    50     [self activateOverlay];
    66     [self activateOverlay];
    51     
    67 
    52     UIButton *theButton = (UIButton*)sender;
    68     UIButton *theButton = (UIButton*)sender;
    53     switch (theButton.tag) {
    69     switch (theButton.tag) {
    54         case 0:
    70         case 0:
    55            	HW_walkLeft();
    71            	HW_walkLeft();
    56             break;
    72             break;
    65             break;
    81             break;
    66         case 4:
    82         case 4:
    67             HW_shoot();
    83             HW_shoot();
    68             break;
    84             break;
    69         case 5:
    85         case 5:
    70             HW_pause();
    86             HW_jump();
    71             break;
    87             break;
    72         case 6:
    88         case 6:
    73             HW_chat();
    89             HW_backjump();
    74             break;
    90             break;
    75         default:
    91         default:
       
    92             // HW_chat() HW_tab() HW_pause()
    76             break;
    93             break;
    77     }
    94     }
    78 }
    95 }
    79 
    96 
    80 
    97