Esempio n. 1
0
        public static void Show(UpdateInfo updateInfo, out bool updateApplied)
        {
            SDL.SDL_MessageBoxButtonData[] buttons =
            {
                new SDL.SDL_MessageBoxButtonData()
                {
                    buttonid = 0,
                    flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
                    text     = "No",
                },
                new SDL.SDL_MessageBoxButtonData()
                {
                    buttonid = 1,
                    flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
                    text     = "Yes",
                },
            };

            SDL.SDL_MessageBoxData data = new SDL.SDL_MessageBoxData
            {
                flags   = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION,
                window  = IntPtr.Zero,
                title   = Program.name + " Update",
                message =
                    "New update available for " + Program.name + "\n\n" +
                    "Download and apply update " + Utility.GetVersionString(updateInfo.version) + "?",
                numbuttons  = buttons.Length,
                buttons     = buttons,
                colorScheme = null
            };

            int result = -1;

            SDL.SDL_ShowMessageBox(ref data, out result);

            if (result == 1)
            {
                string updateFile = Updater.DownloadUpdate(updateInfo);
                Updater.ApplyUpdate(updateFile, updateInfo);
                updateApplied = true;
            }
            else
            {
                updateApplied = false;
            }
        }
    public static NativeMessageBox.Result Show(string text, string caption, NativeMessageBox.Type messageBoxType, IntPtr sdlWindowHandle)
    {
        List <SDL.SDL_MessageBoxButtonData> buttons = new List <SDL.SDL_MessageBoxButtonData>();

        switch (messageBoxType)
        {
        case NativeMessageBox.Type.YesNo:
        {
            buttons.Add(NO_BUTTON);
            buttons.Add(YES_BUTTON);
            break;
        }

        case NativeMessageBox.Type.YesNoCancel:
        {
            buttons.Add(CANCEL_BUTTON);
            buttons.Add(NO_BUTTON);
            buttons.Add(YES_BUTTON);
            break;
        }

        default:
        {
            UnityEngine.Debug.LogError("Unabled message box type");
            break;
        }
        }

        SDL.SDL_MessageBoxData messageBoxData = new SDL.SDL_MessageBoxData();
        messageBoxData.window     = sdlWindowHandle;
        messageBoxData.title      = caption;
        messageBoxData.message    = text;
        messageBoxData.buttons    = buttons.ToArray();
        messageBoxData.numbuttons = buttons.Count;

        int buttonId;

        if (SDL.SDL_ShowMessageBox(ref messageBoxData, out buttonId) < 0)
        {
            UnityEngine.Debug.LogError("SDL Message box error- " + SDL2.SDL.SDL_GetError());
        }

        UnityEngine.Debug.Log("SDL message box button id = " + buttonId);

        return((NativeMessageBox.Result)buttonId);
    }
Esempio n. 3
0
 public static int ShowMessageBoxEx(MessageBoxFlags flags, string title, string message, string[] buttons, SDLWindow window = null, int btnEnter = -1, int btnEscape = -1)
 {
     SDL.SDL_MessageBoxData data = new SDL.SDL_MessageBoxData();
     data.title   = title;
     data.message = message;
     if (window != null)
     {
         data.window = window.GetPointer();
     }
     else
     {
         data.window = IntPtr.Zero;
     }
     data.numbuttons = buttons.Length;
     data.flags      = (SDL.SDL_MessageBoxFlags)flags;
     SDL.SDL_MessageBoxButtonData[] buttonStructs = new SDL.SDL_MessageBoxButtonData[buttons.Length];
     for (var i = 0; i < buttons.Length; i++)
     {
         buttonStructs[i].buttonid = i;
         buttonStructs[i].text     = buttons[i];
         if (i == btnEnter)
         {
             buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
         }
         else if (i == btnEscape)
         {
             buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
         }
     }
     data.buttons = buttonStructs;
     if (SDL.SDL_ShowMessageBox(ref data, out int btnClicked) != 0)
     {
         throw new SDLException();
     }
     return(btnClicked);
 }
