project_files/HedgewarsMobile/Classes/RestoreViewController.m
author unc0rr
Mon, 06 Feb 2017 18:15:29 +0300
changeset 12149 44b06731278b
parent 11232 0425d60cd046
child 12872 00215a7ec5f5
permissions -rw-r--r--
Fix handlers module
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6353
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
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
     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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 6869
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
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
    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
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
#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
    21
#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
    22
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    23
@interface RestoreViewController ()
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    24
@property (retain, nonatomic) IBOutlet UIButton *restoreButton;
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    25
@property (retain, nonatomic) IBOutlet UIButton *dismissButton;
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    26
@end
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    27
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
    28
@implementation RestoreViewController
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
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
-(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
    31
    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
    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) {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    39
        [[AudioManagerController mainManager] playClickSound];
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    40
        [GameInterfaceBridge registerCallingController:self.presentingViewController];
11207
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    41
        
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    42
        // Since iOS 8, the file system layout of app containers has changed.
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    43
        // So, we must rely now on saved game filename, not full path.
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    44
        NSString *oldSavedGamePath = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    45
        NSString *savedGameFile = [oldSavedGamePath lastPathComponent];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    46
        NSString *newSavedGamePath = [NSString stringWithFormat:@"%@%@", SAVES_DIRECTORY(), savedGameFile];
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    47
        
279ed2931be8 - Fix for wrong path of restored game
antonc27 <antonc27@mail.ru>
parents: 11205
diff changeset
    48
        [GameInterfaceBridge startSaveGame:newSavedGamePath];
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
    } else {
6869
a187c280dd3d ios: convert audio operation from class to instance, plays better with memory
koda
parents: 6832
diff changeset
    50
        [[AudioManagerController mainManager] 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
    51
        [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
    52
        [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
    53
    }
11116
102684240fe8 - Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents: 10108
diff changeset
    54
    [self.presentingViewController dismissViewControllerAnimated:YES completion: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
    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
-(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
    58
    [super viewDidLoad];
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    59
    
11232
0425d60cd046 - Localization for missed strings in RestoreViewController (for eng(as reference) and rus)
antonc27 <antonc27@mail.ru>
parents: 11207
diff changeset
    60
    [self.restoreButton setTitle:NSLocalizedString(@"Restore", nil) forState:UIControlStateNormal];
0425d60cd046 - Localization for missed strings in RestoreViewController (for eng(as reference) and rus)
antonc27 <antonc27@mail.ru>
parents: 11207
diff changeset
    61
    [self.dismissButton setTitle:NSLocalizedString(@"Dismiss", nil) forState:UIControlStateNormal];
0425d60cd046 - Localization for missed strings in RestoreViewController (for eng(as reference) and rus)
antonc27 <antonc27@mail.ru>
parents: 11207
diff changeset
    62
    
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    63
    [self.restoreButton applyDarkBlueQuickStyle];
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    64
    [self.dismissButton applyDarkBlueQuickStyle];
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
    65
}
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
5666
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    67
-(void) didReceiveMemoryWarning {
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    68
    [super didReceiveMemoryWarning];
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    69
}
cc79eb30346e this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents: 5220
diff changeset
    70
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
    71
-(void) 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
    72
    [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
    73
}
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
    74
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
    75
-(void) dealloc {
11205
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    76
    [_restoreButton release];
9fd7b8d3cf4d - Button's restyling for RestoreViewController
antonc27 <antonc27@mail.ru>
parents: 11116
diff changeset
    77
    [_dismissButton release];
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 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
    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
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
    82
@end