Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

BeginShowKeyboardInput fixed for iOS #2260

Merged
merged 5 commits into from

5 participants

@Nezz

Keyboard input wasn't really working, so I rewrote it. This PR fixes #1689. The new code is much cleaner.

I have also included the hiding of the status bar on iOS 7.

@mgbot
Collaborator

Test FAILed.
Refer to this link for build results: http://build.monogame.net/job/PullRequestTester/609/

@Nezz

The build has failed because the build bot doesn't seem to have XCode 5.0. Without its support for iOS7, there is no PrefersStatusBarHidden method to override.

@totallyeviljake

is there a way to check if you are targeting IOS7 and ifdef this code?

@Nezz

Sadly it is not possible. When iOS 6 came and broke the autorotation, we had to add some method overrides similar to this.
Since this is a seperate problem from the keyboard, should I separate it into a second PR?

@KonajuGames
Owner

All iOS apps submitted to the App Store must now be built with the iOS 7 SDK, so this is one reason to update Xcode and the iOS SDK on the build bot. The app can still target iOS 6, but it must be built with the iOS 7 SDK. Will the addition of PreferStatusBarHidden break if the dev sets iOS 6 as a target and runs on a iOS 6 device?

Hiding the status bar should only be done if the dev has set GraphicsDeviceManager.IsFullScreen to true. Otherwise they want it visible.

@Nezz

Removed the status bar part from this PR so it can be discussed further in #2265 and we can merge this PR.

@mgbot
Collaborator

Test PASSed.
Refer to this link for build results: http://build.monogame.net/job/PullRequestTester/618/

@azchohfi

This also fixes the Guide.IsVisible not being set to false at the end of the process.
This needs to be updated to work with protobuild.

@Nezz

Update complete to work with protobuild.

@mgbot
Collaborator

Test PASSed.
Refer to this link for build results: http://build.monogame.net/job/PullRequestTester/661/

@Nezz

Can we go on with the merge?

@azchohfi

Please, do.

@KonajuGames KonajuGames merged commit a5dc465 into from
@KonajuGames
Owner

Merged.

@Nezz Nezz deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2014
  1. @Nezz
Commits on Mar 7, 2014
  1. @Nezz
Commits on Mar 27, 2014
  1. @Nezz

    Merge branch 'develop' of https://github.com/mono/MonoGame into ioske…

    Nezz authored
    …yboardfix
    
    Conflicts:
    	MonoGame.Framework/MonoGame.Framework.iOS.csproj
  2. @Nezz
  3. @Nezz

    Updated Protobuild definition

    Nezz authored
