Ejemplo n.º 1
0
        public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onAbort, Action<string> onRetry)
        {
            var panel = widget;
            var abortButton = panel.Get<ButtonWidget>("ABORT_BUTTON");
            var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");

            abortButton.Visible = onAbort != null;
            abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };

            retryButton.Visible = onRetry != null;
            retryButton.OnClick = () =>
            {
                var password = passwordField != null && passwordField.IsVisible() ? passwordField.Text : orderManager.Password;

                Ui.CloseWindow();
                onRetry(password);
            };

            widget.Get<LabelWidget>("CONNECTING_DESC").GetText = () =>
                "Could not connect to {0}:{1}".F(orderManager.Host, orderManager.Port);

            var connectionError = widget.Get<LabelWidget>("CONNECTION_ERROR");
            connectionError.GetText = () => orderManager.ServerError;

            passwordField = panel.GetOrNull<PasswordFieldWidget>("PASSWORD");
            if (passwordField != null)
            {
                passwordField.Text = orderManager.Password;
                passwordField.IsVisible = () => orderManager.AuthenticationFailed;
                var passwordLabel = widget.Get<LabelWidget>("PASSWORD_LABEL");
                passwordLabel.IsVisible = passwordField.IsVisible;
                passwordField.OnEnterKey = () => { retryButton.OnClick(); return true; };
                passwordField.OnEscKey = () => { abortButton.OnClick(); return true; };
            }

            passwordOffsetAdjusted = false;
            var connectionFailedTicker = panel.GetOrNull<LogicTickerWidget>("CONNECTION_FAILED_TICKER");
            if (connectionFailedTicker != null)
            {
                connectionFailedTicker.OnTick = () =>
                {
                    // Adjust the dialog once the AuthenticationError is parsed.
                    if (passwordField.IsVisible() && !passwordOffsetAdjusted)
                    {
                        var offset = passwordField.Bounds.Y - connectionError.Bounds.Y;
                        abortButton.Bounds.Y += offset;
                        retryButton.Bounds.Y += offset;
                        panel.Bounds.Height += offset;
                        panel.Bounds.Y -= offset / 2;

                        var background = panel.GetOrNull("CONNECTION_BACKGROUND");
                        if (background != null)
                            background.Bounds.Height += offset;

                        passwordOffsetAdjusted = true;
                    }
                };
            }
        }
Ejemplo n.º 2
0
        public ConnectionFailedLogic(Widget widget, OrderManager orderManager, Action onAbort, Action <string> onRetry)
        {
            var panel       = widget;
            var abortButton = panel.Get <ButtonWidget>("ABORT_BUTTON");
            var retryButton = panel.Get <ButtonWidget>("RETRY_BUTTON");

            abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };
            retryButton.OnClick = () =>
            {
                var password = passwordField != null && passwordField.IsVisible() ? passwordField.Text : orderManager.Password;

                Ui.CloseWindow();
                onRetry(password);
            };

            widget.Get <LabelWidget>("CONNECTING_DESC").GetText = () =>
                                                                  "Could not connect to {0}:{1}".F(orderManager.Host, orderManager.Port);

            var connectionError = widget.Get <LabelWidget>("CONNECTION_ERROR");

            connectionError.GetText = () => orderManager.ServerError;

            passwordField = panel.GetOrNull <PasswordFieldWidget>("PASSWORD");
            if (passwordField != null)
            {
                passwordField.Text      = orderManager.Password;
                passwordField.IsVisible = () => orderManager.AuthenticationFailed;
                var passwordLabel = widget.Get <LabelWidget>("PASSWORD_LABEL");
                passwordLabel.IsVisible = passwordField.IsVisible;
            }

            passwordOffsetAdjusted = false;
            var connectionFailedTicker = panel.GetOrNull <LogicTickerWidget>("CONNECTION_FAILED_TICKER");

            if (connectionFailedTicker != null)
            {
                connectionFailedTicker.OnTick = () =>
                {
                    // Adjust the dialog once the AuthenticationError is parsed.
                    if (passwordField.IsVisible() && !passwordOffsetAdjusted)
                    {
                        var offset = passwordField.Bounds.Y - connectionError.Bounds.Y;
                        abortButton.Bounds.Y += offset;
                        retryButton.Bounds.Y += offset;
                        panel.Bounds.Height  += offset;
                        panel.Bounds.Y       -= offset / 2;

                        var background = panel.GetOrNull("CONNECTION_BACKGROUND");
                        if (background != null)
                        {
                            background.Bounds.Height += offset;
                        }

                        passwordOffsetAdjusted = true;
                    }
                };
            }
        }
Ejemplo n.º 3
0
        public ConnectionFailedLogic(Widget widget, OrderManager orderManager, NetworkConnection connection, string password, Action onAbort, Action <string> onRetry)
        {
            var panel       = widget;
            var abortButton = panel.Get <ButtonWidget>("ABORT_BUTTON");
            var retryButton = panel.Get <ButtonWidget>("RETRY_BUTTON");

            abortButton.Visible = onAbort != null;
            abortButton.OnClick = () => { Ui.CloseWindow(); onAbort(); };

            retryButton.Visible = onRetry != null;
            retryButton.OnClick = () =>
            {
                var pass = passwordField != null && passwordField.IsVisible() ? passwordField.Text : password;

                Ui.CloseWindow();
                onRetry(pass);
            };

            widget.Get <LabelWidget>("CONNECTING_DESC").GetText = () => $"Could not connect to {connection.Target}";

            var connectionError = widget.Get <LabelWidget>("CONNECTION_ERROR");

            connectionError.GetText = () => Ui.Translate(orderManager.ServerError) ?? connection.ErrorMessage ?? "Unknown error";

            var panelTitle = widget.Get <LabelWidget>("TITLE");

            panelTitle.GetText = () => orderManager.AuthenticationFailed ? "Password Required" : "Connection Failed";

            passwordField = panel.GetOrNull <PasswordFieldWidget>("PASSWORD");
            if (passwordField != null)
            {
                passwordField.TakeKeyboardFocus();
                passwordField.IsVisible = () => orderManager.AuthenticationFailed;
                var passwordLabel = widget.Get <LabelWidget>("PASSWORD_LABEL");
                passwordLabel.IsVisible  = passwordField.IsVisible;
                passwordField.OnEnterKey = _ => { retryButton.OnClick(); return(true); };
                passwordField.OnEscKey   = _ => { abortButton.OnClick(); return(true); };
            }

            passwordOffsetAdjusted = false;
            var connectionFailedTicker = panel.GetOrNull <LogicTickerWidget>("CONNECTION_FAILED_TICKER");

            if (connectionFailedTicker != null)
            {
                connectionFailedTicker.OnTick = () =>
                {
                    // Adjust the dialog once the AuthenticationError is parsed.
                    if (passwordField.IsVisible() && !passwordOffsetAdjusted)
                    {
                        var offset = passwordField.Bounds.Y - connectionError.Bounds.Y;
                        abortButton.Bounds.Y += offset;
                        retryButton.Bounds.Y += offset;
                        panel.Bounds.Height  += offset;
                        panel.Bounds.Y       -= offset / 2;

                        var background = panel.GetOrNull("CONNECTION_BACKGROUND");
                        if (background != null)
                        {
                            background.Bounds.Height += offset;
                        }

                        passwordOffsetAdjusted = true;
                    }
                };
            }
        }