diff -r 6e2bff0c173c -r eb371ada631d project_files/HedgewarsMobile/Classes/OverlayViewController.m --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Oct 31 00:06:46 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Oct 31 01:49:20 2010 +0200 @@ -20,7 +20,6 @@ #import "OverlayViewController.h" -#import "SDL_uikitappdelegate.h" #import "InGameMenuViewController.h" #import "HelpPageViewController.h" #import "AmmoMenuViewController.h" @@ -29,17 +28,13 @@ #import "CGPointUtils.h" #import "SDL_config_iphoneos.h" #import "SDL_mouse.h" +#import "ObjcExports.h" #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] #define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] #define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT] #define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] -#define CONFIRMATION_TAG 5959 -#define GRENADE_TAG 9595 -#define REPLAYBLACKVIEW_TAG 9955 -#define ACTIVITYINDICATOR_TAG 987654 -#define ANIMATION_DURATION 0.25 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; @implementation OverlayViewController @@ -112,10 +107,7 @@ #pragma mark View Management -(id) initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { - isGameRunning = NO; - isReplay = NO; - cachedGrenadeTime = 2; - + objcExportsInit(); isAttacking = NO; wasVisible = NO; isPopoverVisible = NO; // it is called "popover" even on the iphone @@ -288,7 +280,7 @@ #pragma mark overlay user interaction // nice transition for dimming, should be called only by the timer himself -(void) dimOverlay { - if (isGameRunning) { + if (isGameRunning()) { [UIView beginAnimations:@"overlay dim" context:NULL]; [UIView setAnimationDuration:0.6]; self.view.alpha = 0.2; @@ -304,7 +296,7 @@ // dim the overlay when there's no more input for a certain amount of time -(IBAction) buttonReleased:(id) sender { - if (isGameRunning == NO) + if (isGameRunning() == NO) return; UIButton *theButton = (UIButton *)sender; @@ -337,7 +329,7 @@ -(IBAction) buttonPressed:(id) sender { [self activateOverlay]; - if (isGameRunning == NO) + if (isGameRunning() == NO) return; if (isPopoverVisible) @@ -422,9 +414,9 @@ -(void) setGrenadeTime:(id) sender { UISegmentedControl *theSegment = (UISegmentedControl *)sender; - if (cachedGrenadeTime != theSegment.selectedSegmentIndex) { + if (cachedGrenadeTime() != theSegment.selectedSegmentIndex) { HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); - cachedGrenadeTime = theSegment.selectedSegmentIndex; + setGrenadeTime(theSegment.selectedSegmentIndex); } } @@ -490,7 +482,7 @@ NSSet *allTouches = [event allTouches]; UITouch *first, *second; - if (isGameRunning == NO) + if (isGameRunning() == NO) return; // hide in-game menu @@ -529,7 +521,7 @@ NSSet *allTouches = [event allTouches]; CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; - if (isGameRunning == NO) + if (isGameRunning() == NO) return; switch ([allTouches count]) { @@ -582,7 +574,7 @@ [grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); - grenadeTime.selectedSegmentIndex = cachedGrenadeTime; + grenadeTime.selectedSegmentIndex = cachedGrenadeTime(); grenadeTime.tag = GRENADE_TAG; [self.view addSubview:grenadeTime]; [grenadeTime release]; @@ -621,7 +613,7 @@ int x, y, dx, dy; UITouch *touch, *first, *second; - if (isGameRunning == NO) + if (isGameRunning() == NO) return; switch ([allTouches count]) { @@ -674,97 +666,4 @@ } } -#pragma mark - -#pragma mark Functions called by pascal code -void inline setGameRunning(BOOL value) { - isGameRunning = value; -} - -// called by uStore from AddProgress -void startSpinning() { - setGameRunning(NO); - UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; - UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; - indicator.tag = ACTIVITYINDICATOR_TAG; - int offset; - if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) - offset = -120; - else - offset = 120; - if (IS_DUALHEAD()) - indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset); - else - indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2); - indicator.hidesWhenStopped = YES; - [indicator startAnimating]; - [theWindow addSubview:indicator]; - [indicator release]; -} - -// called by uStore from FinishProgress and by OverlayViewController by replayBegan -void stopSpinning() { - UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; - UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG]; - [indicator stopAnimating]; - HW_zoomSet(1.7); - if (isReplay == NO) - setGameRunning(YES); -} - -// called by CCHandlers from chNextTurn -void clearView() { - UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]; - UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; - UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; - - [UIView beginAnimations:@"remove button" context:NULL]; - [UIView setAnimationDuration:ANIMATION_DURATION]; - theButton.alpha = 0; - theSegment.alpha = 0; - [UIView commitAnimations]; - - if (theButton) - [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION]; - if (theSegment) - [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION]; - - cachedGrenadeTime = 2; -} - -// called by hwengine -void replayBegan() { - UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; - UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame]; - blackView.backgroundColor = [UIColor blackColor]; - blackView.alpha = 0.6; - blackView.tag = REPLAYBLACKVIEW_TAG; - blackView.exclusiveTouch = NO; - blackView.multipleTouchEnabled = NO; - blackView.userInteractionEnabled = NO; - UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; - indicator.center = theWindow.center; - [indicator startAnimating]; - [blackView addSubview:indicator]; - [indicator release]; - [theWindow addSubview:blackView]; - [blackView release]; - isReplay = YES; - stopSpinning(); -} - -// called by uGame -void replayFinished() { - UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; - UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG]; - - [UIView beginAnimations:@"removing black" context:NULL]; - [UIView setAnimationDuration:1]; - blackView.alpha = 0; - [UIView commitAnimations]; - [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1]; - - setGameRunning(YES); - isReplay = NO; -} - @end