project_files/HedgewarsMobile/Classes/ObjcExports.m
author koda
Sun, 31 Oct 2010 04:16:10 +0100
changeset 4032 4aeab704d006
parent 4028 eb371ada631d
child 4034 634a8c8682de
permissions -rw-r--r--
can move the new ammo menu freely
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() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    36
        gameRunning = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    37
        savedGame = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    38
        grenadeTime = 2;
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
// called by uStore from AddProgress
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    60
void startSpinning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    61
    gameRunning = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    62
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    63
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    64
    indicator.tag = ACTIVITYINDICATOR_TAG;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    65
    int offset;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    66
    if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    67
        offset = -120;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    68
    else
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    69
        offset = 120;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    70
    if (IS_DUALHEAD())
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    71
        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
    72
    else
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    73
        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
    74
    indicator.hidesWhenStopped = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    75
    [indicator startAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    76
    [theWindow addSubview:indicator];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    77
    [indicator release];
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
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    80
// called by uStore from FinishProgress and by OverlayViewController by replayBegan
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    81
void stopSpinning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    82
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    83
    UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    84
    [indicator stopAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    85
    HW_zoomSet(1.7);
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    86
    if (savedGame == NO)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    87
        gameRunning = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    88
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    89
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    90
// called by CCHandlers from chNextTurn
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    91
void clearView() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    92
    UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    93
    UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    94
    UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    95
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    96
    [UIView beginAnimations:@"remove button" context:NULL];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    97
    [UIView setAnimationDuration:ANIMATION_DURATION];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    98
    theButton.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    99
    theSegment.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   100
    [UIView commitAnimations];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   101
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   102
    if (theButton)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   103
        [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   104
    if (theSegment)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   105
        [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION];
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
    grenadeTime = 2;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   108
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   109
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   110
// called by hwengine
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   111
void replayBegan() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   112
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   113
    UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   114
    blackView.backgroundColor = [UIColor blackColor];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   115
    blackView.alpha = 0.6;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   116
    blackView.tag = REPLAYBLACKVIEW_TAG;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   117
    blackView.exclusiveTouch = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   118
    blackView.multipleTouchEnabled = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   119
    blackView.userInteractionEnabled = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   120
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   121
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   122
    indicator.center = theWindow.center;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   123
    [indicator startAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   124
    [blackView addSubview:indicator];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   125
    [indicator release];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   126
    [theWindow addSubview:blackView];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   127
    [blackView release];
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
    savedGame = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   130
    stopSpinning();
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   131
}
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
// called by uGame
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   134
void replayFinished() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   135
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   136
    UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   137
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   138
    [UIView beginAnimations:@"removing black" context:NULL];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   139
    [UIView setAnimationDuration:1];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   140
    blackView.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   141
    [UIView commitAnimations];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   142
    [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   143
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   144
    gameRunning = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   145
    savedGame = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   146
}