Esempio n. 4
0
        static void ShowErrorDialog()
        {
            var viewLogs = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 2,
                text     = "View Logs",
                flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
            };

            var viewFaq = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 1,
                text     = "View FAQ"
            };

            var quit = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 0,
                text     = "Quit",
                flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
            };

            var dialog = new SDL.SDL_MessageBoxData
            {
                flags      = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
                title      = "Fatal Error",
                message    = displayName + " has encountered a fatal error and must close.\nRefer to the crash logs and FAQ for more information.",
                buttons    = new[] { quit, viewFaq, viewLogs },
                numbuttons = 3
            };

            // SDL_ShowMessageBox may create the error dialog behind other windows.
            // We want to bring it to the foreground, but can't do it from the main thread
            // because SDL_ShowMessageBox blocks until the user presses a button.
            // HACK: Spawn a thread to raise it to the foreground after a short delay.
            Task.Run(() =>
            {
                Thread.Sleep(1000);
                SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            });

            if (SDL.SDL_ShowMessageBox(ref dialog, out var buttonid) < 0)
            {
                Exit();
            }

            switch (buttonid)
            {
            case 0: Exit(); break;

            case 1:
            {
                try
                {
                    Process.Start(faqUrl);
                }
                catch { }
                break;
            }

            case 2:
            {
                try
                {
                    Process.Start(Path.Combine(Platform.SupportDir, "Logs"));
                }
                catch { }
                break;
            }
            }
        }
Esempio n. 5
0
        public static bool ShowMessageBox(Cv_MessageBoxParams mBoxParams, out Cv_ButtonType result)
        {
            var colorScheme = new SDL.SDL_MessageBoxColorScheme();

            var sdlBgColor = new SDL.SDL_MessageBoxColor();

            sdlBgColor.r = mBoxParams.bgColor.R;
            sdlBgColor.g = mBoxParams.bgColor.G;
            sdlBgColor.b = mBoxParams.bgColor.B;

            var sdlTextColor = new SDL.SDL_MessageBoxColor();

            sdlTextColor.r = mBoxParams.textColor.R;
            sdlTextColor.g = mBoxParams.textColor.G;
            sdlTextColor.b = mBoxParams.textColor.B;

            var sdlBorderColor = new SDL.SDL_MessageBoxColor();

            sdlBorderColor.r = mBoxParams.btBorderColor.R;
            sdlBorderColor.g = mBoxParams.btBorderColor.G;
            sdlBorderColor.b = mBoxParams.btBorderColor.B;

            var sdlBtBgColor = new SDL.SDL_MessageBoxColor();

            sdlBtBgColor.r = mBoxParams.btBgColor.R;
            sdlBtBgColor.g = mBoxParams.btBgColor.G;
            sdlBtBgColor.b = mBoxParams.btBgColor.B;

            var sdlBtSelectedColor = new SDL.SDL_MessageBoxColor();

            sdlBtSelectedColor.r = mBoxParams.btSelectedColor.R;
            sdlBtSelectedColor.g = mBoxParams.btSelectedColor.G;
            sdlBtSelectedColor.b = mBoxParams.btSelectedColor.B;

            colorScheme.colors = new SDL.SDL_MessageBoxColor[] {
                sdlBgColor, sdlTextColor, sdlBorderColor, sdlBtBgColor, sdlBtSelectedColor
            };

            SDL.SDL_MessageBoxFlags flags;

            switch (mBoxParams.messageType)
            {
            case Cv_MessageType.CV_MESSAGE_ERROR:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR;
                break;

            case Cv_MessageType.CV_MESSAGE_WARNING:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_WARNING;
                break;

            default:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION;
                break;
            }

            var btArray = new SDL.SDL_MessageBoxButtonData[mBoxParams.buttons.Length];

            for (var i = 0; i < mBoxParams.buttons.Length; i++)
            {
                btArray[i] = new SDL.SDL_MessageBoxButtonData();
                if (mBoxParams.buttons[i] == mBoxParams.defaultButton)
                {
                    btArray[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
                }
                else
                {
                    btArray[i].flags = 0;
                }

                btArray[i].text     = GetButtonText(mBoxParams.buttons[i]);
                btArray[i].buttonid = (int)mBoxParams.buttons[i];
            }

            var messageBoxData = new SDL.SDL_MessageBoxData();

            messageBoxData.flags       = flags;
            messageBoxData.window      = IntPtr.Zero;
            messageBoxData.title       = mBoxParams.title;
            messageBoxData.message     = mBoxParams.message;
            messageBoxData.numbuttons  = mBoxParams.buttons.Length;
            messageBoxData.buttons     = btArray;
            messageBoxData.colorScheme = colorScheme;

            // show the dialog box
            int sdlResult;

            if (SDL.SDL_ShowMessageBox(ref messageBoxData, out sdlResult) < 0)
            {
                result = Cv_ButtonType.CV_BUTTON_ABORT;
                return(false);
            }

            result = (Cv_ButtonType)sdlResult;
            return(true);
        }