half reworking of the settings page with delegation
authorkoda
Tue, 20 Jul 2010 03:14:43 +0200
changeset 3659 f8d5ac50e307
parent 3658 113cb9345be1
child 3660 bc125bea5849
half reworking of the settings page with delegation some graphical enhancements, leaks and fixes
project_files/HedgewarsMobile/Classes/EditableCellView.h
project_files/HedgewarsMobile/Classes/EditableCellView.m
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.h
project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h
project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m
project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
project_files/HedgewarsMobile/Classes/TeamSettingsViewController.h
project_files/HedgewarsMobile/Classes/WeaponCellView.m
project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/EditableCellView.h	Tue Jul 20 03:14:43 2010 +0200
@@ -0,0 +1,29 @@
+//
+//  WeaponCellView.h
+//  Hedgewars
+//
+//  Created by Vittorio on 03/07/10.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@protocol EditableCellViewDelegate <NSObject>
+
+-(void) saveTextFieldValue:(NSString *)textString;
+
+@end
+
+@interface EditableCellView : UITableViewCell <UITextFieldDelegate> {
+    id<EditableCellViewDelegate> delegate;
+    UITextField *textField;
+}
+
+@property (nonatomic,assign) id<EditableCellViewDelegate> delegate;
+@property (nonatomic,retain,readonly) UITextField *textField;
+
+-(void) replyKeyboard;
+-(void) cancel:(id) sender;
+-(void) save:(id) sender;
+
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/EditableCellView.m	Tue Jul 20 03:14:43 2010 +0200
@@ -0,0 +1,121 @@
+//
+//  WeaponCellView.m
+//  Hedgewars
+//
+//  Created by Vittorio on 03/07/10.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "EditableCellView.h"
+#import "CommodityFunctions.h"
+
+@implementation EditableCellView
+@synthesize delegate, textField;
+
+-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
+        delegate = nil;
+        
+        textField = [[UITextField alloc] initWithFrame:CGRectZero];
+        textField.backgroundColor = [UIColor clearColor];
+        textField.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
+        textField.delegate = self;
+        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
+        textField.clearsOnBeginEditing = NO;
+        textField.returnKeyType = UIReturnKeyDone;
+        textField.adjustsFontSizeToFitWidth = YES;
+        [textField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
+        
+        [self.contentView addSubview:textField];
+        [textField release];
+    }
+    return self;
+}
+
+-(void) layoutSubviews {
+    [super layoutSubviews];
+
+    CGRect contentRect = self.contentView.bounds;
+    CGFloat boundsX = contentRect.origin.x;
+    
+    textField.frame = CGRectMake(boundsX+10, 11, 250, [UIFont labelFontSize] + 2);
+}
+
+/*
+-(void) setSelected:(BOOL)selected animated:(BOOL)animated {
+    [super setSelected:selected animated:animated];
+    // Configure the view for the selected state
+}
+*/
+
+-(void) dealloc {
+    [textField release];
+    [super dealloc];
+}
+
+#pragma mark -
+#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 {
+    int limit = 64;
+    return !([aTextField.text length] > limit && [string length] > range.length);
+}
+
+// allow editing only if delegate is set 
+-(BOOL) textFieldShouldBeginEditing:(UITextField *)aTextField {
+    return (delegate != nil);
+}
+
+// the textfield is being modified, update the navigation controller
+-(void) textFieldDidBeginEditing:(UITextField *)aTextField{
+    // don't scroll when editing
+    ((UITableView*)[self superview]).scrollEnabled = NO;
+    
+    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"")
+                                                                     style:UIBarButtonItemStylePlain
+                                                                    target:self
+                                                                    action:@selector(cancel:)];
+    [(UITableViewController *)delegate navigationItem].leftBarButtonItem = cancelButton;
+    [cancelButton release];
+    
+    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"")
+                                                                     style:UIBarButtonItemStyleDone
+                                                                    target:self
+                                                                    action:@selector(save:)];
+    [(UITableViewController *)delegate navigationItem].rightBarButtonItem = saveButton;
+    [saveButton release];
+}
+
+
+// don't accept 0-length strings
+-(BOOL) textFieldShouldEndEditing:(UITextField *)aTextField {
+    return ([aTextField.text length] > 0); 
+}
+
+// the textfield has been modified, tell the delegate to do something
+-(void) textFieldDidEndEditing:(UITextField *)aTextField{
+    ((UITableView*)[self superview]).scrollEnabled = YES;
+    
+    [(UITableViewController *)delegate navigationItem].rightBarButtonItem = [(UITableViewController *)delegate navigationItem].backBarButtonItem;
+    [(UITableViewController *)delegate navigationItem].leftBarButtonItem = nil;
+}
+
+-(void) replyKeyboard {
+    [self.textField becomeFirstResponder];
+}
+
+// the user pressed cancel so hide keyboard
+-(void) cancel:(id) sender {
+    [self.textField resignFirstResponder];
+}
+
+// send the value to the delegate
+-(void) save:(id) sender {
+    if (delegate == nil)
+        return;
+    
+    [delegate saveTextFieldValue:self.textField.text];
+    [self.textField resignFirstResponder];
+}
+
+@end
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -199,7 +199,7 @@
             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
         if (teamConfigViewController == nil)
             teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStylePlain];
