project_files/HedgewarsMobile/Classes/ObjcExports.m
changeset 4028 eb371ada631d
child 4034 634a8c8682de
equal deleted inserted replaced
4027:6e2bff0c173c 4028:eb371ada631d
       
     1 /*
       
     2  * Hedgewars-iOS, a Hedgewars port for iOS devices
       
     3  * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
       
    17  *
       
    18  * File created on 30/10/2010.
       
    19  */
       
    20 
       
    21 
       
    22 #import "ObjcExports.h"
       
    23 
       
    24 #pragma mark -
       
    25 #pragma mark internal variables
       
    26 // actual game started (controls should be enabled)
       
    27 BOOL gameRunning;
       
    28 // black screen present
       
    29 BOOL savedGame;
       
    30 // cache the grenade time
       
    31 NSInteger grenadeTime;
       
    32 
       
    33 #pragma mark -
       
    34 #pragma mark functions called like oop
       
    35 void objcExportsInit() {
       
    36         gameRunning = NO;
       
    37         savedGame = NO;
       
    38         grenadeTime = 2;
       
    39 }
       
    40 
       
    41 BOOL inline isGameRunning() {
       
    42     return gameRunning;
       
    43 }
       
    44 
       
    45 void inline setGameRunning(BOOL value) {
       
    46     gameRunning = value;
       
    47 }
       
    48 
       
    49 NSInteger cachedGrenadeTime() {
       
    50     return grenadeTime;
       
    51 }
       
    52 
       
    53 void inline setGrenadeTime(NSInteger value) {
       
    54     grenadeTime = value;
       
    55 }
       
    56 
       
    57 #pragma mark -
       
    58 #pragma mark functions called by pascal code
       
    59 // called by uStore from AddProgress
       
    60 void startSpinning() {
       
    61     gameRunning = NO;
       
    62     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
    63     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
    64     indicator.tag = ACTIVITYINDICATOR_TAG;
       
    65     int offset;
       
    66     if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
       
    67         offset = -120;
       
    68     else
       
    69         offset = 120;
       
    70     if (IS_DUALHEAD())
       
    71         indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset);
       
    72     else
       
    73         indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2);
       
    74     indicator.hidesWhenStopped = YES;
       
    75     [indicator startAnimating];
       
    76     [theWindow addSubview:indicator];
       
    77     [indicator release];
       
    78 }
       
    79 
       
    80 // called by uStore from FinishProgress and by OverlayViewController by replayBegan
       
    81 void stopSpinning() {
       
    82     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
    83     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG];
       
    84     [indicator stopAnimating];
       
    85     HW_zoomSet(1.7);
       
    86     if (savedGame == NO)
       
    87         gameRunning = YES;
       
    88 }
       
    89 
       
    90 // called by CCHandlers from chNextTurn
       
    91 void clearView() {
       
    92     UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
       
    93     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
       
    94     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
       
    95 
       
    96     [UIView beginAnimations:@"remove button" context:NULL];
       
    97     [UIView setAnimationDuration:ANIMATION_DURATION];
       
    98     theButton.alpha = 0;
       
    99     theSegment.alpha = 0;
       
   100     [UIView commitAnimations];
       
   101 
       
   102     if (theButton)
       
   103         [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION];
       
   104     if (theSegment)
       
   105         [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION];
       
   106 
       
   107     grenadeTime = 2;
       
   108 }
       
   109 
       
   110 // called by hwengine
       
   111 void replayBegan() {
       
   112     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   113     UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
       
   114     blackView.backgroundColor = [UIColor blackColor];
       
   115     blackView.alpha = 0.6;
       
   116     blackView.tag = REPLAYBLACKVIEW_TAG;
       
   117     blackView.exclusiveTouch = NO;
       
   118     blackView.multipleTouchEnabled = NO;
       
   119     blackView.userInteractionEnabled = NO;
       
   120 
       
   121     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   122     indicator.center = theWindow.center;
       
   123     [indicator startAnimating];
       
   124     [blackView addSubview:indicator];
       
   125     [indicator release];
       
   126     [theWindow addSubview:blackView];
       
   127     [blackView release];
       
   128 
       
   129     savedGame = YES;
       
   130     stopSpinning();
       
   131 }
       
   132 
       
   133 // called by uGame
       
   134 void replayFinished() {
       
   135     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   136     UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG];
       
   137 
       
   138     [UIView beginAnimations:@"removing black" context:NULL];
       
   139     [UIView setAnimationDuration:1];
       
   140     blackView.alpha = 0;
       
   141     [UIView commitAnimations];
       
   142     [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1];
       
   143 
       
   144     gameRunning = YES;
       
   145     savedGame = NO;
       
   146 }