project_files/HedgewarsMobile/Classes/ObjcExports.m
author koda
Mon, 25 Apr 2011 06:38:59 +0200
changeset 5174 f5294509783e
parent 5106 517bdd3865f1
child 5175 a3da220dbb3f
permissions -rw-r--r--
initial refactoring of ObjcExports and OverlayViewController
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4948
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
4028
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"
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    23
#import "OverlayViewController.h"
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    24
#import "AmmoMenuViewController.h"
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    25
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    26
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    27
#pragma mark internal variables
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    28
// actual game started (controls should be enabled)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    29
BOOL gameRunning;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    30
// black screen present
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    31
BOOL savedGame;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    32
// cache the grenade time
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    33
NSInteger grenadeTime;
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    34
// the reference to the newMenu instance
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    35
OverlayViewController *overlay_instance;
4461
2f4f5d649bcd add a simple check to prevent loading sounds when device is muted
koda
parents: 4362
diff changeset
    36
// the audiosession must be initialized before using properties
2f4f5d649bcd add a simple check to prevent loading sounds when device is muted
koda
parents: 4362
diff changeset
    37
BOOL gAudioSessionInited = NO;
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    38
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    39
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    40
#pragma mark functions called like oop
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    41
void objcExportsInit(OverlayViewController* instance) {
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    42
    overlay_instance = instance;
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    43
    gameRunning = NO;
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    44
    savedGame = NO;
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
    45
    grenadeTime = 2;
4028
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
BOOL inline isGameRunning() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    49
    return gameRunning;
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
void inline setGameRunning(BOOL value) {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    53
    gameRunning = value;
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
NSInteger cachedGrenadeTime() {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    57
    return grenadeTime;
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
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    60
void inline setGrenadeTime(NSInteger value) {
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    61
    grenadeTime = value;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    62
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    63
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
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    66
void startSpinningProgress() {
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    67
    gameRunning = NO;
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    68
    overlay_instance.lowerIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    69
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    70
    CGPoint center = overlay_instance.view.center;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    71
    overlay_instance.lowerIndicator.center = (IS_DUALHEAD() ? CGPointMake(center.y, center.x)
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    72
                                              : CGPointMake(center.y, center.x * 5/3));
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    73
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    74
    [overlay_instance.lowerIndicator startAnimating];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    75
    [overlay_instance.view addSubview:overlay_instance.lowerIndicator];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    76
    [overlay_instance.lowerIndicator release];
4028
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
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    79
void stopSpinningProgress() {
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    80
    [overlay_instance.lowerIndicator stopAnimating];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    81
    [overlay_instance.lowerIndicator removeFromSuperview];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    82
    HW_zoomSet(1.7);
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    83
    if (savedGame == NO)
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    84
        gameRunning = YES;
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
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    87
void clearView() {
4504
8906b2409d97 add the appirater class for getting more positive reviews
koda
parents: 4488
diff changeset
    88
    // don't use any engine calls here as this function is called every time the ammomenu is opened
5002
a9c44a8ffec8 we get our own AppDelegate, subclassing SDL_UikitAppDelegate so that we don't have to mess with sdl build system
koda
parents: 4976
diff changeset
    89
    UIWindow *theWindow = (IS_DUALHEAD()) ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
4028
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
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   107
void saveBeganSynching() {
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   108
    overlay_instance.view.backgroundColor = [UIColor blackColor];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   109
    overlay_instance.view.alpha = 0.75;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   110
    overlay_instance.view.userInteractionEnabled = NO;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   111
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   112
    overlay_instance.savesIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   113
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   114
    CGPoint center = overlay_instance.view.center;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   115
    overlay_instance.savesIndicator.center = CGPointMake(center.y, center.x);
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   116
    overlay_instance.savesIndicator.hidesWhenStopped = YES;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   117
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   118
    [overlay_instance.savesIndicator startAnimating];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   119
    [overlay_instance.view addSubview:overlay_instance.savesIndicator];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   120
    [overlay_instance.savesIndicator release];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   121
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   122
    savedGame = YES;
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   123
    stopSpinningProgress();
4028
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
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   126
void saveFinishedSynching() {
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   127
    [UIView beginAnimations:@"fading from save synch" context:NULL];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   128
    [UIView setAnimationDuration:1];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   129
    overlay_instance.view.backgroundColor = [UIColor clearColor];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   130
    overlay_instance.view.alpha = 1;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   131
    overlay_instance.view.userInteractionEnabled = YES;
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   132
    [UIView commitAnimations];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   133
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   134
    [overlay_instance.savesIndicator stopAnimating];
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   135
    [overlay_instance.savesIndicator performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   136
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   137
    gameRunning = YES;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   138
    savedGame = NO;
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
   139
}
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   140
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   141
void updateVisualsNewTurn(void) {
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
   142
    [overlay_instance.amvc updateAmmoVisuals];
4034
634a8c8682de add some phone rumbling to big explosions, airbomb and sinegun
koda
parents: 4028
diff changeset
   143
}
5106
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
   144
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
   145
// dummy function to prevent linkage fail
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
   146
int SDL_main(int argc, char **argv) {
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
   147
    return 0;
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
   148
}