-        teamConfigViewController.view.frame = CGRectMake(0, 224, 300, 472);
+        teamConfigViewController.view.frame = CGRectMake(3, 224, 300, 472);
         teamConfigViewController.view.backgroundColor = [UIColor clearColor];
         [mapConfigViewController.view addSubview:teamConfigViewController.view];
         if (schemeWeaponConfigViewController == nil)
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -17,7 +17,6 @@
     return rotationManager(interfaceOrientation);
 }
 
-
 #pragma mark -
 #pragma mark textfield methods
 // return to previous table
@@ -138,47 +137,6 @@
     isWriteNeeded = YES;
 }
 
-/*
-#pragma mark -
-#pragma mark UIActionSheet Methods
--(IBAction) deleteData: (id)sender {
-    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
-                                 delegate:self
-                            cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
-                           destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
-                            otherButtonTitles:nil];
-    [actionSheet showInView:self.view];
-    [actionSheet release];
-}
-
--(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
-    if ([actionSheet cancelButtonIndex] != buttonIndex) {
-        // get the documents dirctory
-        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-        NSString *documentsDirectory = [paths objectAtIndex:0];
-        
-        // get the content of the directory
-        NSFileManager *fm = [NSFileManager defaultManager];
-        NSArray *dirContent = [fm directoryContentsAtPath:documentsDirectory];
-        NSError *error;
-        
-        // delete data
-        for (NSString *fileName in dirContent) {
-            [fm removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:fileName] error:&error];
-        }
-        
-        // force resetting
-        UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Hit Home Button to Exit", @"")
-                                  message:NSLocalizedString(@"\nEverything is gone!\nNow you need to restart the game...", @"")
-                                 delegate:self
-                            cancelButtonTitle:nil
-                            otherButtonTitles:nil];
-        [anAlert show];
-        [anAlert release];
-    }
-}
-*/
-
 #pragma mark -
 #pragma mark TableView Methods
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
@@ -371,9 +329,7 @@
 #pragma mark -
 #pragma mark Memory management
 -(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 {
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h	Tue Jul 20 03:14:43 2010 +0200
@@ -31,6 +31,8 @@
     BOOL isInGame;
 }
 
+@property (nonatomic,retain) MainMenuViewController *mainViewController;
+
 +(SDLUIKitDelegate *)sharedAppDelegate;
 -(void) startSDLgame:(NSDictionary *)gameDictionary;
 -(void) displayOverlayLater;
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Tue Jul 20 03:14:43 2010 +0200
@@ -54,6 +54,7 @@
 }
 
 @implementation SDLUIKitDelegate
