project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 5174 f5294509783e
parent 5166 d1eb1560b4d5
child 5175 a3da220dbb3f
equal deleted inserted replaced
5173:4056310a161a 5174:f5294509783e
    36 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    36 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    37 
    37 
    38 #define removeInputWidget() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; \
    38 #define removeInputWidget() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; \
    39                             [[self.view viewWithTag:GRENADE_TAG] removeFromSuperview];
    39                             [[self.view viewWithTag:GRENADE_TAG] removeFromSuperview];
    40 
    40 
       
    41 
    41 @implementation OverlayViewController
    42 @implementation OverlayViewController
    42 @synthesize popoverController, popupMenu, helpPage, amvc, useClassicMenu, initialScreenCount, initialOrientation;
    43 @synthesize popoverController, popupMenu, helpPage, amvc, useClassicMenu, initialScreenCount, initialOrientation, lowerIndicator, savesIndicator;
    43 
    44 
    44 #pragma mark -
    45 #pragma mark -
    45 #pragma mark rotation
    46 #pragma mark rotation
    46 
    47 
    47 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    48 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    88 
    89 
    89 #pragma mark -
    90 #pragma mark -
    90 #pragma mark View Management
    91 #pragma mark View Management
    91 -(id) initWithCoder:(NSCoder *)aDecoder {
    92 -(id) initWithCoder:(NSCoder *)aDecoder {
    92     if ((self = [super initWithCoder:aDecoder])) {
    93     if ((self = [super initWithCoder:aDecoder])) {
    93         objcExportsInit();
       
    94         isAttacking = NO;
    94         isAttacking = NO;
    95         isPopoverVisible = NO;
    95         isPopoverVisible = NO;
    96         initialScreenCount = (IS_DUALHEAD() ? 2 : 1);
    96         initialScreenCount = (IS_DUALHEAD() ? 2 : 1);
    97         initialOrientation = 0;
    97         initialOrientation = 0;
       
    98         lowerIndicator = nil;
       
    99         savesIndicator = nil;
    98     }
   100     }
    99     return self;
   101     return self;
   100 }
   102 }
   101 
   103 
   102 -(void) viewDidLoad {
   104 -(void) viewDidLoad {
   171     dimTimer = nil;
   173     dimTimer = nil;
   172     self.helpPage = nil;
   174     self.helpPage = nil;
   173     [self dismissPopover];
   175     [self dismissPopover];
   174     self.popoverController = nil;
   176     self.popoverController = nil;
   175     self.amvc = nil;
   177     self.amvc = nil;
       
   178     self.lowerIndicator = nil;
       
   179     self.savesIndicator = nil;
   176     MSG_DIDUNLOAD();
   180     MSG_DIDUNLOAD();
   177     [super viewDidUnload];
   181     [super viewDidUnload];
   178 }
   182 }
   179 
   183 
   180 -(void) didReceiveMemoryWarning {
   184 -(void) didReceiveMemoryWarning {
   182         self.popupMenu = nil;
   186         self.popupMenu = nil;
   183     if (self.helpPage.view.superview == nil)
   187     if (self.helpPage.view.superview == nil)
   184         self.helpPage = nil;
   188         self.helpPage = nil;
   185     if (self.amvc.view.superview == nil)
   189     if (self.amvc.view.superview == nil)
   186         self.amvc = nil;
   190         self.amvc = nil;
       
   191     if (self.lowerIndicator.superview == nil)
       
   192         self.lowerIndicator = nil;
       
   193     if (self.savesIndicator.superview == nil)
       
   194         self.savesIndicator = nil;
   187     if (IS_IPAD())
   195     if (IS_IPAD())
   188         if (((UIPopoverController *)self.popoverController).contentViewController.view.superview == nil)
   196         if (((UIPopoverController *)self.popoverController).contentViewController.view.superview == nil)
   189             self.popoverController = nil;
   197             self.popoverController = nil;
   190 
   198 
   191     MSG_MEMCLEAN();
   199     MSG_MEMCLEAN();
   195 -(void) dealloc {
   203 -(void) dealloc {
   196     [popupMenu release];
   204     [popupMenu release];
   197     [helpPage release];
   205     [helpPage release];
   198     [popoverController release];
   206     [popoverController release];
   199     [amvc release];
   207     [amvc release];
       
   208     [lowerIndicator release];
       
   209     [savesIndicator release];
   200     // dimTimer is autoreleased
   210     // dimTimer is autoreleased
   201     [super dealloc];
   211     [super dealloc];
   202 }
   212 }
   203 
   213 
   204 -(void) numberOfScreensIncreased {
   214 -(void) numberOfScreensIncreased {
   341             removeInputWidget();
   351             removeInputWidget();
   342             
   352             
   343             if (IS_DUALHEAD() || self.useClassicMenu == NO) {
   353             if (IS_DUALHEAD() || self.useClassicMenu == NO) {
   344                 if (self.amvc == nil)
   354                 if (self.amvc == nil)
   345                     self.amvc = [[AmmoMenuViewController alloc] init];
   355                     self.amvc = [[AmmoMenuViewController alloc] init];
   346                 setAmmoMenuInstance(amvc);
   356 
   347                 if (self.amvc.isVisible) {
   357                 if (self.amvc.isVisible) {
   348                     doDim();
   358                     doDim();
   349                     [self.amvc disappear];
   359                     [self.amvc disappear];
   350                 } else {
   360                 } else {
   351                     if (HW_isAmmoMenuNotAllowed() == NO) {
   361                     if (HW_isAmmoMenuNotAllowed() == NO) {
   352                         doNotDim();
   362                         doNotDim();
   353                         [self.amvc appearInView:self.view];
   363                         [self.amvc appearInView:self.view];
   354                     }
   364                     }
   355                 }
   365                 }
   356             } else {
   366             } else
   357                 setAmmoMenuInstance(nil);
       
   358                 HW_ammoMenu();
   367                 HW_ammoMenu();
   359             }
       
   360             break;
   368             break;
   361         default:
   369         default:
   362             DLog(@"Nope");
   370             DLog(@"Nope");
   363             break;
   371             break;
   364     }
   372     }
   504             break;
   512             break;
   505     }
   513     }
   506 }
   514 }
   507 
   515 
   508 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   516 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   509     CGRect screen = [[UIScreen mainScreen] bounds];
       
   510     NSSet *allTouches = [event allTouches];
   517     NSSet *allTouches = [event allTouches];
   511     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
       
   512 
       
   513     if ([self shouldIgnoreTouch:allTouches] == YES)
   518     if ([self shouldIgnoreTouch:allTouches] == YES)
   514         return;
   519         return;
       
   520 
       
   521     CGRect screen = [[UIScreen mainScreen] bounds];
       
   522     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   515 
   523 
   516     switch ([allTouches count]) {
   524     switch ([allTouches count]) {
   517         case 1:
   525         case 1:
   518             // if we're in the menu we just click in the point
   526             // if we're in the menu we just click in the point
   519             if (HW_isAmmoMenuOpen()) {
   527             if (HW_isAmmoMenuOpen()) {
   595 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   603 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   596     [self touchesEnded:touches withEvent:event];
   604     [self touchesEnded:touches withEvent:event];
   597 }
   605 }
   598 
   606 
   599 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   607 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
       
   608     NSSet *allTouches = [event allTouches];
       
   609     if ([self shouldIgnoreTouch:allTouches] == YES)
       
   610         return;
       
   611 
   600     CGRect screen = [[UIScreen mainScreen] bounds];
   612     CGRect screen = [[UIScreen mainScreen] bounds];
   601     NSSet *allTouches = [event allTouches];
       
   602     int x, y, dx, dy;
   613     int x, y, dx, dy;
   603     UITouch *touch, *first, *second;
   614     UITouch *touch, *first, *second;
   604 
       
   605     if ([self shouldIgnoreTouch:allTouches] == YES)
       
   606         return;
       
   607 
   615 
   608     switch ([allTouches count]) {
   616     switch ([allTouches count]) {
   609         case 1:
   617         case 1:
   610             touch = [[allTouches allObjects] objectAtIndex:0];
   618             touch = [[allTouches allObjects] objectAtIndex:0];
   611             CGPoint currentPosition = [touch locationInView:self.view];
   619             CGPoint currentPosition = [touch locationInView:self.view];