draw a hedgehog when presenting hats
authorkoda
Mon, 19 Apr 2010 01:39:55 +0000
changeset 3357 3836a31879e7
parent 3356 3ae3fccb439e
child 3358 546e75f839ce
draw a hedgehog when presenting hats other lazy loading procedure fix crash when loading multiple games
cocoaTouch/DetailViewController.m
cocoaTouch/FortsViewController.m
cocoaTouch/HogHatViewController.m
cocoaTouch/MasterViewController.h
cocoaTouch/MasterViewController.m
cocoaTouch/OverlayViewController.m
cocoaTouch/PopoverMenuViewController.m
project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj
--- a/cocoaTouch/DetailViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/DetailViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -22,7 +22,7 @@
 	return rotationManager(interfaceOrientation);
 }
 
-- (void)viewDidLoad {
+-(void) viewDidLoad {
     self.title = NSLocalizedString(@"Settings",@"");
 
     // allocate controllers and store them into the array
@@ -37,7 +37,13 @@
     // on ipad make the general setting the first view, on iphone add the "Done" button on top left
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         
-        // show some stuff
+        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(112, 112, 480, 320)];
+        label.text = @"Press the buttons on the left";
+        label.font = [UIFont systemFontOfSize:20];
+        label.textAlignment = UITextAlignmentCenter;
+        [self.view addSubview:label];
+        [label release];
+        
         
         //[self.navigationController pushViewController:nextController animated:NO];
     } else {
@@ -53,7 +59,11 @@
 #pragma mark -
 #pragma mark Table view data source
 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
-    return 1;
+    // don't display 
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+        return 0;
+    else
+        return 1;
 }
 
 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@@ -78,6 +88,8 @@
     return cell;
 }
 
+#pragma mark -
+#pragma mark Table view delegate
 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSInteger row = [indexPath row];
     UIViewController *nextController;
--- a/cocoaTouch/FortsViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/FortsViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -52,6 +52,9 @@
     }
     self.fortSprites = spriteArray;
     [spriteArray release];
+    
+    // statically set row height instead of using delegate method for performance reasons
+    self.tableView.rowHeight = 200;
 }
 
 
@@ -174,9 +177,6 @@
     [self.navigationController popViewControllerAnimated:YES];
 }
 
--(CGFloat) tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-    return 200;
-}
 
 #pragma mark -
 #pragma mark Memory management
--- a/cocoaTouch/HogHatViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/HogHatViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -29,15 +29,20 @@
     NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatsDirectory error:NULL];
     self.hatArray = array;
     
+    NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
+    UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
+    [normalHogFile release];
+    
     // load all the hat images from the previous array but save only the first sprite and store it in hatSprites
     NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]];
     for (NSString *hat in hatArray) {
         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,hat];
         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
         [hatFile release];
-        [spriteArray addObject:hatSprite];
+        [spriteArray addObject:[normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)]];
         [hatSprite release];
     }
+    [normalHogSprite release];
     self.hatSprites = spriteArray;
     [spriteArray release];
 }
--- a/cocoaTouch/MasterViewController.h	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/MasterViewController.h	Mon Apr 19 01:39:55 2010 +0000
@@ -10,17 +10,23 @@
 
 
 @class DetailViewController;
+@class GeneralSettingsViewController;
+@class TeamSettingsViewController;
+@class WeaponSettingsViewController;
+@class SchemeSettingsViewController;
 
 @interface MasterViewController : UITableViewController {
     DetailViewController *detailViewController;
-    NSArray *optionList;
-    NSArray *controllers;
+    NSArray *controllerNames;
     NSIndexPath *lastIndexPath;
+    GeneralSettingsViewController *generalSettingsViewController;
+    TeamSettingsViewController *teamSettingsViewController;
+    WeaponSettingsViewController *weaponSettingsViewController;
+    SchemeSettingsViewController *schemeSettingsViewController;
 }
 
 @property (nonatomic, retain) DetailViewController *detailViewController;
