project_files/HedgewarsMobile/Classes/ObjcExports.m
author koda
Sun, 28 Nov 2010 23:49:09 +0100
changeset 4362 8dae325dc625
parent 4034 634a8c8682de
child 4461 2f4f5d649bcd
permissions -rw-r--r--
added missing graphics and fixed some glitches/crashes/bugs
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"
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    23
#import "AmmoMenuViewController.h"
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    24
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    25
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    26
#pragma mark internal variables
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    27
// actual game started (controls should be enabled)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    28
BOOL gameRunning;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    29
// black screen present
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    30
BOOL savedGame;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    31
// cache the grenade time
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    32
NSInteger grenadeTime;
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    33
// the reference to the newMenu instance
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    34
AmmoMenuViewController *amvc_instance;
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    35
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    36
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    37
#pragma mark functions called like oop
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    38
void objcExportsInit() {
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    39
    gameRunning = NO;
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    40
    savedGame = NO;
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    41
    grenadeTime = 2;
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    42
}
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
BOOL inline isGameRunning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    45
    return gameRunning;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    46
}
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
void inline setGameRunning(BOOL value) {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    49
    gameRunning = value;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    50
}
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
NSInteger cachedGrenadeTime() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    53
    return grenadeTime;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    54
}
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
void inline setGrenadeTime(NSInteger value) {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    57
    grenadeTime = value;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    58
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    59
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    60
void inline setAmmoMenuInstance(AmmoMenuViewController *instance) {
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    61
    amvc_instance = instance;
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    62
}
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    63
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    64
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    65
#pragma mark functions called by pascal code
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    66
void startSpinning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    67
    gameRunning = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    68
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    69
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    70
    indicator.tag = ACTIVITYINDICATOR_TAG;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    71
    int offset;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    72
    if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    73
        offset = -120;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    74
    else
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    75
        offset = 120;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    76
    if (IS_DUALHEAD())
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    77
        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
    78
    else
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    79
        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
    80
    indicator.hidesWhenStopped = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    81
    [indicator startAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    82
    [theWindow addSubview:indicator];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    83
    [indicator release];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    84
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    85
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    86
void stopSpinning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    87
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    88
    UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    89
    [indicator stopAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    90
    HW_zoomSet(1.7);
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    91
    if (savedGame == NO)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    92
        gameRunning = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    93
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    94
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    95
void clearView() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    96
    UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    97
    UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    98
    UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    99
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   100
    [UIView beginAnimations:@"remove button" context:NULL];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   101
    [UIView setAnimationDuration:ANIMATION_DURATION];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   102
    theButton.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   103
    theSegment.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   104
    [UIView commitAnimations];
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
    if (theButton)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   107
        [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   108
    if (theSegment)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   109
        [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   110
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   111
    grenadeTime = 2;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   112
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   113
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   114
void replayBegan() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   115
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   116
    UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   117
    blackView.backgroundColor = [UIColor blackColor];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   118
    blackView.alpha = 0.6;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   119
    blackView.tag = REPLAYBLACKVIEW_TAG;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   120
    blackView.exclusiveTouch = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   121
    blackView.multipleTouchEnabled = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   122
    blackView.userInteractionEnabled = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   123
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   124
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   125
    indicator.center = theWindow.center;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   126
    [indicator startAnimating];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   127
    [blackView addSubview:indicator];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   128
    [indicator release];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   129
    [theWindow addSubview:blackView];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   130
    [blackView release];
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
    savedGame = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   133
    stopSpinning();
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   134
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   135
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   136
void replayFinished() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   137
    UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   138
    UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   139
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   140
    [UIView beginAnimations:@"removing black" context:NULL];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   141
    [UIView setAnimationDuration:1];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   142
    blackView.alpha = 0;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   143
    [UIView commitAnimations];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   144
    [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1];
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   145
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   146
    gameRunning = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   147
    savedGame = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   148
}
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   149
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   150
void updateVisualsNewTurn(void) {
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
   151
    DLog(@"updating visuals");
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
   152
    [amvc_instance updateAmmoVisuals];
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   153
}