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