+@synthesize mainViewController;
 
 // convenience method
 +(SDLUIKitDelegate *)sharedAppDelegate {
@@ -117,11 +118,12 @@
     uiwindow.backgroundColor = [UIColor blackColor];
     
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-        mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil];
+        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil];
     else
-        mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil];
+        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil];
 
-    [uiwindow addSubview:mainViewController.view];
+    [uiwindow addSubview:self.mainViewController.view];
+    [self.mainViewController release];
     [uiwindow makeKeyAndVisible];
 
     // Set working directory to resource path
@@ -138,8 +140,8 @@
 }
 
 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
-    if (mainViewController.view.superview == nil)
-        mainViewController = nil;
+    if (self.mainViewController.view.superview == nil)
+        self.mainViewController = nil;
     MSG_MEMCLEAN();
     print_free_memory();
 }
--- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.h	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.h	Tue Jul 20 03:14:43 2010 +0200
@@ -7,6 +7,7 @@
 //
 
 #import <UIKit/UIKit.h>
+
 @class SingleSchemeViewController;
 
 @interface SchemeSettingsViewController : UITableViewController {
--- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -17,7 +17,6 @@
     return rotationManager(interfaceOrientation);
 }
 
-
 #pragma mark -
 #pragma mark View lifecycle
 -(void) viewDidLoad {
@@ -127,7 +126,7 @@
     NSString *selectedSchemeFile = [self.listOfSchemes objectAtIndex:row];
     
     // this must be set so childController can load the correct plist
-    childController.title = [selectedSchemeFile stringByDeletingPathExtension];
+    childController.schemeName = [selectedSchemeFile stringByDeletingPathExtension];
     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
 
     [self.navigationController pushViewController:childController animated:YES];
@@ -140,6 +139,7 @@
     [super didReceiveMemoryWarning];
     if (childController.view.superview == nil )
         childController = nil;
+    MSG_MEMCLEAN();
 }
 
 -(void) viewDidUnload {
@@ -151,7 +151,7 @@
 
 
 -(void) dealloc {
-    [self.listOfSchemes release];
+    [listOfSchemes release];
     [childController release];
     [super dealloc];
 }
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -31,6 +31,8 @@
         [self.tableView setBackgroundView:nil]; 
         self.view.backgroundColor = [UIColor clearColor];
     }
+    self.tableView.separatorColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
+    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
 }
 
 -(void) viewWillAppear:(BOOL) animated {
@@ -92,7 +94,6 @@
             self.lastIndexPath_we = indexPath;
         }
     }
-
     return cell;
 }
 
--- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.h	Tue Jul 20 03:14:43 2010 +0200
@@ -7,17 +7,16 @@
 //
 
 #import <UIKit/UIKit.h>
-
+#import "EditableCellView.h"
 
-@interface SingleSchemeViewController : UITableViewController <UITextFieldDelegate> {
-    UITextField *textFieldBeingEdited;
-    NSMutableArray *schemeArray;
-    
+@interface SingleSchemeViewController : UITableViewController <EditableCellViewDelegate> {
+    NSString *schemeName;
+    NSMutableArray *schemeArray;    
     NSArray *basicSettingList;
     NSArray *gameModifierArray;
 }
 
-@property (nonatomic, retain) UITextField *textFieldBeingEdited;
+@property (nonatomic, retain) NSString *schemeName;
 @property (nonatomic, retain) NSMutableArray *schemeArray;
 @property (nonatomic, retain) NSArray *basicSettingList;
 @property (nonatomic, retain) NSArray *gameModifierArray;
--- a/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SingleSchemeViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -15,7 +15,7 @@
 #define SLIDER_TAG 54321
 
 @implementation SingleSchemeViewController
-@synthesize textFieldBeingEdited, schemeArray, basicSettingList, gameModifierArray;
+@synthesize schemeName, schemeArray, basicSettingList, gameModifierArray;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -104,13 +104,15 @@
                               nil];
     self.basicSettingList = basicSettings;
     [basicSettings release];
