add a nice group of hogs in lobby page
authorkoda
Sat, 28 Aug 2010 00:30:29 +0200
changeset 3778 2e61bb50cc57
parent 3777 5276f2150d65
child 3779 3351a017d4ad
add a nice group of hogs in lobby page
hedgewars/PascalExports.pas
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/GameConfigViewController.h
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/UIImageExtra.m
project_files/HedgewarsMobile/Classes/WeaponCellView.m
--- a/hedgewars/PascalExports.pas	Thu Aug 26 22:58:38 2010 +0200
+++ b/hedgewars/PascalExports.pas	Sat Aug 28 00:30:29 2010 +0200
@@ -73,7 +73,6 @@
 
 function HW_zoomLevel: LongInt; cdecl; export;
 begin
-    writelntoconsole(inttostr(trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) ));
     exit( trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) );
 end;
 
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Thu Aug 26 22:58:38 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sat Aug 28 00:30:29 2010 +0200
@@ -55,7 +55,7 @@
                                                         error:NULL];
     }
 
-    NSDictionary *theWeapon;
+    NSDictionary *theWeapon = nil;
     switch (type) {
         case 0: //default
             theWeapon = [[NSDictionary alloc] initWithObjectsAndKeys:
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.h	Thu Aug 26 22:58:38 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.h	Sat Aug 28 00:30:29 2010 +0200
@@ -13,12 +13,18 @@
 @class SchemeWeaponConfigViewController;
 
 @interface GameConfigViewController : UIViewController <MapConfigDelegate> {
+    UIImage *hedgehogImage;
+    UIView *imgContainer;
+    
     UIViewController *activeController;
     MapConfigViewController *mapConfigViewController;
     TeamConfigViewController *teamConfigViewController;
     SchemeWeaponConfigViewController *schemeWeaponConfigViewController;
 }
 
+@property (nonatomic,retain) UIImage *hedgehogImage;
+@property (nonatomic,retain) UIView *imgContainer;
+
 -(IBAction) buttonPressed:(id) sender;
 -(IBAction) segmentPressed:(id) sender;
 -(void) startGame:(UIButton *)button;
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Thu Aug 26 22:58:38 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Sat Aug 28 00:30:29 2010 +0200
@@ -11,10 +11,10 @@
 #import "CommodityFunctions.h"
 #import "TeamConfigViewController.h"
 #import "SchemeWeaponConfigViewController.h"
-
+#import "UIImageExtra.h"
 
 @implementation GameConfigViewController
-
+@synthesize hedgehogImage, imgContainer;
 
 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return rotationManager(interfaceOrientation);
@@ -185,6 +185,14 @@
     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        // load a base image that will be updated in viewWill Load
+        NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
+        UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)];
+        self.hedgehogImage = sprite;
+        [sprite release];
+        srandom(time(NULL));
+        
+        // load other controllers
         if (mapConfigViewController == nil)
             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
         mapConfigViewController.delegate = self;
@@ -213,10 +221,33 @@
 }
 
 -(void) viewWillAppear:(BOOL)animated {
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
+        int numberOfHats = [hatArray count];
+        if (self.imgContainer == nil)
+            self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
+        
+        for (int i=0; i < 1 + random()%40; i++) {
+            NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
+            
+            NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
+            UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
+            [hatFile release];
+            UIImage *hogWithHat = [self.hedgehogImage mergeWith:hatSprite atPoint:CGPointMake(0, -5)];
+            [hatSprite release];
+            
+            UIImageView *hog = [[UIImageView alloc] initWithImage:hogWithHat];
+            hog.frame = CGRectMake(10*(i+1)+random()%30, 30, 32, 32);
+            [self.imgContainer addSubview:hog];
+            [hog release];
+        }
+        [self.view addSubview:self.imgContainer];
+    }
+
     [mapConfigViewController viewWillAppear:animated];
     [teamConfigViewController viewWillAppear:animated];
     [schemeWeaponConfigViewController viewWillAppear:animated];
-    // ADD other controllers here
+    // add other controllers here and below
 
     [super viewWillAppear:animated];
 }
@@ -236,6 +267,11 @@
 }
 
 -(void) viewDidDisappear:(BOOL)animated {
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
+        [self.imgContainer removeFromSuperview];
+        releaseAndNil(self.imgContainer);
+    }
+    
     [mapConfigViewController viewDidDisappear:animated];
     [teamConfigViewController viewDidDisappear:animated];
     [schemeWeaponConfigViewController viewDidDisappear:animated];
@@ -243,21 +279,25 @@
 }
 
 -(void) didReceiveMemoryWarning {
+    // Releases the view if it doesn't have a superview.
     if (activeController.view.superview == nil)
         activeController = nil;
-    // Releases the view if it doesn't have a superview.
-    [super didReceiveMemoryWarning];
-    // Release any cached data, images, etc that aren't in use.
     if (mapConfigViewController.view.superview == nil)
         mapConfigViewController = nil;
     if (teamConfigViewController.view.superview == nil)
         teamConfigViewController = nil;
     if (schemeWeaponConfigViewController.view.superview == nil)
-        schemeWeaponConfigViewController = nil;
+        schemeWeaponConfigViewController = nil;    
+    // Release any cached data, images, etc that aren't in use.
+
+    self.imgContainer = nil;
+    [super didReceiveMemoryWarning];
     MSG_MEMCLEAN();
 }
 
 -(void) viewDidUnload {
+    hedgehogImage = nil;
+    imgContainer = nil;
     activeController = nil;
     mapConfigViewController = nil;
     teamConfigViewController = nil;
@@ -267,6 +307,8 @@
 }
 
 -(void) dealloc {
+    [hedgehogImage release];
+    [imgContainer release];
     [mapConfigViewController release];
     [teamConfigViewController release];
     [schemeWeaponConfigViewController release];
--- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Thu Aug 26 22:58:38 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m	Sat Aug 28 00:30:29 2010 +0200
@@ -36,6 +36,11 @@
 }
 
 -(UIImage *)mergeWith:(UIImage *)secondImage atPoint:(CGPoint) secondImagePoint atSize:(CGSize) resultingSize {
+    if (secondImage == nil) {
+        DLog(@"Warning, secondImage == nil");
+        return self;
+    }
+    
     // Create a bitmap graphics context; this will also set it as the current context
     UIGraphicsBeginImageContext(resultingSize);
 
--- a/project_files/HedgewarsMobile/Classes/WeaponCellView.m	Thu Aug 26 22:58:38 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/WeaponCellView.m	Sat Aug 28 00:30:29 2010 +0200
@@ -203,7 +203,7 @@
 }
 
 -(void) stopDragging:(id) sender {
-    self.helpLabel.text =@"";
+    self.helpLabel.text = @"";
 }
 
 -(void) dealloc {
@@ -222,6 +222,7 @@
     releaseAndNil(probabilityLab);
     releaseAndNil(delayLab);
     releaseAndNil(crateLab);
+    releaseAndNil(helpLabel);
     [super dealloc];
 }