This page is out of date. Refresh to see the latest.
View
3  Build/Projects/MonoGame.Framework.definition
@@ -961,9 +961,6 @@
<Compile Include="iOS\GamerServices\Guide.cs">
<Platforms>iOS</Platforms>
</Compile>
- <Compile Include="iOS\GamerServices\KeyboardInputAsyncResult.cs">
- <Platforms>iOS</Platforms>
- </Compile>
<Compile Include="iOS\GamerServices\KeyboardInputViewController.cs">
<Platforms>iOS</Platforms>
</Compile>
View
76 MonoGame.Framework/iOS/GamerServices/Guide.cs
@@ -147,8 +147,6 @@ public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
public static class Guide
{
- private static int _showKeyboardInputRequestCount;
-
private static GKLeaderboardViewController leaderboardController;
private static GKAchievementViewController achievementController;
private static GKPeerPickerController peerPickerController;
@@ -219,6 +217,40 @@ private static void AssertInitialised ()
"Gamer services functionality has not been initialized.");
}
+ delegate string ShowKeyboardInputDelegate(
+ string title, string description, string defaultText, Object state, bool usePasswordMode);
+
+ private static string ShowKeyboardInput(
+ string title, string description, string defaultText, Object state, bool usePasswordMode)
+ {
+ string result = null;
+
+ IsVisible = true;
+ EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
+
+ keyboardViewController = new KeyboardInputViewController(
+ title, description, defaultText, usePasswordMode, _gameViewController);
+
+ UIApplication.SharedApplication.InvokeOnMainThread (delegate {
+ _gameViewController.PresentViewController (keyboardViewController, true, null);
+
+ keyboardViewController.View.InputAccepted += (sender, e) => {
+ _gameViewController.DismissViewController (true, null);
+ result = keyboardViewController.View.Text;
+ waitHandle.Set ();
+ };
+
+ keyboardViewController.View.InputCanceled += (sender, e) => {
+ _gameViewController.DismissViewController (true, null);
+ waitHandle.Set ();
+ };
+ });
+ waitHandle.WaitOne ();
+
+ IsVisible = false;
+ return result;
+ }
+
public static IAsyncResult BeginShowKeyboardInput (
PlayerIndex player, string title, string description, string defaultText,
AsyncCallback callback, Object state)
@@ -233,46 +265,18 @@ private static void AssertInitialised ()
{
AssertInitialised ();
- if (keyboardViewController != null)
- return null;
-
- int requestCount = Interlocked.Increment (ref _showKeyboardInputRequestCount);
- if (requestCount != 1) {
- Interlocked.Decrement (ref _showKeyboardInputRequestCount);
- // FIXME: Return the in-progress IAsyncResult?
- return null;
- }
-
- IsVisible = true;
-
- keyboardViewController = new KeyboardInputViewController(
- title, description, defaultText, usePasswordMode, _gameViewController);
-
- _gameViewController.PresentModalViewController (keyboardViewController, true);
-
- keyboardViewController.View.InputAccepted += (sender, e) => {
- _gameViewController.DismissModalViewControllerAnimated(true);
- Interlocked.Decrement (ref _showKeyboardInputRequestCount);
- };
+ if (IsVisible)
+ throw new GuideAlreadyVisibleException("The function cannot be completed at this time: the Guide UI is already active. Wait until Guide.IsVisible is false before issuing this call.");
- keyboardViewController.View.InputCanceled += (sender, e) => {
- _gameViewController.DismissModalViewControllerAnimated(true);
- Interlocked.Decrement (ref _showKeyboardInputRequestCount);
- };
+ ShowKeyboardInputDelegate ski = ShowKeyboardInput;
- return new KeyboardInputAsyncResult (keyboardViewController, callback, state);
+ return ski.BeginInvoke(title, description, defaultText, state, usePasswordMode, callback, ski);
}
public static string EndShowKeyboardInput (IAsyncResult result)
{
- AssertInitialised ();
-
keyboardViewController = null;
-
- if (!(result is KeyboardInputAsyncResult))
- throw new ArgumentException ("result");
-
- return (result as KeyboardInputAsyncResult).GetResult();
+ return (result.AsyncState as ShowKeyboardInputDelegate).EndInvoke (result);
}
delegate Nullable<int> ShowMessageBoxDelegate(
@@ -318,7 +322,7 @@ public static string EndShowKeyboardInput (IAsyncResult result)
ShowMessageBoxDelegate smb = ShowMessageBox;
- return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
+ return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
}
public static IAsyncResult BeginShowMessageBox (
View
161 MonoGame.Framework/iOS/GamerServices/KeyboardInputAsyncResult.cs
@@ -1,161 +0,0 @@
-#region License
-/*
-Microsoft Public License (Ms-PL)
-MonoGame - Copyright © 2009-2012 The MonoGame Team
-
-All rights reserved.
-
-This license governs use of the accompanying software. If you use the software,
-you accept this license. If you do not accept the license, do not use the
-software.
-
-1. Definitions
-
-The terms "reproduce," "reproduction," "derivative works," and "distribution"
-have the same meaning here as under U.S. copyright law.
-
-A "contribution" is the original software, or any additions or changes to the
-software.
-
-A "contributor" is any person that distributes its contribution under this
-license.
-
-"Licensed patents" are a contributor's patent claims that read directly on its
-contribution.
-
-2. Grant of Rights
-
-(A) Copyright Grant- Subject to the terms of this license, including the
-license conditions and limitations in section 3, each contributor grants you a
-non-exclusive, worldwide, royalty-free copyright license to reproduce its
-contribution, prepare derivative works of its contribution, and distribute its
-contribution or any derivative works that you create.
-
-(B) Patent Grant- Subject to the terms of this license, including the license
-conditions and limitations in section 3, each contributor grants you a
-non-exclusive, worldwide, royalty-free license under its licensed patents to
-make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
-its contribution in the software or derivative works of the contribution in the
-software.
-
-3. Conditions and Limitations
-
-(A) No Trademark License- This license does not grant you rights to use any
-contributors' name, logo, or trademarks.
-
-(B) If you bring a patent claim against any contributor over patents that you
-claim are infringed by the software, your patent license from such contributor
-to the software ends automatically.
-
-(C) If you distribute any portion of the software, you must retain all
-copyright, patent, trademark, and attribution notices that are present in the
-software.
-
-(D) If you distribute any portion of the software in source code form, you may
-do so only under this license by including a complete copy of this license with
-your distribution. If you distribute any portion of the software in compiled or
-object code form, you may only do so under a license that complies with this
-license.
-
-(E) The software is licensed "as-is." You bear the risk of using it. The
-contributors give no express warranties, guarantees or conditions. You may have
-additional consumer rights under your local laws which this license cannot
-change. To the extent permitted under your local laws, the contributors exclude
-the implied warranties of merchantability, fitness for a particular purpose and
-non-infringement.
-*/
-#endregion License
-
-using System;
-using System.Threading;
-
-using MonoTouch.CoreFoundation;
-using MonoTouch.Foundation;
-using MonoTouch.UIKit;
-
-namespace Microsoft.Xna.Framework {
- class KeyboardInputAsyncResult : IAsyncResult {
- private readonly KeyboardInputViewController _viewController;
- private readonly AsyncCallback _callback;
- public KeyboardInputAsyncResult (
- KeyboardInputViewController viewController, AsyncCallback callback, object asyncState)
- {
- if (viewController == null)
- throw new ArgumentNullException ("viewController");
-
- _viewController = viewController;
- _callback = callback;
- _asyncState = asyncState;
- _asyncWaitHandle = new Lazy<ManualResetEvent>(
- () => new ManualResetEvent(false),
- LazyThreadSafetyMode.ExecutionAndPublication);
-
- _viewController.View.InputAccepted += ViewController_InputAccepted;
- _viewController.View.InputCanceled += ViewController_InputCanceled;
- }
-
- private string _result;
- public string GetResult ()
- {
- // FIXME: CFRunLoop.CFDefaultRunLoopMode is currently
- // returning null. So for now, cast from the
- // CLR string version.
- var mode = (NSString)CFRunLoop.ModeDefault;
- while (!_isCompleted)
- CFRunLoop.Main.RunInMode (mode, 0.1, false);
- return _result;
- }
-
- private void ViewController_InputAccepted (object sender, EventArgs e)
- {
- UnsubscribeViewEvents ();
- MarkComplete (_viewController.View.Text);
- }
-
- private void ViewController_InputCanceled (object sender, EventArgs e)
- {
- UnsubscribeViewEvents ();
- MarkComplete (null);
- }
-
- private void MarkComplete (string result)
- {
- _result = result;
- _isCompleted = true;
- if (_asyncWaitHandle.IsValueCreated)
- _asyncWaitHandle.Value.Set ();
-
- if (_callback != null)
- UIApplication.SharedApplication.BeginInvokeOnMainThread(() => _callback (this));
- }
-
- private void UnsubscribeViewEvents ()
- {
- _viewController.View.InputAccepted -= ViewController_InputAccepted;
- _viewController.View.InputCanceled -= ViewController_InputCanceled;
- }
-
- #region IAsyncResult Members
-
- private readonly object _asyncState;
- public object AsyncState {
- get { return _asyncState; }
- }
-
- private readonly Lazy<ManualResetEvent> _asyncWaitHandle;
- public WaitHandle AsyncWaitHandle {
- get { return _asyncWaitHandle.Value; }
- }
-
- public bool CompletedSynchronously {
- get { return false; }
- }
-
- private bool _isCompleted;
- public bool IsCompleted {
- get { return _isCompleted; }
- }
-
- #endregion IAsyncResult Members
- }
-}
Something went wrong with that request. Please try again.