+    
+    self.title = NSLocalizedString(@"Edit scheme preferences",@"");
 }
 
 // load from file
 -(void) viewWillAppear:(BOOL) animated {
     [super viewWillAppear:animated];
     
-    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title];
+    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName];
     NSMutableArray *scheme = [[NSMutableArray alloc] initWithContentsOfFile:schemeFile];
     [schemeFile release];
     self.schemeArray = scheme;
@@ -123,69 +125,23 @@
 -(void) viewWillDisappear:(BOOL) animated {
     [super viewWillDisappear:animated];
     
-    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title];
+    NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName];
     [self.schemeArray writeToFile:schemeFile atomically:YES];
     [schemeFile release];
 }
 
 #pragma mark -
-#pragma mark textfield methods
--(void) cancel:(id) sender {
-    if (textFieldBeingEdited != nil)
-        [self.textFieldBeingEdited resignFirstResponder];
-}
-
+#pragma mark editableCellView delegate
 // set the new value
--(BOOL) save:(id) sender {    
-    if (textFieldBeingEdited != nil) {
-        if ([textFieldBeingEdited.text length] == 0) 
-            textFieldBeingEdited.text = self.title;
-        
-        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] error:NULL];
-        self.title = self.textFieldBeingEdited.text;
-        [self.schemeArray writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.title] atomically:YES];
-        [self.textFieldBeingEdited resignFirstResponder];
-        return YES;
-    }
-    return NO;
+-(void) saveTextFieldValue:(NSString *)textString {    
+    // delete old file
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] error:NULL];
+    // update filename
+    self.schemeName = textString;
+    // save new file
+    [self.schemeArray writeToFile:[NSString stringWithFormat:@"%@/%@.plist",SCHEMES_DIRECTORY(),self.schemeName] atomically:YES];
 }
 
