示例#1
0
        /// <summary>Called by Lua when it is requesting a login popup to be shown.</summary>
        /// <param name="sender">The CoronaRuntimeEnvironment that dispatched this event.</param>
        /// <param name="e">Provides the Lua vent table's fields/properties.</param>
        /// <returns>Returns a boxed object to Lua.</returns>
        private CoronaLabs.Corona.WinRT.ICoronaBoxedData OnRequestingLogin(
            CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender,
            CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e)
        {
            // Fetch the "event.loginName" property, if provided.
            string username      = string.Empty;
            var    boxedUsername = e.Properties.Get("username") as CoronaLabs.Corona.WinRT.CoronaBoxedString;

            if (boxedUsername != null)
            {
                username = boxedUsername.ToString();
            }

            // Display your login popup here using the "loginName" fetched up above.
            var inputForm = new InputForm();

            inputForm.Username            = username;
            inputForm.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            inputForm.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
            inputForm.Submitted          += OnFormInputSubmitted;
            inputForm.Canceled           += OnFormInputCanceled;
            fCoronaPanel.Children.Add(inputForm);

            // This returns nil to Lua.
            return(null);
        }
示例#2
0
        /// <summary>Dispatches InputForm data received by after a "Submitted" or "Canceled" event.</summary>
        /// <param name="inputForm">Reference to the input form.</param>
        /// <param name="wasSubmitted">Set true if the OK button was clicked. Set false if canceled.</param>
        private void HandleFormInput(InputForm inputForm, bool wasSubmitted)
        {
            // Validate argument.
            if (inputForm == null)
            {
                return;
            }

            // Close the input form and remove our event handlers from it.
            // This will remove all references to this form, allowing it to be garbage collected.
            fCoronaPanel.Children.Remove(inputForm);
            inputForm.Submitted -= OnFormInputSubmitted;
            inputForm.Canceled  -= OnFormInputCanceled;

            // Dispatch an event to Corona about the received input form data.
            if (fCoronaRuntimeEnvironment != null)
            {
                // Create a custom Corona event named "userLoggedIn" with the following properties.
                // This will be converted into a Lua "event" table once dispatched by Corona.
                var eventProperties = CoronaLabs.Corona.WinRT.CoronaLuaEventProperties.CreateWithName("onLoginInfo");
                eventProperties.Set("submitted", wasSubmitted);
                if (wasSubmitted)
                {
                    eventProperties.Set("username", inputForm.Username);
                    eventProperties.Set("password", inputForm.Password);
                }

                // Dispatch the event to Lua.
                var eventArgs = new CoronaLabs.Corona.WinRT.CoronaLuaEventArgs(eventProperties);
                fCoronaRuntimeEnvironment.DispatchEvent(eventArgs);
            }
        }