update some files for new graphics and new ios4.2
authorkoda
Thu, 25 Nov 2010 02:45:52 +0100
changeset 4356 d1d26f8963a3
parent 4354 c4e1820fa792
child 4358 0445d807193e
update some files for new graphics and new ios4.2 most importantly rotation finally seems to work on iphone also fix two glitches for old gen devices
project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/MapConfigViewController.m
project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m
project_files/HedgewarsMobile/Classes/OverlayViewController.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
project_files/HedgewarsMobile/Classes/SplitViewRootController.h
project_files/HedgewarsMobile/Classes/SplitViewRootController.m
project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
project_files/HedgewarsMobile/Classes/UIImageExtra.m
--- a/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -27,7 +27,7 @@
 
 #define BTNS_PER_ROW         9
 #define DEFAULT_DESCRIPTION  IS_IPAD() ? \
-                             NSLocalizedString(@"Hold your finger on a weapon to see what it does...",@"") : \
+                             NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nYou can move this window anywhere on the screen.",@"") : \
                              NSLocalizedString(@"Hold your finger on a weapon to see what it does.\nTap anywhere to dismiss.",@"")
 
 @implementation AmmoMenuViewController
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Thu Nov 25 02:45:52 2010 +0100
@@ -29,11 +29,8 @@
 #import "PascalImports.h"
 
 BOOL inline rotationManager (UIInterfaceOrientation interfaceOrientation) {
-    if (IS_IPAD())
-        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
-               (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
-    else
-        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
+    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
+           (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
 }
 
 NSInteger inline randomPort () {
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -389,10 +389,10 @@
     NSMutableArray *mapArray = [[NSMutableArray alloc] init];
     for (NSString *str in mapArrayFull) {
         CGSize imgSize = PSPNGSizeFromMetaData([MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]);
-        //DLog(@"%@ %f %f", str, imgSize.width, imgSize.height);
+        // remove images that are too big for certain devices
         if (IS_NOT_POWERFUL() && imgSize.height > 1024.0f)
             continue;
-        if (IS_IPAD() && imgSize.height > 1280.0f)
+        if ([modelType() hasPrefix:@"iPad1"] && [[[UIDevice currentDevice] systemVersion] intValue] < 4 && imgSize.height > 1280.0f)
             continue;
         [mapArray addObject:str];
     }
@@ -401,10 +401,10 @@
     NSMutableArray *missionArray = [[NSMutableArray alloc] init];
     for (NSString *str in missionArrayFull) {
         CGSize imgSize = PSPNGSizeFromMetaData([MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]);
-        //DLog(@"%@ %f %f", str, imgSize.width, imgSize.height);
+        // remove images that are too big for certain devices
         if (IS_NOT_POWERFUL() && imgSize.height > 1024.0f)
             continue;
-        if (IS_IPAD() && imgSize.height > 1280.0f)
+        if ([modelType() hasPrefix:@"iPad1"] && [[[UIDevice currentDevice] systemVersion] intValue] < 4 && imgSize.height > 1280.0f)
             continue;
         [missionArray addObject:str];
     }
@@ -449,7 +449,7 @@
 
     if ([self.tableView respondsToSelector:@selector(setBackgroundView:)])
         [self.tableView setBackgroundView:nil];
-    self.view.backgroundColor = [UIColor clearColor];
+    self.tableView.backgroundColor = [UIColor clearColor];
     self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
 }
@@ -491,14 +491,16 @@
 
 -(void) didReceiveMemoryWarning {
     self.dataSourceArray = nil;
+    [super didReceiveMemoryWarning];
 
-    self.tableView = nil;
-    self.maxLabel = nil;
-    self.sizeLabel = nil;
-    self.slider = nil;
+    if (self.view.superview == nil) {
+        self.tableView = nil;
+        self.maxLabel = nil;
+        self.sizeLabel = nil;
+        self.slider = nil;
+    }
 
     MSG_MEMCLEAN();
-    [super didReceiveMemoryWarning];
 }
 
 -(void) dealloc {
--- a/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/MapPreviewButtonView.m	Thu Nov 25 02:45:52 2010 +0100
@@ -53,11 +53,12 @@
 #pragma mark -
 #pragma mark image wrappers
 -(void) setBackgroundImageRounded:(UIImage *)image forState:(UIControlState)state {
-    [self setBackgroundImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];    
+    // TODO:http://stackoverflow.com/questions/4272476/setbackgroundimage-behaviour-changed-on-ipad-4-2
+    [self setBackgroundImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:state];
 }
 
 -(void) setImageRounded:(UIImage *)image forState:(UIControlState)state {
-    [self setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];    
+    [self setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:state];
 }
 
 -(void) setImageRoundedForNormalState:(UIImage *)image {
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Thu Nov 25 02:45:52 2010 +0100
@@ -51,6 +51,7 @@
     // stuff initialized externally
     BOOL isNetGame;
     BOOL useClassicMenu;
+    NSInteger initialOrientation;
     
     // dual head support
     NSInteger initialScreenCount;
@@ -63,6 +64,7 @@
 @property (nonatomic,retain) AmmoMenuViewController *amvc;
 @property (assign) BOOL isNetGame;
 @property (assign) BOOL useClassicMenu;
+@property (assign) NSInteger initialOrientation;
 
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -38,16 +38,22 @@
 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
 
 @implementation OverlayViewController
-@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu;
+@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation;
 
 #pragma mark -
 #pragma mark rotation
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
+    // don't rotate until the game is running for performance and synchronization with the sdlview
+    if (isGameRunning() == NO)
+        return (interfaceOrientation == (UIInterfaceOrientation) self.initialOrientation);
     return rotationManager(interfaceOrientation);
 }
 
 // pause the game and remove objc menus so that animation is smoother
 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{
+    if (isGameRunning() == NO)
+        return;
+
     [self dismissPopover];
     if (HW_isPaused() == NO)
         HW_pause();
@@ -75,6 +81,9 @@
 
 // now restore previous state
 -(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation {
+    if (isGameRunning() == NO)
+        return;
+
     if (wasVisible || IS_DUALHEAD())
         [self.amvc appearInView:self.view];
     if (HW_isPaused() == YES)
@@ -85,6 +94,9 @@
 
 // while in dual head the above rotation functions are not called
 -(void) dualHeadRotation:(NSNotification *)notification {
+    if (isGameRunning() == NO)
+        return;
+
     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
     
     [UIView beginAnimations:@"rotation" context:NULL];
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Thu Nov 25 02:45:52 2010 +0100
@@ -128,7 +128,11 @@
     [setup release];
 
     // since the sdlwindow is not yet created, we add the overlayController with a delay
-    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:isNetGameNum,@"net",menuStyle,@"menu",nil];
+    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
+                          isNetGameNum,@"net",
+                          menuStyle,@"menu",
+                          [[gameDictionary objectForKey:@"game_dictionary"] objectForKey:@"orientation"],@"orientation",
+                          nil];
     [self performSelector:@selector(displayOverlayLater:) withObject:dict afterDelay:1];
 
     // this is the pascal fuction that starts the game (wrapped around isInGame)
@@ -157,6 +161,7 @@
     self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
     self.overlayController.isNetGame = [[dict objectForKey:@"net"] boolValue];
     self.overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue];
+    self.overlayController.initialOrientation = [[dict objectForKey:@"orientation"] intValue];
     
     UIWindow *gameWindow;
     if (IS_DUALHEAD())
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -47,7 +47,7 @@
         if (IS_IPAD())
             [self.tableView setBackgroundView:nil];
         else {
-            UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"backgroundCenter.png"];
+            UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"];
             UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage];
             [backgroundImage release];
             [self.tableView setBackgroundView:background];
--- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.h	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.h	Thu Nov 25 02:45:52 2010 +0100
@@ -25,8 +25,12 @@
 
 @interface SplitViewRootController: UIViewController {
     MasterViewController *activeController;
+    UINavigationController *rightNavController;
+    UISplitViewController *splitViewRootController;
 }
 
 @property (nonatomic,retain) MasterViewController *activeController;
+@property (nonatomic,retain) UINavigationController *rightNavController;
+@property (nonatomic,retain) UISplitViewController *splitViewRootController;
 
 @end
--- a/project_files/HedgewarsMobile/Classes/SplitViewRootController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/SplitViewRootController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -24,7 +24,7 @@
 #import "CommodityFunctions.h"
 
 @implementation SplitViewRootController
-@synthesize activeController;
+@synthesize activeController, rightNavController, splitViewRootController;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -49,7 +49,7 @@
         self.activeController = rightController;
         [rightController release];
     }
-    UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
+    self.rightNavController = [[UINavigationController alloc] initWithRootViewController:self.activeController];
 
     if (IS_IPAD()) {
         MasterViewController *leftController = [[MasterViewController alloc] initWithStyle:UITableViewStylePlain];
@@ -57,18 +57,18 @@
         UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftController];
         [leftController release];
 
-        UISplitViewController *splitViewRootController = [[UISplitViewController alloc] init];
-        splitViewRootController.delegate = nil;
-        splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
-        splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, rightNavController, nil];
+        self.splitViewRootController = [[UISplitViewController alloc] init];
+        self.splitViewRootController.delegate = nil;
+        self.splitViewRootController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+        self.splitViewRootController.viewControllers = [NSArray arrayWithObjects: leftNavController, self.rightNavController, nil];
         [leftNavController release];
-        [rightNavController release];
+        [self.rightNavController release];
 
         // add view to main controller
-        [self.view addSubview:splitViewRootController.view];
+        [self.view addSubview:self.splitViewRootController.view];
     } else {
-        rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
-        [self.view addSubview:rightNavController.view];
+        self.rightNavController.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
+        [self.view addSubview:self.rightNavController.view];
     }
 
     [super viewDidLoad];