-// the textfield is being modified, update the navigation controller
--(void) textFieldDidBeginEditing:(UITextField *)aTextField{   
-    self.textFieldBeingEdited = aTextField;
-
-    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from schemes table")
-                                                                     style:UIBarButtonItemStylePlain
-                                                                    target:self
-                                                                    action:@selector(cancel:)];
-    self.navigationItem.leftBarButtonItem = cancelButton;
-    [cancelButton release];
-    
-    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from schemes 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{
-    if ([textFieldBeingEdited.text length] == 0) 
-        textFieldBeingEdited.text = [NSString stringWithFormat:@"New Scheme"];
-
-    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 {
-    int limit = 64;
-    return !([textField.text length] > limit && [string length] > range.length);
-}
-
-
 #pragma mark -
 #pragma mark Table view data source
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
@@ -214,39 +170,23 @@
     static NSString *CellIdentifier2 = @"Cell2";
     
     UITableViewCell *cell = nil;
+    EditableCellView *editableCell = nil;
     NSInteger row = [indexPath row];
     
     switch ([indexPath section]) {
         case 0:
-            cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
-            if (cell == nil) {
-                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
+            editableCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
+            if (editableCell == nil) {
+                editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault 
                                                reuseIdentifier:CellIdentifier0] autorelease];
-                // create a uitextfield for each row, expand it to take the maximum size
-                UITextField *aTextField = [[UITextField alloc] 
-                                           initWithFrame:CGRectMake(5, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
-                aTextField.clearsOnBeginEditing = NO;
-                aTextField.returnKeyType = UIReturnKeyDone;
-                aTextField.adjustsFontSizeToFitWidth = YES;
-                aTextField.delegate = self;
-                aTextField.tag = [indexPath row];
-                aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
-                aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
-                [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
-                [cell.contentView addSubview:aTextField];
-                [aTextField release];
+                editableCell.delegate = self;
             }
             
-            for (UIView *oneView in cell.contentView.subviews) {
-                if ([oneView isMemberOfClass:[UITextField class]]) {
-                    // we find the uitextfied and we'll use its tag to understand which one is being edited
-                    UITextField *textFieldFound = (UITextField *)oneView;
-                    textFieldFound.text = self.title;
-                }
-            }
-            cell.detailTextLabel.text = nil;
-            cell.imageView.image = nil;
-            cell.selectionStyle = UITableViewCellSelectionStyleNone;
+            editableCell.textField.text = self.schemeName;
+            editableCell.detailTextLabel.text = nil;
+            editableCell.imageView.image = nil;
+            editableCell.selectionStyle = UITableViewCellSelectionStyleNone;
+            cell = editableCell;
             break;
         case 1:
             cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
@@ -259,7 +199,7 @@
                 
                 int offset = 0;
                 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-                    offset = 45;
+                    offset = 50;
                 
                 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(offset+260, 12, offset+150, 23)];
                 slider.maximumValue = [[detail objectForKey:@"max"] floatValue];
@@ -349,17 +289,13 @@
 #pragma mark Table view delegate
 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     UITableViewCell *cell = [aTableView cellForRowAtIndexPath:indexPath];
-    UISwitch *sw = nil;
+    EditableCellView *editableCell = nil;
     UISlider *cellSlider = nil;
     
     switch ([indexPath section]) {
         case 0:
-            for (UIView *oneView in cell.contentView.subviews) {
-                if ([oneView isMemberOfClass:[UITextField class]]) {
-                    textFieldBeingEdited = (UITextField *)oneView;
-                    [textFieldBeingEdited becomeFirstResponder];
-                }
-            }
+            editableCell = (EditableCellView *)cell;
+            [editableCell replyKeyboard];
             break;
         case 1:
             cellSlider = (UISlider *)[cell.contentView viewWithTag:[indexPath row]+[self.gameModifierArray count]];
@@ -379,6 +315,24 @@
     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
 }
 
+-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
+    NSString *sectionTitle = nil;
+    switch (section) {
+        case 0:
+            sectionTitle = NSLocalizedString(@"Scheme Name", @"");
+            break;
+        case 1:
+            sectionTitle = NSLocalizedString(@"Game Settings", @"");
+            break;
+        case 2:
+            sectionTitle = NSLocalizedString(@"Game Modifiers", @"");
+            break;
+        default:
+            DLog(@"nope");
+            break;
+    }
+    return sectionTitle;
+}
 
 #pragma mark -
 #pragma mark Memory management
@@ -387,7 +341,7 @@
 }
 
 -(void) viewDidUnload {
-    self.textFieldBeingEdited = nil;
+    self.schemeName = nil;
     self.schemeArray = nil;
     self.basicSettingList = nil;
     self.gameModifierArray = nil;
@@ -396,13 +350,11 @@
 }
 
 -(void) dealloc {
-    [textFieldBeingEdited release];
+    [schemeName release];
     [schemeArray release];
     [basicSettingList release];
     [gameModifierArray release];
     [super dealloc];
 }
 
-
 @end
-
--- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -378,6 +378,7 @@
         nextController.title = [secondaryItems objectAtIndex:row];
         [nextController setTeamDictionary:teamDictionary];
         [self.navigationController pushViewController:nextController animated:YES];
+        [nextController release];
     } else {
         cell = [aTableView cellForRowAtIndexPath:indexPath];
         for (UIView *oneView in cell.contentView.subviews) {
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.h	Tue Jul 20 03:14:43 2010 +0200
@@ -7,9 +7,12 @@
 //
 
 #import <UIKit/UIKit.h>
+#import "EditableCellView.h"
 #import "WeaponCellView.h"
 
-@interface SingleWeaponViewController : UITableViewController <WeaponButtonControllerDelegate> {
+@interface SingleWeaponViewController : UITableViewController <EditableCellViewDelegate, WeaponButtonControllerDelegate> {
+    NSString *weaponName;
+    
     UIImage *ammoStoreImage;
     NSArray *ammoNames;
     
@@ -19,8 +22,10 @@
     char *crateness;
 }
 
+@property (nonatomic,retain) NSString *weaponName;
 @property (nonatomic,retain) UIImage *ammoStoreImage;
 @property (nonatomic,retain) NSArray *ammoNames;
 
+-(void) saveAmmos;
 
 @end
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -12,7 +12,7 @@
 #import "UIImageExtra.h"
 
 @implementation SingleWeaponViewController
-@synthesize ammoStoreImage, ammoNames;
+@synthesize weaponName, ammoStoreImage, ammoNames;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -84,13 +84,13 @@
     self.ammoStoreImage = img;
     [img release];
     
-    self.tableView.rowHeight = 120;
+    self.title = NSLocalizedString(@"Edit weapons preferences",@"");
 }
 
 -(void) viewWillAppear:(BOOL) animated {
     [super viewWillAppear:animated];
     
-    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title];
+    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
     NSDictionary *weapon = [[NSDictionary alloc] initWithContentsOfFile:ammoFile];
     [ammoFile release];
     
@@ -121,7 +121,10 @@
 
 -(void) viewWillDisappear:(BOOL) animated {
     [super viewWillDisappear:animated];
-    
+    [self saveAmmos];
+}
+
+-(void) saveAmmos {
     quantity[CURRENT_AMMOSIZE] = '\0';
     probability[CURRENT_AMMOSIZE] = '\0';
     delay[CURRENT_AMMOSIZE] = '\0';
@@ -139,7 +142,7 @@
                             delayStr,@"ammostore_delay",
                             cratenessStr,@"ammostore_crate", nil];
 
-    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.title];
+    NSString *ammoFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName];
     [weapon writeToFile:ammoFile atomically:YES];
     [ammoFile release];
     [weapon release];
