Exemplo n.º 1
0
        /// <summary>Called when 'ok' is pressed in a blocking dialogue.</summary>
        public static void Ok(UIEvent e)
        {
            // Get the window:
            Window window = e.htmlDocument.window;

            // Get the dialogue:
            BlockingDialogue bd = window.BlockingDialogue;

            window.BlockingDialogue = null;

            if (bd == null)
            {
                return;
            }

            // Restore it with a true or content from 'input zone':
            HtmlElement inputZone = null;

            if (bd.Type == "prompt")
            {
                inputZone = window.document.getElementById("spark-prompt-input-zone") as HtmlElement;
            }

            if (inputZone != null)
            {
                bd.Resume(inputZone.value);
            }
            else
            {
                bd.Resume(true);
            }
        }
Exemplo n.º 2
0
        /// <summary>Asks the user to confirm something.</summary>
        public bool confirm(object request)
        {
            // Open the dialogue:
            BlockingDialogue dialogue = BlockingDialogues.Open("confirm", this, request);

            if (dialogue == null)
            {
                // It failed to open.
                // E.g. because 'prevent this page from opening other dialogues' was ticked.
                return(false);
            }

            // Return the response received from the user:
            return(dialogue.OkResponse);
        }
Exemplo n.º 3
0
        /// <summary>Called when 'cancel' is pressed in a blocking dialogue.</summary>
        public static void Cancel(UIEvent e)
        {
            // Get the window:
            Window window = e.htmlDocument.window;

            // Get the dialogue:
            BlockingDialogue bd = window.BlockingDialogue;

            window.BlockingDialogue = null;

            if (bd == null)
            {
                return;
            }

            // Restore it with a false:
            bd.Resume(false);
        }
Exemplo n.º 4
0
        /// <summary>Asks the user for some textual information.</summary>
        public string prompt(object request)
        {
            // Open the dialogue:
            BlockingDialogue dialogue = BlockingDialogues.Open("prompt", this, request);

            if (dialogue == null)
            {
                // It failed to open.
                // E.g. because 'prevent this page from opening other dialogues' was ticked.
                return("");
            }

            // Return the response received from the user:
            if (dialogue.Response is string)
            {
                return((string)dialogue.Response);
            }

            // Empty string otherwise
            return("");
        }
Exemplo n.º 5
0
        /// <summary>Opens a blocking dialogue in the given window.</summary>
        public static BlockingDialogue Open(string type, Window window, object message)
        {
            // Get the thread:
            System.Threading.Thread thread = System.Threading.Thread.CurrentThread;

            // Safety check: We can only block the 'blockable' thread.
            // This prevents it from blocking the Unity main thread.
            if (thread != window.BlockableThread)
            {
                UnityEngine.Debug.LogWarning("Failed to open a '" + type + "' dialogue because it was on a thread other than the window's main Javascript thread (and we don't want to block it).");
                return(null);
            }

            if (window.BlockingDialogue != null)
            {
                // Hmm, one is already open - we shouldn't open another.
                UnityEngine.Debug.LogWarning("Unexpected '" + type + "' dialogue request. One is already open.");
                return(null);
            }

            // Create the dialogue:
            BlockingDialogue bd = new BlockingDialogue(type, window);

            // Pop now:
            string text;

            Templates.TryGetValue(bd.Type, out text);

            if (string.IsNullOrEmpty(text))
            {
                // UI unavailable.
                return(null);
            }

            if (window.document.html == null)
            {
                Dom.Log.Add("Can't prompt without a html node.");
                return(null);
            }

            // Append it:
            HtmlElement background = window.document.createElement("div") as HtmlElement;

            background.id        = "spark-prompt-background";
            background.innerHTML = "<div id='spark-prompt'>" + text + "</div>";
            window.document.html.appendChild(background);

            // Get the message zone:
            HtmlElement content = background.getElementById("spark-prompt-content-zone") as HtmlElement;

            if (content != null && message != null)
            {
                // Write the message:
                content.innerHTML = message.ToString();
            }

            // Add the element:
            bd.Element = background;

            // Add to the window:
            window.BlockingDialogue = bd;

            // Cache the thread:
            bd.Thread = thread;

            try{
                // Going down! Sleep now:
                System.Threading.Thread.Sleep(Timeout.Infinite);
            }catch (System.Threading.ThreadInterruptedException) {
                // Back up again!
            }

            return(bd);
        }