muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon May 30 01:14:25 2011 +0200
@@ -154,16 +154,18 @@
[self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3];
// keep track of uncompleted games
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults setObject:self.savePath forKey:@"savedGamePath"];
- [defaults synchronize];
+ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+ [userDefaults setObject:self.savePath forKey:@"savedGamePath"];
+ [userDefaults synchronize];
+
+ [HedgewarsAppDelegate pauseBackgroundMusic];
// SYSTEMS ARE GO!!
[self startGameEngine];
-
+
// remove completed games notification
- [defaults setObject:@"" forKey:@"savedGamePath"];
- [defaults synchronize];
+ [userDefaults setObject:@"" forKey:@"savedGamePath"];
+ [userDefaults synchronize];
// now we can remove the cover with a transition
[UIView beginAnimations:@"fade in" context:NULL];
@@ -180,8 +182,12 @@
[self.parentController viewWillAppear:YES];
// release the network manager and the savepath as they are not needed anymore
- [self.engineProtocol release];
- [self.savePath release];
+ releaseAndNil(self.engineProtocol);
+ if (self.gameType != gtSave)
+ releaseAndNil(self.savePath);
+
+ if ([[userDefaults objectForKey:@"music"] boolValue])
+ [HedgewarsAppDelegate playBackgroundMusic];
}
// set up variables for a local game
--- a/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/GeneralSettingsViewController.m Mon May 30 01:14:25 2011 +0200
@@ -41,7 +41,11 @@
}
-(void) viewWillDisappear:(BOOL)animated {
- [[NSUserDefaults standardUserDefaults] synchronize];
+ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
+ [userDefaults synchronize];
+ if ([[userDefaults objectForKey:@"music"] boolValue] == NO)
+ [HedgewarsAppDelegate stopBackgroundMusic];
+
[super viewWillDisappear:animated];
}
@@ -53,20 +57,26 @@
switch (theSwitch.tag) {
case 10: //soundSwitch
- // this turn off also the switch below
+ // setting this off will turn off also the switch below (music)
[settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"sound"];
[settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
[theOtherSwitch setOn:NO animated:YES];
break;
case 20: //musicSwitch
- // if switch above is off, never turn on
+ // if switch above (sound) is off, never turn on
if (NO == [[settings objectForKey:@"sound"] boolValue]) {
[settings setObject:[NSNumber numberWithBool:NO] forKey:@"music"];
theOtherSwitch = (UISwitch *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]].accessoryView;
[theOtherSwitch setOn:NO animated:YES];
} else
[settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"music"];
+
+ if (theSwitch.on)
+ [HedgewarsAppDelegate playBackgroundMusic];
+ else
+ [HedgewarsAppDelegate pauseBackgroundMusic];
+
break;
case 30: //alternateSwitch
[settings setObject:[NSNumber numberWithBool:theSwitch.on] forKey:@"alternate"];
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h Mon May 30 01:14:25 2011 +0200
@@ -23,20 +23,27 @@
#import "SDL_uikitappdelegate.h"
@class MainMenuViewController;
+@class AVAudioPlayer;
@interface HedgewarsAppDelegate : SDLUIKitDelegate {
MainMenuViewController *mainViewController;
UIWindow *uiwindow;
UIWindow *secondWindow;
BOOL isInGame;
+ AVAudioPlayer *backgroundMusic;
}
-@property (assign) BOOL isInGame;
@property (nonatomic,retain) MainMenuViewController *mainViewController;
@property (nonatomic,retain) UIWindow *uiwindow;
@property (nonatomic,retain) UIWindow *secondWindow;
+@property (assign) BOOL isInGame;
+@property (nonatomic,retain) AVAudioPlayer *backgroundMusic;
+(HedgewarsAppDelegate *)sharedAppDelegate;
++(void) playBackgroundMusic;
++(void) pauseBackgroundMusic;
++(void) stopBackgroundMusic;
++(void) loadBackgroundMusic;
@end
--- a/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Mon May 30 01:14:25 2011 +0200
@@ -24,6 +24,7 @@
#import "ObjcExports.h"
#import "CommodityFunctions.h"
#import "MainMenuViewController.h"
+#import "AVFoundation/AVAudioPlayer.h"
#import "Appirater.h"
#include <unistd.h>
@@ -37,19 +38,50 @@
@end
@implementation HedgewarsAppDelegate
-@synthesize mainViewController, uiwindow, secondWindow, isInGame;
+@synthesize mainViewController, uiwindow, secondWindow, isInGame, backgroundMusic;
// convenience method
+(HedgewarsAppDelegate *)sharedAppDelegate {
return (HedgewarsAppDelegate *)[[UIApplication sharedApplication] delegate];
}
+#pragma mark -
+#pragma mark Music control
++(void) playBackgroundMusic {
+ if ([HedgewarsAppDelegate sharedAppDelegate].backgroundMusic == nil)
+ [HedgewarsAppDelegate loadBackgroundMusic];
+ [[HedgewarsAppDelegate sharedAppDelegate].backgroundMusic play];
+}
+
++(void) pauseBackgroundMusic {
+ [[HedgewarsAppDelegate sharedAppDelegate].backgroundMusic pause];
+}
+
++(void) stopBackgroundMusic {
+ [[HedgewarsAppDelegate sharedAppDelegate].backgroundMusic stop];
+}
+
++(void) loadBackgroundMusic {
+ NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"];
+ AVAudioPlayer *background = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil];
+
+ background.delegate = nil;
+ background.volume = 0.5f;
+ background.numberOfLoops = -1;
+ [background prepareToPlay];
+ [HedgewarsAppDelegate sharedAppDelegate].backgroundMusic = background;
+ [background release];
+}
+
+#pragma mark -
+#pragma mark AppDelegate methods
-(id) init {
if (self = [super init]){
mainViewController = nil;
uiwindow = nil;
secondWindow = nil;
isInGame = NO;
+ backgroundMusic = nil;
}
return self;
}
@@ -58,6 +90,7 @@
[mainViewController release];
[uiwindow release];
[secondWindow release];
+ [backgroundMusic release];
[super dealloc];
}
@@ -100,6 +133,8 @@
-(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
// don't clean mainMenuViewController here!!!
+ [self.backgroundMusic stop];
+ self.backgroundMusic = nil;
MSG_MEMCLEAN();
print_free_memory();
}
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m Mon May 30 01:14:25 2011 +0200
@@ -107,6 +107,9 @@
[self createNecessaryFiles];
}
+ if ([[userDefaults objectForKey:@"music"] boolValue])
+ [HedgewarsAppDelegate playBackgroundMusic];
+
NSString *saveString = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedGamePath"];
if (saveString != nil && [saveString isEqualToString:@""] == NO) {
if (self.restoreViewController == nil) {
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Sun May 29 23:58:28 2011 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Mon May 30 01:14:25 2011 +0200
@@ -70,6 +70,8 @@
611F4D4B11B27A9900F9759A /* uScript.pas in Sources */ = {isa = PBXBuildFile; fileRef = 611F4D4A11B27A9900F9759A /* uScript.pas */; };
61272339117DF778005B90CF /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61272338117DF778005B90CF /* MobileCoreServices.framework */; };
6129B9F711EFB04D0017E305 /* denied.png in Resources */ = {isa = PBXBuildFile; fileRef = 6129B9F611EFB04D0017E305 /* denied.png */; };
+ 612CABAB1391CE68005E9596 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 612CABAA1391CE68005E9596 /* AVFoundation.framework */; };
+ 612CABC81391D3CC005E9596 /* hwclassic.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 612CABC71391D3CC005E9596 /* hwclassic.mp3 */; };
61370653117B1D50004EE44A /* Entitlements-Distribution.plist in Resources */ = {isa = PBXBuildFile; fileRef = 61370652117B1D50004EE44A /* Entitlements-Distribution.plist */; };
61399013125D19C0003C2DC0 /* uMobile.pas in Sources */ = {isa = PBXBuildFile; fileRef = 61399012125D19C0003C2DC0 /* uMobile.pas */; };
6147DAD31253DCDE0010357E /* savesButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 6147DAD21253DCDE0010357E /* savesButton.png */; };
@@ -355,6 +357,8 @@
6127232E117DF752005B90CF /* SDL_image.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDL_image.xcodeproj; path = ../../../Library/SDL_image/Xcode_iPhone/SDL_image.xcodeproj; sourceTree = SOURCE_ROOT; };
61272338117DF778005B90CF /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
6129B9F611EFB04D0017E305 /* denied.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = denied.png; path = Resources/denied.png; sourceTree = "<group>"; };
+ 612CABAA1391CE68005E9596 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
+ 612CABC71391D3CC005E9596 /* hwclassic.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = hwclassic.mp3; sourceTree = "<group>"; };
61370652117B1D50004EE44A /* Entitlements-Distribution.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Entitlements-Distribution.plist"; sourceTree = "<group>"; };
61399012125D19C0003C2DC0 /* uMobile.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uMobile.pas; path = ../../hedgewars/uMobile.pas; sourceTree = SOURCE_ROOT; };
6147DAD21253DCDE0010357E /* savesButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = savesButton.png; path = Resources/Frontend/savesButton.png; sourceTree = "<group>"; };
@@ -595,6 +599,7 @@
61272339117DF778005B90CF /* MobileCoreServices.framework in Frameworks */,
6199E81612463EA800DADF8C /* CFNetwork.framework in Frameworks */,
6199E81A12463EC400DADF8C /* SystemConfiguration.framework in Frameworks */,
+ 612CABAB1391CE68005E9596 /* AVFoundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -674,6 +679,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
+ 612CABCA1391D3D1005E9596 /* Sounds */,
6199E86C12464A8E00DADF8C /* surprise.png */,
611EEBC0122B34A800DF6938 /* helpingame.png */,
611EEC30122B54D700DF6938 /* helpplain.png */,
@@ -682,9 +688,6 @@
611EEBC3122B355700DF6938 /* helpright.png */,
61842B3F122B66280096E335 /* helpleft.png */,
6129B9F611EFB04D0017E305 /* denied.png */,
- 611EE973122A9C4100DF6938 /* clickSound.wav */,
- 611EE9D7122AA10A00DF6938 /* backSound.wav */,
- 611EE9D8122AA10A00DF6938 /* selSound.wav */,
61F7A42811E2905C0040BA66 /* Icons */,
61F903FA11DF58680068B24D /* Frontend */,
6179936611501D1E00BA94A9 /* Overlay */,
@@ -698,6 +701,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 612CABAA1391CE68005E9596 /* AVFoundation.framework */,
619599BA1364E65900B429B6 /* Freetype.xcodeproj */,
6195993F1364C82B00B429B6 /* Lua.xcodeproj */,
619598181364BCD200B429B6 /* Tremor.xcodeproj */,
@@ -738,6 +742,17 @@
name = "Other Controllers";
sourceTree = "<group>";
};
+ 612CABCA1391D3D1005E9596 /* Sounds */ = {
+ isa = PBXGroup;
+ children = (
+ 612CABC71391D3CC005E9596 /* hwclassic.mp3 */,
+ 611EE973122A9C4100DF6938 /* clickSound.wav */,
+ 611EE9D7122AA10A00DF6938 /* backSound.wav */,
+ 611EE9D8122AA10A00DF6938 /* selSound.wav */,
+ );
+ name = Sounds;
+ sourceTree = "<group>";
+ };
6163EE4C11CC2478001C0453 /* Settings Pages */ = {
isa = PBXGroup;
children = (
@@ -1337,6 +1352,7 @@
6174F7C912CD62E300205D6F /* smallerTitle@2x.png in Resources */,
6167A6771391514600AA6D07 /* RestoreViewController-iPhone.xib in Resources */,
6167A72D13919E6800AA6D07 /* RestoreViewController-iPad.xib in Resources */,
+ 612CABC81391D3CC005E9596 /* hwclassic.mp3 in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Binary file project_files/HedgewarsMobile/hwclassic.mp3 has changed