@@ -148,53 +151,88 @@
 #pragma mark -
 #pragma mark Table view data source
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    return 1;
+    return 2;
 }
 
 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return CURRENT_AMMOSIZE;
+    if (section == 0)
+        return 1;
+    else
+        return CURRENT_AMMOSIZE;
 }
 
 // Customize the appearance of table view cells.
--(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-    static NSString *CellIdentifier = @"Cell";
+-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+    static NSString *CellIdentifier0 = @"Cell0";
+    static NSString *CellIdentifier1 = @"Cell1";
     NSInteger row = [indexPath row];
-    
-    WeaponCellView *cell = (WeaponCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-    if (cell == nil) {
-        cell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
-        cell.delegate = self;
+    UITableViewCell *cell = nil;
+
+    if (0 == [indexPath section]) {
+        EditableCellView *customCell = (EditableCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
+        if (customCell == nil) {
+            customCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault 
+                                            reuseIdentifier:CellIdentifier0] autorelease];
+            customCell.delegate = self;
+        }
+        
+        customCell.textField.text = self.weaponName;
+        customCell.detailTextLabel.text = nil;
+        customCell.imageView.image = nil;
+        customCell.selectionStyle = UITableViewCellSelectionStyleNone;
+        cell = customCell;
+    } else {
+        WeaponCellView *customCell = (WeaponCellView *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
+        if (customCell == nil) {
+            customCell = [[[WeaponCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
+            customCell.delegate = self;
+        }
+        
+        int x = ((row*32)/1024)*32;
+        int y = (row*32)%1024;
+        
+        UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
+        customCell.weaponIcon.image = img;
+        customCell.weaponName.text = [ammoNames objectAtIndex:row];
+        customCell.tag = row;
+        
+        [customCell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
+        [customCell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
+        [customCell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
+        [customCell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO];
+        cell = customCell;
     }
     
-    int x = ((row*32)/1024)*32;
-    int y = (row*32)%1024;
-
-    UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
-    cell.weaponIcon.image = img;
-    cell.weaponName.text = [ammoNames objectAtIndex:row];
-    cell.tag = row;
-    
-    [cell.initialQt setValue:[[NSString stringWithFormat:@"%c",quantity[row]] intValue] animated:NO];
-    [cell.probabilityQt setValue:[[NSString stringWithFormat:@"%c", probability[row]] intValue] animated:NO];
-    [cell.delayQt setValue:[[NSString stringWithFormat:@"%c", delay[row]] intValue] animated:NO];
-    [cell.crateQt setValue:[[NSString stringWithFormat:@"%c", crateness[row]] intValue] animated:NO];
-    
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     return cell;
 }
 
+-(CGFloat) tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+    if (0 == [indexPath section])
+        return aTableView.rowHeight;
+    else
+        return 120;
+}
 
 #pragma mark -
 #pragma mark Table view delegate
--(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-    // Navigation logic may go here. Create and push another view controller.
-    /*
-     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
-     // ...
-     // Pass the selected object to the new view controller.
-     [self.navigationController pushViewController:detailViewController animated:YES];
-     [detailViewController release];
-     */
+-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+    if (0 == [indexPath section]) {
+        EditableCellView *editableCell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
+        [editableCell replyKeyboard];
+    }
+}
+
+#pragma mark -
+#pragma mark editableCellView delegate
+// set the new value
+-(void) saveTextFieldValue:(NSString *)textString {    
+    // delete old file
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.plist",WEAPONS_DIRECTORY(),self.weaponName] error:NULL];
+    // update filename
+    self.weaponName = textString;
+    // save new file
+    [self saveAmmos];
 }
 
 #pragma mark -
@@ -209,22 +247,26 @@
 #pragma mark -
 #pragma mark Memory management
 -(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 {
-    free(quantity);
-    free(probability);
-    free(delay);
-    free(crateness);
+    free(quantity); quantity = NULL;
+    free(probability); probability = NULL;
+    free(delay); delay = NULL;
+    free(crateness); crateness = NULL;
     [super viewDidUnload];
+    self.weaponName = nil;
+    self.ammoStoreImage = nil;
+    self.ammoNames = nil;
     MSG_DIDUNLOAD();
 }
 
 
 -(void) dealloc {
+    [weaponName release];
+    [ammoStoreImage release];
+    [ammoNames release];
     [super dealloc];
 }
 
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -125,7 +125,7 @@
         [squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]];
         squareButton.ownerDictionary = selectedRow;
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-            cellLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1 ];
+            cellLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
         }
     } else {
         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
--- a/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.h	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.h	Tue Jul 20 03:14:43 2010 +0200
@@ -7,6 +7,7 @@
 //
 
 #import <UIKit/UIKit.h>
+
 @class SingleTeamViewController;
 
 @interface TeamSettingsViewController : UITableViewController {
--- a/project_files/HedgewarsMobile/Classes/WeaponCellView.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/WeaponCellView.m	Tue Jul 20 03:14:43 2010 +0200
@@ -161,8 +161,15 @@
     [probabilityQt release];
     [delayQt release];
     [crateQt release];
+    [initialImg release];
+    [probabImg release];
+    [delayImg release];
+    [crateImg release];
+    [initialLab release];
+    [probLab release];
+    [delLab release];
+    [craLab release];
     [super dealloc];
 }
 
-
 @end
--- a/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Tue Jul 20 03:14:43 2010 +0200
@@ -126,7 +126,7 @@
     NSString *selectedWeaponFile = [self.listOfWeapons objectAtIndex:row];
     
     // this must be set so childController can load the correct plist
-    childController.title = [selectedWeaponFile stringByDeletingPathExtension];
+    childController.weaponName = [selectedWeaponFile stringByDeletingPathExtension];
     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
 
     [self.navigationController pushViewController:childController animated:YES];
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Tue Jul 20 03:14:43 2010 +0200
@@ -123,6 +123,7 @@
 		61A1188511683A8C00359010 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61A117FE1168322700359010 /* CoreGraphics.framework */; };
 		61A118D311683CD100359010 /* HedgewarsTitle.png in Resources */ = {isa = PBXBuildFile; fileRef = 611FD9CB1155A28C00C2203D /* HedgewarsTitle.png */; };
 		61B3D71C11EA6F2700EC7420 /* uKeys.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987FE114AA34C00BA94A9 /* uKeys.pas */; };
+		61C079E411F35A300072BF46 /* EditableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C079E311F35A300072BF46 /* EditableCellView.m */; };
 		61C3255B1179A384001E70B1 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61C3255A1179A384001E70B1 /* OpenAL.framework */; };
 		61C325901179A732001E70B1 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61C3255A1179A384001E70B1 /* OpenAL.framework */; };
 		61C325A31179A7AD001E70B1 /* libopenalbridge.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61C3251D1179A300001E70B1 /* libopenalbridge.a */; };
