some interface tricks for iphone as well
authorkoda
Sat, 13 Nov 2010 01:24:39 +0100
changeset 4287 7dbdc862097c
parent 4284 57a501a69e5f
child 4290 82f1f1d819c0
some interface tricks for iphone as well
project_files/HedgewarsMobile/Classes/MainMenuViewController.m
project_files/HedgewarsMobile/Classes/MapConfigViewController.m
project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.h
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m
project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -103,9 +103,9 @@
                                                         error:NULL];
     createWeaponNamed(@"Default", 0);
     createWeaponNamed(@"Crazy", 1);
-    createWeaponNamed(@"Pro mode", 2);
+    createWeaponNamed(@"Pro Mode", 2);
     createWeaponNamed(@"Shoppa", 3);
-    createWeaponNamed(@"Clean slate", 4);
+    createWeaponNamed(@"Clean Slate", 4);
     createWeaponNamed(@"Minefield", 5);
     createWeaponNamed(@"Thinking with Portals", 6);
 
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -72,7 +72,7 @@
     // perform as if user clicked on an entry
     [self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
     if (IS_NOT_POWERFUL() == NO)
-        [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
+        [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
 }
 
 -(void) turnOffWidgets {
--- a/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SchemeSettingsViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -81,12 +81,14 @@
     createSchemeNamed([fileName stringByDeletingPathExtension]);
 
     [self.listOfSchemes addObject:fileName];
-    [fileName release];
 
     // order the array alphabetically, so schemes will keep their position
     [self.listOfSchemes sortUsingSelector:@selector(compare:)];
+    [self.tableView reloadData];
 
-    [self.tableView reloadData];
+    NSInteger index = [self.listOfSchemes indexOfObject:fileName];
+    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
+    [fileName release];
 }
 
 #pragma mark -
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.h	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.h	Sat Nov 13 01:24:39 2010 +0100
@@ -31,13 +31,16 @@
 
     NSString *selectedScheme;
     NSString *selectedWeapon;
+
+    UISwitch *syncSwitch;
 }
 
-@property (nonatomic, retain) NSArray *listOfSchemes;
-@property (nonatomic, retain) NSArray *listOfWeapons;
+@property (nonatomic,retain) NSArray *listOfSchemes;
+@property (nonatomic,retain) NSArray *listOfWeapons;
 @property (nonatomic,retain) NSIndexPath *lastIndexPath_sc;
 @property (nonatomic,retain) NSIndexPath *lastIndexPath_we;
 @property (nonatomic,retain) NSString *selectedScheme;
 @property (nonatomic,retain) NSString *selectedWeapon;
+@property (nonatomic,retain) UISwitch *syncSwitch;
 
 @end
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -24,7 +24,7 @@
 #import "SDL_uikitappdelegate.h"
 
 @implementation SchemeWeaponConfigViewController
-@synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon;
+@synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon, syncSwitch;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -81,27 +81,30 @@
 #pragma mark -
 #pragma mark Table view data source
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    return 2;
+    return 3;
 }
 
 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     if (section == 0)
         return [self.listOfSchemes count];
+    else if (section == 1)
+        return [self.listOfWeapons count];
     else
-        return [self.listOfWeapons count];
+        return 1;
 }
 
 // Customize the appearance of table view cells.
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CellIdentifier = @"Cell";
     NSInteger row = [indexPath row];
+    NSInteger section = [indexPath section];
 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil)
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
 
     cell.accessoryView = nil;
-    if ([indexPath section] == 0) {
+    if (0 == section) {
         cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension];
         NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]];
         NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str];
@@ -113,7 +116,7 @@
             [checkbox release];
             self.lastIndexPath_sc = indexPath;
         }
-    } else {
+    } else if (1 == section) {
         cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension];
         NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]];
         NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str];
@@ -125,8 +128,19 @@
             [checkbox release];
             self.lastIndexPath_we = indexPath;
         }
