project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3629 86212d2b116a
parent 3628 2b4d878ba565
child 3635 38d3e31556d3
equal deleted inserted replaced
3628:2b4d878ba565 3629:86212d2b116a
    18 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
    18 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
    19 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    19 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    20 
    20 
    21 
    21 
    22 @implementation OverlayViewController
    22 @implementation OverlayViewController
    23 @synthesize popoverController, popupMenu, writeChatTextField, spinningWheel;
    23 @synthesize popoverController, popupMenu;
    24 
    24 
    25 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    25 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    26     return rotationManager(interfaceOrientation);
    26     return rotationManager(interfaceOrientation);
    27 }
    27 }
    28 
    28 
   105 
   105 
   106 #pragma mark -
   106 #pragma mark -
   107 #pragma mark View Management
   107 #pragma mark View Management
   108 -(void) viewDidLoad {
   108 -(void) viewDidLoad {
   109     isPopoverVisible = NO;
   109     isPopoverVisible = NO;
   110     singleton = self.spinningWheel;
       
   111     canDim = NO;
       
   112     self.view.alpha = 0;
   110     self.view.alpha = 0;
   113     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
   111     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
   114     
   112     
   115     // set initial orientation
   113     // set initial orientation
   116     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   114     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   150     [UIView commitAnimations];
   148     [UIView commitAnimations];
   151 }
   149 }
   152 
   150 
   153 /* these are causing problems at reloading so let's remove 'em
   151 /* these are causing problems at reloading so let's remove 'em
   154 -(void) viewDidUnload {
   152 -(void) viewDidUnload {
   155     [popoverController dismissPopoverAnimated:NO];
       
   156     [dimTimer invalidate];
   153     [dimTimer invalidate];
   157     self.writeChatTextField = nil;
       
   158     self.popoverController = nil;
   154     self.popoverController = nil;
   159     self.popupMenu = nil;
   155     self.popupMenu = nil;
   160     self.spinningWheel = nil;
       
   161     [super viewDidUnload];
   156     [super viewDidUnload];
   162     MSG_DIDUNLOAD();
   157     MSG_DIDUNLOAD();
   163 }
   158 }
   164 
   159 
   165 -(void) didReceiveMemoryWarning {
   160 -(void) didReceiveMemoryWarning {
   171     MSG_MEMCLEAN();
   166     MSG_MEMCLEAN();
   172 }
   167 }
   173 */
   168 */
   174 
   169 
   175 -(void) dealloc {
   170 -(void) dealloc {
   176     [writeChatTextField release];
       
   177     [popupMenu release];
   171     [popupMenu release];
   178     [popoverController release];
   172     [popoverController release];
   179     // dimTimer is autoreleased
   173     // dimTimer is autoreleased
   180     [spinningWheel release];
       
   181     [super dealloc];
   174     [super dealloc];
   182 }
   175 }
   183 
   176 
   184 #pragma mark -
   177 #pragma mark -
   185 #pragma mark Overlay actions and members
   178 #pragma mark Overlay actions and members
   186 // nice transition for dimming, should be called only by the timer himself
   179 // nice transition for dimming, should be called only by the timer himself
   187 -(void) dimOverlay {
   180 -(void) dimOverlay {
   188     if (canDim) {
   181     if (isGameRunning) {
   189         [UIView beginAnimations:@"overlay dim" context:NULL];
   182         [UIView beginAnimations:@"overlay dim" context:NULL];
   190         [UIView setAnimationDuration:0.6];
   183         [UIView setAnimationDuration:0.6];
   191         self.view.alpha = 0.2;
   184         self.view.alpha = 0.2;
   192         [UIView commitAnimations];
   185         [UIView commitAnimations];
   193     }
   186     }
   199     [dimTimer setFireDate:HIDING_TIME_NEVER];
   192     [dimTimer setFireDate:HIDING_TIME_NEVER];
   200 }
   193 }
   201 
   194 
   202 // dim the overlay when there's no more input for a certain amount of time
   195 // dim the overlay when there's no more input for a certain amount of time
   203 -(IBAction) buttonReleased:(id) sender {
   196 -(IBAction) buttonReleased:(id) sender {
       
   197     if (!isGameRunning)
       
   198         return;
       
   199     
   204     UIButton *theButton = (UIButton *)sender;
   200     UIButton *theButton = (UIButton *)sender;
   205     
   201     
   206     switch (theButton.tag) {
   202     switch (theButton.tag) {
   207         case 0:
   203         case 0:
   208         case 1:
   204         case 1:
   227 -(IBAction) buttonPressed:(id) sender {
   223 -(IBAction) buttonPressed:(id) sender {
   228     [self activateOverlay];
   224     [self activateOverlay];
   229     if (isPopoverVisible) {
   225     if (isPopoverVisible) {
   230         [self dismissPopover];
   226         [self dismissPopover];
   231     }
   227     }
       
   228     
       
   229     if (!isGameRunning)
       
   230         return;
       
   231     
   232     UIButton *theButton = (UIButton *)sender;
   232     UIButton *theButton = (UIButton *)sender;
   233     
   233     
   234     switch (theButton.tag) {
   234     switch (theButton.tag) {
   235         case 0:
   235         case 0:
   236             HW_walkLeft();
   236             HW_walkLeft();
   331 
   331 
   332 -(void) textFieldDoneEditing:(id) sender{
   332 -(void) textFieldDoneEditing:(id) sender{
   333     [sender resignFirstResponder];
   333     [sender resignFirstResponder];
   334 }
   334 }
   335 
   335 
   336 // this function is called by pascal FinishProgress and removes the spinning wheel when loading is done
       
   337 void spinningWheelDone (void) {
       
   338     [singleton stopAnimating];
       
   339     singleton = nil;
       
   340     canDim = YES;
       
   341 }
       
   342 
   336 
   343 #pragma mark -
   337 #pragma mark -
   344 #pragma mark Custom touch event handling
   338 #pragma mark Custom touch event handling
   345 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   339 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   346     NSArray *twoTouches;
   340     NSArray *twoTouches;
   349     CGPoint currentPosition = [touch locationInView:self.view];
   343     CGPoint currentPosition = [touch locationInView:self.view];
   350     
   344     
   351     if (isPopoverVisible) {
   345     if (isPopoverVisible) {
   352         [self dismissPopover];
   346         [self dismissPopover];
   353     }
   347     }
       
   348     /*
   354     if (writeChatTextField) {
   349     if (writeChatTextField) {
   355         [self.writeChatTextField resignFirstResponder];
   350         [self.writeChatTextField resignFirstResponder];
   356         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   351         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   357     }
   352     }
   358     
   353     */
   359     if (currentPosition.y < screen.size.width - 120) {
   354 
       
   355     if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) {
   360         switch ([touches count]) {
   356         switch ([touches count]) {
   361             case 1:
   357             case 1:
   362                 DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
   358                 DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
   363                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   359                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   364                 if (2 == [touch tapCount])
   360                 if (2 == [touch tapCount])
   426         default:
   422         default:
   427             break;
   423             break;
   428     }
   424     }
   429 }
   425 }
   430 
   426 
       
   427 // called from AddProgress and FinishProgress (respectively)
       
   428 void startSpinning() {
       
   429     isGameRunning = NO;
       
   430     CGRect screen = [[UIScreen mainScreen] bounds];
       
   431     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   432     indicator.tag = 987654;
       
   433     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
       
   434     indicator.hidesWhenStopped = YES;
       
   435     [indicator startAnimating];
       
   436     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] addSubview:indicator];
       
   437     [indicator release];
       
   438 }
       
   439 
       
   440 void stopSpinning() {
       
   441     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] viewWithTag:987654];
       
   442     [indicator stopAnimating];
       
   443     isGameRunning = YES;
       
   444 }
   431 
   445 
   432 @end
   446 @end