@@ -383,6 +384,8 @@
 		618736B8118CA28600123B23 /* GearDrawing.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = GearDrawing.inc; path = ../../hedgewars/GearDrawing.inc; sourceTree = SOURCE_ROOT; };
 		619C09E911E8B8D600F1DF16 /* title_small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = title_small.png; path = "Resources/Frontend-iPhone/title_small.png"; sourceTree = "<group>"; };
 		61A117FE1168322700359010 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+		61C079E211F35A300072BF46 /* EditableCellView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditableCellView.h; sourceTree = "<group>"; };
+		61C079E311F35A300072BF46 /* EditableCellView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditableCellView.m; sourceTree = "<group>"; };
 		61C3251D1179A300001E70B1 /* libopenalbridge.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libopenalbridge.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		61C3255A1179A384001E70B1 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
 		61E1F4F711D004240016A5AA /* adler32.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = adler32.pas; path = ../../hedgewars/adler32.pas; sourceTree = SOURCE_ROOT; };
@@ -633,6 +636,8 @@
 				6163EE7D11CC2600001C0453 /* SingleWeaponViewController.m */,
 				616591FE11CA9BA200D6E256 /* SingleSchemeViewController.h */,
 				616591FF11CA9BA200D6E256 /* SingleSchemeViewController.m */,
