Esempio n. 1
0
        private void BindInput()
        {
            var txtUsername = gui.GetChild <TextBlock>("txtUsername");
            var btnRegister = gui.GetChild <Button>("btnRegister");
            var busyMessage = gui.GetChild <TextBlock>("busyMessage");

            if (busyMessage != null)
            {
                busyMessage.Enabled = false;
            }

            if (txtUsername != null)
            {
                defaultUsernameLabel   = txtUsername.Text;
                txtUsername.Triggered +=
                    (b) =>
                {
                    Guide.BeginShowKeyboardInput(PlayerIndex.One, "Username", "Please enter your desired username.", userName, KeyboardCallback, null);
                };
            }

            if (btnRegister != null)
            {
                btnRegister.Triggered +=
                    (b) =>
                {
                    if (!string.IsNullOrWhiteSpace(userName))
                    {
                        // Disable button while performing network operations
                        btnRegister.Enabled = false;
                        if (busyMessage != null)
                        {
                            busyMessage.Enabled = true;
                        }

                        API.CreatePlayer(userName,
                                         (p, e) =>
                        {
                            // Were there Connection issues?
                            if (e == null)
                            {
                                // Is the Username valid and the player has been created?
                                if (p.Ok)
                                {
                                    Manager.GetOrCreateScreen <MainMenuScreen>().Player = p.Player;
                                    Manager.TransitionTo <MainMenuScreen>();
                                }
                                else
                                {
                                    Guide.BeginShowMessageBox("Username Taken", "This username has already been taken, please choose another.", new string[] { "Ok" }, 0, MessageBoxIcon.Alert, null, null);
                                }
                            }
                            else
                            {
                                Guide.BeginShowMessageBox("Error", e.Message, new string[] { "Ok" }, 0, MessageBoxIcon.Error, null, null);
                            }
                            // Re-enable button now that network ops are complete
                            btnRegister.Enabled = true;
                            if (busyMessage != null)
                            {
                                busyMessage.Enabled = false;
                            }
                        });
                    }
                };
            }
        }