Пример #1
0
        public void PushMessageBox(string message, MessageBox.ButtonFlags buttons, float opacity, Action<int> action)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            var buttonTexts = new TextRenderer.IFormattedText[MessageBox.NumButtons];
            for (int i = 0; i < MessageBox.NumButtons; ++i)
            {
                buttonTexts[i] = ((uint)buttons & (1U << i)) != 0 ? m_buttonTexts[i] : null;
            }
            var messageBox = new MessageBox(m_buttonFace, buttonTexts)
            {
                Text = GameApp.Service<TextRenderer>().FormatText(message, new Graphics.TextRenderer.FormatOptions(m_msgFont))
            };
            messageBox.ButtonClicked += button =>
            {
                if (action != null)
                {
                    action(button);
                }
                System.Diagnostics.Debug.Assert(m_dialogStack.Peek().Content == messageBox);
                PopTopDialog();
            };

            var modalDialog = new UI.ModalDialog
            {
                Opacity = opacity
            };
            modalDialog.Begin(GameApp.Service<UIManager>().Root.Listeners.Last(l => l is UI.EventDispatcher) as UI.EventDispatcher, messageBox);
            m_dialogStack.Push(modalDialog);
        }
Пример #2
0
        public NumberSelector(TextRenderer.IFormattedText[] digits, TextRenderer.IFormattedText[] signs, Graphics.TexturedQuad upButtonFace, Graphics.TexturedQuad downButtonFace,
            Graphics.TexturedQuad okCancelButtonFace, TextRenderer.IFormattedText[] okCancelTexts)
        {
            if (digits == null)
            {
                throw new ArgumentNullException("digits");
            }
            else if (digits.Length != 10 || digits.Contains(null))
            {
                throw new ArgumentException("Digits array is not provided appropriately.");
            }
            else if (signs == null)
            {
                throw new ArgumentNullException("signs");
            }
            else if (signs.Length != 2 || signs.Contains(null))
            {
                throw new ArgumentException("Signs array is not provided appropriately.");
            }
            else if (upButtonFace == null)
            {
                throw new ArgumentNullException("upButtonFace");
            }
            else if (downButtonFace == null)
            {
                throw new ArgumentNullException("downButtonFace");
            }
            else if (okCancelTexts == null)
            {
                throw new ArgumentNullException("okCancelTexts");
            }
            else if (okCancelTexts.Length != NumButtons || okCancelTexts.Contains(null))
            {
                throw new ArgumentException("OkCancelTexts array is not provided appropriately.");
            }

            m_digits = digits;
            m_signs = signs;
            m_upButtonFace = upButtonFace;
            m_downButtonFace = downButtonFace;

            var buttonTexts = new TextRenderer.IFormattedText[CommonButtons.NumButtons];
            buttonTexts[CommonButtons.ButtonOK] = okCancelTexts[ButtonOK];
            buttonTexts[CommonButtons.ButtonCancel] = okCancelTexts[ButtonCancel];
            m_commonButtons = new CommonButtons(okCancelButtonFace, buttonTexts);
            m_commonButtons.Dispatcher = this;
            m_commonButtons.ButtonClicked += btn =>
            {
                if (ButtonClicked != null)
                {
                    ButtonClicked(btn, CurrentValue);
                }
            };
            m_renderableProxy = new RenderableProxy(this);

            SetRange(0, 1);
        }