WIP for an objc ammomenu implementation
authorkoda
Mon, 04 Oct 2010 00:00:42 +0200
changeset 3924 2a9ace189288
parent 3923 694e6f6e0e30
child 3926 668b71f31e51
WIP for an objc ammomenu implementation
hedgewars/PascalExports.pas
project_files/HedgewarsMobile/Classes/AmmoMenuViewController.h
project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m
project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/PascalImports.h
project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib
--- a/hedgewars/PascalExports.pas	Sun Oct 03 00:23:05 2010 +0200
+++ b/hedgewars/PascalExports.pas	Mon Oct 04 00:00:42 2010 +0200
@@ -13,7 +13,8 @@
 unit PascalExports;
 
 interface
-uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, uGears, uSound, hwengine;
+uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, 
+     uGears, uSound, hwengine, uAmmos; // don't change the order!
 
 {$INCLUDE "config.inc"}
 
@@ -258,6 +259,12 @@
             else PlaySound(sndPiano8);
         end;
 end;
+
+
+procedure HW_setWeapon(whichone: LongInt); cdecl; export;
+begin
+    SetWeapon(TAmmoType(whichone));
+end;
 {$ENDIF}
 
 end.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.h	Mon Oct 04 00:00:42 2010 +0200
@@ -0,0 +1,33 @@
+/*
+ * Hedgewars-iOS, a Hedgewars port for iOS devices
+ * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 03/10/2010.
+ */
+
+
+#import <UIKit/UIKit.h>
+
+
+@interface AmmoMenuViewController : UIViewController {
+    NSArray *imagesArray;
+}
+
+@property (nonatomic,retain) NSArray *imagesArray;
+
+-(void) buttonPressed:(id)sender;
+
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m	Mon Oct 04 00:00:42 2010 +0200
@@ -0,0 +1,92 @@
+/*
+ * Hedgewars-iOS, a Hedgewars port for iOS devices
+ * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * File created on 03/10/2010.
+ */
+
+
+#import "AmmoMenuViewController.h"
+#import <QuartzCore/QuartzCore.h>
+#import "CommodityFunctions.h"
+#import "UIImageExtra.h"
+#import "PascalImports.h"
+
+@implementation AmmoMenuViewController
+@synthesize imagesArray;;
+
+
+-(void) viewDidLoad {
+    [super viewDidLoad];
+    self.view.frame = CGRectMake(0, 0, 480, 320);
+    self.view.backgroundColor = [UIColor blackColor];
+    [self.view.layer setCornerRadius:10];
+    [self.view.layer setMasksToBounds:YES];
+
+    NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()];
+    UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str];
+    
+    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:CURRENT_AMMOSIZE];
+    for (int i = 0; i < CURRENT_AMMOSIZE; i++) {
+        int x_src = ((i*32)/(int)ammoStoreImage.size.height)*32;
+        int y_src = (i*32)%(int)ammoStoreImage.size.height;
+        int x_dst = 10+(i%10)*44;
+        int y_dst = 10+(i/10)*44;
+        
+        if (i / 10 % 2 != 0)
+            x_dst += 20;
+        UIImage *img = [ammoStoreImage cutAt:CGRectMake(x_src, y_src, 32, 32)];
+        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x_dst, y_dst, 40, 40)];
+        button.tag = i+1;
+        button.layer.borderWidth = 1;
+        button.layer.borderColor = [UICOLOR_HW_YELLOW_TEXT CGColor];
+        [button.layer setCornerRadius:6];
+        [button.layer setMasksToBounds:YES];
+        [button setImage:img forState:UIControlStateNormal];
+        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
+        [self.view addSubview:button];
+        [array addObject:button];
+        [button release];
+    }
+    self.imagesArray = array;
+    [array release];
+    [ammoStoreImage release];
+
+}
+
+-(void) buttonPressed:(id) sender {
+    UIButton *theButton = (UIButton *)sender;
+    HW_setWeapon(theButton.tag);
+}
+
+-(void) didReceiveMemoryWarning {
+    // Releases the view if it doesn't have a superview.
+    [super didReceiveMemoryWarning];
+    // Release any cached data, images, etc that aren't in use.
+}
+
+-(void) viewDidUnload {
+    [super viewDidUnload];
+    self.imagesArray = nil;
+}
+
+-(void) dealloc {
+    [imagesArray release];
+    [super dealloc];
+}
+
+
+@end
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Mon Oct 04 00:00:42 2010 +0200
@@ -178,10 +178,8 @@
         [UIView commitAnimations];
     }
 
-    if ([actionSheet cancelButtonIndex] != buttonIndex) {
+    if ([actionSheet cancelButtonIndex] != buttonIndex)
         [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil];
-        HW_terminate(NO);
-    }
 }
 
 @end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Mon Oct 04 00:00:42 2010 +0200
@@ -23,6 +23,7 @@
 #import "SDL_uikitappdelegate.h"
 #import "InGameMenuViewController.h"
 #import "HelpPageViewController.h"
