# HG changeset patch # User koda # Date 1285198235 -7200 # Node ID 88f8e7b1777e5ab19afacb46606232771ee0458a # Parent 0a9c3735a713d2e1cb11e64bd48d9557c1fa4795# Parent 59de68d541f1cdd8e2d1beb86a3a03039b9a0b02 merge diff -r 59de68d541f1 -r 88f8e7b1777e hedgewars/uStore.pas --- a/hedgewars/uStore.pas Wed Sep 22 21:58:32 2010 +0200 +++ b/hedgewars/uStore.pas Thu Sep 23 01:30:35 2010 +0200 @@ -732,8 +732,13 @@ end; procedure DrawCentered(X, Top: LongInt; Source: PTexture); +var scale: GLfloat; begin -DrawTexture(X - Source^.w shr 1, Top, Source) + if (Source^.w + 20) > cScreenWidth then + scale:= cScreenWidth / (Source^.w + 20) + else + scale:= 1.0; + DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) end; procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/CommodityFunctions.h --- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Thu Sep 23 01:30:35 2010 +0200 @@ -31,6 +31,7 @@ #define TEAMS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Teams/"] #define WEAPONS_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Weapons/"] #define SCHEMES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Schemes/"] +#define SAVES_DIRECTORY() [DOCUMENTS_FOLDER() stringByAppendingString:@"/Saves/"] #define GRAPHICS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/"] #define HATS_DIRECTORY() [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"] diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/GameConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Sep 23 01:30:35 2010 +0200 @@ -192,17 +192,9 @@ DLog(@"sending config %@", gameDictionary); if ([[gameDictionary allKeys] count] == 9) { - UIView *black = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; - black.opaque = YES; - black.backgroundColor = [UIColor blackColor]; - [self.view addSubview:black]; - [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary]; - [UIView beginAnimations:@"fading in from ingame" context:NULL]; - [UIView setAnimationDuration:1]; - black.alpha = 0; - [UIView commitAnimations]; - [black performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; - [black performSelector:@selector(release) withObject:nil afterDelay:1]; + NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", @"",@"savefile", + [NSNumber numberWithBool:NO],@"netgame", nil]; + [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; } else { DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n", mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController); diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/GameSetup.h --- a/project_files/HedgewarsMobile/Classes/GameSetup.h Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.h Thu Sep 23 01:30:35 2010 +0200 @@ -28,19 +28,24 @@ NSInteger ipcPort; // Port on which engine will listen TCPsocket csd; // Client socket descriptor + + NSString *savePath; + BOOL isNetGame; } @property (nonatomic, retain) NSDictionary *systemSettings; @property (nonatomic, retain) NSDictionary *gameConfig; +@property (nonatomic, retain) NSString *savePath; -(id) initWithDictionary:(NSDictionary *)gameDictionary; -(void) engineProtocol; -(void) startThread:(NSString *)selector; -(int) sendToEngine:(NSString *)string; +-(int) sendToEngineNoSave:(NSString *)string; -(void) provideTeamData:(NSString *)teamName forHogs:(NSInteger) numberOfPlayingHogs withHealth:(NSInteger) initialHealth ofColor:(NSNumber *)teamColor; -(void) provideAmmoData:(NSString *)ammostoreName forPlayingTeams:(NSInteger) numberOfTeams; -(NSInteger) provideScheme:(NSString *)schemeName; --(const char **)getSettings; +-(const char **)getSettings:(NSString *)recordFile; @end diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Thu Sep 23 01:30:35 2010 +0200 @@ -24,12 +24,12 @@ #import "SDL_net.h" #import "PascalImports.h" #import "CommodityFunctions.h" +#import "NSStringExtra.h" -#define BUFFER_SIZE 256 +#define BUFFER_SIZE 64 @implementation GameSetup - -@synthesize systemSettings, gameConfig; +@synthesize systemSettings, gameConfig, savePath; -(id) initWithDictionary:(NSDictionary *)gameDictionary { if (self = [super init]) { @@ -40,7 +40,18 @@ self.systemSettings = dictSett; [dictSett release]; - self.gameConfig = gameDictionary; + self.gameConfig = [gameDictionary objectForKey:@"game_dictionary"]; + isNetGame = [[gameDictionary objectForKey:@"netgame"] boolValue]; + NSString *path = [gameDictionary objectForKey:@"savefile"]; + // if path is empty it means i have to create a new file, otherwise i read from that file + if ([path isEqualToString:@""] == YES) { + NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; + [outputFormatter setDateFormat:@"yyyy-MM-dd 'at' HH,mm"]; + NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]]; + self.savePath = [SAVES_DIRECTORY() stringByAppendingFormat:@"%@.hws", newDateString]; + [outputFormatter release]; + } else + self.savePath = path; } return self; } @@ -48,6 +59,7 @@ -(void) dealloc { [gameConfig release]; [systemSettings release]; + [savePath release]; [super dealloc]; } @@ -238,10 +250,19 @@ [NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; } -// wrapper that computes the length of the message and then sends the command string +// wrapper that computes the length of the message and then sends the command string, saving the command on a file -(int) sendToEngine: (NSString *)string { uint8_t length = [string length]; + [[NSString stringWithFormat:@"%c%@",length,string] appendToFile:savePath]; + SDLNet_TCP_Send(csd, &length , 1); + return SDLNet_TCP_Send(csd, [string UTF8String], length); +} + +// wrapper that computes the length of the message and then sends the command string, skipping file writing +-(int) sendToEngineNoSave: (NSString *)string { + uint8_t length = [string length]; + SDLNet_TCP_Send(csd, &length , 1); return SDLNet_TCP_Send(csd, [string UTF8String], length); } @@ -294,8 +315,12 @@ case 'C': DLog(@"sending game config...\n%@",self.gameConfig); - // local game - [self sendToEngine:@"TL"]; + if (isNetGame == YES) + [self sendToEngineNoSave:@"TN"]; + else + [self sendToEngineNoSave:@"TL"]; + NSString *saveHeader = @"TS"; + [[NSString stringWithFormat:@"%c%@",[saveHeader length], saveHeader] appendToFile:savePath]; // seed info [self sendToEngine:[self.gameConfig objectForKey:@"seed_command"]]; @@ -335,6 +360,8 @@ clientQuit = YES; break; case 'e': + buffer[msgSize] = '\0'; + [[NSString stringWithUTF8String:buffer] appendToFile:savePath]; sscanf(buffer, "%*s %d", &eProto); short int netProto = 0; char *versionStr; @@ -361,7 +388,9 @@ default: // empty packet or just statistics -- in either cases gameTicks is sent gameTicks = SDLNet_Read16 (&buffer[msgSize - 2]); - //DLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer); + DLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer); + buffer[msgSize] = '\0'; + [[NSString stringWithUTF8String:buffer] appendToFile:savePath]; break; } } @@ -380,7 +409,7 @@ #pragma mark - #pragma mark Setting methods // returns an array of c-strings that are read by engine at startup --(const char **)getSettings { +-(const char **)getSettings: (NSString *)recordFile { NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", ipcPort]; NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; CGRect screenBounds = [[UIScreen mainScreen] bounds]; @@ -421,7 +450,7 @@ gameArgs[ 7] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled gameArgs[ 8] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage gameArgs[ 9] = NULL; //unused - gameArgs[10] = NULL; //recordFileName + gameArgs[10] = [recordFile UTF8String]; //recordFileName [wSize release]; [hSize release]; diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/MainMenuViewController.h --- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.h Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.h Thu Sep 23 01:30:35 2010 +0200 @@ -24,18 +24,21 @@ @class SplitViewRootController; @class GameConfigViewController; @class AboutViewController; +@class SavedGamesViewController; @interface MainMenuViewController : UIViewController { UILabel *versionLabel; GameConfigViewController *gameConfigViewController; SplitViewRootController *settingsViewController; AboutViewController *aboutViewController; + SavedGamesViewController *savedGamesViewController; } @property (nonatomic,retain) IBOutlet UILabel *versionLabel; @property (nonatomic,retain) GameConfigViewController *gameConfigViewController; @property (nonatomic,retain) SplitViewRootController *settingsViewController; @property (nonatomic,retain) AboutViewController *aboutViewController; +@property (nonatomic,retain) SavedGamesViewController *savedGamesViewController; -(IBAction) switchViews:(id)sender; diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/MainMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Thu Sep 23 01:30:35 2010 +0200 @@ -27,9 +27,10 @@ #import "GameConfigViewController.h" #import "SplitViewRootController.h" #import "AboutViewController.h" +#import "SavedGamesViewController.h" @implementation MainMenuViewController -@synthesize versionLabel, gameConfigViewController, settingsViewController, aboutViewController; +@synthesize versionLabel, gameConfigViewController, settingsViewController, aboutViewController, savedGamesViewController; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { return rotationManager(interfaceOrientation); @@ -76,6 +77,11 @@ NSString *directoryToCheck, *fileToCheck, *fileToUpdate; DLog(@"Creating necessary files"); + // create an empty saves directory by deleting the previous one (saves are incompatible between releases) + if ([[NSFileManager defaultManager] fileExistsAtPath:SAVES_DIRECTORY()]) + [[NSFileManager defaultManager] removeItemAtPath:SAVES_DIRECTORY() error:NULL]; + [[NSFileManager defaultManager] createDirectoryAtPath:SAVES_DIRECTORY() withIntermediateDirectories:NO attributes:nil error:NULL]; + // if the settings file is already present, we merge current preferences with the update directoryToCheck = [NSString stringWithFormat:@"%@/Settings/settings.plist",resDir]; if ([[NSFileManager defaultManager] fileExistsAtPath:SETTINGS_FILE()]) { @@ -225,7 +231,8 @@ -(IBAction) switchViews:(id) sender { UIButton *button = (UIButton *)sender; UIAlertView *alert; - NSString *xib; + NSString *xib = nil; + NSString *debugStr = nil; playSound(@"clickSound"); switch (button.tag) { @@ -255,16 +262,7 @@ [self presentModalViewController:self.settingsViewController animated:YES]; break; case 3: - if (nil == self.aboutViewController) { - AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; - about.modalTransitionStyle = UIModalTransitionStyleCoverVertical; - about.modalPresentationStyle = UIModalPresentationFormSheet; - self.aboutViewController = about; - [about release]; - } - - [self presentModalViewController:self.aboutViewController animated:YES]; - /* +#ifdef DEBUG debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE()]; UITextView *scroll = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; scroll.text = debugStr; @@ -278,7 +276,28 @@ [scroll addSubview:btn]; [self.view addSubview:scroll]; [scroll release]; - */ +#else + if (nil == self.aboutViewController) { + AboutViewController *about = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; + about.modalTransitionStyle = UIModalTransitionStyleCoverVertical; + about.modalPresentationStyle = UIModalPresentationFormSheet; + self.aboutViewController = about; + [about release]; + } + + [self presentModalViewController:self.aboutViewController animated:YES]; +#endif + break; + case 4: + if (nil == self.savedGamesViewController) { + SavedGamesViewController *savedgames = [[SavedGamesViewController alloc] initWithNibName:@"SavedGamesViewController" bundle:nil]; + savedgames.modalTransitionStyle = UIModalTransitionStyleCoverVertical; + savedgames.modalPresentationStyle = UIModalPresentationFormSheet; + self.savedGamesViewController = savedgames; + [savedgames release]; + } + + [self presentModalViewController:self.savedGamesViewController animated:YES]; break; default: alert = [[UIAlertView alloc] initWithTitle:@"Not Yet Implemented" @@ -303,6 +322,7 @@ self.gameConfigViewController = nil; self.settingsViewController = nil; self.aboutViewController = nil; + self.savedGamesViewController = nil; MSG_DIDUNLOAD(); [super viewDidUnload]; } @@ -312,6 +332,7 @@ [settingsViewController release]; [gameConfigViewController release]; [aboutViewController release]; + [savedGamesViewController release]; [super dealloc]; } diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/NSStringExtra.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/NSStringExtra.h Thu Sep 23 01:30:35 2010 +0200 @@ -0,0 +1,29 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 21/09/2010. + */ + + +#import + +@interface NSString (extra) + +-(BOOL) appendToFile:(NSString *)path; +-(BOOL) appendToFile:(NSString *)path usingEncoding:(NSStringEncoding) encoding; + +@end diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/NSStringExtra.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/NSStringExtra.m Thu Sep 23 01:30:35 2010 +0200 @@ -0,0 +1,55 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 21/09/2010. + */ + + +#import "NSStringExtra.h" + +@implementation NSString (extra) + +-(BOOL) appendToFile:(NSString *)path { + NSOutputStream* os = [[NSOutputStream alloc] initToFileAtPath:path append:YES]; + NSData *allData = [self dataUsingEncoding:NSUTF8StringEncoding]; + + [os open]; + [os write:[allData bytes] maxLength:[allData length]]; + [os close]; + + [os release]; + return YES; +} + + +// by http://iphonedevelopment.blogspot.com/2010/08/nsstring-appendtofileusingencoding.html +-(BOOL) appendToFile:(NSString *)path usingEncoding:(NSStringEncoding) encoding { + NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:path]; + if (fh == nil) + return [self writeToFile:path atomically:YES encoding:encoding error:nil]; + + [fh truncateFileAtOffset:[fh seekToEndOfFile]]; + NSData *encoded = [self dataUsingEncoding:encoding]; + + if (encoded == nil) + return NO; + + [fh writeData:encoded]; + return YES; +} + +@end diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Sep 23 01:30:35 2010 +0200 @@ -78,16 +78,25 @@ } // main routine for calling the actual game engine --(IBAction) startSDLgame: (NSDictionary *)gameDictionary { +-(void) startSDLgame:(NSDictionary *)gameDictionary { + UIWindow *aWin = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; + + UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aWin.frame.size.width, aWin.frame.size.height)]; + blackView.opaque = YES; + blackView.backgroundColor = [UIColor blackColor]; + [aWin addSubview:blackView]; + // pull out useful configuration info from various files GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary]; - - [setup startThread:@"engineProtocol"]; - const char **gameArgs = [setup getSettings]; + NSNumber *isNetGameNum = [gameDictionary objectForKey:@"netgame"]; + + if ([isNetGameNum boolValue] == NO) + [setup startThread:@"engineProtocol"]; + const char **gameArgs = [setup getSettings:[gameDictionary objectForKey:@"savefile"]]; [setup release]; // since the sdlwindow is not yet created, we add the overlayController with a delay - [self performSelector:@selector(displayOverlayLater) withObject:nil afterDelay:0.1]; + [self performSelector:@selector(displayOverlayLater:) withObject:isNetGameNum afterDelay:0.1]; // this is the pascal fuction that starts the game (wrapped around isInGame) isInGame = YES; @@ -95,15 +104,16 @@ isInGame = NO; free(gameArgs); - // bring the uiwindow below in front - UIWindow *aWin = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; [aWin makeKeyAndVisible]; - - // notice that in the simulator this reports 2 windows - DLog(@"%@",[[UIApplication sharedApplication] windows]); + [UIView beginAnimations:@"fading in from ingame" context:NULL]; + [UIView setAnimationDuration:1]; + blackView.alpha = 0; + [UIView commitAnimations]; + [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; + [blackView performSelector:@selector(release) withObject:nil afterDelay:1]; } --(void) displayOverlayLater { +-(void) displayOverlayLater:(NSNumber *)isNetGame { // overlay with controls, become visible later, with a transparency effect OverlayViewController *overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SavedGamesViewController.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.h Thu Sep 23 01:30:35 2010 +0200 @@ -0,0 +1,36 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 22/09/2010. + */ + + +#import + + +@interface SavedGamesViewController : UIViewController { + UITableView *tableView; + NSMutableArray *listOfSavegames; +} + +@property (nonatomic,retain) IBOutlet UITableView *tableView; +@property (nonatomic,retain) NSMutableArray *listOfSavegames; + + +-(IBAction) buttonPressed:(id) sender; + +@end diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SavedGamesViewController.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Thu Sep 23 01:30:35 2010 +0200 @@ -0,0 +1,112 @@ +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 22/09/2010. + */ + + +#import "SavedGamesViewController.h" +#import "SDL_uikitappdelegate.h" +#import "CommodityFunctions.h" + +@implementation SavedGamesViewController +@synthesize tableView, listOfSavegames; + +-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { + return rotationManager(interfaceOrientation); +} + +-(void) viewDidLoad { + self.tableView.backgroundView = nil; + + [super viewDidLoad]; +} + +-(void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + + NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SAVES_DIRECTORY() error:NULL]; + NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; + self.listOfSavegames = array; + [array release]; + + [self.tableView reloadData]; +} + +-(IBAction) buttonPressed:(id) sender { + playSound(@"backSound"); + [[self parentViewController] dismissModalViewControllerAnimated:YES]; +} + +#pragma mark - +#pragma mark Table view data source +-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return [self.listOfSavegames count]; +} + +-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier = @"Cell"; + + UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; + + // first all the names, then the title (which is offset 5) + cell.textLabel.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + + return cell; +} + +#pragma mark - +#pragma mark Table view delegate +-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; + + NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]]; + + NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys: + [NSDictionary dictionary],@"game_dictionary", + filePath,@"savefile", + [NSNumber numberWithBool:NO],@"netgame", + nil]; + [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; +} + +#pragma mark - +#pragma mark Memory Management +-(void) didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} + +-(void) viewDidUnload { + self.tableView = nil; + self.listOfSavegames = nil; + [super viewDidUnload]; +} + +-(void) dealloc { + [tableView release]; + [listOfSavegames release]; + [super dealloc]; +} + +@end diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib Thu Sep 23 01:30:35 2010 +0200 @@ -0,0 +1,502 @@ + + + + 1024 + 10F569 + 788 + 1038.29 + 461.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 117 + + + YES + + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + YES + + + + YES + + IBFilesOwner + IBIPadFramework + + + IBFirstResponder + IBIPadFramework + + + + 292 + + YES + + + 290 + {408, 44} + + NO + IBIPadFramework + + YES + + IBIPadFramework + 1 + + 0 + + + + + + 274 + {{0, 44}, {408, 414}} + + + 1 + MCAwIDAgMAA + + YES + IBIPadFramework + YES + 1 + 2 + 0 + YES + 44 + 10 + 10 + + + {408, 458} + + + 3 + MQA + + NO + + 3 + + IBIPadFramework + + + + + YES + + + view + + + + 3 + + + + buttonPressed: + + + + 6 + + + + dataSource + + + + 8 + + + + delegate + + + + 9 + + + + tableView + + + + 10 + + + + + YES + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 2 + + + YES + + + + + + + 4 + + + YES + + + + + + 5 + + + + + 7 + + + + + + + YES + + YES + -1.CustomClassName + -2.CustomClassName + 2.IBEditorWindowLastContentRect + 2.IBPluginDependency + 4.IBPluginDependency + 5.IBPluginDependency + 7.IBPluginDependency + + + YES + SavedGamesViewController + UIResponder + {{677, 547}, {408, 458}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 10 + + + + YES + + SavedGamesViewController + UIViewController + + buttonPressed: + id + + + buttonPressed: + + buttonPressed: + id + + + + tableView + UITableView + + + tableView + + tableView + UITableView + + + + IBProjectSource + Classes/SavedGamesViewController.h + + + + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CAAnimation.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CALayer.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIBarButtonItem + UIBarItem + + IBFrameworkSource + UIKit.framework/Headers/UIBarButtonItem.h + + + + UIBarItem + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIBarItem.h + + + + UIResponder + NSObject + + + + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UITableView + UIScrollView + + IBFrameworkSource + UIKit.framework/Headers/UITableView.h + + + + UIToolbar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIToolbar.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UIPopoverController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UISplitViewController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + + 0 + IBIPadFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + ../Hedgewars.xcodeproj + 3 + 117 + + diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SupportViewController.h --- a/project_files/HedgewarsMobile/Classes/SupportViewController.h Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SupportViewController.h Thu Sep 23 01:30:35 2010 +0200 @@ -1,14 +1,26 @@ -// -// SupportViewController.h -// Hedgewars -// -// Created by Vittorio on 19/09/10. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// +/* + * Hedgewars-iOS, a Hedgewars port for iOS devices + * Copyright (c) 2009-2010 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * File created on 19/09/2010. + */ + #import - @interface SupportViewController : UIViewController { } diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Classes/SupportViewController.m --- a/project_files/HedgewarsMobile/Classes/SupportViewController.m Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SupportViewController.m Thu Sep 23 01:30:35 2010 +0200 @@ -18,6 +18,7 @@ * File created on 19/09/2010. */ + #import "SupportViewController.h" #import "CommodityFunctions.h" diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Sep 23 01:30:35 2010 +0200 @@ -25,6 +25,9 @@ 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD14FF0DC6FC520079059D /* OpenGLES.framework */; }; 28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD15070DC6FC5B0079059D /* QuartzCore.framework */; settings = {ATTRIBUTES = (Required, ); }; }; + 611D9B12124949D000008271 /* NSStringExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 611D9B11124949D000008271 /* NSStringExtra.m */; }; + 611D9BFB12497E9800008271 /* SavedGamesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 611D9BF912497E9800008271 /* SavedGamesViewController.m */; }; + 611D9BFC12497E9800008271 /* SavedGamesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 611D9BFA12497E9800008271 /* SavedGamesViewController.xib */; }; 611E03E711FA747C0077A41E /* libvorbis.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 611E037C11FA74590077A41E /* libvorbis.a */; }; 611E0E5111FA92170077A41E /* libfreetype.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 611E0E5011FA92130077A41E /* libfreetype.a */; }; 611E0EE711FB20610077A41E /* ammoButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 611E0EE511FB20610077A41E /* ammoButton.png */; }; @@ -692,6 +695,11 @@ 28FD14FF0DC6FC520079059D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 28FD15070DC6FC5B0079059D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 32CA4F630368D1EE00C91783 /* Hedgewars_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Hedgewars_Prefix.pch; sourceTree = ""; }; + 611D9B10124949D000008271 /* NSStringExtra.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSStringExtra.h; path = Classes/NSStringExtra.h; sourceTree = ""; }; + 611D9B11124949D000008271 /* NSStringExtra.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NSStringExtra.m; path = Classes/NSStringExtra.m; sourceTree = ""; }; + 611D9BF812497E9800008271 /* SavedGamesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SavedGamesViewController.h; sourceTree = ""; }; + 611D9BF912497E9800008271 /* SavedGamesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SavedGamesViewController.m; sourceTree = ""; }; + 611D9BFA12497E9800008271 /* SavedGamesViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SavedGamesViewController.xib; sourceTree = ""; }; 611E02EC11FA74580077A41E /* cocos2d-iphone.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "cocos2d-iphone.xcodeproj"; path = "../../../Library/cocos2d/cocos2d-iphone.xcodeproj"; sourceTree = SOURCE_ROOT; }; 611E0E4B11FA92130077A41E /* freetype.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = freetype.xcodeproj; path = "../../../Library/freetype/Xcode-iPhoneOS/freetype.xcodeproj"; sourceTree = SOURCE_ROOT; }; 611E0EE511FB20610077A41E /* ammoButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ammoButton.png; path = Resources/Overlay/ammoButton.png; sourceTree = ""; }; @@ -920,6 +928,7 @@ children = ( 6163EE4D11CC247D001C0453 /* Game Config */, 6163EE4C11CC2478001C0453 /* Settings Pages */, + 611D9BF312497B7700008271 /* Other Controllers */, 6163EE6C11CC253F001C0453 /* Overlay */, 616591F011CA9BA200D6E256 /* MainMenuViewController.h */, 616591F111CA9BA200D6E256 /* MainMenuViewController.m */, @@ -972,6 +981,8 @@ 6165922B11CA9BD500D6E256 /* SquareButtonView.m */, 6165922C11CA9BD500D6E256 /* UIImageExtra.h */, 6165922D11CA9BD500D6E256 /* UIImageExtra.m */, + 611D9B10124949D000008271 /* NSStringExtra.h */, + 611D9B11124949D000008271 /* NSStringExtra.m */, ); name = "Other Sources"; sourceTree = ""; @@ -1027,6 +1038,19 @@ name = Frameworks; sourceTree = ""; }; + 611D9BF312497B7700008271 /* Other Controllers */ = { + isa = PBXGroup; + children = ( + 61F2E7CB1205EDE0005734F7 /* AboutViewController.h */, + 61F2E7CC1205EDE0005734F7 /* AboutViewController.m */, + 61F2E7CD1205EDE0005734F7 /* AboutViewController.xib */, + 611D9BF812497E9800008271 /* SavedGamesViewController.h */, + 611D9BF912497E9800008271 /* SavedGamesViewController.m */, + 611D9BFA12497E9800008271 /* SavedGamesViewController.xib */, + ); + name = "Other Controllers"; + sourceTree = ""; + }; 611E02ED11FA74580077A41E /* Products */ = { isa = PBXGroup; children = ( @@ -1208,9 +1232,6 @@ 616591F611CA9BA200D6E256 /* OverlayViewController.h */, 616591F711CA9BA200D6E256 /* OverlayViewController.m */, 6165925011CA9CB400D6E256 /* OverlayViewController.xib */, - 61F2E7CB1205EDE0005734F7 /* AboutViewController.h */, - 61F2E7CC1205EDE0005734F7 /* AboutViewController.m */, - 61F2E7CD1205EDE0005734F7 /* AboutViewController.xib */, 611EEAEB122B2A4D00DF6938 /* HelpPageViewController.h */, 611EEAEC122B2A4D00DF6938 /* HelpPageViewController.m */, 611EEAED122B2A4D00DF6938 /* HelpPageLobbyViewController.xib */, @@ -2029,6 +2050,7 @@ 61842B40122B66280096E335 /* helpleft.png in Resources */, 6199E83A124647DE00DADF8C /* SupportViewController.xib in Resources */, 6199E86D12464A8E00DADF8C /* surpise.png in Resources */, + 611D9BFC12497E9800008271 /* SavedGamesViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2155,6 +2177,8 @@ 61F2E7CE1205EDE0005734F7 /* AboutViewController.m in Sources */, 611EEAEE122B2A4D00DF6938 /* HelpPageViewController.m in Sources */, 6199E839124647DE00DADF8C /* SupportViewController.m in Sources */, + 611D9B12124949D000008271 /* NSStringExtra.m in Sources */, + 611D9BFB12497E9800008271 /* SavedGamesViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff -r 59de68d541f1 -r 88f8e7b1777e project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib --- a/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Wed Sep 22 21:58:32 2010 +0200 +++ b/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Thu Sep 23 01:30:35 2010 +0200 @@ -120,7 +120,7 @@ 292 - {{20, 729}, {18, 19}} + {{20, 19}, {18, 19}} NO 3 @@ -182,11 +182,30 @@ MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - + NSImage settingsButton.png + + + 292 + {{20, 686}, {72, 62}} + + NO + 4 + IBIPadFramework + 0 + 0 + + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + {1024, 768} @@ -255,6 +274,15 @@ 54 + + + switchViews: + + + 7 + + 89 + @@ -273,9 +301,10 @@ - + + @@ -322,6 +351,11 @@ + + 88 + + + @@ -338,6 +372,7 @@ 45.IBPluginDependency 50.IBPluginDependency 52.IBPluginDependency + 88.IBPluginDependency YES @@ -351,6 +386,7 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -369,7 +405,7 @@ - 87 + 89