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 /// Sends a message through JGE
/// Currently used only to communicate with the JNI Layer in Android /// Currently used only to communicate with the JNI Layer in Android
void SendCommand(std::string command); void SendCommand(std::string command);
void SendCommand(std::string command, std::string parameter);
#if defined (ANDROID) #if defined (ANDROID)
/// Access to JNI Environment /// Access to JNI Environment

View File

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

View File

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

View File

@@ -10,6 +10,8 @@
#include "JRenderer.h" #include "JRenderer.h"
#include "JGameLauncher.h" #include "JGameLauncher.h"
#include "GameApp.h"
#import "AdWhirlView.h" #import "AdWhirlView.h"
#import "wagicAppDelegate.h" #import "wagicAppDelegate.h"
@@ -532,6 +534,31 @@ static NSString *_MY_AD_WHIRL_APPLICATION_KEY_IPAD = @"2e70e3f3da40408588b9a3170
} }
#pragma mark - #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 //These are the methods for the AdWhirl Delegate, you have to implement them
#pragma mark AdWhirlDelegate methods #pragma mark AdWhirlDelegate methods

View File

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

View File

@@ -10,15 +10,26 @@
@synthesize bannerIsVisible; @synthesize bannerIsVisible;
@synthesize eaglView; @synthesize eaglView;
@synthesize inputField;
#pragma mark initialization / deallocation methods #pragma mark initialization / deallocation methods
- (id)init { - (id)init {
self = [super init]; self = [super init];
if (self) { 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]; CGRect frame = [[UIScreen mainScreen] applicationFrame];
eaglView = [[EAGLView alloc] initWithFrame:frame]; eaglView = [[EAGLView alloc] initWithFrame:frame];
[self setView: eaglView]; [self setView: eaglView];
[self.view addSubview: inputField];
[inputField release];
} }
return self; return self;
} }
@@ -26,6 +37,7 @@
- (void)dealloc { - (void)dealloc {
[eaglView setDelegate: nil]; [eaglView setDelegate: nil];
[eaglView release], eaglView = nil; [eaglView release], eaglView = nil;
[inputField release], inputField = nil;
[super dealloc]; [super dealloc];
} }
@@ -157,4 +169,46 @@
#pragma mark - #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 @end

View File

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

View File

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

View File

@@ -347,7 +347,7 @@ public:
string mFilename; string mFilename;
int save(); int save();
int load(); int load();
GameOption * get(int); GameOption * get(int);
GameOption * get(string optionName); GameOption * get(string optionName);
GameOption& operator[](int); GameOption& operator[](int);
@@ -383,6 +383,31 @@ public:
return false; return false;
} }
void keypadUpdateText(unsigned char key)
{
if (keypad)
{
switch (key)
{
case 1: // save the current text
keypad->pressKey( key);
break;
case 10: // cancel the edit
keypad->CancelEdit();
break;
case 32:
keypad->pressKey( KPD_SPACE );
break;
case 127:
keypad->pressKey( KPD_DEL );
break;
default:
keypad->pressKey( key );
break;
}
}
}
void keypadUpdate(float dt) void keypadUpdate(float dt)
{ {
if(keypad) if(keypad)
@@ -422,6 +447,7 @@ public:
private: private:
GameApp* theGame; GameApp* theGame;
SimplePad* keypad; SimplePad* keypad;
StyleManager* styleMan; StyleManager* styleMan;
void createProfileFolders(); void createProfileFolders();
}; };

View File

@@ -44,7 +44,8 @@ public:
void Render(); void Render();
void Update(float dt); void Update(float dt);
void pressKey(unsigned char id); void pressKey(unsigned char id);
void CancelEdit();
SimplePad(); SimplePad();
~SimplePad(); ~SimplePad();

View File

