예제 #1
0
파일: Guide.cs 프로젝트: bjarkeeck/GCGJ
        public static IAsyncResult BeginShowMessageBox(
            PlayerIndex player,
            string title,
            string text,
            IEnumerable <string> buttons,
            int focusButton,
            MessageBoxIcon icon,
            AsyncCallback callback,
            Object state
            )
        {
#if WINDOWS_PHONE
            // Call the Microsoft implementation of BeginShowMessageBox using an alias.
            return(MsXna_Guide.BeginShowMessageBox(
                       (MsXna_PlayerIndex)player,
                       title, text,
                       buttons, focusButton,
                       (MsXna_MessageBoxIcon)icon,
                       callback, state));
#else
            // TODO: GuideAlreadyVisibleException
            if (IsVisible)
            {
                throw new Exception("The function cannot be completed at this time: the Guide UI is already active. Wait until Guide.IsVisible is false before issuing this call.");
            }

            if (player != PlayerIndex.One)
            {
                throw new ArgumentOutOfRangeException("player", "Specified argument was out of the range of valid values.");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title", "This string cannot be null or empty, and must be less than 256 characters long.");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text", "This string cannot be null or empty, and must be less than 256 characters long.");
            }
            if (buttons == null)
            {
                throw new ArgumentNullException("buttons", "Value can not be null.");
            }

            ShowMessageBoxDelegate smb = ShowMessageBox;

            return(smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb));
#endif
        }
예제 #2
0
        private static Task <int?> PlatformShow(string title, string description, List <string> buttons)
        {
            tcs = new TaskCompletionSource <int?>();
            MsXna_Guide.BeginShowMessageBox(MsXna_PlayerIndex.One, title, description, buttons, 0, MsXna_MessageBoxIcon.None,
                                            ar =>
            {
                var result = MsXna_Guide.EndShowMessageBox(ar);

                if (!tcs.Task.IsCompleted)
                {
                    tcs.SetResult(result);
                }
            },
                                            null);

            return(tcs.Task);
        }
예제 #3
0
        public static IAsyncResult BeginShowMessageBox(
            MGXna_Framework.PlayerIndex player,
            string title,
            string text,
            IEnumerable <string> buttons,
            int focusButton,
            MessageBoxIcon icon,
            AsyncCallback callback,
            Object state
            )
        {
#if WINDOWS_PHONE
            // Call the Microsoft implementation of BeginShowMessageBox using an alias.
            return(MsXna_Guide.BeginShowMessageBox(
                       (MsXna_PlayerIndex)player,
                       title, text,
                       buttons, focusButton,
                       (MsXna_MessageBoxIcon)icon,
                       callback, state));
#elif !WINDOWS_UAP
            // TODO: GuideAlreadyVisibleException
            if (IsVisible)
            {
                throw new Exception("The function cannot be completed at this time: the Guide UI is already active. Wait until Guide.IsVisible is false before issuing this call.");
            }

            if (player != PlayerIndex.One)
            {
                throw new ArgumentOutOfRangeException("player", "Specified argument was out of the range of valid values.");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title", "This string cannot be null or empty, and must be less than 256 characters long.");
            }
            if (text == null)
            {
                throw new ArgumentNullException("text", "This string cannot be null or empty, and must be less than 256 characters long.");
            }
            if (buttons == null)
            {
                throw new ArgumentNullException("buttons", "Value can not be null.");
            }

            ShowMessageBoxDelegate smb = ShowMessageBox;

            return(smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb));
#else
            var tcs  = new TaskCompletionSource <int?>(state);
            var task = Task.Run <int?>(() => ShowMessageBox(title, text, buttons, focusButton, icon));
            task.ContinueWith(t =>
            {
                // Copy the task result into the returned task.
                if (t.IsFaulted)
                {
                    tcs.TrySetException(t.Exception.InnerExceptions);
                }
                else if (t.IsCanceled)
                {
                    tcs.TrySetCanceled();
                }
                else
                {
                    tcs.TrySetResult(t.Result);
                }

                // Invoke the user callback if necessary.
                if (callback != null)
                {
                    callback(tcs.Task);
                }
            });
            return(tcs.Task);
#endif
        }