# HG changeset patch
# User koda
# Date 1285465268 -7200
# Node ID 22e4d74240e5f5f0178e9e0fa98cf87daa52d545
# Parent db01c37494aff6f730616058ba388a02883f65a8
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
diff -r db01c37494af -r 22e4d74240e5 hedgewars/PascalExports.pas
--- a/hedgewars/PascalExports.pas Sat Sep 25 18:38:05 2010 +0200
+++ b/hedgewars/PascalExports.pas Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 hedgewars/SDLh.pas
--- a/hedgewars/SDLh.pas Sat Sep 25 18:38:05 2010 +0200
+++ b/hedgewars/SDLh.pas Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 hedgewars/hwengine.pas
--- a/hedgewars/hwengine.pas Sat Sep 25 18:38:05 2010 +0200
+++ b/hedgewars/hwengine.pas Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 hedgewars/uGame.pas
--- a/hedgewars/uGame.pas Sat Sep 25 18:38:05 2010 +0200
+++ b/hedgewars/uGame.pas Sun Sep 26 03:41:08 2010 +0200
@@ -26,7 +26,7 @@
////////////////////
implementation
////////////////////
-uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript, uSound;
+uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript, uSound, SDLh;
procedure DoGameTick(Lag: LongInt);
var i: LongInt;
@@ -68,6 +68,9 @@
if isSoundEnabled then playMusic;
GameType:= gmtLocal;
InitIPC;
+{$IFDEF IPHONEOS}
+ replayFinished();
+{$ENDIF}
end;
end
else ProcessGears
diff -r db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/EditableCellView.h
--- a/project_files/HedgewarsMobile/Classes/EditableCellView.h Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/EditableCellView.h Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/EditableCellView.m
--- a/project_files/HedgewarsMobile/Classes/EditableCellView.m Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/GameSetup.m
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Sun Sep 26 03:41:08 2010 +0200
@@ -25,6 +25,7 @@
#import "PascalImports.h"
#import "CommodityFunctions.h"
#import "NSStringExtra.h"
+#import "OverlayViewController.h"
#define BUFFER_SIZE 255 // like in original frontend
@@ -375,7 +376,6 @@
DLog(@"ERROR - wrong protocol number: [%s] - expecting %d", &buffer[1], eProto);
clientQuit = YES;
}
-
break;
case 'i':
switch (buffer[1]) {
@@ -393,6 +393,10 @@
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:
// is it performant to reopen the stream every time?
diff -r db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/OverlayViewController.h
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/OverlayViewController.m
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/PascalImports.h
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h Sun Sep 26 03:41:08 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 db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/SavedGamesViewController.m
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m Sun Sep 26 03:41:08 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];
}
@@ -53,16 +56,9 @@
[[self parentViewController] dismissModalViewControllerAnimated:YES];
}
-// modifies the navigation bar to add the "Add" and "Done" buttons
-(IBAction) toggleEdit:(id) sender {
BOOL isEditing = self.tableView.editing;
[self.tableView setEditing:!isEditing animated:YES];
-
- UIBarButtonItem *barButton = (UIBarButtonItem *)sender;
- if (isEditing)
- [barButton setTitle:NSLocalizedString(@"Edit",@"")];
- else
- [barButton setTitle:NSLocalizedString(@"Commit",@"")];
}
#pragma mark -
@@ -84,7 +80,7 @@
editableCell.delegate = self;
}
editableCell.tag = [indexPath row];
-
+ editableCell.respectEditing = YES;
editableCell.textField.text = [[self.listOfSavegames objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
editableCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
@@ -97,13 +93,24 @@
return (UITableViewCell *)editableCell;
}
-/*
+
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section {
- UITableViewCellEditingStyleInsert
-}*//*
--(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
- return UITableViewCellEditingStyleInsert;
-}*/
+ 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.",@"");
+
+ label.backgroundColor = [UIColor clearColor];
+ [footer addSubview:label];
+ [label release];
+ return [footer autorelease];
+}
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
diff -r db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.xib Sun Sep 26 03:41:08 2010 +0200
@@ -12,7 +12,7 @@
diff -r db01c37494af -r 22e4d74240e5 project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib
--- a/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Sat Sep 25 18:38:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Resources/MainMenuViewController-iPad.xib Sun Sep 26 03:41:08 2010 +0200
@@ -12,7 +12,6 @@