+#import "AmmoMenuViewController.h"
 #import "PascalImports.h"
 #import "CommodityFunctions.h"
 #import "CGPointUtils.h"
@@ -161,6 +162,10 @@
     [UIView setAnimationDuration:1];
     self.view.alpha = 1;
     [UIView commitAnimations];
+    
+    AmmoMenuViewController *amvc = [[AmmoMenuViewController alloc] init];
+    amvc.view.center = self.view.center;
+    [self.view addSubview:amvc.view];
 }
 
 -(void) showHelp:(id) sender {
@@ -201,6 +206,7 @@
 
 -(void) cleanup {
     [self dismissPopover];
+    HW_terminate(NO);
     [self.view removeFromSuperview];
 }
 
@@ -317,7 +323,7 @@
 // present a further check before closing game
 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
     if ([actionSheet cancelButtonIndex] != buttonIndex)
-        HW_terminate(NO);
+        [self cleanup];
     else
         HW_pause();
 }
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Mon Oct 04 00:00:42 2010 +0200
@@ -80,6 +80,7 @@
 
     void HW_setGrenadeTime(int time);
     void HW_setPianoSound(int snd);
+    void HW_setWeapon(int whichone);
 
 #ifdef __cplusplus
 }
--- a/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleTeamViewController.m	Mon Oct 04 00:00:42 2010 +0200
@@ -288,45 +288,48 @@
 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSInteger row = [indexPath row];
     NSInteger section = [indexPath section];
-    UITableViewController *nextController = nil;
 
     if (2 == section) {
         switch (row) {
             case 0: // grave
                 if (nil == gravesViewController)
                     gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
-                nextController = gravesViewController;
+                
+                [gravesViewController setTeamDictionary:teamDictionary];
+                [self.navigationController pushViewController:gravesViewController animated:YES];
                 break;
             case 1: // voice
                 if (nil == voicesViewController)
                     voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
-                nextController = voicesViewController;
+                
+                [voicesViewController setTeamDictionary:teamDictionary];
+                [self.navigationController pushViewController:voicesViewController animated:YES];
                 break;
             case 2: // fort
                 if (nil == fortsViewController)
                     fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
-                nextController = fortsViewController;
+                
+                [fortsViewController setTeamDictionary:teamDictionary];
+                [self.navigationController pushViewController:fortsViewController animated:YES];
                 break;
             case 3: // flag
                 if (nil == flagsViewController)
                     flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
-                nextController = flagsViewController;
+                
+                [flagsViewController setTeamDictionary:teamDictionary];
+                [self.navigationController pushViewController:flagsViewController animated:YES];
                 break;
             case 4: // level
                 if (nil == levelViewController)
                     levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped];
-
-                nextController = levelViewController;
+                
+                [levelViewController setTeamDictionary:teamDictionary];
+                [self.navigationController pushViewController:levelViewController animated:YES];
+                break;
+            default:
+                DLog(@"Nope");
                 break;
         }
-
-        if ([nextController respondsToSelector:@selector(setTeamDictionary:)])
-            [nextController setTeamDictionary:teamDictionary];
-        [self.navigationController pushViewController:nextController animated:YES];
     } else {
         EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
         [cell replyKeyboard];
--- a/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SingleWeaponViewController.m	Mon Oct 04 00:00:42 2010 +0200
@@ -215,8 +215,8 @@
             weaponCell.delegate = self;
         }
 
-        int x = ((row*32)/1024)*32;
-        int y = (row*32)%1024;
+        int x = ((row*32)/(int)self.ammoStoreImage.size.height)*32;
+        int y = (row*32)%(int)self.ammoStoreImage.size.height;
 
         UIImage *img = [[self.ammoStoreImage cutAt:CGRectMake(x, y, 32, 32)] makeRoundCornersOfSize:CGSizeMake(7, 7)];
         weaponCell.weaponIcon.image = img;
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Mon Oct 04 00:00:42 2010 +0200
@@ -142,6 +142,7 @@
 		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 */; };
+		61DE8F221257EB1100B80214 /* AmmoMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61DE8F211257EB1100B80214 /* AmmoMenuViewController.m */; };
 		61E1F4F811D004240016A5AA /* adler32.pas in Sources */ = {isa = PBXBuildFile; fileRef = 61E1F4F711D004240016A5AA /* adler32.pas */; };
 		61EBA62A11DFF2BC0048B68A /* title.png in Resources */ = {isa = PBXBuildFile; fileRef = 61EBA62811DFF2BC0048B68A /* title.png */; };
 		61EBA62D11DFF3310048B68A /* backgroundAndTitle.png in Resources */ = {isa = PBXBuildFile; fileRef = 61EBA62C11DFF3310048B68A /* backgroundAndTitle.png */; };
@@ -879,6 +880,8 @@
 		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>"; };
