tap to play piano notes, fix for audio and pause glitch
authorkoda
Sun, 25 Jul 2010 01:59:41 +0200
changeset 3668 3f7a95234d8a
parent 3667 9359a70df013
child 3669 19be65b12c43
child 3670 4c673e57f0d7
tap to play piano notes, fix for audio and pause glitch
hedgewars/PascalExports.pas
hedgewars/SDLh.pas
hedgewars/uConsts.pas
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/InGameMenuViewController.h
project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/PascalImports.h
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
--- a/hedgewars/PascalExports.pas	Sat Jul 24 23:23:10 2010 +0200
+++ b/hedgewars/PascalExports.pas	Sun Jul 25 01:59:41 2010 +0200
@@ -13,14 +13,13 @@
 unit PascalExports;
 
 interface
-uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, uGears, hwengine;
+uses uKeys, GLunit, uWorld, uMisc, uConsole, uTeams, uConsts, uChat, uGears, uSound, hwengine;
 
 {$INCLUDE "config.inc"}
 
 implementation
 
 {$IFDEF HWLIBRARY}
-var xx, yy: LongInt;
 
 // retrieve protocol information
 procedure HW_versionInfo(netProto: PShortInt; versionStr: PPChar); cdecl; export;
@@ -170,18 +169,24 @@
     y^:= CursorPoint.Y;
 end;
 
-procedure HW_saveCursor(reset: boolean); cdecl; export;
+procedure HW_setPianoSound(snd: LongInt); cdecl; export;
+var CurSlot, CurAmmo: LongWord;
 begin
-    if reset then
-    begin
-        CursorPoint.X:= xx;
-        CursorPoint.Y:= yy;
-    end
-    else
-    begin
-        xx:= CursorPoint.X;
-        yy:= CursorPoint.Y;
-    end;
+    CurSlot:= CurrentHedgehog^.CurSlot;
+    CurAmmo:= CurrentHedgehog^.CurAmmo;
+    // this most likely won't work in network game
+    if (CurrentHedgehog^.Ammo^[CurSlot, CurAmmo].AmmoType = amPiano) then
+        case snd of 
+            0: PlaySound(sndPiano0);
+            1: PlaySound(sndPiano1);
+            2: PlaySound(sndPiano2);
+            3: PlaySound(sndPiano3);
+            4: PlaySound(sndPiano4);
+            5: PlaySound(sndPiano5);
+            6: PlaySound(sndPiano6);
+            7: PlaySound(sndPiano7);
+            else PlaySound(sndPiano8);
+        end;
 end;
 
 function HW_isAmmoOpen: boolean; cdecl; export;
@@ -213,6 +218,11 @@
         exit(false)
 end;
 
+function HW_isPaused: boolean; cdecl; export;
+begin
+    exit( isPaused );
+end;
+
 procedure HW_setGrenadeTime(time: LongInt); cdecl; export;
 begin
     ParseCommand('/timer ' + inttostr(time), true);
--- a/hedgewars/SDLh.pas	Sat Jul 24 23:23:10 2010 +0200
+++ b/hedgewars/SDLh.pas	Sun Jul 25 01:59:41 2010 +0200
@@ -846,6 +846,7 @@
 procedure clearView; cdecl; external;
 procedure startSpinning; cdecl; external;
 procedure stopSpinning; cdecl; external;
+function  isPhone: Boolean; cdecl; external;
 {$ENDIF}
 implementation
 
--- a/hedgewars/uConsts.pas	Sat Jul 24 23:23:10 2010 +0200
+++ b/hedgewars/uConsts.pas	Sun Jul 25 01:59:41 2010 +0200
@@ -295,15 +295,12 @@
 
     cKeyMaxIndex = 1023;
 
+    cDefaultZoomLevel = 2.0;
 {$IFDEF IPHONEOS}
-    cMaxCaptions = 3;
-    cDefaultZoomLevel = 2.0;
     cMaxZoomLevel = 0.5;
     cMinZoomLevel = 3.5;
     cZoomDelta = 0.20;
 {$ELSE}
-    cMaxCaptions = 4;
-    cDefaultZoomLevel = 2.0;
     cMaxZoomLevel = 1.0;
     cMinZoomLevel = 3.0;
     cZoomDelta = 0.25;
@@ -459,6 +456,7 @@
     LAND_HEIGHT :longint;
     LAND_WIDTH_MASK  :longWord;
     LAND_HEIGHT_MASK :longWord;
