--- a/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/AmmoMenuViewController.m Sun Oct 10 03:16:25 2010 +0200
@@ -188,7 +188,8 @@
UIButton *theButton = (UIButton *)sender;
HW_setWeapon(theButton.tag);
playSound(@"clickSound");
- [self disappear];
+ if (IS_DUALHEAD() == NO)
+ [self disappear];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Sun Oct 10 03:16:25 2010 +0200
@@ -51,14 +51,17 @@
#define UICOLOR_HW_YELLOW_TEXT [UIColor colorWithRed:(CGFloat)0xF0/255 green:(CGFloat)0xD0/255 blue:0 alpha:1]
#define UICOLOR_HW_DARKBLUE [UIColor colorWithRed:(CGFloat)0x0F/255 green:0 blue:(CGFloat)0x42/255 alpha:1]
+#define IS_DUALHEAD() ([[UIScreen screens] count] > 1)
+
+
void createTeamNamed (NSString *nameWithoutExt);
void createWeaponNamed (NSString *nameWithoutExt, int type);
void createSchemeNamed (NSString *nameWithoutExt);
-void print_free_memory ();
+void print_free_memory (void);
void playSound (NSString *snd);
void popError (const char *title, const char *message);
BOOL rotationManager (UIInterfaceOrientation interfaceOrientation);
-BOOL isApplePhone ();
-NSInteger randomPort ();
-NSString *modelType ();
-NSArray *getAvailableColors(void);
+BOOL isApplePhone (void);
+NSInteger randomPort (void);
+NSString *modelType (void);
+NSArray *getAvailableColors (void);
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sun Oct 10 03:16:25 2010 +0200
@@ -259,7 +259,7 @@
AudioServicesPlaySystemSound(soundID);
}
-NSArray *getAvailableColors(void) {
+NSArray inline *getAvailableColors(void) {
return [NSArray arrayWithObjects:[NSNumber numberWithUnsignedInt:0x4376e9], // bluette
[NSNumber numberWithUnsignedInt:0x3e9321], // greeeen
[NSNumber numberWithUnsignedInt:0xa23dbb], // violett
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m Sun Oct 10 03:16:25 2010 +0200
@@ -442,7 +442,7 @@
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", ipcPort];
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
NSString *rotation;
- if ([[UIScreen screens] count] > 1) {
+ if (IS_DUALHEAD()) {
CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds];
width = (int) screenBounds.size.width;
height = (int) screenBounds.size.height;
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sun Oct 10 03:16:25 2010 +0200
@@ -50,6 +50,9 @@
// stuff initialized externally
BOOL isNetGame;
BOOL useClassicMenu;
+
+ // dual head support
+ NSInteger initialScreenCount;
}
@property (nonatomic,retain) id popoverController;
@@ -71,6 +74,7 @@
-(void) dismissPopover;
-(void) dimOverlay;
-(void) activateOverlay;
+-(void) cleanup;
@end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sun Oct 10 03:16:25 2010 +0200
@@ -32,7 +32,7 @@
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000]
-#define doDim() [dimTimer setFireDate: ([[UIScreen screens] count] == 1) ? HIDING_TIME_DEFAULT : HIDING_TIME_NEVER]
+#define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT]
#define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER]
#define CONFIRMATION_TAG 5959
@@ -60,13 +60,13 @@
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
- if ([[UIScreen screens] count] == 1)
+ if (IS_DUALHEAD() == NO)
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
HW_setLandscape(YES);
break;
case UIDeviceOrientationLandscapeRight:
- if ([[UIScreen screens] count] == 1)
+ if (IS_DUALHEAD() == NO)
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
HW_setLandscape(YES);
@@ -111,17 +111,19 @@
self.view.alpha = 0;
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
+ initialScreenCount = [[UIScreen screens] count];
+
// set initial orientation wrt the controller orientation
UIDeviceOrientation orientation = self.interfaceOrientation;
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
switch (orientation) {
case UIDeviceOrientationLandscapeLeft:
- if ([[UIScreen screens] count] == 1)
+ if (IS_DUALHEAD() == NO)
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
break;
case UIDeviceOrientationLandscapeRight:
- if ([[UIScreen screens] count] == 1)
+ if (IS_DUALHEAD() == NO)
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
break;
@@ -132,7 +134,7 @@
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
- dimTimer = [[NSTimer alloc] initWithFireDate:([[UIScreen screens] count] == 1) ? [NSDate dateWithTimeIntervalSinceNow:6] : HIDING_TIME_NEVER
+ dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6]
interval:1000
target:self
selector:@selector(dimOverlay)
@@ -158,12 +160,50 @@
name:@"remove overlay"
object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(numberOfScreensIncreased)
+ name:UIScreenDidConnectNotification
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(numberOfScreensDecreased)
+ name:UIScreenDidDisconnectNotification
+ object:nil];
+
[UIView beginAnimations:@"showing overlay" context:NULL];
[UIView setAnimationDuration:1];
self.view.alpha = 1;
[UIView commitAnimations];
}
+-(void) numberOfScreensIncreased {
+ if (initialScreenCount == 1) {
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New display detected"
+ message:NSLocalizedString(@"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game.",@"")
+ delegate:nil
+ cancelButtonTitle:@"Ok"
+ otherButtonTitles:nil];
+ [alert show];
+ [alert release];
+ if (HW_isPaused() == NO)
+ HW_pause();
+ }
+}
+
+-(void) numberOfScreensDecreased {
+ if (initialScreenCount == 2) {
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oh noes! Display disconnected"
+ message:NSLocalizedString(@"A monitor has been disconnected while playing and this has ended the match! You need to restart the game if you wish to use the second display again.",@"")
+ delegate:nil
+ cancelButtonTitle:@"Ok"
+ otherButtonTitles:nil];
+ [alert show];
+ [alert release];
+ [self cleanup];
+ }
+}
+
+
-(void) showHelp:(id) sender {
if (self.helpPage == nil)
self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil];
@@ -307,7 +347,7 @@
case 10:
playSound(@"clickSound");
HW_pause();
- if (self.amvc.isVisible) {
+ if (self.amvc.isVisible && IS_DUALHEAD() == NO) {
doDim();
[self.amvc disappear];
}
@@ -318,10 +358,7 @@
playSound(@"clickSound");
removeConfirmationInput();
- if (self.useClassicMenu)
- HW_ammoMenu();
- else {
- // TODO: removal and multimonitor experience
+ if (IS_DUALHEAD() || self.useClassicMenu == NO) {
if (self.amvc == nil)
self.amvc = [[AmmoMenuViewController alloc] init];
@@ -332,6 +369,8 @@
doNotDim();
[self.amvc appearInView:self.view];
}
+ } else {
+ HW_ammoMenu();
}
break;
default:
@@ -411,7 +450,7 @@
if (isPopoverVisible)
[self dismissPopover];
- if (amvc.isVisible) {
+ if (self.amvc.isVisible && IS_DUALHEAD() == NO) {
doDim();
[self.amvc disappear];
}
@@ -621,7 +660,7 @@
offset = -120;
else
offset = 120;
- if ([[UIScreen screens] count] > 1)
+ if (IS_DUALHEAD())
indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset);
else
indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2);
@@ -643,7 +682,7 @@
// called by CCHandlers from chNextTurn
void clearView() {
- UIWindow *theWindow = ([[UIScreen screens] count] == 1) ? [[UIApplication sharedApplication] keyWindow] : [SDLUIKitDelegate sharedAppDelegate].uiwindow;
+ UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Sun Oct 10 02:06:42 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m Sun Oct 10 03:16:25 2010 +0200
@@ -86,30 +86,36 @@
// main routine for calling the actual game engine
-(void) startSDLgame:(NSDictionary *)gameDictionary {
UIWindow *gameWindow;
- if ([[UIScreen screens] count] > 1)
+ if (IS_DUALHEAD())
gameWindow = self.secondWindow;
else
gameWindow = self.uiwindow;
+
UIView *blackView = [[UIView alloc] initWithFrame:gameWindow.frame];
blackView.backgroundColor = [UIColor blackColor];
blackView.opaque = YES;
blackView.tag = BLACKVIEW_TAG;
- [gameWindow addSubview:blackView];
- [blackView release];
-
- if ([[UIScreen screens] count] > 1) {
+ [gameWindow addSubview:blackView];
+ if (IS_DUALHEAD()) {
+ blackView.alpha = 0;
+ [UIView beginAnimations:@"fading to game first" context:NULL];
+ [UIView setAnimationDuration:1];
+ blackView.alpha = 1;
+ [UIView commitAnimations];
+
UIView *secondBlackView = [[UIView alloc] initWithFrame:self.uiwindow.frame];
secondBlackView.backgroundColor = [UIColor blackColor];
secondBlackView.opaque = YES;
secondBlackView.tag = SECONDBLACKVIEW_TAG;
secondBlackView.alpha = 0;
[self.uiwindow addSubview:secondBlackView];
- [UIView beginAnimations:@"fading to game" context:NULL];
+ [UIView beginAnimations:@"fading to game second" context:NULL];
[UIView setAnimationDuration:1];
secondBlackView.alpha = 1;
[UIView commitAnimations];
[secondBlackView release];
}
+ [blackView release];
// pull out useful configuration info from various files
GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary];
@@ -153,12 +159,12 @@
overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue];
UIWindow *gameWindow;
- if ([[UIScreen screens] count] > 1)
+ if (IS_DUALHEAD())
gameWindow = self.uiwindow;
else
gameWindow = [[UIApplication sharedApplication] keyWindow];
[gameWindow addSubview:overlayController.view];
- //[overlayController release];
+ [overlayController release];
}
// override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib)
@@ -181,7 +187,7 @@
[[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];
// check for dual monitor support
- if ([[UIScreen screens] count] > 1) {
+ if (IS_DUALHEAD()) {
DLog(@"dual head mode ftw");
self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]];
self.secondWindow.backgroundColor = [UIColor blackColor];