+		61DE8F201257EB1100B80214 /* AmmoMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AmmoMenuViewController.h; sourceTree = "<group>"; };
+		61DE8F211257EB1100B80214 /* AmmoMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AmmoMenuViewController.m; sourceTree = "<group>"; };
 		61E1F4F711D004240016A5AA /* adler32.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = adler32.pas; path = ../../hedgewars/adler32.pas; sourceTree = SOURCE_ROOT; };
 		61EBA62811DFF2BC0048B68A /* title.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = title.png; path = "Resources/Frontend-iPad/title.png"; sourceTree = "<group>"; };
 		61EBA62C11DFF3310048B68A /* backgroundAndTitle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = backgroundAndTitle.png; path = "Resources/Frontend-iPad/backgroundAndTitle.png"; sourceTree = "<group>"; };
@@ -995,22 +998,17 @@
 		29B97315FDCFA39411CA2CEA /* Other Sources */ = {
 			isa = PBXGroup;
 			children = (
+				61DE91561258B76800B80214 /* Custom Buttons */,
 				32CA4F630368D1EE00C91783 /* Hedgewars_Prefix.pch */,
 				6165922911CA9BD500D6E256 /* PascalImports.h */,
+				6165922411CA9BD500D6E256 /* CGPointUtils.h */,
+				6165922311CA9BD500D6E256 /* CGPointUtils.c */,
 				6165929C11CA9E2F00D6E256 /* SDL_uikitappdelegate.h */,
 				6165929D11CA9E2F00D6E256 /* SDL_uikitappdelegate.m */,
-				6165922411CA9BD500D6E256 /* CGPointUtils.h */,
-				6165922311CA9BD500D6E256 /* CGPointUtils.c */,
 				6165922511CA9BD500D6E256 /* CommodityFunctions.h */,
 				6165922611CA9BD500D6E256 /* CommodityFunctions.m */,
-				6165922711CA9BD500D6E256 /* HogButtonView.h */,
-				6165922811CA9BD500D6E256 /* HogButtonView.m */,
-				6165922A11CA9BD500D6E256 /* SquareButtonView.h */,
-				6165922B11CA9BD500D6E256 /* SquareButtonView.m */,
 				6165922C11CA9BD500D6E256 /* UIImageExtra.h */,
 				6165922D11CA9BD500D6E256 /* UIImageExtra.m */,
-				619C5BA0124FA59000D041AE /* MapPreviewButtonView.h */,
-				619C5BA1124FA59000D041AE /* MapPreviewButtonView.m */,
 			);
 			name = "Other Sources";
 			sourceTree = "<group>";
@@ -1266,6 +1264,8 @@
 				611EEAEC122B2A4D00DF6938 /* HelpPageViewController.m */,
 				611EEAED122B2A4D00DF6938 /* HelpPageLobbyViewController.xib */,
 				61842B23122B619D0096E335 /* HelpPageInGameViewController.xib */,
+				61DE8F201257EB1100B80214 /* AmmoMenuViewController.h */,
+				61DE8F211257EB1100B80214 /* AmmoMenuViewController.m */,
 			);
 			name = Overlay;
 			sourceTree = "<group>";
@@ -1347,6 +1347,19 @@
 			name = Products;
 			sourceTree = "<group>";
 		};
+		61DE91561258B76800B80214 /* Custom Buttons */ = {
+			isa = PBXGroup;
+			children = (
+				6165922711CA9BD500D6E256 /* HogButtonView.h */,
+				6165922811CA9BD500D6E256 /* HogButtonView.m */,
+				6165922A11CA9BD500D6E256 /* SquareButtonView.h */,
+				6165922B11CA9BD500D6E256 /* SquareButtonView.m */,
+				619C5BA0124FA59000D041AE /* MapPreviewButtonView.h */,
+				619C5BA1124FA59000D041AE /* MapPreviewButtonView.m */,
+			);
+			name = "Custom Buttons";
+			sourceTree = "<group>";
+		};
 		61F7A42811E2905C0040BA66 /* Icons */ = {
 			isa = PBXGroup;
 			children = (
@@ -2247,6 +2260,7 @@
 				611D9BFB12497E9800008271 /* SavedGamesViewController.m in Sources */,
 				619C5AF4124F7E3100D041AE /* LuaPas.pas in Sources */,
 				619C5BA2124FA59000D041AE /* MapPreviewButtonView.m in Sources */,
+				61DE8F221257EB1100B80214 /* AmmoMenuViewController.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
--- a/project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib	Sun Oct 03 00:23:05 2010 +0200
+++ b/project_files/HedgewarsMobile/Resources/MapConfigViewController-iPad.xib	Mon Oct 04 00:00:42 2010 +0200
@@ -763,7 +763,7 @@
 					<bool key="EncodedWithXMLCoder">YES</bool>
 					<string>MapConfigViewController</string>
 					<string>UIResponder</string>
-					<string>{{205, 295}, {1024, 768}}</string>
+					<string>{{489, 236}, {1024, 768}}</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -804,7 +804,7 @@
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">115</int>
+			<int key="maxID">119</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">