project_files/HedgewarsMobile/Classes/SavedGamesViewController.m
author koda
Sun, 19 Feb 2012 02:52:19 +0100
changeset 6719 d2afc6b2d88e
parent 6700 e04da46ee43c
child 6832 fae8fd118da9
permissions -rw-r--r--
added one button play feature, like in desktop frontend; need to make sure that the hardcoded stuff never gets deleted
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     1
/*
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
6700
e04da46ee43c the most important commit of the year
koda
parents: 6673
diff changeset
     3
 * Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com>
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     4
 *
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     8
 *
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    13
 *
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    17
 *
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    18
 * File created on 22/09/2010.
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    19
 */
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    20
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    21
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    22
#import "SavedGamesViewController.h"
5156
641abe679bf0 work in progress yet again (can run some games now)
koda
parents: 5002
diff changeset
    23
#import "GameInterfaceBridge.h"
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: 6000
diff changeset
    24
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    25
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    26
@implementation SavedGamesViewController
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6083
diff changeset
    27
@synthesize tableView, listOfSavegames, numberOfItems;
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    28
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    29
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    30
    return rotationManager(interfaceOrientation);
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    31
}
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    32
3923
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    33
-(void) updateTable {
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    34
    NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SAVES_DIRECTORY() error:NULL];
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    35
    NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES];
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    36
    self.listOfSavegames = array;
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    37
    [array release];
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    38
    self.numberOfItems = [self.listOfSavegames count];
3923
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    39
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    40
    [self.tableView reloadData];
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    41
}
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    42
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    43
-(void) viewDidLoad {
6673
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    44
    [self.tableView setBackgroundColorForAnyTable:[UIColor clearColor]];
4082
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 4030
diff changeset
    45
6083
72c882c0fd0f first pass for implementing missions/training selection on ipad (not yet running)
koda
parents: 6078
diff changeset
    46
    NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
4030
adbb37b8c487 fix background for the about and saves controller
koda
parents: 3996
diff changeset
    47
    UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
6673
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    48
    UIImageView *background = [[UIImageView alloc] initWithImage:img];
4030
adbb37b8c487 fix background for the about and saves controller
koda
parents: 3996
diff changeset
    49
    [img release];
6673
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    50
    background.frame = self.view.frame;
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    51
    background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    52
    [self.view insertSubview:background atIndex:0];
1ee72dcea263 colorWithPatternImage uses too much memory
koda
parents: 6353
diff changeset
    53
    [background release];
4082
bfe14b38dad1 better support for wimpier i-devices
koda
parents: 4030
diff changeset
    54
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    55
    if (self.listOfSavegames == nil)
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    56
        [self updateTable];
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    57
    [super viewDidLoad];
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    58
}
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    59
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    60
-(void) viewWillAppear:(BOOL)animated {
3978
9660600e43cb fix some glitches
koda
parents: 3971
diff changeset
    61
    [self updateTable];
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    62
    [super viewWillAppear:animated];
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    63
}
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
    64
3923
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    65
#pragma mark -
694e6f6e0e30 various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents: 3904
diff changeset
    66
#pragma mark button functions
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
    67
-(IBAction) buttonPressed:(id) sender {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    68
    UIButton *button = (UIButton *)sender;
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    69
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    70
    if (button.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: 5700
diff changeset
    71
        [AudioManagerController playBackSound];
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    72
        [self.tableView setEditing:NO animated:YES];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    73
        [[self parentViewController] dismissModalViewControllerAnimated:YES];
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    74
    } else {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    75
        NSString *titleStr, *cancelStr, *confirmStr;
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    76
        titleStr = NSLocalizedString(@"Are you reeeeeally sure?", @"");
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    77
        cancelStr = NSLocalizedString(@"Well, maybe not...", @"");
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    78
        confirmStr = NSLocalizedString(@"Of course!", @"");
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    79
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    80
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleStr
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    81
                                                                 delegate:self
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    82
                                                        cancelButtonTitle:cancelStr
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    83
                                                   destructiveButtonTitle:confirmStr
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    84
                                                        otherButtonTitles:nil];
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    85
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    86
        if (IS_IPAD())
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    87
            [actionSheet showFromBarButtonItem:(UIBarButtonItem *)sender animated:YES];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    88
        else
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    89
            [actionSheet showInView:self.view];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    90
        [actionSheet release];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    91
    }
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    92
}
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    93
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    94
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    95
    if ([actionSheet cancelButtonIndex] != buttonIndex) {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    96
        // remove all files and recreate the directory
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    97
        [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL];
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
    98
        [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL];
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
    99
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   100
        // update the table and the cached list
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   101
        NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:self.numberOfItems];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   102
        for (int i = 0; i < self.numberOfItems; i++)
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   103
            [array addObject:[NSIndexPath indexPathForRow:i inSection:0]];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   104
        self.numberOfItems = 0;
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   105
        [self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   106
        [self.listOfSavegames removeAllObjects];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   107
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   108
        [array release];
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   109
    }
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   110
}
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   111
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   112
#pragma mark -
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   113
#pragma mark Table view data source
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   114
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   115
    return 1;
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   116
}
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   117
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   118
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   119
    return self.numberOfItems;
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   120
}
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   121
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   122
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   123
    static NSString *CellIdentifier = @"Cell";
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   124
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   125
    if (self.listOfSavegames == nil)
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   126
        [self updateTable];
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   127
    EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   128
    if (editableCell == nil) {
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   129
        editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   130
        editableCell.delegate = self;
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   131
    }
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   132
    editableCell.respectEditing = YES;
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   133
    editableCell.textField.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   134
    editableCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   135
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   136
    return (UITableViewCell *)editableCell;
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   137
}
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   138
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   139
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   140
    UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 60)];
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   141
    footer.backgroundColor = [UIColor clearColor];
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   142
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   143
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width*60/100, 60)];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   144
    label.center = CGPointMake(self.tableView.frame.size.width/2, 30);
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   145
    label.textAlignment = UITextAlignmentCenter;
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   146
    label.font = [UIFont italicSystemFontOfSize:16];
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   147
    label.textColor = [UIColor lightGrayColor];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   148
    label.numberOfLines = 5;
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   149
    label.text = NSLocalizedString(@"Press to resume playing or swipe to delete the save file.",@"");