@@ -7,6 +7,10 @@
#include "StyleManager.h" #include "StyleManager.h"
#include "Credits.h" #include "Credits.h"
#ifdef IOS
#include "JGE.h"
#endif
const string Options::optionNames[] = { const string Options::optionNames[] = {
//Global options //Global options
"Profile", "Profile",
@@ -71,6 +75,8 @@ const string Options::optionNames[] = {
"aw_collector", "aw_collector",
}; };
#pragma mark Options
int Options::getID(string name) int Options::getID(string name)
{ {
if (0 == name.size()) if (0 == name.size())
@@ -187,6 +193,10 @@ int Options::optionInterrupt(int gamePhase)
return INVALID_OPTION; return INVALID_OPTION;
} }
#pragma mark -
#pragma mark GameOption
GameOption::GameOption(int value) : GameOption::GameOption(int value) :
number(value) number(value)
{ {
@@ -307,6 +317,9 @@ bool GameOption::write(std::ofstream * file, string name)
return true; return true;
} }
#pragma mark -
#pragma mark GameOptions
GameOptions::GameOptions(string filename) GameOptions::GameOptions(string filename)
{ {
mFilename = filename; mFilename = filename;
@@ -397,6 +410,12 @@ int GameOptions::save()
return 1; return 1;
} }
GameSettings GameOptions::getGameSettings()
{
return options;
}
GameOption& GameOptions::operator[](int optionID) GameOption& GameOptions::operator[](int optionID)
{ {
GameOption * go = get(optionID); GameOption * go = get(optionID);
@@ -524,6 +543,10 @@ GameOptions::~GameOptions()
unknownMap.clear(); unknownMap.clear();
} }
#pragma mark -
#pragma mark GameSettings
GameSettings options; GameSettings options;
GameSettings::GameSettings() GameSettings::GameSettings()
@@ -828,6 +851,14 @@ SimplePad * GameSettings::keypadStart(string input, string * _dest, bool _cancel
{ {
if (keypad == NULL) if (keypad == NULL)
keypad = NEW SimplePad(); keypad = NEW SimplePad();
// show keyboard
#ifdef IOS
JGE *engine = JGE::GetInstance();
engine->SendCommand( "displayKeyboard", input);
#elif ANDROID
JGE *engine = JGE::GetInstance();
engine->SendCommand( "displayKeyboard:" << input);
#endif
keypad->bShowCancel = _cancel; keypad->bShowCancel = _cancel;
keypad->bShowNumpad = _numpad; keypad->bShowNumpad = _numpad;
keypad->mX = _x; keypad->mX = _x;
@@ -848,6 +879,10 @@ void GameSettings::keypadShutdown()
SAFE_DELETE(keypad); SAFE_DELETE(keypad);
} }
#pragma mark -
#pragma mark EnumDefinition
//EnumDefinition //EnumDefinition
int EnumDefinition::findIndex(int value) int EnumDefinition::findIndex(int value)
{ {
@@ -908,6 +943,10 @@ bool GameOptionEnum::read(string input)
return false; return false;
} }
#pragma mark -
#pragma mark OptionMaxGrade
//Enum Definitions //Enum Definitions
OptionMaxGrade OptionMaxGrade::mDef; OptionMaxGrade OptionMaxGrade::mDef;
OptionMaxGrade::OptionMaxGrade() OptionMaxGrade::OptionMaxGrade()
@@ -921,6 +960,10 @@ OptionMaxGrade::OptionMaxGrade()
} }
; ;
#pragma mark -
#pragma mark OptionASkipPhase
OptionASkipPhase OptionASkipPhase::mDef; OptionASkipPhase OptionASkipPhase::mDef;
OptionASkipPhase::OptionASkipPhase() OptionASkipPhase::OptionASkipPhase()
{ {
@@ -929,6 +972,9 @@ OptionASkipPhase::OptionASkipPhase()
mDef.values.push_back(EnumDefinition::assoc(Constants::ASKIP_FULL, "Full")); mDef.values.push_back(EnumDefinition::assoc(Constants::ASKIP_FULL, "Full"));
} }
; ;
#pragma mark -
#pragma mark OptionWhosFirst
OptionWhosFirst OptionWhosFirst::mDef; OptionWhosFirst OptionWhosFirst::mDef;
OptionWhosFirst::OptionWhosFirst() OptionWhosFirst::OptionWhosFirst()
@@ -996,6 +1042,10 @@ OptionKicker::OptionKicker()
mDef.values.push_back(EnumDefinition::assoc(Constants::KICKER_CHOICE, "Offer Choice")); mDef.values.push_back(EnumDefinition::assoc(Constants::KICKER_CHOICE, "Offer Choice"));
} }
; ;
#pragma mark -
#pragma mark GameOptionAward
//GameOptionAward //GameOptionAward
GameOptionAward::GameOptionAward() GameOptionAward::GameOptionAward()
{ {
@@ -1131,6 +1181,10 @@ static JButton u32_to_button(u32 b)
return JGE_BTN_NONE; return JGE_BTN_NONE;
} }
#pragma mark -
#pragma mark GameOptionKeyBindings
bool GameOptionKeyBindings::read(string input) bool GameOptionKeyBindings::read(string input)
{ {
istringstream iss(input); istringstream iss(input);
@@ -1178,3 +1232,4 @@ bool GameOptionKeyBindings::write(std::ofstream* file, string name)
*file << endl; *file << endl;
return true; return true;
} }
#pragma mark -

View File

@@ -44,7 +44,11 @@ SimplePad::SimplePad()
{ {
nbitems = 0; nbitems = 0;
bActive = false; bActive = false;
#ifdef IOS
selected = KPD_OK;
#else
selected = 0; selected = 0;
#endif
priorKey = 0; priorKey = 0;
cursor = 0; cursor = 0;
bShowCancel = false; bShowCancel = false;
@@ -175,11 +179,16 @@ void SimplePad::pressKey(unsigned char key)
Finish(); Finish();
else if (key == KPD_CANCEL) else if (key == KPD_CANCEL)
{ {
bCanceled = true; CancelEdit();
Finish();
} }
} }
void SimplePad::CancelEdit()
{
bCanceled = true;
Finish();
}
void SimplePad::MoveSelection(unsigned char moveto) void SimplePad::MoveSelection(unsigned char moveto)
{ {
if (!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9) if (!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9)
@@ -370,7 +379,8 @@ void SimplePad::Render()
offY += kH + 12; offY += kH + 12;
if (!bShowNumpad) vSpacing -= kH + 12; if (!bShowNumpad) vSpacing -= kH + 12;
#ifndef IOS
for (int x = 0; x < nbitems; x++) for (int x = 0; x < nbitems; x++)
if (keys[x]) if (keys[x])
{ {
@@ -445,6 +455,7 @@ void SimplePad::Render()
mFont->DrawString(keys[x]->displayValue.c_str(), mX + offX, mY + offY); mFont->DrawString(keys[x]->displayValue.c_str(), mX + offX, mY + offY);
offX += kW + 14; offX += kW + 14;
} }
#endif
} }
unsigned int SimplePad::cursorPos() unsigned int SimplePad::cursorPos()

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleDocumentTypes</key>
<array/>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleIconFile</key>
<string>wagic-64x64.png</string>
<key>CFBundleIdentifier</key>
<string>net.wagic.core</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array/>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>UIFileSharingEnabled</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UTExportedTypeDeclarations</key>
<array/>
<key>UTImportedTypeDeclarations</key>
<array/>
</dict>
</plist>

File diff suppressed because it is too large Load Diff