project_files/HedgewarsMobile/Classes/RestoreViewController.m
author koda
Sat, 24 Sep 2011 22:35:31 +0200
changeset 6019 8843ea756cfc
parent 6008 215f0c9719e3
child 6020 c792d4b3e080
permissions -rw-r--r--
warnings round also for ios
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     1
/*
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     4
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     8
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    13
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    17
 *
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    18
 * File created on 28/05/2011.
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    19
 */
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    20
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    21
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    22
#import "RestoreViewController.h"
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    23
#import "GameInterfaceBridge.h"
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    24
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    25
@implementation RestoreViewController
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    26
@synthesize interfaceBridge;
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    27
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    28
// Override to allow orientations other than the default portrait orientation.
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    29
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    30
    return rotationManager(interfaceOrientation);
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    31
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    32
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    33
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    34
-(IBAction) buttonReleased:(id) sender {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    35
    UIButton *theButton = (UIButton *)sender;
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    36
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    37
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    38
    if (theButton.tag != 0) {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents: 5699
diff changeset
    39
        [AudioManagerController playClickSound];
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    40
        if (self.interfaceBridge == nil) {
5668
koda
parents: 5666
diff changeset
    41
            GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self.parentViewController];
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    42
            self.interfaceBridge = bridge;
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    43
            [bridge release];
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    44
        }
6008
215f0c9719e3 fix a crash in getting statistics and a glitch that made background music start while in-game
koda
parents: 6000
diff changeset
    45
        // TODO: it is useless to keep the modalcontroller around when calling interfacebridge
215f0c9719e3 fix a crash in getting statistics and a glitch that made background music start while in-game
koda
parents: 6000
diff changeset
    46
        // but as long as it is an instance we mustn't release it beforehand
215f0c9719e3 fix a crash in getting statistics and a glitch that made background music start while in-game
koda
parents: 6000
diff changeset
    47
        // moreover in this way the stats don't show up :/
215f0c9719e3 fix a crash in getting statistics and a glitch that made background music start while in-game
koda
parents: 6000
diff changeset
    48
        [self.interfaceBridge startSaveGame:[defaults objectForKey:@"savedGamePath"]];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    49
        [self.parentViewController dismissModalViewControllerAnimated:NO];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    50
    } else {
6000
dbcebcd3d79f ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents: 5699
diff changeset
    51
        [AudioManagerController playBackSound];
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    52
        [defaults setObject:@"" forKey:@"savedGamePath"];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    53
        [defaults synchronize];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    54
        [self.parentViewController dismissModalViewControllerAnimated:YES];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    55
    }
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    56
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    57
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    58
-(void) viewDidLoad {
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    59
    NSString *imgName;
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    60
    if (IS_IPAD())
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    61
        imgName = @"smallerBackground~ipad.png";
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    62
    else
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    63
        imgName = @"smallerBackground~iphone.png";
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    64
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    65
    self.view.backgroundColor = [UIColor colorWithPatternImage:img];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    66
    [img release];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    67
    [super viewDidLoad];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    68
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    69
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    70
-(void) didReceiveMemoryWarning {
5699
1a9a6a7662aa ios: respond more gracefully to didReceiveMemoryWarning and add sounds to two buttons
koda
parents: 5668
diff changeset
    71
    // don't nil this one or it won't be able to send messages
1a9a6a7662aa ios: respond more gracefully to didReceiveMemoryWarning and add sounds to two buttons
koda
parents: 5668
diff changeset
    72
    //self.interfaceBridge = nil;
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    73
    [super didReceiveMemoryWarning];
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    74
}
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    75
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    76
-(void) viewDidUnload {
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    77
    self.interfaceBridge = nil;
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    78
    [super viewDidUnload];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    79
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    80
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    81
-(void) dealloc {
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    82
    releaseAndNil(interfaceBridge);
5220
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    83
    [super dealloc];
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    84
}
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    85
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    86
76a2246f18f0 when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
diff changeset
    87
@end