@@ -76,12 +76,16 @@
 
 -(void) viewDidUnload {
     self.activeController = nil;
+    self.rightNavController = nil;
+    self.splitViewRootController = nil;
     MSG_DIDUNLOAD();
     [super viewDidUnload];
 }
 
 -(void) dealloc {
-    [self.activeController release];
+    [activeController release];
+    [rightNavController release];
+    [splitViewRootController release];
     [super dealloc];
 }
 
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Thu Nov 25 02:45:52 2010 +0100
@@ -43,7 +43,7 @@
         if (IS_IPAD())
             [self.tableView setBackgroundView:nil];
         else {
-            UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"backgroundCenter.png"];
+            UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"];
             UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage];
             [backgroundImage release];
             [self.tableView setBackgroundView:background];
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Wed Nov 24 23:35:41 2010 +0100
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Thu Nov 25 02:45:52 2010 +0100
@@ -232,16 +232,22 @@
 }
 
 +(UIImage *)whiteImage:(CGSize) ofSize {
-    UIGraphicsBeginImageContext(ofSize);
-    CGContextRef context = UIGraphicsGetCurrentContext();
-    UIGraphicsPushContext(context);
+    CGFloat w = ofSize.width;
+    CGFloat h = ofSize.height;
 
+    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+    CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
+
+    CGContextBeginPath(context);
     CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
     CGContextFillRect(context,CGRectMake(0,0,ofSize.width,ofSize.height));
 
-    UIGraphicsPopContext();
-    UIImage *bkgImg = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
+    CGImageRef image = CGBitmapContextCreateImage(context);
+    CGContextRelease(context);
+    CGColorSpaceRelease(colorSpace);
+
+    UIImage *bkgImg = [UIImage imageWithCGImage:image];
+    CGImageRelease(image);
     return bkgImg;
 }