added new signature for SendCommand in JGE that takes in a command string and a parameter

added native keyboard handling in iOS
TODO: add same feature for Android tablets/phones
This commit is contained in:
techdragon.nguyen@gmail.com
2011-12-15 11:11:08 +00:00
parent f9016f70ab
commit dc7d52c48c
14 changed files with 785 additions and 535 deletions

View File

@@ -369,6 +369,7 @@ class JGE
/// Sends a message through JGE
/// Currently used only to communicate with the JNI Layer in Android
void SendCommand(std::string command);
void SendCommand(std::string command, std::string parameter);
#if defined (ANDROID)
/// Access to JNI Environment

View File

@@ -588,12 +588,17 @@ void JGE::SendCommand(string command)
#if defined (ANDROID)
sendJNICommand(command);
#endif
#ifdef IOS
}
void JGE::SendCommand(std::string command, std::string parameter)
{
#if defined (IOS)
// get the app delegate and have it handle the command
wagicAppDelegate *delegate = [ [UIApplication sharedApplication] delegate];
const char* commandString = command.c_str();
DebugTrace("Command: "<< command << endl);
[delegate handleWEngineCommand:[NSString stringWithUTF8String: commandString]];
DebugTrace("Command: "<< command << " with parameter: " << parameter << endl);
[delegate handleWEngineCommand:[NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding]
withParameter: [NSString stringWithCString: parameter.c_str() encoding:NSUTF8StringEncoding]];
#endif
}

View File

@@ -2,6 +2,7 @@
#import <QuartzCore/QuartzCore.h>
#import "AdWhirlDelegateProtocol.h"
#import "EAGLViewController.h"
#import "EAGLView.h"
#import "ESRenderer.h"
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
@@ -35,6 +36,7 @@
- (void)stopAnimation;
- (void)drawView:(id)sender;
- (void)updateKeyboard: (NSString *) inputString;
- (void)removeAds;
- (void)displayAds;

View File

@@ -10,6 +10,8 @@
#include "JRenderer.h"
#include "JGameLauncher.h"
#include "GameApp.h"
#import "AdWhirlView.h"
#import "wagicAppDelegate.h"
@@ -532,6 +534,31 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
}
#pragma mark -
#include "GameOptions.h"
#pragma mark Keyboard related methods
- (void) updateKeyboard:( NSString *) inputString
{
// send the new string to JGE to update the string
unsigned char key = [inputString characterAtIndex: 0];
if ([inputString length] > 1)
{
if ([inputString isEqualToString: @"DELETE"])
key = 127;
else if ([inputString isEqualToString:@"SPACE"])
key = 32;
else if ([inputString isEqualToString: @"SAVE"])
key = 1;
else if ([inputString isEqualToString: @"CANCEL"])
key = 10;
}
options.keypadUpdateText( key );
if ( key < 11 )
g_engine->HoldKey_NoRepeat( JGE_BTN_OK) ;
}
//These are the methods for the AdWhirl Delegate, you have to implement them
#pragma mark AdWhirlDelegate methods

View File

@@ -1,11 +1,13 @@
#import <UIKit/UIKit.h>
#import "AdWhirlDelegateProtocol.h"
@interface EAGLViewController : UIViewController {
@interface EAGLViewController : UIViewController<UITextFieldDelegate> {
BOOL bannerIsVisible;
}
@property (nonatomic, retain) id eaglView;
@property (nonatomic, retain) UITextField *inputField;
@property (nonatomic, assign) BOOL bannerIsVisible;
@property (nonatomic, retain) id eaglView;
@end

View File

@@ -10,15 +10,26 @@
@synthesize bannerIsVisible;
@synthesize eaglView;
@synthesize inputField;
#pragma mark initialization / deallocation methods
- (id)init {
self = [super init];
if (self) {
inputField = [[UITextField alloc] initWithFrame: CGRectMake(-50, -50, 25, 25)] ;
[self.inputField setEnablesReturnKeyAutomatically: YES];
[self.inputField setEnabled: YES];
[self.inputField setDelegate: self];
[inputField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[inputField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[inputField setAutocorrectionType:UITextAutocorrectionTypeNo];
[inputField setKeyboardType: UIKeyboardTypeNamePhonePad];
CGRect frame = [[UIScreen mainScreen] applicationFrame];
eaglView = [[EAGLView alloc] initWithFrame:frame];
[self setView: eaglView];
[self.view addSubview: inputField];
[inputField release];
}
return self;
}
@@ -26,6 +37,7 @@
- (void)dealloc {
[eaglView setDelegate: nil];
[eaglView release], eaglView = nil;
[inputField release], inputField = nil;
[super dealloc];
}
@@ -157,4 +169,46 @@
#pragma mark -
#pragma mark UITextFieldDelegate methods
- (void)toggleKeyboardWithState: (NSString *) initialText
{
UIView *blockerView = [[[UIView alloc] initWithFrame: [self.view frame]] autorelease];
[blockerView setBackgroundColor: [UIColor clearColor]];
[self.view addSubview: blockerView];
if ([[self inputField] becomeFirstResponder])
{
[inputField setText: initialText];
// success in displaying the keyboard
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([string isEqualToString:@" "])
[eaglView updateKeyboard: @"SPACE"];
else if ( (string == nil || [string isEqualToString: @""]) && (1 == range.length))
[eaglView updateKeyboard: @"DELETE"];
else if ( (string == nil || [string isEqualToString: @""]) && (range.location == (range.length-1)))
[eaglView updateKeyboard: @"CLEAR"];
else
[eaglView updateKeyboard: string];
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[eaglView updateKeyboard: @"SAVE"];
return YES;
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
#pragma mark -
@end

View File

@@ -1,20 +1,19 @@
#import <UIKit/UIKit.h>
#import "Reachability.h"
#import "WagicDownloadProgressViewController.h"
#import "Reachability.h"
@class EAGLViewController;
@interface wagicAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EAGLViewController *glViewController;
//Reachability variables
Reachability* hostReach;
Reachability* internetReach;
Reachability* wifiReach;
Reachability *hostReach, *internetReach, *wifiReach;
}
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
- (void) handleWEngineCommand:(NSString *) command;
- (void) handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) EAGLViewController *glViewController;

View File

@@ -103,6 +103,8 @@
[self.window setBackgroundColor: [UIColor blackColor]];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
@@ -137,8 +139,13 @@
[self.glViewController.view stopAnimation];
}
- (void)initializeKeyboard: (id) initialState
{
[self.glViewController toggleKeyboardWithState: initialState];
}
- (void)handleWEngineCommand:(NSString *) command
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
{
BOOL isDevicePhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;
@@ -154,10 +161,13 @@
if (isDevicePhone)
[glViewController.eaglView removeAds];
}
else if ([command isEqualToString: @"displayKeyboard"])
{
[self initializeKeyboard: parameter];
}
}
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
bool isPhone = (UI_USER_INTERFACE_IDIOM()) == UIUserInterfaceIdiomPhone;