# HG changeset patch # User koda # Date 1285465290 -7200 # Node ID 7768ac820d5a91eb1b2bb63e0a09cb1e7db8fb51 # Parent 22e4d74240e5f5f0178e9e0fa98cf87daa52d545# Parent 124b4755914b388e94711d6aee567a175f768197 merge diff -r 124b4755914b -r 7768ac820d5a hedgewars/PascalExports.pas --- a/hedgewars/PascalExports.pas Sat Sep 25 23:01:52 2010 +0400 +++ b/hedgewars/PascalExports.pas Sun Sep 26 03:41:30 2010 +0200 @@ -165,11 +165,6 @@ if closeFrontend then alsoShutdownFrontend:= true; end; -procedure HW_dismissReady; cdecl; export; -begin - ReadyTimeLeft:= 0; -end; - procedure HW_setLandscape(landscape: boolean); cdecl; export; begin if landscape then diff -r 124b4755914b -r 7768ac820d5a hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sat Sep 25 23:01:52 2010 +0400 +++ b/hedgewars/SDLh.pas Sun Sep 26 03:41:30 2010 +0200 @@ -848,6 +848,8 @@ procedure startSpinning; cdecl; external; procedure stopSpinning; cdecl; external; function isPhone: Boolean; cdecl; external; +procedure replayBegan; cdecl; external; +procedure replayFinished; cdecl; external; {$ENDIF} implementation diff -r 124b4755914b -r 7768ac820d5a hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sat Sep 25 23:01:52 2010 +0400 +++ b/hedgewars/hwengine.pas Sun Sep 26 03:41:30 2010 +0200 @@ -266,10 +266,6 @@ ControllerInit(); // has to happen before InitKbdKeyTable to map keys InitKbdKeyTable(); - if recordFileName = '' then - InitIPC; - WriteLnToConsole(msgGettingConfig); - LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english if cLocaleFName <> 'en.txt' then begin @@ -279,10 +275,19 @@ LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName); end; + WriteLnToConsole(msgGettingConfig); if recordFileName = '' then - SendIPCAndWaitReply('C') // ask for game config + begin + InitIPC; + SendIPCAndWaitReply('C'); // ask for game config + end else + begin LoadRecordFromFile(recordFileName); +{$IFDEF IPHONEOS} + replayBegan(); +{$ENDIF} + end; ScriptOnGameInit; diff -r 124b4755914b -r 7768ac820d5a hedgewars/uGame.pas --- a/hedgewars/uGame.pas Sat Sep 25 23:01:52 2010 +0400 +++ b/hedgewars/uGame.pas Sun Sep 26 03:41:30 2010 +0200 @@ -26,7 +26,7 @@ //////////////////// implementation //////////////////// -uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript; +uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript, uSound, SDLh; procedure DoGameTick(Lag: LongInt); var i: LongInt; @@ -65,7 +65,12 @@ SetBinds(CurrentTeam^.Binds); //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos isSoundEnabled:= isSEBackup; - GameType:= gmtLocal + if isSoundEnabled then playMusic; + GameType:= gmtLocal; + InitIPC; +{$IFDEF IPHONEOS} + replayFinished(); +{$ENDIF} end; end else ProcessGears diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/AboutViewController.xib --- a/project_files/HedgewarsMobile/Classes/AboutViewController.xib Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/AboutViewController.xib Sun Sep 26 03:41:30 2010 +0200 @@ -12,7 +12,6 @@ YES - YES @@ -50,8 +49,9 @@ 292 - {{70, 7}, {289, 30}} + {{127, 7}, {289, 30}} + NO IBIPadFramework 2 @@ -99,8 +99,9 @@ - {429, 44} + {543, 44} + IBIPadFramework YES @@ -120,8 +121,9 @@ 274 - {{0, 44}, {429, 433}} + {{0, 44}, {543, 577}} + NO IBIPadFramework @@ -132,8 +134,9 @@ 274 - {{0, 44}, {429, 433}} + {{0, 44}, {543, 577}} + 1 MCAwIDAgMAA @@ -150,8 +153,9 @@ 10 - {429, 477} + {543, 621} + 3 MQA @@ -318,7 +322,7 @@ UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - {{505, 182}, {429, 477}} + {{376, 170}, {543, 621}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -685,7 +689,7 @@ 3 background_small.png - {320, 436} + {539, 639} 117 diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/EditableCellView.h --- a/project_files/HedgewarsMobile/Classes/EditableCellView.h Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/EditableCellView.h Sun Sep 26 03:41:30 2010 +0200 @@ -33,6 +33,7 @@ UILabel *titleLabel; NSInteger minimumCharacters; NSInteger maximumCharacters; + BOOL respectEditing; @private NSString *oldValue; @@ -43,6 +44,7 @@ @property (nonatomic,retain,readonly) UILabel *titleLabel; @property (nonatomic,assign) NSInteger minimumCharacters; @property (nonatomic,assign) NSInteger maximumCharacters; +@property (nonatomic,assign) BOOL respectEditing; @property (nonatomic,retain) NSString *oldValue; -(void) replyKeyboard; diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/EditableCellView.m --- a/project_files/HedgewarsMobile/Classes/EditableCellView.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m Sun Sep 26 03:41:30 2010 +0200 @@ -23,7 +23,7 @@ #import "CommodityFunctions.h" @implementation EditableCellView -@synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, oldValue; +@synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, respectEditing, oldValue; -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { @@ -37,6 +37,7 @@ textField.clearsOnBeginEditing = NO; textField.returnKeyType = UIReturnKeyDone; textField.adjustsFontSizeToFitWidth = YES; + textField.userInteractionEnabled = YES; [textField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit]; [self.contentView addSubview:textField]; @@ -51,6 +52,7 @@ minimumCharacters = 1; maximumCharacters = 64; + respectEditing = NO; oldValue = nil; } return self; @@ -98,9 +100,11 @@ return !([aTextField.text length] > self.maximumCharacters && [string length] > range.length); } -// allow editing only if delegate is set and conformant to protocol +// allow editing only if delegate is set and conformant to protocol, and if editableOnlyWhileEditing -(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField { - return (delegate != nil) && [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)]; + return (delegate != nil) && + [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)] && + (respectEditing) ? ((UITableView*)[self superview]).editing : YES; } // the textfield is being modified, update the navigation controller @@ -177,4 +181,12 @@ self.oldValue = nil; } +// when field is editable only when the tableview is editable, resign responder when exiting editing mode +-(void) willTransitionToState:(UITableViewCellStateMask)state { + if (respectEditing && state == UITableViewCellStateDefaultMask) + [self save:nil]; + + [super willTransitionToState:state]; +} + @end diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/GameSetup.m --- a/project_files/HedgewarsMobile/Classes/GameSetup.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Sun Sep 26 03:41:30 2010 +0200 @@ -25,8 +25,9 @@ #import "PascalImports.h" #import "CommodityFunctions.h" #import "NSStringExtra.h" +#import "OverlayViewController.h" -#define BUFFER_SIZE 64 +#define BUFFER_SIZE 255 // like in original frontend @implementation GameSetup @synthesize systemSettings, gameConfig, savePath; @@ -255,7 +256,7 @@ uint8_t length = [string length]; [[NSString stringWithFormat:@"%c%@",length,string] appendToFile:savePath]; - SDLNet_TCP_Send(csd, &length , 1); + SDLNet_TCP_Send(csd, &length, 1); return SDLNet_TCP_Send(csd, [string UTF8String], length); } @@ -263,7 +264,7 @@ -(int) sendToEngineNoSave: (NSString *)string { uint8_t length = [string length]; - SDLNet_TCP_Send(csd, &length , 1); + SDLNet_TCP_Send(csd, &length, 1); return SDLNet_TCP_Send(csd, [string UTF8String], length); } @@ -274,9 +275,8 @@ IPaddress ip; int eProto; BOOL clientQuit; - char buffer[BUFFER_SIZE]; + uint8_t buffer[BUFFER_SIZE]; uint8_t msgSize; - uint16_t gameTicks; clientQuit = NO; csd = NULL; @@ -304,12 +304,14 @@ SDLNet_TCP_Close(sd); while (!clientQuit) { + NSString *msgToSave = nil; + NSOutputStream *os = nil; msgSize = 0; - memset(buffer, 0, BUFFER_SIZE); + memset(buffer, '\0', BUFFER_SIZE); if (SDLNet_TCP_Recv(csd, &msgSize, sizeof(uint8_t)) <= 0) - clientQuit = YES; + break; if (SDLNet_TCP_Recv(csd, buffer, msgSize) <=0) - clientQuit = YES; + break; switch (buffer[0]) { case 'C': @@ -360,9 +362,10 @@ clientQuit = YES; break; case 'e': - buffer[msgSize] = '\0'; - [[NSString stringWithUTF8String:buffer] appendToFile:savePath]; - sscanf(buffer, "%*s %d", &eProto); + msgToSave = [NSString stringWithFormat:@"%c%s",msgSize,buffer]; + [msgToSave appendToFile:self.savePath]; + + sscanf((char *)buffer, "%*s %d", &eProto); short int netProto = 0; char *versionStr; @@ -373,24 +376,36 @@ DLog(@"ERROR - wrong protocol number: [%s] - expecting %d", &buffer[1], eProto); clientQuit = YES; } - break; case 'i': switch (buffer[1]) { case 'r': - NSLog(@"Winning team: %s", &buffer[2]); + DLog(@"Winning team: %s", &buffer[2]); break; case 'k': - NSLog(@"Best Hedgehog: %s", &buffer[2]); + DLog(@"Best Hedgehog: %s", &buffer[2]); + break; + default: + // TODO: losta stats stuff break; } break; + case 'q': + // game ended, can remove the savefile + [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; + // so update the relative viewcontroler + [[NSNotificationCenter defaultCenter] postNotificationName:@"removedSave" object:nil]; + // and disable the overlay + setGameRunning(NO); + break; 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); - buffer[msgSize] = '\0'; - [[NSString stringWithUTF8String:buffer] appendToFile:savePath]; + // is it performant to reopen the stream every time? + os = [[NSOutputStream alloc] initToFileAtPath:self.savePath append:YES]; + [os open]; + [os write:&msgSize maxLength:1]; + [os write:buffer maxLength:msgSize]; + [os close]; + [os release]; break; } } diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/MainMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Sun Sep 26 03:41:30 2010 +0200 @@ -292,7 +292,7 @@ if (nil == self.savedGamesViewController) { SavedGamesViewController *savedgames = [[SavedGamesViewController alloc] initWithNibName:@"SavedGamesViewController" bundle:nil]; savedgames.modalTransitionStyle = UIModalTransitionStyleCoverVertical; - savedgames.modalPresentationStyle = UIModalPresentationFormSheet; + savedgames.modalPresentationStyle = UIModalPresentationPageSheet; self.savedGamesViewController = savedgames; [savedgames release]; } diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/NSStringExtra.m --- a/project_files/HedgewarsMobile/Classes/NSStringExtra.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/NSStringExtra.m Sun Sep 26 03:41:30 2010 +0200 @@ -35,6 +35,11 @@ return YES; } +-(BOOL) appendToFile:(NSString *)path usingStream:(NSOutputStream *)os { + NSData *allData = [self dataUsingEncoding:NSUTF8StringEncoding]; + [os write:[allData bytes] maxLength:[allData length]]; + return YES; +} // by http://iphonedevelopment.blogspot.com/2010/08/nsstring-appendtofileusingencoding.html -(BOOL) appendToFile:(NSString *)path usingEncoding:(NSStringEncoding) encoding { diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/OverlayViewController.h --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sun Sep 26 03:41:30 2010 +0200 @@ -66,7 +66,10 @@ @end -// understands when the loading screen is done +// actual game started (controls should be enabled) BOOL isGameRunning; +void setGameRunning(BOOL value); +// black screen present +BOOL isReplay; // cache the grenade time NSInteger cachedGrenadeTime; \ No newline at end of file diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/OverlayViewController.m --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Sep 26 03:41:30 2010 +0200 @@ -36,6 +36,7 @@ #define CONFIRMATION_TAG 5959 #define GRENADE_TAG 9595 +#define BLACKVIEW_TAG 9955 #define ANIMATION_DURATION 0.25 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; @@ -97,6 +98,7 @@ #pragma mark View Management -(void) viewDidLoad { isGameRunning = NO; + isReplay = NO; cachedGrenadeTime = 2; isAttacking = NO; @@ -212,7 +214,7 @@ // dim the overlay when there's no more input for a certain amount of time -(IBAction) buttonReleased:(id) sender { - if (!isGameRunning) + if (isGameRunning == NO) return; UIButton *theButton = (UIButton *)sender; @@ -244,15 +246,12 @@ // issue certain action based on the tag of the button -(IBAction) buttonPressed:(id) sender { [self activateOverlay]; - if (isPopoverVisible) { + + if (isGameRunning == NO) + return; + + if (isPopoverVisible) [self dismissPopover]; - } - - if (!isGameRunning) - return; - - if (HW_isWaiting()) - HW_dismissReady(); UIButton *theButton = (UIButton *)sender; switch (theButton.tag) { @@ -402,12 +401,11 @@ NSSet *allTouches = [event allTouches]; CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; + if (isGameRunning == NO) + return; + switch ([allTouches count]) { case 1: - // this dismisses the "get ready" - if (HW_isWaiting()) - HW_dismissReady(); - // if we're in the menu we just click in the point if (HW_isAmmoOpen()) { HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); @@ -507,9 +505,11 @@ CGRect screen = [[UIScreen mainScreen] bounds]; NSSet *allTouches = [event allTouches]; int x, y, dx, dy; - UITouch *touch, *first, *second; + if (isGameRunning == NO) + return; + switch ([allTouches count]) { case 1: touch = [[allTouches allObjects] objectAtIndex:0]; @@ -562,9 +562,13 @@ #pragma mark - #pragma mark Functions called by pascal -// called from AddProgress and FinishProgress (respectively) +void setGameRunning(BOOL value) { + isGameRunning = value; +} + +// called by uStore from AddProgress void startSpinning() { - isGameRunning = NO; + setGameRunning(NO); CGRect screen = [[UIScreen mainScreen] bounds]; UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; indicator.tag = 987654; @@ -575,13 +579,16 @@ [indicator release]; } +// called by uStore from FinishProgress void stopSpinning() { UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654]; [indicator stopAnimating]; - isGameRunning = YES; HW_zoomSet(1.7); + if (isReplay == NO) + setGameRunning(YES); } +// called by CCHandlers from chNextTurn void clearView() { UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; @@ -599,4 +606,34 @@ cachedGrenadeTime = 2; } +// called by hwengine +void replayBegan() { + UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; + UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame]; + blackView.backgroundColor = [UIColor blackColor]; + blackView.alpha = 0.6; + blackView.tag = BLACKVIEW_TAG; + blackView.exclusiveTouch = NO; + blackView.multipleTouchEnabled = NO; + blackView.userInteractionEnabled = NO; + [theWindow addSubview:blackView]; + [blackView release]; + isReplay = YES; +} + +// called by uGame +void replayFinished() { + UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; + UIView *blackView = (UIView *)[theWindow viewWithTag:BLACKVIEW_TAG]; + + [UIView beginAnimations:@"removing black" context:NULL]; + [UIView setAnimationDuration:1]; + blackView.alpha = 0; + [UIView commitAnimations]; + [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1]; + + setGameRunning(YES); + isReplay = NO; +} + @end diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/PascalImports.h --- a/project_files/HedgewarsMobile/Classes/PascalImports.h Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/PascalImports.h Sun Sep 26 03:41:30 2010 +0200 @@ -66,7 +66,6 @@ void HW_pause(void); void HW_terminate(BOOL andCloseFrontend); - void HW_dismissReady(void); void HW_setLandscape(BOOL rotate); void HW_setCursor(int x, int y); @@ -74,7 +73,6 @@ BOOL HW_isAmmoOpen(void); BOOL HW_isPaused(void); - BOOL HW_isWaiting(void); BOOL HW_isWeaponRequiringClick(void); BOOL HW_isWeaponTimerable(void); BOOL HW_isWeaponSwitch(void); diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/SavedGamesViewController.h --- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.h Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.h Sun Sep 26 03:41:30 2010 +0200 @@ -20,9 +20,9 @@ #import - +#import "EditableCellView.h" -@interface SavedGamesViewController : UIViewController { +@interface SavedGamesViewController : UIViewController { UITableView *tableView; NSMutableArray *listOfSavegames; } @@ -30,7 +30,7 @@ @property (nonatomic,retain) IBOutlet UITableView *tableView; @property (nonatomic,retain) NSMutableArray *listOfSavegames; - -(IBAction) buttonPressed:(id) sender; +-(IBAction) toggleEdit:(id) sender; @end diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/SavedGamesViewController.m --- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sun Sep 26 03:41:30 2010 +0200 @@ -32,7 +32,10 @@ -(void) viewDidLoad { self.tableView.backgroundView = nil; - + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(viewWillAppear:) + name:@"removedSave" + object:nil]; [super viewDidLoad]; } @@ -49,9 +52,15 @@ -(IBAction) buttonPressed:(id) sender { playSound(@"backSound"); + [self.tableView setEditing:NO animated:YES]; [[self parentViewController] dismissModalViewControllerAnimated:YES]; } +-(IBAction) toggleEdit:(id) sender { + BOOL isEditing = self.tableView.editing; + [self.tableView setEditing:!isEditing animated:YES]; +} + #pragma mark - #pragma mark Table view data source -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { @@ -65,15 +74,72 @@ -(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]; + EditableCellView *editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (editableCell == nil) { + editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + editableCell.delegate = self; + } + editableCell.tag = [indexPath row]; + editableCell.respectEditing = YES; + editableCell.textField.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; + editableCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + + UIImage *addImg = [UIImage imageWithContentsOfFile:@"plus.png"]; + UIButton *customButton = [UIButton buttonWithType:UIButtonTypeContactAdd]; + customButton.tag = [indexPath row]; + [customButton setImage:addImg forState:UIControlStateNormal]; + [customButton addTarget:self action:@selector(duplicateEntry:) forControlEvents:UIControlEventTouchUpInside]; + editableCell.editingAccessoryView = customButton; + + return (UITableViewCell *)editableCell; +} + +-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section { + UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)]; + footer.backgroundColor = [UIColor clearColor]; + + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width*80/100, 100)]; + label.center = CGPointMake(self.tableView.frame.size.width/2,70); + label.textAlignment = UITextAlignmentCenter; + label.font = [UIFont systemFontOfSize:16]; + label.textColor = [UIColor lightGrayColor]; + label.numberOfLines = 5; + label.text = NSLocalizedString(@"Games are automatically saved and can be resumed by selecting an entry above.\nYou can modify this list by pressing the 'Edit' button.\nNotice that completed games are deleted, so make backups.",@""); - // first all the names, then the title (which is offset 5) - cell.textLabel.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; - cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + label.backgroundColor = [UIColor clearColor]; + [footer addSubview:label]; + [label release]; + return [footer autorelease]; +} - return cell; +-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + NSUInteger row = [indexPath row]; + [(EditableCellView *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]] save:nil]; + + NSString *saveName = [self.listOfSavegames objectAtIndex:row]; + NSString *currentFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),saveName]; + [[NSFileManager defaultManager] removeItemAtPath:currentFilePath error:nil]; + [self.listOfSavegames removeObject:saveName]; + + [self.tableView reloadData]; +} + +-(void) duplicateEntry:(id) sender { + UIButton *button = (UIButton *)sender; + NSUInteger row = button.tag; + + [(EditableCellView *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]] save:nil]; + NSString *currentSaveName = [self.listOfSavegames objectAtIndex:row]; + NSString *newSaveName = [[currentSaveName stringByDeletingPathExtension] stringByAppendingFormat:@" %d.hws",[self.listOfSavegames count]]; + + NSString *currentFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),currentSaveName]; + NSString *newFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),newSaveName]; + [[NSFileManager defaultManager] copyItemAtPath:currentFilePath toPath:newFilePath error:nil]; + [self.listOfSavegames addObject:newSaveName]; + [self.listOfSavegames sortUsingSelector:@selector(compare:)]; + + //[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[self.listOfSavegames indexOfObject:newSaveName] inSection:0]] withRowAnimation:UITableViewRowAnimationFade]; + [self.tableView reloadData]; } #pragma mark - @@ -81,6 +147,8 @@ -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; + [(EditableCellView *)[self.tableView cellForRowAtIndexPath:indexPath] save:nil]; + NSString *filePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:[indexPath row]]]; NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys: @@ -92,6 +160,20 @@ } #pragma mark - +#pragma mark editableCellView delegate +// rename old file if names differ +-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { + NSString *oldFilePath = [NSString stringWithFormat:@"%@/%@",SAVES_DIRECTORY(),[self.listOfSavegames objectAtIndex:tagValue]]; + NSString *newFilePath = [NSString stringWithFormat:@"%@/%@.hws",SAVES_DIRECTORY(),textString]; + + if ([oldFilePath isEqualToString:newFilePath] == NO) { + [[NSFileManager defaultManager] moveItemAtPath:oldFilePath toPath:newFilePath error:nil]; + [self.listOfSavegames replaceObjectAtIndex:tagValue withObject:[textString stringByAppendingString:@".hws"]]; + } + +} + +#pragma mark - #pragma mark Memory Management -(void) didReceiveMemoryWarning { [super didReceiveMemoryWarning]; diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib --- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib Sun Sep 26 03:41:30 2010 +0200 @@ -12,7 +12,7 @@ YES - + YES @@ -42,10 +42,22 @@ 292 YES + + + 292 + {768, 768} + + NO + IBIPadFramework + + NSImage + background_med.png + + 290 - {408, 44} + {768, 44} NO IBIPadFramework @@ -57,12 +69,22 @@ 0 + + IBIPadFramework + + 5 + + + IBIPadFramework + + 2 + 274 - {{0, 44}, {408, 414}} + {{0, 44}, {768, 724}} 1 @@ -80,7 +102,7 @@ 10 - {408, 458} + {768, 768} 3 @@ -136,6 +158,14 @@ 10 + + + toggleEdit: + + + + 14 + @@ -164,6 +194,7 @@ YES + @@ -173,6 +204,8 @@ YES + + @@ -186,6 +219,21 @@ + + 11 + + + + + 12 + + + + + 13 + + + @@ -194,6 +242,9 @@ YES -1.CustomClassName -2.CustomClassName + 11.IBPluginDependency + 12.IBPluginDependency + 13.IBPluginDependency 2.IBEditorWindowLastContentRect 2.IBPluginDependency 4.IBPluginDependency @@ -204,7 +255,10 @@ YES SavedGamesViewController UIResponder - {{677, 547}, {408, 458}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{486, 215}, {768, 768}} com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -227,7 +281,7 @@ - 10 + 14 @@ -236,14 +290,35 @@ SavedGamesViewController UIViewController - buttonPressed: - id + YES + + YES + buttonPressed: + toggleEdit: + + + YES + id + id + - buttonPressed: - - buttonPressed: - id + YES + + YES + buttonPressed: + toggleEdit: + + + YES + + buttonPressed: + id + + + toggleEdit: + id + @@ -387,6 +462,14 @@ + UIImageView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIImageView.h + + + UIResponder NSObject @@ -497,6 +580,10 @@ YES ../Hedgewars.xcodeproj 3 + + background_med.png + {768, 768} + 117 diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Sun Sep 26 03:41:30 2010 +0200 @@ -41,7 +41,6 @@ action:@selector(toggleEdit:)]; self.navigationItem.rightBarButtonItem = editButton; [editButton release]; - } -(void) viewWillAppear:(BOOL) animated { diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/UIImageExtra.h --- a/project_files/HedgewarsMobile/Classes/UIImageExtra.h Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.h Sun Sep 26 03:41:30 2010 +0200 @@ -30,6 +30,7 @@ -(id) initWithContentsOfFile:(NSString *)path andCutAt:(CGRect) rect; -(UIImage *)cutAt:(CGRect) rect; -(UIImage *)convertToGrayScale; +-(UIImage *)convertToNegative; -(UIImage *)maskImageWith:(UIImage *)maskImage; -(UIImage *)makeRoundCornersOfSize:(CGSize) sizewh; diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Classes/UIImageExtra.m --- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m Sun Sep 26 03:41:30 2010 +0200 @@ -207,4 +207,17 @@ return newImage; } +// by http://www.sixtemia.com/journal/2010/06/23/uiimage-negative-color-effect/ +-(UIImage *)convertToNegative { + UIGraphicsBeginImageContext(self.size); + CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); + [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)]; + CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference); + CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor); + CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.size.width, self.size.height)); + UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return result; +} + @end diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Sun Sep 26 03:41:30 2010 +0200 @@ -28,6 +28,8 @@ 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 */; }; + 611DA031124E2BC500008271 /* background_med.png in Resources */ = {isa = PBXBuildFile; fileRef = 611DA030124E2BC500008271 /* background_med.png */; }; + 611DA1D0124E5C6300008271 /* plus.png in Resources */ = {isa = PBXBuildFile; fileRef = 611DA1CF124E5C6300008271 /* plus.png */; }; 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 */; }; @@ -700,6 +702,8 @@ 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 = ""; }; + 611DA030124E2BC500008271 /* background_med.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = background_med.png; path = Resources/Overlay/background_med.png; sourceTree = ""; }; + 611DA1CF124E5C6300008271 /* plus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = plus.png; path = Resources/Overlay/plus.png; 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 = ""; }; @@ -1291,6 +1295,8 @@ 6179936611501D1E00BA94A9 /* Overlay */ = { isa = PBXGroup; children = ( + 611DA1CF124E5C6300008271 /* plus.png */, + 611DA030124E2BC500008271 /* background_med.png */, 611E0EE511FB20610077A41E /* ammoButton.png */, 611E0EE611FB20610077A41E /* cornerButton.png */, 61EF920511DF57AC003441C4 /* arrowDown.png */, @@ -2051,6 +2057,8 @@ 6199E83A124647DE00DADF8C /* SupportViewController.xib in Resources */, 6199E86D12464A8E00DADF8C /* surpise.png in Resources */, 611D9BFC12497E9800008271 /* SavedGamesViewController.xib in Resources */, + 611DA031124E2BC500008271 /* background_med.png in Resources */, + 611DA1D0124E5C6300008271 /* plus.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib --- a/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Sat Sep 25 23:01:52 2010 +0400 +++ b/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Sun Sep 26 03:41:30 2010 +0200 @@ -12,7 +12,6 @@ YES - YES @@ -47,6 +46,7 @@ 274 {1024, 768} + NO IBIPadFramework @@ -59,6 +59,7 @@ 292 {{383, 427}, {263, 244}} + NO IBIPadFramework 0 @@ -95,6 +96,7 @@ -2147483356 {{611, 417}, {263, 244}} + NO 1 IBIPadFramework @@ -120,9 +122,11 @@ 292 - {{20, 19}, {18, 19}} + {{788, 300}, {18, 19}} + NO + 0.31690141558647156 3 IBIPadFramework 0 @@ -142,6 +146,7 @@ 292 {{376, 345}, {271, 21}} + NO YES 7 @@ -170,6 +175,7 @@ 292 {{932, 686}, {72, 62}} + NO 2 IBIPadFramework @@ -192,6 +198,7 @@ 292 {{20, 686}, {72, 62}} + NO 4 IBIPadFramework @@ -209,6 +216,7 @@ {1024, 768} + 1 MCAwIDAAA @@ -303,8 +311,8 @@ + - diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Resources/Overlay/background_med.png Binary file project_files/HedgewarsMobile/Resources/Overlay/background_med.png has changed diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Resources/Overlay/background_small.png Binary file project_files/HedgewarsMobile/Resources/Overlay/background_small.png has changed diff -r 124b4755914b -r 7768ac820d5a project_files/HedgewarsMobile/Resources/Overlay/plus.png Binary file project_files/HedgewarsMobile/Resources/Overlay/plus.png has changed