+    cMaxCaptions : LongInt;
 
 const
     cTagsMasks : array[0..15] of byte = (7, 0, 0, 0, 15, 6, 4, 5, 0, 0, 0, 0, 0, 14, 12, 13);
@@ -2201,6 +2199,14 @@
         LAND_WIDTH_MASK:= $FFFFF000;
         LAND_HEIGHT_MASK:= $FFFFF800
     end;
+
+{$IFDEF IPHONEOS}    
+    if isPhone() then
+        cMaxCaptions:= 3
+    else
+{$ENDIF}
+        cMaxCaptions:= 4;
+
 end;
 
 procedure freeModule;
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sun Jul 25 01:59:41 2010 +0200
@@ -154,3 +154,7 @@
     natural_t mem_total = mem_used + mem_free;
     DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
 }
+
+BOOL isPhone() {
+    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
+}
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.h	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.h	Sun Jul 25 01:59:41 2010 +0200
@@ -11,7 +11,6 @@
 
 @interface InGameMenuViewController : UITableViewController <UIActionSheetDelegate> {
     NSArray *menuList;
-    BOOL isPaused;
     SDL_Window *sdlwindow;
 }
 
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sun Jul 25 01:59:41 2010 +0200
@@ -26,10 +26,8 @@
 }
 
 -(void) viewDidLoad {
-    isPaused = NO;
-
     NSArray *array = [[NSArray alloc] initWithObjects:
-                      NSLocalizedString(@"Pause Game", @""),
+                      NSLocalizedString(@"Return to Game", @""),
                       NSLocalizedString(@"Chat", @""),
                       NSLocalizedString(@"End Game", @""),
                       nil];
@@ -100,6 +98,9 @@
     }
     cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
     
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+        cell.textLabel.textAlignment = UITextAlignmentCenter;
+    
     return cell;
 }
 
@@ -109,7 +110,6 @@
     switch ([indexPath row]) {
         case 0:
             HW_pause();
-            isPaused = !isPaused;
             break;
         case 1:
             if (SDL_iPhoneKeyboardIsShown(sdlwindow))
@@ -137,8 +137,6 @@
             [actionSheet showInView:self.view];
             [actionSheet release];
             
-            if (!isPaused) 
-                HW_pause();
             break;
         default:
             DLog(@"Warning: unset case value in section!");
@@ -167,10 +165,7 @@
     }
     
     if ([actionSheet cancelButtonIndex] != buttonIndex)
-        HW_terminate(NO);
-    else
-        if (!isPaused) 
-            HW_pause();     
+        HW_terminate(NO);     
 }
 
 @end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sun Jul 25 01:59:41 2010 +0200
@@ -326,6 +326,8 @@
     // reset default dimming
     doDim();
     
+    HW_setPianoSound([allTouches count]);
+    
     switch ([allTouches count]) {
         case 1:       
             removeConfirmationInput();
@@ -424,7 +426,6 @@
             HW_allKeysUp();
             break;
         default:
-            DLog(@"too many touches");
             break;
     }
     
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Sun Jul 25 01:59:41 2010 +0200
@@ -55,9 +55,11 @@
     void HW_setLandscape(BOOL rotate);
     void HW_setCursor(int x, int y);
     void HW_getCursor(int *x, int *y);
-    void HW_saveCursor(BOOL reset);
+
+    void HW_setPianoSound(int snd);
     
     BOOL HW_isAmmoOpen(void);
+    BOOL HW_isPaused(void);
     BOOL HW_isWeaponRequiringClick(void);
     BOOL HW_isWeaponTimerable(void);
     BOOL HW_isWeaponSwitch(void);
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Sat Jul 24 23:23:10 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Sun Jul 25 01:59:41 2010 +0200
@@ -27,11 +27,13 @@
 #import "../SDL_sysvideo.h"
 #import "jumphack.h"
 #import "SDL_video.h"
+#import "SDL_mixer.h"
+
+#import "PascalImports.h"
+#import "CommodityFunctions.h"
 #import "GameSetup.h"
-#import "PascalImports.h"
 #import "MainMenuViewController.h"
 #import "OverlayViewController.h"
-#import "CommodityFunctions.h"
 
 #ifdef main
 #undef main
@@ -131,7 +133,9 @@
 }
 
 -(void) applicationWillTerminate:(UIApplication *)application {
+    Mix_CloseAudio();
     SDL_SendQuit();
+    
     if (isInGame) {
         HW_terminate(YES);
         // hack to prevent automatic termination. See SDL_uikitevents.m for details