# HG changeset patch # User koda # Date 1279760897 -7200 # Node ID a44406f4369b4002ccade64bc74392a67ea6c852 # Parent 2378ada8a6ee395fadb34a7d2f54a74815bd9dab polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults) diff -r 2378ada8a6ee -r a44406f4369b hedgewars/PascalExports.pas --- a/hedgewars/PascalExports.pas Tue Jul 20 23:30:54 2010 +0200 +++ b/hedgewars/PascalExports.pas Thu Jul 22 03:08:17 2010 +0200 @@ -191,7 +191,10 @@ function HW_isWeaponRequiringClick: boolean; cdecl; export; begin - exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 ) + if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) then + exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 ) + else + exit(false); end; function HW_isWeaponTimerable: boolean; cdecl; export; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/DetailViewController.m --- a/project_files/HedgewarsMobile/Classes/DetailViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/DetailViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -191,8 +191,8 @@ teamSettingsViewController = nil; weaponSettingsViewController = nil; schemeSettingsViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/EditableCellView.h --- a/project_files/HedgewarsMobile/Classes/EditableCellView.h Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/EditableCellView.h Thu Jul 22 03:08:17 2010 +0200 @@ -8,8 +8,6 @@ #import -#define MAX_STRING_LENGTH 64 - @protocol EditableCellViewDelegate -(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue; @@ -19,6 +17,9 @@ @interface EditableCellView : UITableViewCell { id delegate; UITextField *textField; + UILabel *titleLabel; + NSInteger minimumCharacters; + NSInteger maximumCharacters; @private NSString *oldValue; @@ -26,6 +27,9 @@ @property (nonatomic,assign) id delegate; @property (nonatomic,retain,readonly) UITextField *textField; +@property (nonatomic,retain,readonly) UILabel *titleLabel; +@property (nonatomic,assign) NSInteger minimumCharacters; +@property (nonatomic,assign) NSInteger maximumCharacters; @property (nonatomic,retain) NSString *oldValue; -(void) replyKeyboard; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/EditableCellView.m --- a/project_files/HedgewarsMobile/Classes/EditableCellView.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m Thu Jul 22 03:08:17 2010 +0200 @@ -10,7 +10,7 @@ #import "CommodityFunctions.h" @implementation EditableCellView -@synthesize delegate, textField, oldValue; +@synthesize delegate, textField, titleLabel, minimumCharacters, maximumCharacters, oldValue; -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { @@ -29,6 +29,15 @@ [self.contentView addSubview:textField]; [textField release]; + titleLabel = [[UILabel alloc] init]; + titleLabel.textAlignment = UITextAlignmentLeft; + titleLabel.backgroundColor = [UIColor clearColor]; + titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; + [self.contentView addSubview:titleLabel]; + [titleLabel release]; + + minimumCharacters = 1; + maximumCharacters = 64; oldValue = nil; } return self; @@ -41,22 +50,30 @@ CGFloat boundsX = contentRect.origin.x; int offset = 0; + int skew = 0; if (self.imageView != nil) - offset = self.imageView.frame.size.width; + offset += self.imageView.frame.size.width; - textField.frame = CGRectMake(boundsX+offset+10, 10, 250, [UIFont labelFontSize] + 4); + if ([self.titleLabel.text length] == 0) + titleLabel.frame = CGRectZero; + else { + titleLabel.frame = CGRectMake(boundsX+offset+10, 10, 100, [UIFont labelFontSize] + 4); + offset += 100; + skew +=2; + } + + textField.frame = CGRectMake(boundsX+offset+10, skew+10, 250, [UIFont labelFontSize] + 4); } -/* -(void) setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -*/ -(void) dealloc { - [oldValue release]; - [textField release]; + [oldValue release], oldValue = nil; + [titleLabel release], titleLabel = nil; + [textField release], textField = nil; [super dealloc]; } @@ -64,12 +81,12 @@ #pragma mark textField delegate // limit the size of the field to 64 characters like in original frontend -(BOOL) textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { - return !([aTextField.text length] > MAX_STRING_LENGTH && [string length] > range.length); + return !([aTextField.text length] > self.maximumCharacters && [string length] > range.length); } -// allow editing only if delegate is set +// allow editing only if delegate is set and conformant to protocol -(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField { - return (delegate != nil); + return (delegate != nil) && [delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)]; } // the textfield is being modified, update the navigation controller @@ -103,7 +120,7 @@ */ -(BOOL) textFieldShouldReturn:(UITextField *)aTextField { - return ([aTextField.text length] > 0); + return ([aTextField.text length] >= self.minimumCharacters); } // the textfield has been modified, tell the delegate to do something @@ -114,6 +131,9 @@ [(UITableViewController *)delegate navigationItem].leftBarButtonItem = nil; } +#pragma mark - +#pragma mark instance methods +// the user wants to show the keyboard -(void) replyKeyboard { [self.textField becomeFirstResponder]; } @@ -126,7 +146,7 @@ // send the value to the delegate -(void) save:(id) sender { - if (delegate == nil) + if (delegate == nil || ![delegate respondsToSelector:@selector(saveTextFieldValue:withTag:)]) return; // don't save if the textfield is invalid diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/FlagsViewController.m --- a/project_files/HedgewarsMobile/Classes/FlagsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/FlagsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -24,6 +24,8 @@ [super viewDidLoad]; self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; + + self.title = NSLocalizedString(@"Set team flag",@""); } -(void) viewWillAppear:(BOOL)animated { @@ -110,8 +112,8 @@ self.teamDictionary = nil; self.lastIndexPath = nil; self.flagArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/FortsViewController.m --- a/project_files/HedgewarsMobile/Classes/FortsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/FortsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -53,6 +53,8 @@ // statically set row height instead of using delegate method for performance reasons self.tableView.rowHeight = 200; + + self.title = NSLocalizedString(@"Choose team fort",@""); } @@ -143,12 +145,12 @@ self.teamDictionary = nil; self.lastIndexPath = nil; self.fortArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -- (void)dealloc { +-(void) ealloc { [teamDictionary release]; [lastIndexPath release]; [fortArray release]; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/GameConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -262,12 +262,11 @@ mapConfigViewController = nil; teamConfigViewController = nil; schemeWeaponConfigViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { - //[activeController release]; [mapConfigViewController release]; [teamConfigViewController release]; [schemeWeaponConfigViewController release]; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h --- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.h Thu Jul 22 03:08:17 2010 +0200 @@ -7,20 +7,12 @@ // #import - +#import "EditableCellView.h" -@interface GeneralSettingsViewController : UITableViewController { +@interface GeneralSettingsViewController : UITableViewController { NSMutableDictionary *settingsDictionary; - UITextField *textFieldBeingEdited; - UISwitch *musicSwitch; - UISwitch *soundSwitch; - UISwitch *altDamageSwitch; } @property (nonatomic, retain) NSMutableDictionary *settingsDictionary; -@property (nonatomic, retain) UITextField *textFieldBeingEdited;; -@property (nonatomic, retain) UISwitch *musicSwitch; -@property (nonatomic, retain) UISwitch *soundSwitch; -@property (nonatomic, retain) UISwitch *altDamageSwitch; @end diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -8,10 +8,9 @@ #import "GeneralSettingsViewController.h" #import "CommodityFunctions.h" -#import "EditableCellView.h" @implementation GeneralSettingsViewController -@synthesize settingsDictionary, textFieldBeingEdited, musicSwitch, soundSwitch, altDamageSwitch; +@synthesize settingsDictionary; -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { @@ -19,65 +18,9 @@ } #pragma mark - -#pragma mark textfield methods -// return to previous table --(void) cancel:(id) sender { - if (textFieldBeingEdited != nil) - [self.textFieldBeingEdited resignFirstResponder]; -} - -// set the new value --(void) save:(id) sender { - if (textFieldBeingEdited != nil) { - if (textFieldBeingEdited.tag == 0) - [self.settingsDictionary setObject:textFieldBeingEdited.text forKey:@"username"]; - else - [self.settingsDictionary setObject:textFieldBeingEdited.text forKey:@"password"]; - - [self.textFieldBeingEdited resignFirstResponder]; - } -} - -// the textfield is being modified, update the navigation controller --(void) textFieldDidBeginEditing:(UITextField *)aTextField{ - self.textFieldBeingEdited = aTextField; - UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from the settings table") - style:UIBarButtonItemStylePlain - target:self - action:@selector(cancel:)]; - self.navigationItem.leftBarButtonItem = cancelButton; - [cancelButton release]; - - UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from the settings table") - style:UIBarButtonItemStyleDone - target:self - action:@selector(save:)]; - self.navigationItem.rightBarButtonItem = saveButton; - [saveButton release]; -} - -// the textfield has been modified, check for empty strings and restore original navigation bar --(void) textFieldDidEndEditing:(UITextField *)aTextField{ - self.textFieldBeingEdited = nil; - self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem; - self.navigationItem.leftBarButtonItem = nil; -} - -// limit the size of the field to 64 characters like in original frontend --(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { - return !([textField.text length] > MAX_STRING_LENGTH && [string length] > range.length); -} - -#pragma mark - #pragma mark View Lifecycle -(void) viewDidLoad { [super viewDidLoad]; - self.musicSwitch = [[UISwitch alloc] init]; - self.soundSwitch = [[UISwitch alloc] init]; - self.altDamageSwitch = [[UISwitch alloc] init]; - [self.soundSwitch addTarget:self action:@selector(alsoTurnOffMusic:) forControlEvents:UIControlEventValueChanged]; - [self.musicSwitch addTarget:self action:@selector(dontTurnOnMusic:) forControlEvents:UIControlEventValueChanged]; - [self.altDamageSwitch addTarget:self action:@selector(justUpdateDictionary:) forControlEvents:UIControlEventValueChanged]; NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; self.settingsDictionary = dictionary; @@ -87,10 +30,6 @@ -(void) viewWillAppear:(BOOL)animated { [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; - musicSwitch.on = [[settingsDictionary objectForKey:@"music"] boolValue]; - soundSwitch.on = [[settingsDictionary objectForKey:@"sound"] boolValue]; - altDamageSwitch.on = [[settingsDictionary objectForKey:@"alternate"] boolValue]; - [super viewWillAppear:animated]; } @@ -100,26 +39,41 @@ } #pragma mark - -// if the sound system is off, turn off also the background music --(void) alsoTurnOffMusic:(id) sender { - [self.settingsDictionary setObject:[NSNumber numberWithBool:soundSwitch.on] forKey:@"sound"]; - if (YES == self.musicSwitch.on) { - [musicSwitch setOn:NO animated:YES]; - [self.settingsDictionary setObject:[NSNumber numberWithBool:musicSwitch.on] forKey:@"music"]; +-(void) switchValueChanged:(id) sender { + UISwitch *theSwitch = (UISwitch *)sender; + UISwitch *theOtherSwitch = nil; + + switch (theSwitch.tag) { + case 10: //soundSwitch + // this turn off also the switch below + [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"]; + [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; + theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; + [theOtherSwitch setOn:NO animated:YES]; + break; + case 20: //musicSwitch + // if switch above is off, never turn on + if (NO == [[self.settingsDictionary objectForKey:@"sound"] boolValue]) { + [self.settingsDictionary setObject:[NSNumber numberWithBool:NO] forKey:@"music"]; + theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView; + [theOtherSwitch setOn:NO animated:YES]; + } else + [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"]; + break; + case 30: //alternateSwitch + [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"]; + break; + default: + DLog(@"Wrong tag"); + break; } } -// if the sound system is off, don't enable background music --(void) dontTurnOnMusic:(id) sender { - if (NO == self.soundSwitch.on) - [musicSwitch setOn:NO animated:YES]; +-(void) saveTextFieldValue:(NSString *)textString withTag:(NSInteger) tagValue { + if (tagValue == 40) + [self.settingsDictionary setObject:textString forKey:@"username"]; else - [self.settingsDictionary setObject:[NSNumber numberWithBool:musicSwitch.on] forKey:@"music"]; -} - --(void) justUpdateDictionary:(id) sender { - UISwitch *theSwitch = (UISwitch *)sender; - [self.settingsDictionary setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"]; + [self.settingsDictionary setObject:textString forKey:@"password"]; } #pragma mark - @@ -145,99 +99,6 @@ return 0; } --(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString *cellIdentifier = @"systemSettingsCell"; - NSInteger row = [indexPath row]; - NSInteger section = [indexPath section]; - - UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; - UITextField *aTextField; - switch (section) { - case 0: - if (nil == cell) { - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; - if (section == 0) { - UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(-9, 10, 100, [UIFont labelFontSize] + 4)]; - label.textAlignment = UITextAlignmentRight; - label.backgroundColor = [UIColor clearColor]; - label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; - if (row == 0) - label.text = NSLocalizedString(@"Nickname","from the settings table"); - else - label.text = NSLocalizedString(@"Password","from the settings table"); - [cell.contentView addSubview:label]; - [label release]; - - UITextField *aTextField = [[UITextField alloc] initWithFrame: - CGRectMake(110, 10, (cell.frame.size.width + cell.frame.size.width/3) - 90, [UIFont labelFontSize] + 4)]; - aTextField.clearsOnBeginEditing = NO; - aTextField.returnKeyType = UIReturnKeyDone; - aTextField.adjustsFontSizeToFitWidth = YES; - aTextField.delegate = self; - aTextField.tag = row; - aTextField.clearButtonMode = UITextFieldViewModeWhileEditing; - [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit]; - [cell.contentView addSubview:aTextField]; - [aTextField release]; - } - } - for (UIView *oneView in cell.contentView.subviews) - if ([oneView isMemberOfClass:[UITextField class]]) - aTextField = (UITextField *)oneView; - - switch (row) { - case 0: - aTextField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@""); - aTextField.text = [self.settingsDictionary objectForKey:@"username"]; - aTextField.secureTextEntry = NO; - break; - case 1: - aTextField.placeholder = NSLocalizedString(@"Insert your password",@""); - aTextField.text = [self.settingsDictionary objectForKey:@"password"]; - aTextField.secureTextEntry = YES; - break; - default: - break; - } - break; - - cell.accessoryView = nil; - case 1: - if (nil == cell) - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; - - switch (row) { - case 0: - cell.textLabel.text = NSLocalizedString(@"Sound", @""); - cell.accessoryView = soundSwitch; - break; - case 1: - cell.textLabel.text = NSLocalizedString(@"Music", @""); - cell.accessoryView = musicSwitch; - break; - default: - break; - } - break; - - case 2: - if (nil == cell) - cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; - - cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @""); - cell.accessoryView = altDamageSwitch; - break; - default: - break; - } - - cell.accessoryType = UITableViewCellAccessoryNone; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - cell.imageView.image = nil; - - return cell; -} - -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *sectionTitle = nil; switch (section) { @@ -257,6 +118,75 @@ return sectionTitle; } +-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *cellIdentifier0 = @"Cell0"; + static NSString *cellIdentifier1 = @"Cell1"; + NSInteger row = [indexPath row]; + NSInteger section = [indexPath section]; + + UITableViewCell *cell = nil; + EditableCellView *editableCell = nil; + if (section == 0) { + editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:cellIdentifier0]; + if (nil == editableCell) { + editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier0] autorelease]; + editableCell.minimumCharacters = 0; + editableCell.delegate = self; + editableCell.textField.font = [UIFont systemFontOfSize:[UIFont systemFontSize]]; + editableCell.textField.textColor = [UIColor lightGrayColor]; + } + + if (row == 0) { + editableCell.titleLabel.text = NSLocalizedString(@"Nickname","from the settings table"); + editableCell.textField.placeholder = NSLocalizedString(@"Insert your username (if you have one)",@""); + editableCell.textField.text = [self.settingsDictionary objectForKey:@"username"]; + editableCell.textField.secureTextEntry = NO; + editableCell.tag = 40; + } else { + editableCell.titleLabel.text = NSLocalizedString(@"Password","from the settings table"); + editableCell.textField.placeholder = NSLocalizedString(@"Insert your password",@""); + editableCell.textField.text = [self.settingsDictionary objectForKey:@"password"]; + editableCell.textField.secureTextEntry = YES; + editableCell.tag = 50; + } + + editableCell.accessoryView = nil; + cell = editableCell; + } else { + cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier1]; + if (nil == cell) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] autorelease]; + UISwitch *theSwitch = [[UISwitch alloc] init]; + [theSwitch addTarget:self action:@selector(switchValueChanged:) forControlEvents:UIControlEventValueChanged]; + cell.accessoryView = theSwitch; + [theSwitch release]; + } + + UISwitch *switchContent = (UISwitch *)cell.accessoryView; + if (section == 1) { + if (row == 0) { + cell.textLabel.text = NSLocalizedString(@"Sound", @""); + switchContent.on = [[self.settingsDictionary objectForKey:@"sound"] boolValue]; + switchContent.tag = 10; + } else { + cell.textLabel.text = NSLocalizedString(@"Music", @""); + switchContent.on = [[self.settingsDictionary objectForKey:@"music"] boolValue]; + switchContent.tag = 20; + } + } else { + cell.textLabel.text = NSLocalizedString(@"Alternate Damage", @""); + switchContent.on = [[self.settingsDictionary objectForKey:@"alternate"] boolValue]; + switchContent.tag = 30; + } + } + + cell.accessoryType = UITableViewCellAccessoryNone; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + cell.imageView.image = nil; + + return cell; +} + /* -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *containerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)] autorelease]; @@ -299,24 +229,15 @@ } */ -/* - causes segfault if pressing twice cancel #pragma mark - #pragma mark Table view delegate -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell; if (0 == [indexPath section]) { - cell = [aTableView cellForRowAtIndexPath:indexPath]; - for (UIView *oneView in cell.contentView.subviews) { - if ([oneView isMemberOfClass:[UITextField class]]) { - textFieldBeingEdited = (UITextField *)oneView; - [textFieldBeingEdited becomeFirstResponder]; - } - } - [aTableView deselectRowAtIndexPath:indexPath animated:NO]; + EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; + [cell replyKeyboard]; } } -*/ + #pragma mark - #pragma mark Memory management @@ -326,22 +247,13 @@ -(void) viewDidUnload { self.settingsDictionary = nil; - self.textFieldBeingEdited = nil; - self.musicSwitch = nil; - self.soundSwitch = nil; - self.altDamageSwitch = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { [settingsDictionary release]; - [textFieldBeingEdited release]; - [musicSwitch release]; - [soundSwitch release]; - [altDamageSwitch release]; [super dealloc]; } - @end diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/GravesViewController.m --- a/project_files/HedgewarsMobile/Classes/GravesViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/GravesViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -26,6 +26,8 @@ // load all the grave names and store them into graveArray self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; + + self.title = NSLocalizedString(@"Choose hedgehog graves",@""); } -(void) viewWillAppear:(BOOL)animated { @@ -101,21 +103,21 @@ #pragma mark - #pragma mark Memory management -- (void)didReceiveMemoryWarning { +-(void) didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Relinquish ownership any cached data, images, etc that aren't in use. } -- (void)viewDidUnload { +-(void) viewDidUnload { self.lastIndexPath = nil; self.teamDictionary = nil; self.graveArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -- (void)dealloc { +-(void) dealloc { [graveArray release]; [teamDictionary release]; [lastIndexPath release]; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/HogHatViewController.m --- a/project_files/HedgewarsMobile/Classes/HogHatViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/HogHatViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -35,12 +35,13 @@ [normalHogFile release]; self.normalHogSprite = hogSprite; [hogSprite release]; + + self.title = NSLocalizedString(@"Change hedgehog's hat",@""); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - self.title = [[[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog] objectForKey:@"hogname"]; - + // this updates the hog name and its hat [self.tableView reloadData]; // this moves the tableview to the top @@ -132,8 +133,8 @@ self.normalHogSprite = nil; self.teamDictionary = nil; self.hatArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } - (void)dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/InGameMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -46,8 +46,8 @@ -(void) viewDidUnload { self.menuList = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/LevelViewController.m --- a/project_files/HedgewarsMobile/Classes/LevelViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/LevelViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -34,6 +34,8 @@ nil]; self.levelArray = array; [array release]; + + self.title = NSLocalizedString(@"Set difficulty level",@""); } - (void)viewWillAppear:(BOOL)animated { @@ -160,8 +162,8 @@ self.teamDictionary = nil; self.levelArray = nil; self.levelSprites = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/MainMenuViewController.m --- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -155,8 +155,8 @@ self.versionLabel = nil; gameConfigViewController = nil; settingsViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/MapConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -560,8 +560,8 @@ self.themeArray = nil; self.mapArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/MasterViewController.m --- a/project_files/HedgewarsMobile/Classes/MasterViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/MasterViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -132,8 +132,8 @@ teamSettingsViewController = nil; weaponSettingsViewController = nil; schemeSettingsViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/OverlayViewController.m --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -128,13 +128,11 @@ sdlwindow = display->windows; } -/* these are causing problems at reloading so let's remove 'em -(void) viewDidUnload { - [dimTimer invalidate]; - self.popoverController = nil; - self.popupMenu = nil; + // only object initialized in viewDidLoad should be here + dimTimer = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) didReceiveMemoryWarning { @@ -145,7 +143,7 @@ popupMenu = nil; MSG_MEMCLEAN(); } -*/ + -(void) dealloc { [popupMenu release]; @@ -448,7 +446,7 @@ -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGRect screen = [[UIScreen mainScreen] bounds]; NSSet *allTouches = [event allTouches]; - int x, y; + int x, y, dx, dy; UITouch *touch, *first, *second; @@ -462,11 +460,13 @@ HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); } else { // panning \o/ + dx = startingPoint.x - currentPosition.x; + dy = currentPosition.y - startingPoint.y; HW_getCursor(&x, &y); - x = x + currentPosition.x - startingPoint.x; - y = y + currentPosition.y - startingPoint.y; - HW_setCursor(x, y); - + // momentum (or something like that) + if (abs(dx) > 40) dx *= log(abs(dx)/4); + if (abs(dy) > 40) dy *= log(abs(dy)/4); + HW_setCursor(x + dx, y + dy); startingPoint = currentPosition; } break; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m --- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Thu Jul 22 03:08:17 2010 +0200 @@ -140,10 +140,10 @@ } -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application { + //if (self.mainViewController.view.superview == nil) + // self.mainViewController = nil; + MSG_MEMCLEAN(); print_free_memory(); - if (self.mainViewController.view.superview == nil) - self.mainViewController = nil; - MSG_MEMCLEAN(); } -(void) applicationWillResignActive:(UIApplication *)application { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -145,8 +145,8 @@ -(void) viewDidUnload { self.listOfSchemes = nil; childController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -154,6 +154,7 @@ self.selectedScheme = nil; self.selectedWeapon = nil; MSG_DIDUNLOAD(); + [super viewDidUnload]; } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m --- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -345,8 +345,8 @@ self.schemeArray = nil; self.basicSettingList = nil; self.gameModifierArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SingleTeamViewController.m --- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -295,10 +295,9 @@ break; } - nextController.title = [secondaryItems objectAtIndex:row]; - [nextController setTeamDictionary:teamDictionary]; + if ([nextController respondsToSelector:@selector(setTeamDictionary:)]) + [nextController setTeamDictionary:teamDictionary]; [self.navigationController pushViewController:nextController animated:YES]; - [nextController release]; } else { EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath]; [cell replyKeyboard]; @@ -309,9 +308,8 @@ // action to perform when you want to change a hog hat -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { - if (nil == hogHatViewController) { + if (nil == hogHatViewController) hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped]; - } // cache the dictionary file of the team, so that other controllers can modify it hogHatViewController.teamDictionary = self.teamDictionary; @@ -345,17 +343,19 @@ } -(void) viewDidUnload { + [super viewDidUnload]; self.teamDictionary = nil; self.teamName = nil; self.normalHogSprite = nil; self.secondaryItems = nil; hogHatViewController = nil; + gravesViewController = nil; + voicesViewController = nil; flagsViewController = nil; fortsViewController = nil; - gravesViewController = nil; levelViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { @@ -364,8 +364,9 @@ [normalHogSprite release]; [secondaryItems release]; [hogHatViewController release]; + [gravesViewController release]; [fortsViewController release]; - [gravesViewController release]; + [voicesViewController release]; [flagsViewController release]; [levelViewController release]; [super dealloc]; diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m --- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -260,6 +260,7 @@ self.ammoStoreImage = nil; self.ammoNames = nil; MSG_DIDUNLOAD(); + [super viewDidUnload]; } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SplitViewRootController.h --- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.h Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.h Thu Jul 22 03:08:17 2010 +0200 @@ -9,6 +9,7 @@ #import @class DetailViewController; + @interface SplitViewRootController: UIViewController { DetailViewController *detailViewController; } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/SplitViewRootController.m --- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.m Thu Jul 22 03:08:17 2010 +0200 @@ -35,12 +35,10 @@ [detailViewController release]; CGRect rect = [[UIScreen mainScreen] bounds]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init]; - //splitViewRootController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); MasterViewController *masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain]; @@ -64,17 +62,14 @@ -(void) viewDidUnload { detailViewController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { [detailViewController release]; [super dealloc]; } --(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ - [detailViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; -} #pragma mark - #pragma mark additional methods as we're using a UINavigationController programmatically diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/TeamConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -106,7 +106,7 @@ UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; label.textAlignment = UITextAlignmentLeft; label.backgroundColor = [UIColor clearColor]; - label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; + label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize] + 2]; label.tag = LABEL_TAG; [cell.contentView addSubview:label]; [label release]; @@ -169,8 +169,8 @@ -(void) viewDidUnload { self.listOfTeams = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -18,7 +18,6 @@ return rotationManager(interfaceOrientation); } - #pragma mark - #pragma mark View lifecycle // add an edit button @@ -152,8 +151,8 @@ -(void) viewDidUnload { self.listOfTeams = nil; childController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/VoicesViewController.m --- a/project_files/HedgewarsMobile/Classes/VoicesViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/VoicesViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -22,7 +22,7 @@ #pragma mark - #pragma mark View lifecycle -- (void)viewDidLoad { +-(void) viewDidLoad { [super viewDidLoad]; srandom(time(NULL)); @@ -33,9 +33,11 @@ // it's here and not in viewWillAppear because user cannot add/remove them NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:VOICES_DIRECTORY() error:NULL]; self.voiceArray = array; + + self.title = NSLocalizedString(@"Set hedgehog voices",@""); } -- (void)viewWillAppear:(BOOL)animated { +-(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // this moves the tableview to the top @@ -134,8 +136,8 @@ self.lastIndexPath = nil; self.teamDictionary = nil; self.voiceArray = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } -(void) dealloc { diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m --- a/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m Thu Jul 22 03:08:17 2010 +0200 @@ -144,8 +144,8 @@ -(void) viewDidUnload { self.listOfWeapons = nil; childController = nil; + MSG_DIDUNLOAD(); [super viewDidUnload]; - MSG_DIDUNLOAD(); } diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Jul 22 03:08:17 2010 +0200 @@ -1292,8 +1292,8 @@ "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL_net/\"", "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL/include/\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 3.0; - ONLY_ACTIVE_ARCH = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ( "-lz", "-Wl,-no_order_inits", @@ -1410,8 +1410,8 @@ "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL_net/\"", "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL/include/\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 3.0; - ONLY_ACTIVE_ARCH = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ( "-lz", "-Wl,-no_order_inits", @@ -1612,8 +1612,8 @@ "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL_net/\"", "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL/include/\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 3.0; - ONLY_ACTIVE_ARCH = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ( "-lz", "-Wl,-no_order_inits", @@ -1654,8 +1654,8 @@ "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL_net/\"", "\"$(SRCROOT)/../../../Library/SDL-1.3/SDL/include/\"", ); - IPHONEOS_DEPLOYMENT_TARGET = 3.0; - ONLY_ACTIVE_ARCH = YES; + IPHONEOS_DEPLOYMENT_TARGET = 3.1; + ONLY_ACTIVE_ARCH = NO; OTHER_LDFLAGS = ( "-lz", "-Wl,-no_order_inits", diff -r 2378ada8a6ee -r a44406f4369b project_files/HedgewarsMobile/Resources/OverlayViewController.xib --- a/project_files/HedgewarsMobile/Resources/OverlayViewController.xib Tue Jul 20 23:30:54 2010 +0200 +++ b/project_files/HedgewarsMobile/Resources/OverlayViewController.xib Thu Jul 22 03:08:17 2010 +0200 @@ -45,7 +45,7 @@ 268 - {{0, 175}, {164, 145}} + {{0, 170}, {180, 150}} 3 @@ -630,8 +630,8 @@ + -