Ejemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="game">The currently running Game object.</param>
        /// <param name="guiManager">GUIManager that this control is part of.</param>
        /// <param name="message">Message to display.</param>
        /// <param name="title">Window title.</param>
        /// <param name="buttons">Tyoe of buttons to display.</param>
        /// <param name="type">Type of icon to use.</param>
        public MessageBox(
            Game game,
            GUIManager guiManager,
            string message,
            string title,
            MessageBoxButtons buttons,
            MessageBoxType type
            )
            : base(game, guiManager)
        {
            this.buttonList = new List <TextButton>();

            #region Create Child Controls
            this.icon    = new Icon(game, guiManager);
            this.message = new Label(game, guiManager);
            #endregion

            this.buttons = buttons;

            if (this.buttons == MessageBoxButtons.OK || this.buttons == MessageBoxButtons.Yes_No)
            {
                HasCloseButton = false;
            }

            this.infoSkin     = defaultInfoSkin;
            this.errorSkin    = defaultErrorSkin;
            this.warningSkin  = defaultWarningSkin;
            this.questionSkin = defaultQuestionSkin;

            this.type = type;

            Add(this.message);
            this.TitleText    = title;
            this.message.Text = message;

            int numButtons = 0;

            if (this.buttons == MessageBoxButtons.OK)
            {
                numButtons = 1;
            }
            else if (this.buttons == MessageBoxButtons.OK_Cancel || this.buttons == MessageBoxButtons.Yes_No)
            {
                numButtons = 2;
            }
            else if (this.buttons == MessageBoxButtons.Yes_No_Cancel)
            {
                numButtons = 3;
            }

            for (int i = 0; i < numButtons; i++)
            {
                TextButton newButton = new TextButton(game, guiManager);
                this.buttonList.Add(newButton);
                Add(newButton);

                if (i == 0)
                {
                    if (this.buttons == MessageBoxButtons.OK || this.buttons == MessageBoxButtons.OK_Cancel)
                    {
                        newButton.Text = "OK";
                    }
                    else
                    {
                        newButton.Text = "Yes";
                    }
                }
                else if (i == 1)
                {
                    if (this.buttons == MessageBoxButtons.OK_Cancel)
                    {
                        newButton.Text = "Cancel";
                    }
                    else
                    {
                        newButton.Text = "No";
                    }
                }
                else
                {
                    newButton.Text = "Cancel";
                }

                newButton.Click += new ClickHandler(OnClick);
            }

            ArrangeWindow(type);
        }