-@property (nonatomic, retain) NSArray *optionList;
-@property (nonatomic, retain) NSArray *controllers;
+@property (nonatomic, retain) NSArray *controllerNames;
 @property (nonatomic, retain) NSIndexPath *lastIndexPath;
 
 -(IBAction) dismissSplitView;
--- a/cocoaTouch/MasterViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/MasterViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -10,10 +10,12 @@
 #import "DetailViewController.h"
 #import "GeneralSettingsViewController.h"
 #import "TeamSettingsViewController.h"
+#import "WeaponSettingsViewController.h"
+#import "SchemeSettingsViewController.h"
 #import "CommodityFunctions.h"
 
 @implementation MasterViewController
-@synthesize detailViewController, optionList, controllers, lastIndexPath;
+@synthesize detailViewController, controllerNames, lastIndexPath;
 
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
@@ -27,34 +29,15 @@
     [super viewDidLoad];
     
     // the list of selectable controllers
-    optionList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
-                                                  NSLocalizedString(@"Teams",@""),
-                                                  NSLocalizedString(@"Weapons",@""),
-                                                  NSLocalizedString(@"Schemes",@""),
-                                                  nil];
+    controllerNames = [[NSArray alloc] initWithObjects:NSLocalizedString(@"General",@""),
+                                                       NSLocalizedString(@"Teams",@""),
+                                                       NSLocalizedString(@"Weapons",@""),
+                                                       NSLocalizedString(@"Schemes",@""),
+                                                       nil];
     // the "Done" button on top left
-    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:0
+    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                                           target:self
                                                                                           action:@selector(dismissSplitView)];
-    // list of allocated viewcontrollers (same in DetailViewController)
-    NSMutableArray *array= [[NSMutableArray alloc] init];
-
-    GeneralSettingsViewController *generalSettingsViewController = [[GeneralSettingsViewController alloc]
-                                                                    initWithStyle:UITableViewStyleGrouped];
-    generalSettingsViewController.title = NSLocalizedString(@"General",@"");
-    generalSettingsViewController.navigationItem.hidesBackButton = YES;
-    [array addObject:generalSettingsViewController];
-    [generalSettingsViewController release];
-    
-    TeamSettingsViewController *teamSettingsViewController = [[TeamSettingsViewController alloc] 
-                                                              initWithStyle:UITableViewStyleGrouped];
-    teamSettingsViewController.title = NSLocalizedString(@"Teams",@"");
-    teamSettingsViewController.navigationItem.hidesBackButton = YES;
-    [array addObject:teamSettingsViewController];
-    [teamSettingsViewController release];
-    
-    self.controllers = array;
-    [array release];
 }
 
 #pragma mark -
@@ -64,12 +47,10 @@
     return 1;
 }
 
-
 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-    return [optionList count];
+    return [controllerNames count];
 }
 
-
 // Customize the appearance of table view cells.
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CellIdentifier = @"Cell";
@@ -77,7 +58,7 @@
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
-        cell.textLabel.text = [optionList objectAtIndex:[indexPath row]];
+        cell.textLabel.text = [controllerNames objectAtIndex:[indexPath row]];
     }
     
     return cell;
@@ -115,13 +96,38 @@
 #pragma mark Table view delegate
 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     int newRow = [indexPath row];
