making chat work... (keyboard support is heavily broken in sdl upstream)
--- a/hedgewars/hwengine.pas Fri Jul 16 00:18:03 2010 +0200
+++ b/hedgewars/hwengine.pas Sat Jul 17 03:59:10 2010 +0200
@@ -151,7 +151,13 @@
while SDL_PollEvent(@event) <> 0 do
begin
case event.type_ of
- SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
+ SDL_KEYDOWN: if GameState = gsChat then
+{$IFDEF IPHONEOS}
+ // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
+ KeyPressChat(event.key.keysym.sym);
+{$ELSE}
+ KeyPressChat(event.key.keysym.unicode);
+{$ENDIF}
{$IFDEF SDL13}
SDL_WINDOWEVENT:
if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.h Sat Jul 17 03:59:10 2010 +0200
@@ -0,0 +1,19 @@
+//
+// popupMenuViewController.h
+// HedgewarsMobile
+//
+// Created by Vittorio on 25/03/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+
+@interface InGameMenuViewController : UITableViewController <UIActionSheetDelegate> {
+ NSArray *menuList;
+ BOOL isPaused;
+ SDL_Window *sdlwindow;
+}
+@property (nonatomic,retain) NSArray *menuList;
+
+@end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m Sat Jul 17 03:59:10 2010 +0200
@@ -0,0 +1,138 @@
+ //
+// popupMenuViewController.m
+// HedgewarsMobile
+//
+// Created by Vittorio on 25/03/10.
+// Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "SDL_uikitappdelegate.h"
+#import "InGameMenuViewController.h"
+#import "PascalImports.h"
+#import "CommodityFunctions.h"
+#import "SDL_sysvideo.h"
+
+@implementation InGameMenuViewController
+@synthesize menuList;
+
+
+-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
+ return rotationManager(interfaceOrientation);
+}
+
+-(void) didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+}
+
+-(void) viewDidLoad {
+ isPaused = NO;
+
+ NSArray *array = [[NSArray alloc] initWithObjects:
+ NSLocalizedString(@"Pause Game", @""),
+ NSLocalizedString(@"Chat", @""),
+ NSLocalizedString(@"End Game", @""),
+ nil];
+ self.menuList = array;
+ [array release];
+
+ // save the sdl window (!= uikit window) for future reference
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ SDL_VideoDisplay *display = &_this->displays[0];
+ sdlwindow = display->windows;
+
+ [super viewDidLoad];
+}
+
+-(void) viewDidUnload {
+ self.menuList = nil;
+ [super viewDidUnload];
+ MSG_DIDUNLOAD();
+}
+
+-(void) dealloc {
+ [menuList release];
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark tableView methods
+-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return 3;
+}
+
+-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ static NSString *cellIdentifier = @"CellIdentifier";
+
+ UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
+ if (nil == cell) {
+ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
+ reuseIdentifier:cellIdentifier] autorelease];
+ }
+ cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
+
+ return cell;
+}
+
+-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ UIActionSheet *actionSheet;
+
+ switch ([indexPath row]) {
+ case 0:
+ HW_pause();
+ isPaused = !isPaused;
+ break;
+ case 1:
+ HW_chat();
+ SDL_iPhoneKeyboardShow(sdlwindow);
+ break;
+ case 2:
+ // expand the view (and table) so that the actionsheet can be selected on the iPhone
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+ [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
+ [UIView beginAnimations:@"table width more" context:NULL];
+ [UIView setAnimationDuration:0.2];
+ self.view.frame = CGRectMake(0, 0, 480, 320);
+ [UIView commitAnimations];
+ }
+ actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
+ delegate:self
+ cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
+ destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
+ otherButtonTitles:nil];
+ [actionSheet showInView:self.view];
+ [actionSheet release];
+
+ if (!isPaused)
+ HW_pause();
+ break;
+ default:
+ NSLog(@"Warning: unset case value in section!");
+ break;
+ }
+
+ [aTableView deselectRowAtIndexPath:indexPath animated:YES];
+}
+
+#pragma mark -
+#pragma mark actionSheet methods
+-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
+ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
+ [UIView beginAnimations:@"table width less" context:NULL];
+ [UIView setAnimationDuration:0.2];
+ self.view.frame = CGRectMake(280, 0, 200, 170);
+ [UIView commitAnimations];
+ }
+
+ if ([actionSheet cancelButtonIndex] != buttonIndex)
+ HW_terminate(NO);
+ else
+ if (!isPaused)
+ HW_pause();
+}
+
+@end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h Fri Jul 16 00:18:03 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h Sat Jul 17 03:59:10 2010 +0200
@@ -7,23 +7,28 @@
//
#import <UIKit/UIKit.h>
+#import "SDL_sysvideo.h"
-@class PopoverMenuViewController;
+@class InGameMenuViewController;
@interface OverlayViewController : UIViewController {
+ // the timer that dims the overlay
NSTimer *dimTimer;
- // used only on the ipad
- UIPopoverController *popoverController;
-
- PopoverMenuViewController *popupMenu;
+ // the in-game menu
+ UIPopoverController *popoverController; // iPad only
+ InGameMenuViewController *popupMenu;
BOOL isPopoverVisible;
+ // ths touch section
CGFloat initialDistanceForPinching;
+
+ // the sdl window underneath
+ SDL_Window *sdlwindow;
}
@property (nonatomic,retain) id popoverController;
-@property (nonatomic,retain) PopoverMenuViewController *popupMenu;
+@property (nonatomic,retain) InGameMenuViewController *popupMenu;
BOOL isGameRunning;
@@ -39,7 +44,5 @@
-(void) dismissPopover;
-(void) dimOverlay;
-(void) activateOverlay;
--(void) chatAppear;
--(void) chatDisappear;
@end
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Fri Jul 16 00:18:03 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sat Jul 17 03:59:10 2010 +0200
@@ -12,7 +12,7 @@
#import "CGPointUtils.h"
#import "SDL_mouse.h"
#import "SDL_config_iphoneos.h"
-#import "PopoverMenuViewController.h"
+#import "InGameMenuViewController.h"
#import "CommodityFunctions.h"
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
@@ -44,13 +44,11 @@
case UIDeviceOrientationLandscapeLeft:
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
- [self chatDisappear];
HW_setLandscape(YES);
break;
case UIDeviceOrientationLandscapeRight:
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
- [self chatDisappear];
HW_setLandscape(YES);
break;
/*
@@ -79,35 +77,6 @@
[UIView commitAnimations];
}
--(void) chatAppear {
- /*
- if (writeChatTextField == nil) {
- writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)];
- writeChatTextField.textColor = [UIColor whiteColor];
- writeChatTextField.backgroundColor = [UIColor blueColor];
- writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
- writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo;
- writeChatTextField.enablesReturnKeyAutomatically = NO;
- writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
- writeChatTextField.keyboardType = UIKeyboardTypeDefault;
- writeChatTextField.returnKeyType = UIReturnKeyDefault;
- writeChatTextField.secureTextEntry = NO;
- [self.view addSubview:writeChatTextField];
- }
- writeChatTextField.alpha = 1;
- [self activateOverlay];
- [dimTimer setFireDate:HIDING_TIME_NEVER];
- */
-}
-
--(void) chatDisappear {
- /*
- writeChatTextField.alpha = 0;
- [writeChatTextField resignFirstResponder];
- [dimTimer setFireDate:HIDING_TIME_DEFAULT];
- */
-}
-
#pragma mark -
#pragma mark View Management
-(void) viewDidLoad {
@@ -151,6 +120,11 @@
[UIView setAnimationDuration:1];
self.view.alpha = 1;
[UIView commitAnimations];
+
+ // find the sdl window we're on
+ SDL_VideoDevice *_this = SDL_GetVideoDevice();
+ SDL_VideoDisplay *display = &_this->displays[0];
+ sdlwindow = display->windows;
}
/* these are causing problems at reloading so let's remove 'em
@@ -290,7 +264,7 @@
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (popupMenu == nil)
- popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain];
+ popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain];
if (popoverController == nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu];
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
@@ -303,7 +277,7 @@
animated:YES];
} else {
if (popupMenu == nil) {
- popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
+ popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped];
popupMenu.view.backgroundColor = [UIColor clearColor];
popupMenu.view.frame = CGRectMake(480, 0, 200, 170);
}
@@ -347,15 +321,13 @@
NSSet *allTouches = [event allTouches];
UITouch *first, *second;
- if (isPopoverVisible) {
+ // hide in-game menu
+ if (isPopoverVisible)
[self dismissPopover];
- }
- /*
- if (writeChatTextField) {
- [self.writeChatTextField resignFirstResponder];
- [dimTimer setFireDate:HIDING_TIME_DEFAULT];
- }
- */
+
+ // remove keyboard from the view
+ if (SDL_iPhoneKeyboardIsShown(sdlwindow))
+ SDL_iPhoneKeyboardHide(sdlwindow);
// reset default dimming
doDim();
--- a/project_files/HedgewarsMobile/Classes/PopoverMenuViewController.h Fri Jul 16 00:18:03 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-//
-// popupMenuViewController.h
-// HedgewarsMobile
-//
-// Created by Vittorio on 25/03/10.
-// Copyright 2010 __MyCompanyName__. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-
-@interface PopoverMenuViewController : UITableViewController <UIActionSheetDelegate> {
- NSArray *menuList;
- BOOL isPaused;
-}
-@property (nonatomic,retain) NSArray *menuList;
-
-@end
--- a/project_files/HedgewarsMobile/Classes/PopoverMenuViewController.m Fri Jul 16 00:18:03 2010 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
- //
-// popupMenuViewController.m
-// HedgewarsMobile
-//
-// Created by Vittorio on 25/03/10.
-// Copyright 2010 __MyCompanyName__. All rights reserved.
-//
-
-#import "SDL_uikitappdelegate.h"
-#import "PopoverMenuViewController.h"
-#import "PascalImports.h"
-#import "CommodityFunctions.h"
-#import "SDL_sysvideo.h"
-
-@implementation PopoverMenuViewController
-@synthesize menuList;
-
-
--(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
- return rotationManager(interfaceOrientation);
-}
-
-
--(void) didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
-}
-
--(void) viewDidLoad {
- isPaused = NO;
-
- NSArray *array = [[NSArray alloc] initWithObjects:
- NSLocalizedString(@"Pause Game", @""),
- NSLocalizedString(@"Chat", @""),
- NSLocalizedString(@"End Game", @""),
- nil];
- self.menuList = array;
- [array release];
-
- [super viewDidLoad];
-}
-
--(void) viewDidUnload {
- self.menuList = nil;
- [super viewDidUnload];
- MSG_DIDUNLOAD();
-}
-
--(void) dealloc {
- [menuList release];
- [super dealloc];
-}
-
-#pragma mark -
-#pragma mark tableView methods
--(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
-}
-
--(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 3;
-}
-
--(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *cellIdentifier = @"CellIdentifier";
-
- UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
- if (nil == cell) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
- reuseIdentifier:cellIdentifier] autorelease];
- }
- cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
-
- return cell;
-}
-
--(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- UIActionSheet *actionSheet;
-
- switch ([indexPath row]) {
- case 0:
- HW_pause();
- isPaused = !isPaused;
- break;
- case 1:
- HW_chat();
- /*
- SDL_VideoDevice *_this = SDL_GetVideoDevice();
- SDL_VideoDisplay *display = &_this->displays[0];
- SDL_Window *window = display->windows;
- SDL_iPhoneKeyboardShow(window);
- */
- break;
- case 2:
- // expand the view (and table) so that the actionsheet can be selected on the iPhone
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
- [UIView beginAnimations:@"table width more" context:NULL];
- [UIView setAnimationDuration:0.2];
- self.view.frame = CGRectMake(0, 0, 480, 320);
- [UIView commitAnimations];
- }
- actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
- delegate:self
- cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
- destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
- otherButtonTitles:nil];
- [actionSheet showInView:self.view];
- [actionSheet release];
-
- if (!isPaused)
- HW_pause();
- break;
- default:
- NSLog(@"Warning: unset case value in section!");
- break;
- }
-
- [aTableView deselectRowAtIndexPath:indexPath animated:YES];
-}
-
-#pragma mark -
-#pragma mark actionSheet methods
--(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
- [UIView beginAnimations:@"table width less" context:NULL];
- [UIView setAnimationDuration:0.2];
- self.view.frame = CGRectMake(280, 0, 200, 170);
- [UIView commitAnimations];
- }
-
- if ([actionSheet cancelButtonIndex] != buttonIndex)
- HW_terminate(NO);
- else
- if (!isPaused)
- HW_pause();
-}
-
-@end
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Fri Jul 16 00:18:03 2010 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Sat Jul 17 03:59:10 2010 +0200
@@ -47,7 +47,7 @@
6165921611CA9BA200D6E256 /* MapConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591F311CA9BA200D6E256 /* MapConfigViewController.m */; };
6165921711CA9BA200D6E256 /* MasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591F511CA9BA200D6E256 /* MasterViewController.m */; };
6165921811CA9BA200D6E256 /* OverlayViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591F711CA9BA200D6E256 /* OverlayViewController.m */; };
- 6165921911CA9BA200D6E256 /* PopoverMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591F911CA9BA200D6E256 /* PopoverMenuViewController.m */; };
+ 6165921911CA9BA200D6E256 /* InGameMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591F911CA9BA200D6E256 /* InGameMenuViewController.m */; };
6165921A11CA9BA200D6E256 /* SchemeSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591FB11CA9BA200D6E256 /* SchemeSettingsViewController.m */; };
6165921B11CA9BA200D6E256 /* SchemeWeaponConfigViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591FD11CA9BA200D6E256 /* SchemeWeaponConfigViewController.m */; };
6165921C11CA9BA200D6E256 /* SingleSchemeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 616591FF11CA9BA200D6E256 /* SingleSchemeViewController.m */; };
@@ -282,8 +282,8 @@
616591F511CA9BA200D6E256 /* MasterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MasterViewController.m; sourceTree = "<group>"; };
616591F611CA9BA200D6E256 /* OverlayViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OverlayViewController.h; sourceTree = "<group>"; };
616591F711CA9BA200D6E256 /* OverlayViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OverlayViewController.m; sourceTree = "<group>"; };
- 616591F811CA9BA200D6E256 /* PopoverMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PopoverMenuViewController.h; sourceTree = "<group>"; };
- 616591F911CA9BA200D6E256 /* PopoverMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PopoverMenuViewController.m; sourceTree = "<group>"; };
+ 616591F811CA9BA200D6E256 /* InGameMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InGameMenuViewController.h; sourceTree = "<group>"; };
+ 616591F911CA9BA200D6E256 /* InGameMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InGameMenuViewController.m; sourceTree = "<group>"; };
616591FA11CA9BA200D6E256 /* SchemeSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SchemeSettingsViewController.h; sourceTree = "<group>"; };
616591FB11CA9BA200D6E256 /* SchemeSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SchemeSettingsViewController.m; sourceTree = "<group>"; };
616591FC11CA9BA200D6E256 /* SchemeWeaponConfigViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SchemeWeaponConfigViewController.h; sourceTree = "<group>"; };
@@ -661,8 +661,8 @@
6163EE6C11CC253F001C0453 /* Overlay */ = {
isa = PBXGroup;
children = (
- 616591F811CA9BA200D6E256 /* PopoverMenuViewController.h */,
- 616591F911CA9BA200D6E256 /* PopoverMenuViewController.m */,
+ 616591F811CA9BA200D6E256 /* InGameMenuViewController.h */,
+ 616591F911CA9BA200D6E256 /* InGameMenuViewController.m */,
616591F611CA9BA200D6E256 /* OverlayViewController.h */,
616591F711CA9BA200D6E256 /* OverlayViewController.m */,
6165925011CA9CB400D6E256 /* OverlayViewController.xib */,
@@ -1163,7 +1163,7 @@
6165921611CA9BA200D6E256 /* MapConfigViewController.m in Sources */,
6165921711CA9BA200D6E256 /* MasterViewController.m in Sources */,
6165921811CA9BA200D6E256 /* OverlayViewController.m in Sources */,
- 6165921911CA9BA200D6E256 /* PopoverMenuViewController.m in Sources */,
+ 6165921911CA9BA200D6E256 /* InGameMenuViewController.m in Sources */,
6165921A11CA9BA200D6E256 /* SchemeSettingsViewController.m in Sources */,
6165921B11CA9BA200D6E256 /* SchemeWeaponConfigViewController.m in Sources */,
6165921C11CA9BA200D6E256 /* SingleSchemeViewController.m in Sources */,