3904
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   150
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   151
    label.backgroundColor = [UIColor clearColor];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   152
    [footer addSubview:label];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   153
    [label release];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   154
    return [footer autorelease];
22e4d74240e5 finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents: 3903
diff changeset
   155
}
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   156
4115
222b8016c773 make the support page more portable
koda
parents: 4082
diff changeset
   157
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   158
    return 60;
4115
222b8016c773 make the support page more portable
koda
parents: 4082
diff changeset
   159
}
222b8016c773 make the support page more portable
koda
parents: 4082
diff changeset
   160
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   161
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   162
    [(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   163
    self.numberOfItems--;
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   164
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   165
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   166
    NSString *saveName = [self.listOfSavegames objectAtIndex:[indexPath row]];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   167
    NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),saveName];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   168
    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   169
    [self.listOfSavegames removeObject:saveName];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   170
}
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   171
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   172
#pragma mark -
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   173
#pragma mark Table view delegate
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   174
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   175
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   176
    if (self.listOfSavegames == nil)
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   177
        [self updateTable];
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   178
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   179
    // duplicate the entry
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   180
    [(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil];
5156
641abe679bf0 work in progress yet again (can run some games now)
koda
parents: 5002
diff changeset
   181
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   182
    NSString *currentSaveName = [self.listOfSavegames objectAtIndex:[indexPath row]];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   183
    NSString *currentFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),currentSaveName];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   184
    NSString *newSaveName = [[NSString alloc] initWithFormat:@"[%@] %@",NSLocalizedString(@"Backup",@""),currentSaveName];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   185
    NSString *newFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),newSaveName];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   186
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   187
    [self.listOfSavegames addObject:newSaveName];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   188
    [newSaveName release];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   189
    [[NSFileManager defaultManager] copyItemAtPath:currentFilePath toPath:newFilePath error:nil];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   190
    [newFilePath release];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   191
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   192
    self.numberOfItems++;
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   193
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   194
6353
d8f62c805619 restore displaying statistics at the end of a game and restore warning lower views that they are going to appear
koda
parents: 6266
diff changeset
   195
    [GameInterfaceBridge registerCallingController:self];
6266
b02a1e92dba2 convert gameinterfacebridge in simple-to-use class methods
koda
parents: 6083
diff changeset
   196
    [GameInterfaceBridge startSaveGame:currentFilePath];
5700
f0960a88ab0e savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents: 5699
diff changeset
   197
    [currentFilePath release];
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   198
}
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   199
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   200
#pragma mark -
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   201
#pragma mark editableCellView delegate
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   202
// rename old file if names differ
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   203
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue {
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   204
    if (self.listOfSavegames == nil)
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   205
        [self updateTable];
3903
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   206
    NSString *oldFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:tagValue]];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   207
    NSString *newFilePath = [NSString stringWithFormat:@"%@/%@.hws",SAVES_DIRECTORY(),textString];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   208
    
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   209
    if ([oldFilePath isEqualToString:newFilePath] == NO) {
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   210
        [[NSFileManager defaultManager] moveItemAtPath:oldFilePath toPath:newFilePath error:nil];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   211
        [self.listOfSavegames replaceObjectAtIndex:tagValue withObject:[textString stringByAppendingString:@".hws"]];
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   212
    }
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   213
    
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   214
}
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   215
db01c37494af pimp-my-savagame-table
koda
parents: 3898
diff changeset
   216
#pragma mark -
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   217
#pragma mark Memory Management
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   218
-(void) didReceiveMemoryWarning {
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   219
    self.listOfSavegames = nil;
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   220
    MSG_MEMCLEAN();
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   221
    [super didReceiveMemoryWarning];
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   222
}
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   223
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   224
-(void) viewDidUnload {
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   225
    self.tableView = nil;
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   226
    self.listOfSavegames = nil;
3971
5c82ee165ed5 minor stuff
koda
parents: 3923
diff changeset
   227
    MSG_DIDUNLOAD();
3898
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   228
    [super viewDidUnload];
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   229
}
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   230
0a9c3735a713 implemented reloading savefiles
koda
parents: 3893
diff changeset
   231
-(void) dealloc {
5208
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5158
diff changeset
   232
    releaseAndNil(tableView);
878e551f0b4a all together now! releaseAndNil ftw
koda
parents: 5158
diff changeset
   233
    releaseAndNil(listOfSavegames);
3893
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   234
    [super dealloc];
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   235
}
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   236
568bfd083465 allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff changeset
   237
@end