-    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : 0;
+    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
+    UIViewController *nextController;
     
     if (newRow != oldRow) {
         [self.tableView deselectRowAtIndexPath:lastIndexPath animated:YES];
         [detailViewController.navigationController popToRootViewControllerAnimated:NO];
         
-        UITableViewController *nextController = [self.controllers objectAtIndex:[indexPath row]];
+        switch (newRow) {
+            case 0:
+                if (nil == generalSettingsViewController)
+                    generalSettingsViewController = [[GeneralSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+                nextController = generalSettingsViewController;
+                break;
+            case 1:
+                if (nil == teamSettingsViewController)
+                    teamSettingsViewController = [[TeamSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+                nextController = teamSettingsViewController;
+                break;
+            case 2:
+                if (nil == weaponSettingsViewController)
+                    weaponSettingsViewController = [[WeaponSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+                nextController = weaponSettingsViewController;
+                break;
+            case 3:
+                if (nil == schemeSettingsViewController)
+                    schemeSettingsViewController = [[SchemeSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
+                nextController = schemeSettingsViewController;
+                break;
+        }
+        
+        nextController.navigationItem.hidesBackButton = YES;
+        nextController.title = [controllerNames objectAtIndex:newRow];
         [detailViewController.navigationController pushViewController:nextController animated:NO];
         self.lastIndexPath = indexPath;
         [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
@@ -137,9 +143,25 @@
     // Relinquish ownership any cached data, images, etc that aren't in use.
 }
 
-- (void)dealloc {
-    [optionList release];
+-(void) viewDidUnload {
+    self.detailViewController = nil;
+    self.controllerNames = nil;
+    self.lastIndexPath = nil;
+    generalSettingsViewController = nil;
+    teamSettingsViewController = nil;
+    weaponSettingsViewController = nil;
+    schemeSettingsViewController = nil;
+    [super viewDidUnload];
+}
+
+-(void) dealloc {
+    [controllerNames release];
     [detailViewController release];
+    [lastIndexPath release];
+    [generalSettingsViewController release];
+    [teamSettingsViewController release];
+    [weaponSettingsViewController release];
+    [schemeSettingsViewController release];
     [super dealloc];
 }
 
--- a/cocoaTouch/OverlayViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/OverlayViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -67,21 +67,28 @@
     
     // add timer too runloop, otherwise it doesn't work
     [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode];
-    // listen for dismissal of the popover (see below)x
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil];
+    
+    // listen for dismissal of the popover (see below)
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(dismissPopover)
+                                                 name:@"dismissPopover"
+                                               object:nil];
     // present the overlay after 2 seconds
-    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO];
+    [NSTimer scheduledTimerWithTimeInterval:2
+                                     target:self
+                                   selector:@selector(showMenuAfterwards)
+                                   userInfo:nil
+                                    repeats:NO];
 }
 
 -(void) viewDidUnload {
-	[dimTimer invalidate];
-	self.dimTimer = nil;
     self.popoverController = nil;
     self.popupMenu = nil;
     [super viewDidUnload];
 }
 
 -(void) dealloc {
+	[dimTimer invalidate];
     [popupMenu release];
     [popoverController release];
     // dimTimer is autoreleased
--- a/cocoaTouch/PopoverMenuViewController.m	Sun Apr 18 23:19:15 2010 +0000
+++ b/cocoaTouch/PopoverMenuViewController.m	Mon Apr 19 01:39:55 2010 +0000
@@ -23,14 +23,11 @@
 -(void) didReceiveMemoryWarning {
     // Releases the view if it doesn't have a superview.
     [super didReceiveMemoryWarning];
-    self.menuList = nil;
 }
 
 -(void) viewDidLoad {
     isPaused = NO;
-    self.tableView.allowsSelection = YES;
-    self.tableView.alwaysBounceVertical = YES;
-    self.tableView.delaysContentTouches = NO;
+
     menuList = [[NSArray alloc] initWithObjects:
                 NSLocalizedString(@"Pause Game", @""),
                 NSLocalizedString(@"Chat", @""),
--- a/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj	Sun Apr 18 23:19:15 2010 +0000
+++ b/project_files/HedgewarsMobile/HedgewarsMobile.xcodeproj/project.pbxproj	Mon Apr 19 01:39:55 2010 +0000
@@ -428,7 +428,6 @@
 				29B97315FDCFA39411CA2CEA /* Other Sources */,
 				29B97323FDCFA39411CA2CEA /* Frameworks */,
 				29B97317FDCFA39411CA2CEA /* Resources */,
-				6100DAD4115446B000F455E0 /* Resources-iPad */,
 				19C28FACFE9D520D11CA2CBB /* Products */,
 				61370652117B1D50004EE44A /* Entitlements-Distribution.plist */,
 				611E12FE117BBBDA0044B62F /* Entitlements-Development.plist */,
@@ -458,6 +457,7 @@
 		29B97317FDCFA39411CA2CEA /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				6100DAD4115446B000F455E0 /* Resources-iPad */,
 				6100DB1711544E8400F455E0 /* XIB */,
 				6179937011501D5800BA94A9 /* buttons */,
 				6179936F11501D4100BA94A9 /* back panels */,
@@ -500,7 +500,6 @@
 			children = (
 				6151347D116C2803001F16D1 /* Icon-iPad.png */,
 				6122CD00116BECCA002648E9 /* Default-Landscape.png */,
-				61CE2509115E74260098C467 /* XIB */,
 				611FD9C81155A1F200C2203D /* Background.png */,
 				611FD9CB1155A28C00C2203D /* HedgewarsTitle.png */,
 				611FD9D11155A41000C2203D /* Multiplayer.png */,
@@ -512,6 +511,8 @@
 		6100DB1711544E8400F455E0 /* XIB */ = {
 			isa = PBXGroup;
 			children = (
+				611E127C117BACC60044B62F /* GameConfigViewController-iPad.xib */,
+				61A118C911683C7600359010 /* MainMenuViewController-iPad.xib */,
 				611E127E117BACCD0044B62F /* GameConfigViewController-iPhone.xib */,
 				615134B0116C2C5F001F16D1 /* OverlayViewController.xib */,
 				61A118CB11683C7A00359010 /* MainMenuViewController-iPhone.xib */,
@@ -712,15 +713,6 @@
 			name = openalbridge;
 			sourceTree = "<group>";
 		};
-		61CE2509115E74260098C467 /* XIB */ = {
-			isa = PBXGroup;
-			children = (
-				611E127C117BACC60044B62F /* GameConfigViewController-iPad.xib */,
-				61A118C911683C7600359010 /* MainMenuViewController-iPad.xib */,
-			);
-			name = XIB;
-			sourceTree = "<group>";
-		};
 		9283015C0F10E48900CC5A3C /* Pascal Sources */ = {
 			isa = PBXGroup;
 			children = (
@@ -1136,8 +1128,9 @@
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
+				CODE_SIGN_ENTITLEMENTS = "Entitlements-Distribution.plist";
 				CODE_SIGN_IDENTITY = "iPhone Distribution";
-				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Vittorio Giovara";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
 				FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B  -Sgix -dLOWRES";
 				FPC_COMPILER_BINARY_DIR = /usr/local/lib/fpc/2.5.1;
 				FPC_MAIN_FILE = "$(PROJECT_DIR)/../../hedgewars/hwLibrary.pas";
@@ -1167,7 +1160,7 @@
 				);
 				PREBINDING = NO;
 				PROVISIONING_PROFILE = "";
-				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "4ABEE8D8-80C1-4CBA-BEAD-95A4349896AA";
+				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
 				SDKROOT = iphoneos3.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};
@@ -1179,7 +1172,7 @@
 				ALWAYS_SEARCH_USER_PATHS = NO;
 				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
 				CODE_SIGN_ENTITLEMENTS = "Entitlements-Distribution.plist";
-				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Vittorio Giovara";
+				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
 				COPY_PHASE_STRIP = YES;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = HedgewarsMobile_Prefix.pch;
@@ -1189,7 +1182,7 @@
 					"\"$(SRCROOT)\"",
 				);
 				PRODUCT_NAME = HedgewarsMobile;
-				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "0CD03A6D-BC86-4124-B76B-03D836E163D1";
+				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
 				TARGETED_DEVICE_FAMILY = "1,2";
 			};
 			name = Distribution;