author | koda |
Fri, 26 Oct 2012 14:19:43 +0100 | |
branch | 0.9.16 |
changeset 6007 | b3b9e995ae90 |
parent 5700 | f0960a88ab0e |
child 6000 | dbcebcd3d79f |
permissions | -rw-r--r-- |
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 |
4976 | 3 |
* Copyright (c) 2009-2011 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 | 23 |
#import "GameInterfaceBridge.h" |
3898 | 24 |
#import "CommodityFunctions.h" |
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 |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
27 |
@synthesize tableView, listOfSavegames, interfaceBridge, numberOfItems; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
28 |
|
3898 | 29 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
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 | 43 |
-(void) viewDidLoad { |
4115 | 44 |
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) |
4082 | 45 |
self.tableView.backgroundView = nil; |
46 |
||
47 |
NSString *imgName; |
|
4030 | 48 |
if (IS_IPAD()) |
49 |
imgName = @"mediumBackground~ipad.png"; |
|
50 |
else |
|
51 |
imgName = @"smallerBackground~iphone.png"; |
|
52 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName]; |
|
53 |
self.view.backgroundColor = [UIColor colorWithPatternImage:img]; |
|
54 |
[img release]; |
|
4082 | 55 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
56 |
if (self.listOfSavegames == nil) |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
57 |
[self updateTable]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
58 |
[super viewDidLoad]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
59 |
} |
3898 | 60 |
|
61 |
-(void) viewWillAppear:(BOOL)animated { |
|
3978 | 62 |
[self updateTable]; |
3898 | 63 |
[super viewWillAppear:animated]; |
64 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
65 |
|
3923
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
66 |
#pragma mark - |
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
67 |
#pragma mark button functions |
3898 | 68 |
-(IBAction) buttonPressed:(id) sender { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
69 |
UIButton *button = (UIButton *)sender; |
3971 | 70 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
71 |
if (button.tag == 0) { |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
72 |
playSound(@"backSound"); |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
73 |
[self.tableView setEditing:NO animated:YES]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
74 |
[[self parentViewController] dismissModalViewControllerAnimated:YES]; |
3971 | 75 |
} else { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
76 |
NSString *titleStr, *cancelStr, *confirmStr; |
3971 | 77 |
titleStr = NSLocalizedString(@"Are you reeeeeally sure?", @""); |
78 |
cancelStr = NSLocalizedString(@"Well, maybe not...", @""); |
|
79 |
confirmStr = NSLocalizedString(@"Of course!", @""); |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
80 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
81 |
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
82 |
delegate:self |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
83 |
cancelButtonTitle:cancelStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
84 |
destructiveButtonTitle:confirmStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
85 |
otherButtonTitles:nil]; |
3971 | 86 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
87 |
if (IS_IPAD()) |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
88 |
[actionSheet showFromBarButtonItem:(UIBarButtonItem *)sender animated:YES]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
89 |
else |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
90 |
[actionSheet showInView:self.view]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
91 |
[actionSheet release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
92 |
} |
3971 | 93 |
} |
94 |
||
95 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
96 |
if ([actionSheet cancelButtonIndex] != buttonIndex) { |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
97 |
// remove all files and recreate the directory |
3971 | 98 |
[[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
99 |
[[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
100 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
101 |
// update the table and the cached list |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
102 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:self.numberOfItems]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
103 |
for (int i = 0; i < self.numberOfItems; i++) |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
104 |
[array addObject:[NSIndexPath indexPathForRow:i inSection:0]]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
105 |
self.numberOfItems = 0; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
106 |
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
107 |
[self.listOfSavegames removeAllObjects]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
108 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
109 |
[array release]; |
3971 | 110 |
} |
3903 | 111 |
} |
112 |
||
3898 | 113 |
#pragma mark - |
114 |
#pragma mark Table view data source |
|
115 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
116 |
return 1; |
|
117 |
} |
|
118 |
||
119 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
120 |
return self.numberOfItems; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
121 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
122 |
|
3898 | 123 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
124 |
static NSString *CellIdentifier = @"Cell"; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
125 |
|
3971 | 126 |
if (self.listOfSavegames == nil) |
127 |
[self updateTable]; |
|
3903 | 128 |
EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
129 |
if (editableCell == nil) { |
|
130 |
editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
131 |
editableCell.delegate = self; |
|
132 |
} |
|
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
|
133 |
editableCell.respectEditing = YES; |
3903 | 134 |
editableCell.textField.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
135 |
editableCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
136 |
||
137 |
return (UITableViewCell *)editableCell; |
|
138 |
} |
|
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
|
139 |
|
3903 | 140 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
141 |
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
|
142 |
footer.backgroundColor = [UIColor clearColor]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
143 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
label.textAlignment = UITextAlignmentCenter; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
label.numberOfLines = 5; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
150 |
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
|
151 |
|
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 |
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
|
153 |
[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
|
154 |
[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
|
155 |
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
|
156 |
} |
3898 | 157 |
|
4115 | 158 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
159 |
return 60; |
4115 | 160 |
} |
161 |
||
3903 | 162 |
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
163 |
[(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
164 |
self.numberOfItems--; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
165 |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
166 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
167 |
NSString *saveName = [self.listOfSavegames objectAtIndex:[indexPath row]]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
168 |
NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),saveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
169 |
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil]; |
3903 | 170 |
[self.listOfSavegames removeObject:saveName]; |
171 |
} |
|
3898 | 172 |
|
173 |
#pragma mark - |
|
174 |
#pragma mark Table view delegate |
|
175 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
176 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
3971 | 177 |
if (self.listOfSavegames == nil) |
178 |
[self updateTable]; |
|
179 |
||
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
180 |
// duplicate the entry |
3903 | 181 |
[(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil]; |
5156 | 182 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
183 |
NSString *currentSaveName = [self.listOfSavegames objectAtIndex:[indexPath row]]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
184 |
NSString *currentFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),currentSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
185 |
NSString *newSaveName = [[NSString alloc] initWithFormat:@"[%@] %@",NSLocalizedString(@"Backup",@""),currentSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
186 |
NSString *newFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),newSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
187 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
188 |
[self.listOfSavegames addObject:newSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
189 |
[newSaveName release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
190 |
[[NSFileManager defaultManager] copyItemAtPath:currentFilePath toPath:newFilePath error:nil]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
191 |
[newFilePath release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
192 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
193 |
self.numberOfItems++; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
194 |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
195 |
|
5666
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
196 |
if (self.interfaceBridge == nil) { |
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
197 |
GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self]; |
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
198 |
self.interfaceBridge = bridge; |
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
199 |
[bridge release]; |
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
200 |
} |
4763
c228a4841e3f
unify stats display on ipad and non-ipad and on saved and normal games
koda
parents:
4476
diff
changeset
|
201 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
202 |
[self.interfaceBridge startSaveGame:currentFilePath]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
203 |
[currentFilePath release]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
204 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
205 |
|
3898 | 206 |
#pragma mark - |
3903 | 207 |
#pragma mark editableCellView delegate |
208 |
// rename old file if names differ |
|
209 |
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { |
|
3971 | 210 |
if (self.listOfSavegames == nil) |
211 |
[self updateTable]; |
|
3903 | 212 |
NSString *oldFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:tagValue]]; |
213 |
NSString *newFilePath = [NSString stringWithFormat:@"%@/%@.hws",SAVES_DIRECTORY(),textString]; |
|
214 |
||
215 |
if ([oldFilePath isEqualToString:newFilePath] == NO) { |
|
216 |
[[NSFileManager defaultManager] moveItemAtPath:oldFilePath toPath:newFilePath error:nil]; |
|
217 |
[self.listOfSavegames replaceObjectAtIndex:tagValue withObject:[textString stringByAppendingString:@".hws"]]; |
|
218 |
} |
|
219 |
||
220 |
} |
|
221 |
||
222 |
#pragma mark - |
|
3898 | 223 |
#pragma mark Memory Management |
224 |
-(void) didReceiveMemoryWarning { |
|
3971 | 225 |
self.listOfSavegames = nil; |
5699
1a9a6a7662aa
ios: respond more gracefully to didReceiveMemoryWarning and add sounds to two buttons
koda
parents:
5666
diff
changeset
|
226 |
// 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:
5666
diff
changeset
|
227 |
//self.interfaceBridge = nil; |
3971 | 228 |
MSG_MEMCLEAN(); |
3898 | 229 |
[super didReceiveMemoryWarning]; |
230 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
231 |
|
3898 | 232 |
-(void) viewDidUnload { |
233 |
self.tableView = nil; |
|
234 |
self.listOfSavegames = nil; |
|
5666
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
235 |
self.interfaceBridge = nil; |
3971 | 236 |
MSG_DIDUNLOAD(); |
3898 | 237 |
[super viewDidUnload]; |
238 |
} |
|
239 |
||
240 |
-(void) dealloc { |
|
5208 | 241 |
releaseAndNil(tableView); |
242 |
releaseAndNil(listOfSavegames); |
|
5666
cc79eb30346e
this should fix the double free that happens when closing the sdl window on ios (untested)
koda
parents:
5208
diff
changeset
|
243 |
releaseAndNil(interfaceBridge); |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
244 |
[super dealloc]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
245 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
246 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
247 |
@end |