project_files/HedgewarsMobile/Classes/ObjcExports.m
author koda
Mon, 26 Mar 2012 03:24:50 +0200
changeset 6822 206db098f8c5
parent 6700 e04da46ee43c
child 6832 fae8fd118da9
permissions -rw-r--r--
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6624
diff changeset
     3
 * Copyright (c) 2009-2012 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"
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    24
4362
8dae325dc625 added missing graphics and fixed some glitches/crashes/bugs
koda
parents: 4034
diff changeset
    25
// the reference to the newMenu instance
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 6018
diff changeset
    26
static OverlayViewController *overlay_instance;
5175
a3da220dbb3f finish overlay refactoring and some leak annihilation
koda
parents: 5174
diff changeset
    27
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    28
#pragma mark -
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    29
#pragma mark functions called by pascal code
5994
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5992
diff changeset
    30
BOOL inline isApplePhone() {
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5992
diff changeset
    31
    return (IS_IPAD() == NO);
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5992
diff changeset
    32
}
3c578f531cc1 don't rumble while synchronising a demo/save
koda
parents: 5992
diff changeset
    33
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    34
void startLoadingIndicator() {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    35
    // this is the first ojbc function called by engine, so we have to initialize some variables here
6259
02765411a912 move objc overlay creation after sdlwindow has been created
koda
parents: 6247
diff changeset
    36
    overlay_instance = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
02765411a912 move objc overlay creation after sdlwindow has been created
koda
parents: 6247
diff changeset
    37
    // in order to get rotation events we have to insert the view inside the first view of the second window
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6259
diff changeset
    38
    [[HWUtils mainSDLViewInstance] addSubview:overlay_instance.view];
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    39
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    40
    if ([HWUtils gameType] == gtSave) {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    41
        [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    42
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    43
        overlay_instance.view.backgroundColor = [UIColor blackColor];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    44
        overlay_instance.view.alpha = 0.75;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    45
        overlay_instance.view.userInteractionEnabled = NO;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    46
    }
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    47
    CGPoint center = overlay_instance.view.center;
6624
e049b5bb0ad1 BUUUUURN OBJC AMMOMENU BUUUURNhg diff! (on a separate note, this reduces the codesize by ~37k)
koda
parents: 6615
diff changeset
    48
    CGPoint loaderCenter = ([HWUtils gameType] == gtSave) ? center : CGPointMake(center.x, center.y * 5/3);
5174
f5294509783e initial refactoring of ObjcExports and OverlayViewController
koda
parents: 5106
diff changeset
    49
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    50
    overlay_instance.loadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    51
    overlay_instance.loadingIndicator.hidesWhenStopped = YES;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    52
    overlay_instance.loadingIndicator.center = loaderCenter;
6615
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6409
diff changeset
    53
    overlay_instance.loadingIndicator.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6409
diff changeset
    54
                                                         UIViewAutoresizingFlexibleRightMargin |
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6409
diff changeset
    55
                                                         UIViewAutoresizingFlexibleTopMargin |
65602f1ef0f8 more ios pages supporting rotaiton
koda
parents: 6409
diff changeset
    56
                                                         UIViewAutoresizingFlexibleBottomMargin;
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    57
    [overlay_instance.loadingIndicator startAnimating];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    58
    [overlay_instance.view addSubview:overlay_instance.loadingIndicator];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    59
    [overlay_instance.loadingIndicator release];
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    60
}
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    61
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    62
void stopLoadingIndicator() {
4028
eb371ada631d move functions called by pascal code outside controller
koda
parents:
diff changeset
    63
    HW_zoomSet(1.7);
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    64
    if ([HWUtils gameType] != gtSave) {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    65
        [overlay_instance.loadingIndicator stopAnimating];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    66
        [overlay_instance.loadingIndicator removeFromSuperview];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    67
        [HWUtils setGameStatus:gsInGame];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    68
    }
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    69
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    70
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    71
void saveFinishedSynching() {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    72
    [UIView beginAnimations:@"fading from save synch" context:NULL];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    73
    [UIView setAnimationDuration:1];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    74
    overlay_instance.view.backgroundColor = [UIColor clearColor];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    75
    overlay_instance.view.alpha = 1;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    76
    overlay_instance.view.userInteractionEnabled = YES;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    77
    [UIView commitAnimations];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    78
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    79
    [overlay_instance.loadingIndicator stopAnimating];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    80
    [overlay_instance.loadingIndicator performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    81
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    82
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6078
diff changeset
    83
    [HWUtils setGameStatus:gsInGame];
4028
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 clearView() {
6822
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
    87
    [overlay_instance clearOverlay];
4028
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
5106
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
    90
// dummy function to prevent linkage fail
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
    91
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
    92
    return 0;
517bdd3865f1 wow we're getting famous http://hg.libsdl.org/SDL/rev/8a04b596b472
koda
parents: 5002
diff changeset
    93
}