Пример #1
0
 public static void Play(byte value)
 {
     if (HapticFeedbackPlayer.Haptics.ContainsKey((HapticEffect)value))
     {
         var on_off_duration_array = HapticFeedbackPlayer.Haptics[(HapticEffect)value];
         if (on_off_duration_array.Length == 1)
         {
             VibrationHelper.Vibrate(on_off_duration_array[0]);
         }
         else
         {
             VibrationHelper.Vibrate(on_off_duration_array);
         }
     }
 }
Пример #2
0
        public static async void OpenMessageDialog(string title, string message)
        {
            if (PlatformFunctions.IsDialogOpen)
            {
                return;
            }

            PlatformFunctions.IsDialogOpen = true;
            Engine.Pause();
#if ANDROID
            var builder = new Android.App.AlertDialog.Builder(NeonPartyGamesControllerGame.AndroidContext);
            var tcs     = new System.Threading.Tasks.TaskCompletionSource <bool>();

            builder.SetTitle(title);
            builder.SetMessage(message);
            builder.SetPositiveButton("OK", (sender_alert, sender_args) => {
                VibrationHelper.Vibrate();
            });
            builder.SetOnDismissListener(new OnDismissListener(() => tcs.TrySetResult(true)));
            builder.Show();
            await tcs.Task;
#elif IOS
            var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>();
            UIKit.UIAlertView alert = new UIKit.UIAlertView();
            alert.Title   = title;
            alert.Message = message;
            alert.AddButton("OK");
            alert.AlertViewStyle = UIKit.UIAlertViewStyle.Default;
            alert.Dismissed     += (object s, UIKit.UIButtonEventArgs ev) => {
                tcs.TrySetResult(true);
            };
            alert.Show();
            await tcs.Task;
#elif NETFX_CORE
            await Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async() =>
            {
                var dialog = new Windows.UI.Popups.MessageDialog(message, title);
                await dialog.ShowAsync();
            });
#endif
            Engine.Resume();
            PlatformFunctions.IsDialogOpen = false;
        }
Пример #3
0
        public static void Vibrate(int[] on_off_duration_array)
        {
            if (on_off_duration_array == null)
            {
                return;
            }
            _current_vibration_task_id++;
            uint my_vibration_task_id = _current_vibration_task_id;
            var  array = (int[])on_off_duration_array.Clone();

            Task.Run(() => {
                int index = 0;
                while (index < array.Length && _current_vibration_task_id == my_vibration_task_id)
                {
                    if (index % 2 == 0)
                    {
                        VibrationHelper.Vibrate(array[index]);
                    }
                    Thread.Sleep(array[index]);
                    index++;
                }
            });
        }
Пример #4
0
        public static async void OpenInputDialog(string title, Action <string> callback, int max_length = 0, object[] args = null)
        {
            if (PlatformFunctions.IsDialogOpen)
            {
                return;
            }

            PlatformFunctions.IsDialogOpen = true;
            string result = "";

            Engine.Pause();
#if ANDROID
            var builder = new Android.App.AlertDialog.Builder(NeonPartyGamesControllerGame.AndroidContext);
            var input   = new Android.Widget.EditText(NeonPartyGamesControllerGame.AndroidContext);
            var tcs     = new System.Threading.Tasks.TaskCompletionSource <bool>();

            builder.SetTitle(title);
            if (args != null && args.Length > 0)
            {
                input.InputType = (Android.Text.InputTypes)args[0];
            }
            else
            {
                input.InputType = Android.Text.InputTypes.ClassText;
            }
            if (max_length > 0)
            {
                input.SetFilters(new Android.Text.IInputFilter[] { new Android.Text.InputFilterLengthFilter(max_length) });
            }
            builder.SetView(input);
            builder.SetPositiveButton("OK", (sender_alert, sender_args) => {
                VibrationHelper.Vibrate();
                result = input.Text;
            });
            builder.SetOnDismissListener(new OnDismissListener(() => tcs.TrySetResult(true)));
            builder.Show();
            await tcs.Task;
#elif IOS
            var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>();
            UIKit.UIAlertView alert = new UIKit.UIAlertView();
            alert.Title = title;
            alert.AddButton("OK");
            alert.AlertViewStyle = UIKit.UIAlertViewStyle.PlainTextInput;
            alert.Clicked       += (object s, UIKit.UIButtonEventArgs ev) => {
                if (ev.ButtonIndex == 0)
                {
                    result = alert.GetTextField(0).Text;
                }
            };
            alert.Dismissed += (object s, UIKit.UIButtonEventArgs ev) => {
                tcs.TrySetResult(true);
            };
            alert.Show();
            await tcs.Task;
#elif NETFX_CORE
            await Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async() =>
            {
                var input_text_box = new Windows.UI.Xaml.Controls.TextBox
                {
                    AcceptsReturn = false,
                    Height        = 32
                };
                if (max_length > 0)
                {
                    input_text_box.MaxLength = max_length;
                }
                var dialog = new Windows.UI.Xaml.Controls.ContentDialog
                {
                    Content                  = input_text_box,
                    Title                    = title,
                    PrimaryButtonText        = "Ok",
                    IsSecondaryButtonEnabled = true,
                    SecondaryButtonText      = "Cancel",
                    DefaultButton            = Windows.UI.Xaml.Controls.ContentDialogButton.Primary
                };
                if (await dialog.ShowAsync() == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    result = input_text_box.Text;
                }
                else
                {
                    result = "";
                }
            });
#else
        #if DEBUG
            await System.Threading.Tasks.Task.Run(() => {
                var debugger = Engine.GetFirstInstanceByType <DebuggerWithTerminal>();
                debugger?.OpenConsoleWithCustomEvaluator(value => result = value);
                while (debugger != null && debugger.ConsoleOpen)
                {
                    System.Threading.Thread.Sleep(1);
                }
            });
        #endif
#endif
            Engine.Resume();
            PlatformFunctions.IsDialogOpen = false;

            if (!string.IsNullOrWhiteSpace(result))
            {
                callback?.Invoke(result);
            }
        }