author | Wuzzy <almikes@aol.com> |
Mon, 08 May 2017 03:42:51 +0200 | |
changeset 12414 | 7cdd8e113dc0 |
parent 11554 | 893722a2a1f9 |
child 12877 | 00215a7ec5f5 |
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 |
6700 | 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 |
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:
8441
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3893
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 |
|
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 |
#import "SavedGamesViewController.h" |
5156 | 21 |
#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
|
22 |
|
11306
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
23 |
@interface SavedGamesViewController () |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
24 |
@property (retain, nonatomic) IBOutlet UIBarButtonItem *clearAllButton; |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
25 |
@end |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
26 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
27 |
@implementation SavedGamesViewController |
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
28 |
@synthesize tableView, listOfSavegames; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
29 |
|
3898 | 30 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
31 |
return rotationManager(interfaceOrientation); |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
32 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
33 |
|
3923
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
34 |
-(void) updateTable { |
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
self.listOfSavegames = array; |
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
38 |
[array release]; |
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 |
|
11306
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
43 |
-(void) viewDidLoad |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
44 |
{ |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
45 |
[super viewDidLoad]; |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
46 |
|
6673 | 47 |
[self.tableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
4082 | 48 |
|
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
49 |
NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png"; |
4030 | 50 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName]; |
6673 | 51 |
UIImageView *background = [[UIImageView alloc] initWithImage:img]; |
4030 | 52 |
[img release]; |
6673 | 53 |
background.frame = self.view.frame; |
54 |
background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
|
55 |
[self.view insertSubview:background atIndex:0]; |
|
56 |
[background release]; |
|
11306
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
57 |
|
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
58 |
[self.clearAllButton setTitle:NSLocalizedString(@"Clear All", nil)]; |
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
59 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
60 |
if (self.listOfSavegames == nil) |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
61 |
[self updateTable]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
62 |
} |
3898 | 63 |
|
64 |
-(void) viewWillAppear:(BOOL)animated { |
|
3978 | 65 |
[self updateTable]; |
3898 | 66 |
[super viewWillAppear:animated]; |
67 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
68 |
|
3923
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
69 |
#pragma mark - |
694e6f6e0e30
various classes updates (new version in mainmenu, opt in mapconfig, clear all in savegames)
koda
parents:
3904
diff
changeset
|
70 |
#pragma mark button functions |
3898 | 71 |
-(IBAction) buttonPressed:(id) sender { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
72 |
UIButton *button = (UIButton *)sender; |
3971 | 73 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
74 |
if (button.tag == 0) { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
75 |
[[AudioManagerController mainManager] playBackSound]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
76 |
[self.tableView setEditing:NO animated:YES]; |
11116
102684240fe8
- Interscreen transitions fixed
Anton Malmygin <antonc27@mail.ru>
parents:
10108
diff
changeset
|
77 |
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; |
3971 | 78 |
} else { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
79 |
NSString *titleStr, *cancelStr, *confirmStr; |
3971 | 80 |
titleStr = NSLocalizedString(@"Are you reeeeeally sure?", @""); |
81 |
cancelStr = NSLocalizedString(@"Well, maybe not...", @""); |
|
82 |
confirmStr = NSLocalizedString(@"Of course!", @""); |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
83 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
84 |
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
85 |
delegate:self |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
86 |
cancelButtonTitle:cancelStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
87 |
destructiveButtonTitle:confirmStr |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
88 |
otherButtonTitles:nil]; |
3971 | 89 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
90 |
if (IS_IPAD()) |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
91 |
[actionSheet showFromBarButtonItem:(UIBarButtonItem *)sender animated:YES]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
92 |
else |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
93 |
[actionSheet showInView:self.view]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
94 |
[actionSheet release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
95 |
} |
3971 | 96 |
} |
97 |
||
98 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
99 |
if ([actionSheet cancelButtonIndex] != buttonIndex) { |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
100 |
// remove all files and recreate the directory |
3971 | 101 |
[[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; |
102 |
[[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
103 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
104 |
// update the table and the cached list |
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
105 |
NSMutableArray *array = [[NSMutableArray alloc] init]; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
106 |
for (int i = 0; i < [self.listOfSavegames count]; i++) |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
107 |
[array addObject:[NSIndexPath indexPathForRow:i inSection:0]]; |
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
108 |
[self.listOfSavegames removeAllObjects]; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
109 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
110 |
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
111 |
[array release]; |
3971 | 112 |
} |
3903 | 113 |
} |
114 |
||
3898 | 115 |
#pragma mark - |
116 |
#pragma mark Table view data source |
|
117 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
118 |
return 1; |
|
119 |
} |
|
120 |
||
121 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
122 |
return [self.listOfSavegames count]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
123 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
124 |
|
3898 | 125 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
126 |
static NSString *CellIdentifier = @"Cell"; |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
127 |
|
3903 | 128 |
EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
129 |
if (editableCell == nil) { |
|
130 |
editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
131 |
editableCell.delegate = nil; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
132 |
editableCell.textField.userInteractionEnabled = NO; |
3903 | 133 |
} |
11254
7f3f96e9fdf1
- Fix for crash while deleting >=2 saved games
antonc27 <antonc27@mail.ru>
parents:
11116
diff
changeset
|
134 |
editableCell.tag = [indexPath row]; |
3903 | 135 |
editableCell.textField.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
136 |
editableCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
|
137 |
||
138 |
return (UITableViewCell *)editableCell; |
|
139 |
} |
|
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
|
140 |
|
3903 | 141 |
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
142 |
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
|
143 |
footer.backgroundColor = [UIColor clearColor]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
144 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
145 |
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
|
146 |
label.center = CGPointMake(self.tableView.frame.size.width/2, 30); |
11554
893722a2a1f9
- Some warnings fixed with text alignment on iOS front-end
antonc27 <antonc27@mail.ru>
parents:
11306
diff
changeset
|
147 |
label.textAlignment = NSTextAlignmentCenter; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
label.numberOfLines = 5; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
151 |
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
|
152 |
|
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.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
|
154 |
[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
|
155 |
[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
|
156 |
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
|
157 |
} |
3898 | 158 |
|
4115 | 159 |
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
160 |
return 60; |
4115 | 161 |
} |
162 |
||
3903 | 163 |
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
164 |
[(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil]; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
165 |
[self fixTagsForStartTag:[indexPath row]]; |
5700
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]; |
11257
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
171 |
|
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
172 |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
173 |
} |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
174 |
|
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
175 |
#pragma mark - Fix cells' tags |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
176 |
|
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
177 |
- (void)fixTagsForStartTag:(NSInteger)tag |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
178 |
{ |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
179 |
for (UITableViewCell *cell in self.tableView.visibleCells) |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
180 |
{ |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
181 |
NSInteger oldTag = cell.tag; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
182 |
|
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
183 |
if (oldTag > tag) |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
184 |
{ |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
185 |
cell.tag--; |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
186 |
} |
62d1a66b353d
- Refactoring of SavedViewController:
antonc27 <antonc27@mail.ru>
parents:
11254
diff
changeset
|
187 |
} |
3903 | 188 |
} |
3898 | 189 |
|
190 |
#pragma mark - |
|
191 |
#pragma mark Table view delegate |
|
192 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
193 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
3971 | 194 |
if (self.listOfSavegames == nil) |
195 |
[self updateTable]; |
|
196 |
||
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
197 |
// duplicate the entry |
3903 | 198 |
[(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil]; |
5156 | 199 |
|
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
200 |
NSString *currentSaveName = [self.listOfSavegames objectAtIndex:[indexPath row]]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
201 |
NSString *currentFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),currentSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
202 |
NSString *newSaveName = [[NSString alloc] initWithFormat:@"[%@] %@",NSLocalizedString(@"Backup",@""),currentSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
203 |
NSString *newFilePath = [[NSString alloc] initWithFormat:@"%@/%@",SAVES_DIRECTORY(),newSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
204 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
205 |
[self.listOfSavegames addObject:newSaveName]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
206 |
[newSaveName release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
207 |
[[NSFileManager defaultManager] copyItemAtPath:currentFilePath toPath:newFilePath error:nil]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
208 |
[newFilePath release]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
209 |
|
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
210 |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; |
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
211 |
|
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
|
212 |
[GameInterfaceBridge registerCallingController:self]; |
6266
b02a1e92dba2
convert gameinterfacebridge in simple-to-use class methods
koda
parents:
6083
diff
changeset
|
213 |
[GameInterfaceBridge startSaveGame:currentFilePath]; |
5700
f0960a88ab0e
savedgamesviewcontroller refactor, added icons to supportviewcontroller
koda
parents:
5699
diff
changeset
|
214 |
[currentFilePath release]; |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
215 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
216 |
|
3898 | 217 |
#pragma mark - |
3903 | 218 |
#pragma mark editableCellView delegate |
219 |
// rename old file if names differ |
|
220 |
-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { |
|
3971 | 221 |
if (self.listOfSavegames == nil) |
222 |
[self updateTable]; |
|
3903 | 223 |
NSString *oldFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:tagValue]]; |
224 |
NSString *newFilePath = [NSString stringWithFormat:@"%@/%@.hws",SAVES_DIRECTORY(),textString]; |
|
8441 | 225 |
|
3903 | 226 |
if ([oldFilePath isEqualToString:newFilePath] == NO) { |
227 |
[[NSFileManager defaultManager] moveItemAtPath:oldFilePath toPath:newFilePath error:nil]; |
|
228 |
[self.listOfSavegames replaceObjectAtIndex:tagValue withObject:[textString stringByAppendingString:@".hws"]]; |
|
229 |
} |
|
8441 | 230 |
|
3903 | 231 |
} |
232 |
||
233 |
#pragma mark - |
|
3898 | 234 |
#pragma mark Memory Management |
235 |
-(void) didReceiveMemoryWarning { |
|
3971 | 236 |
self.listOfSavegames = nil; |
237 |
MSG_MEMCLEAN(); |
|
3898 | 238 |
[super didReceiveMemoryWarning]; |
239 |
} |
|
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
240 |
|
3898 | 241 |
-(void) viewDidUnload { |
242 |
self.tableView = nil; |
|
243 |
self.listOfSavegames = nil; |
|
3971 | 244 |
MSG_DIDUNLOAD(); |
3898 | 245 |
[super viewDidUnload]; |
246 |
} |
|
247 |
||
248 |
-(void) dealloc { |
|
5208 | 249 |
releaseAndNil(tableView); |
250 |
releaseAndNil(listOfSavegames); |
|
11306
7a9464f9e992
- Missed localization for 'Clear All' button on SavedGamesVirewController
antonc27 <antonc27@mail.ru>
parents:
11257
diff
changeset
|
251 |
releaseAndNil(_clearAllButton); |
3893
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
252 |
[super dealloc]; |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
253 |
} |
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
254 |
|
568bfd083465
allow more flexibility between viewcontrollers, also added stub pages for saved games
koda
parents:
diff
changeset
|
255 |
@end |