enabled OK button on GuiCombat screen when choosing defenders/attackers. iOS solution only currently. To implement in Android, we need to create a mask/invisible button above the OK button coordinates and add a listener to activate when a user touches the appropriate area. Not ideal, but it works for now.
TODO: translate functionality into core of engine.
This commit is contained in:
@@ -371,7 +371,8 @@ class JGE
|
||||
/// and in IOS to communicate with the EAGL layer
|
||||
void SendCommand(std::string command);
|
||||
void SendCommand(std::string command, std::string parameter);
|
||||
|
||||
void SendCommand(std::string command, float& x, float& y, float& width, float& height);
|
||||
|
||||
#if defined (ANDROID)
|
||||
/// Access to JNI Environment
|
||||
void SetJNIEnv(JNIEnv * env, jclass cls);
|
||||
|
||||
@@ -589,6 +589,8 @@ void JGE::SendCommand(string command)
|
||||
{
|
||||
#if defined (ANDROID)
|
||||
sendJNICommand(command);
|
||||
#elif defined (IOS)
|
||||
SendCommand(command, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -597,29 +599,42 @@ 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];
|
||||
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
|
||||
}
|
||||
|
||||
#if defined (ANDROID)
|
||||
/// Access to JNI Environment
|
||||
void JGE::SetJNIEnv(JNIEnv * env, jclass cls)
|
||||
{
|
||||
mJNIEnv = env;
|
||||
mJNIClass = cls;
|
||||
midSendCommand = mJNIEnv->GetStaticMethodID(mJNIClass,"jgeSendCommand","(Ljava/lang/String;)V");
|
||||
}
|
||||
|
||||
void JGE::sendJNICommand(string command)
|
||||
{
|
||||
if (midSendCommand) {
|
||||
mJNIEnv->CallStaticVoidMethod(mJNIClass, midSendCommand, mJNIEnv->NewStringUTF(command.c_str()));
|
||||
}
|
||||
}
|
||||
// this controls commands meant to modify/interact with UI
|
||||
void JGE::SendCommand(std::string command, float& x, float& y, float& width, float& height)
|
||||
{
|
||||
#ifdef ANDROID
|
||||
|
||||
#elif IOS
|
||||
wagicAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
||||
[delegate handleWEngineCommand: [NSString stringWithCString: command.c_str() encoding: NSUTF8StringEncoding] withUIParameters: x yCoordinate: y width: width height: height];
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if defined (ANDROID)
|
||||
/// Access to JNI Environment
|
||||
void JGE::SetJNIEnv(JNIEnv * env, jclass cls)
|
||||
{
|
||||
mJNIEnv = env;
|
||||
mJNIClass = cls;
|
||||
midSendCommand = mJNIEnv->GetStaticMethodID(mJNIClass,"jgeSendCommand","(Ljava/lang/String;)V");
|
||||
}
|
||||
|
||||
void JGE::sendJNICommand(string command)
|
||||
{
|
||||
if (midSendCommand) {
|
||||
mJNIEnv->CallStaticVoidMethod(mJNIClass, midSendCommand, mJNIEnv->NewStringUTF(command.c_str()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
std::queue< pair< pair<LocalKeySym, JButton>, bool> > JGE::keyBuffer;
|
||||
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
BOOL bannerIsVisible;
|
||||
}
|
||||
|
||||
- (void)addOkButtonListener: (CGRect) frame;
|
||||
|
||||
@property (nonatomic, retain) id eaglView;
|
||||
@property (nonatomic, retain) UITextField *inputField;
|
||||
@property (nonatomic, retain) UIButton *okButtonView;
|
||||
@property (nonatomic, assign) BOOL bannerIsVisible;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
@synthesize bannerIsVisible;
|
||||
@synthesize eaglView;
|
||||
@synthesize okButtonView;
|
||||
@synthesize inputField;
|
||||
|
||||
#pragma mark initialization / deallocation methods
|
||||
@@ -38,6 +39,7 @@
|
||||
[eaglView setDelegate: nil];
|
||||
[eaglView release], eaglView = nil;
|
||||
[inputField release], inputField = nil;
|
||||
[okButtonView release], okButtonView = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -86,10 +88,32 @@
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
#pragma mark - UIView Creation
|
||||
- (void)addOkButtonListener: (CGRect) frame
|
||||
{
|
||||
// create an invisible view to handle the pressing of the OK button.
|
||||
if ( okButtonView == nil )
|
||||
{
|
||||
okButtonView = [[UIButton alloc] initWithFrame: frame];
|
||||
[okButtonView setBackgroundColor: [UIColor clearColor]];
|
||||
[okButtonView setEnabled: YES];
|
||||
[okButtonView addTarget: self.view action:@selector(handleOK:) forControlEvents: UIControlEventTouchUpInside];
|
||||
[self.view addSubview: okButtonView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.view bringSubviewToFront: okButtonView];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
- (void)removeOkButtonListener
|
||||
{
|
||||
[[self.view.subviews lastObject] removeFromSuperview];
|
||||
[okButtonView release], okButtonView = nil;
|
||||
}
|
||||
|
||||
#pragma mark device orientation handlers
|
||||
|
||||
#pragma mark - device orientation handlers
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
// Overriden to allow any orientation.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
- (void) rotateBackgroundImage:(UIInterfaceOrientation)fromInterfaceOrientation toInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
|
||||
|
||||
- (void) handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter;
|
||||
- (void) handleWEngineCommand:(NSString *) command withUIParameters: (CGFloat) x yCoordinate: (CGFloat) y width: (CGFloat) width height: (CGFloat) height;
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UIWindow *window;
|
||||
@property (nonatomic, retain) EAGLViewController *glViewController;
|
||||
|
||||
@@ -144,6 +144,16 @@
|
||||
[self.glViewController toggleKeyboardWithState: initialState];
|
||||
}
|
||||
|
||||
- (void) handleWEngineCommand:(NSString *) command
|
||||
withUIParameters: (CGFloat) x
|
||||
yCoordinate: (CGFloat) y
|
||||
width: (CGFloat) width
|
||||
height: (CGFloat) height
|
||||
{
|
||||
CGRect uiFrame = CGRectMake(x, y, width, height);
|
||||
if ( [command isEqualToString: @"okbuttoncreated"] )
|
||||
[glViewController addOkButtonListener: uiFrame];
|
||||
}
|
||||
|
||||
- (void)handleWEngineCommand:(NSString *) command withParameter: (NSString *) parameter
|
||||
{
|
||||
@@ -165,6 +175,10 @@
|
||||
{
|
||||
[self initializeKeyboard: parameter];
|
||||
}
|
||||
else if ([command isEqualToString: @"combatGuiEndDamage"])
|
||||
{
|
||||
[glViewController removeOkButtonListener];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user