+    } else {
+        if (self.syncSwitch == nil) {
+            UISwitch *theSwitch = [[UISwitch alloc] init];
+            [theSwitch setOn:YES];
+            self.syncSwitch = theSwitch;
+            [theSwitch release];
+        }
+        cell.textLabel.text = IS_IPAD() ? NSLocalizedString(@"Sync Schemes",@"") : NSLocalizedString(@"Sync Schemes and Weapons",@"");
+        cell.detailTextLabel.text = IS_IPAD() ? nil : NSLocalizedString(@"Choosing a Scheme will select its associated Weapon",@"");
+        cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
+        cell.accessoryView = self.syncSwitch;
     }
-    
+
     cell.backgroundColor = [UIColor blackColor];
     cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
     cell.detailTextLabel.textColor = [UIColor whiteColor];
@@ -142,8 +156,11 @@
     NSString *text;
     if (section == 0) 
         text = NSLocalizedString(@"Schemes",@"");
+    else if (section == 1)
+        text = NSLocalizedString(@"Weapons",@"");
     else
-        text = NSLocalizedString(@"Weapons",@"");
+        text = NSLocalizedString(@"Options",@"");
+
     UILabel *theLabel = createBlueLabel(text, frame);
     theLabel.center = CGPointMake(self.view.frame.size.width/2, 20);
 
@@ -177,6 +194,17 @@
         if ([indexPath section] == 0) {
             self.lastIndexPath_sc = indexPath;
             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
+            if (self.syncSwitch.on) {
+                for (NSString *str in self.listOfWeapons) {
+                    if ([str isEqualToString:self.selectedScheme]) {
+                        int index = [self.listOfSchemes indexOfObject:str];
+                        self.selectedWeapon = str;
+                        self.lastIndexPath_we = [NSIndexPath indexPathForRow:index inSection:1];
+                        [self.tableView reloadData];
+                        break;
+                    }
+                }
+            }
         } else {
             self.lastIndexPath_we = indexPath;
             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
@@ -195,6 +223,7 @@
         self.lastIndexPath_we = nil;
         self.listOfSchemes = nil;
         self.listOfWeapons = nil;
+        self.syncSwitch = nil;
         MSG_MEMCLEAN();
     }
     [super didReceiveMemoryWarning];
@@ -207,6 +236,7 @@
     self.lastIndexPath_we = nil;
     self.selectedScheme = nil;
     self.selectedWeapon = nil;
+    self.syncSwitch = nil;
     MSG_DIDUNLOAD();
     [super viewDidUnload];
 }
@@ -219,6 +249,7 @@
     [lastIndexPath_we release];
     [selectedScheme release];
     [selectedWeapon release];
+    [syncSwitch release];
     [super dealloc];
 }
 
--- a/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/TeamSettingsViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -85,12 +85,14 @@
     createTeamNamed([fileName stringByDeletingPathExtension]);
 
     [self.listOfTeams addObject:fileName];
-    [fileName release];
 
     // order the array alphabetically, so teams will keep their position
     [self.listOfTeams sortUsingSelector:@selector(compare:)];
+    [self.tableView reloadData];
 
-    [self.tableView reloadData];
+    NSInteger index = [self.listOfTeams indexOfObject:fileName];
+    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
+    [fileName release];
 }
 
 #pragma mark -
--- a/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Fri Nov 12 23:59:40 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m	Sat Nov 13 01:24:39 2010 +0100
@@ -82,12 +82,14 @@
     createWeaponNamed([fileName stringByDeletingPathExtension], 0);
 
     [self.listOfWeapons addObject:fileName];
-    [fileName release];
 
     // order the array alphabetically, so schemes will keep their position
     [self.listOfWeapons sortUsingSelector:@selector(compare:)];
+    [self.tableView reloadData];
 
-    [self.tableView reloadData];
+    NSInteger index = [self.listOfWeapons indexOfObject:fileName];
+    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
+    [fileName release];
 }
 
 #pragma mark -