+				61C079E211F35A300072BF46 /* EditableCellView.h */,
+				61C079E311F35A300072BF46 /* EditableCellView.m */,
 				61F904D511DF7DA30068B24D /* WeaponCellView.h */,
 				61F904D611DF7DA30068B24D /* WeaponCellView.m */,
 			);
@@ -1183,6 +1188,7 @@
 				61E1F4F811D004240016A5AA /* adler32.pas in Sources */,
 				61F904D711DF7DA30068B24D /* WeaponCellView.m in Sources */,
 				61B3D71C11EA6F2700EC7420 /* uKeys.pas in Sources */,
+				61C079E411F35A300072BF46 /* EditableCellView.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
--- a/project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib	Mon Jul 19 23:38:18 2010 +0400
+++ b/project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib	Tue Jul 20 03:14:43 2010 +0200
@@ -12,7 +12,7 @@
 		</object>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
-			<integer value="1"/>
+			<integer value="7"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
@@ -100,7 +100,7 @@
 					<object class="IBUISegmentedControl" id="88728219">
 						<reference key="NSNextResponder" ref="191373211"/>
 						<int key="NSvFlags">289</int>
-						<string key="NSFrame">{{754, 171}, {240, 30}}</string>
+						<string key="NSFrame">{{754, 169}, {240, 30}}</string>
 						<reference key="NSSuperview" ref="191373211"/>
 						<bool key="IBUIOpaque">NO</bool>
 						<string key="targetRuntimeIdentifier">IBIPadFramework</string>
@@ -137,6 +137,10 @@
 							<reference ref="4"/>
 							<reference ref="4"/>
 						</object>
+						<object class="NSColor" key="IBTintColor">
+							<int key="NSColorSpace">1</int>
+							<bytes key="NSRGB">MCAwLjUwMTk2MDgxNCAwAA</bytes>
+						</object>
 					</object>
 					<object class="IBUISlider" id="938256702">
 						<reference key="NSNextResponder" ref="191373211"/>