Esempio n. 1
0
        public void SetInstructions(Rectangle rect, string text, bool okButton)
        {
            m_Lines = Happiness.FormatLines(rect.Width - (m_iTextMarginLeftRight * 2), text, Assets.HelpFont);

            int buttonHeight = okButton ? m_iButtonHeight + m_iTextMarginTopBottom : 0;
            int autoHeight   = ((m_Lines.Length + 1) * m_iTextLineHeight) + buttonHeight;

            m_InstructionRect  = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height == 0 ? autoHeight : rect.Height);
            m_InstructionFrame = new UIFrame(1, m_InstructionRect);

            if (okButton)
            {
                m_OKButton = new UIButton(0, "OK", Assets.HelpFont, new Rectangle(m_InstructionRect.Left + (m_InstructionRect.Width >> 1) - (m_iButtonWidth >> 1), m_InstructionRect.Bottom - (m_iButtonHeight + m_iTextMarginTopBottom), m_iButtonWidth, m_iButtonHeight), Assets.ScrollBar);
            }
            else
            {
                m_OKButton = null;
            }
        }
Esempio n. 2
0
        public MessageBox(string message, MessageBoxButtons buttons, int context, int screenWidth, int screenHeight, string checkboxText = null)
        {
            m_iContext  = context;
            m_TextColor = Color.White;

            int iCheckboxSize = (int)(Constants.MessageBox_CheckboxSize * screenHeight);

            m_iMarginLeftRight = (int)(Constants.MessageBox_LeftRightMargin * screenWidth);
            m_iMarginTopBottom = (int)(Constants.MessageBox_TopBottomMargin * screenHeight);

            int checkboxHeight = checkboxText == null ? 0 : m_iMarginTopBottom + iCheckboxSize;

            int width = (int)(Constants.MessageBox_Width * screenWidth);

            m_Lines = Happiness.FormatLines(width - (m_iMarginLeftRight * 2), message, Assets.DialogFont);

            int buttonWidth  = (int)(Constants.MessageBox_ButtonWidth * screenWidth);
            int buttonHeight = (int)(Constants.MessageBox_ButtonHeight * screenHeight);

            int     lineSpace    = (int)(Constants.MessageBox_LineSpace * screenHeight);
            Vector2 testTextSize = Assets.DialogFont.MeasureString("TEST");

            m_iTextLineHeight = (int)testTextSize.Y + lineSpace;

            int buttonAreaHeight = buttons == MessageBoxButtons.None ? 0 : m_iMarginTopBottom + buttonHeight;
            int dialogHeight     = (m_iMarginTopBottom + m_iMarginTopBottom) + (m_iTextLineHeight * m_Lines.Length) + buttonAreaHeight + checkboxHeight;

            int halfScreenW = screenWidth >> 1;
            int halfScreenH = screenHeight >> 1;
            int halfDialogW = width >> 1;
            int halfDialogH = dialogHeight >> 1;

            m_iCenterDialogX = halfScreenW;

            m_Rect = new Rectangle(halfScreenW - halfDialogW, halfScreenH - halfDialogH, width, dialogHeight);

            int buttonY         = (m_Rect.Bottom - m_iMarginTopBottom) - buttonHeight;
            int halfButtonWidth = buttonWidth >> 1;

            switch (buttons)
            {
            case MessageBoxButtons.OK:
                m_Buttons    = new UIButton[1];
                m_Buttons[0] = new UIButton((int)MessageBoxResult.OK, "OK", Assets.HelpFont, new Rectangle(halfScreenW - halfButtonWidth, buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
                break;

            case MessageBoxButtons.YesNo:
                m_Buttons    = new UIButton[2];
                m_Buttons[0] = new UIButton((int)MessageBoxResult.Yes, "Yes", Assets.HelpFont, new Rectangle(halfScreenW - (halfButtonWidth + buttonWidth), buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
                m_Buttons[1] = new UIButton((int)MessageBoxResult.No, "No", Assets.HelpFont, new Rectangle(halfScreenW + halfButtonWidth, buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
                break;

            case MessageBoxButtons.BuyCoinsCancel:
                m_Buttons    = new UIButton[2];
                m_Buttons[0] = new UIButton((int)MessageBoxResult.BuyCoins, "Buy Coins", Assets.HelpFont, new Rectangle(halfScreenW - (halfButtonWidth + buttonWidth), buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
                m_Buttons[1] = new UIButton((int)MessageBoxResult.Cancel, "Cancel", Assets.HelpFont, new Rectangle(halfScreenW + halfButtonWidth, buttonY, buttonWidth, buttonHeight), Assets.ScrollBar);
                break;

            case MessageBoxButtons.None:
                break;
            }

            if (checkboxText != null)
            {
                m_CheckBox      = new UICheckbox(checkboxText, 0, buttonY - (m_iMarginTopBottom + iCheckboxSize), screenHeight);
                m_CheckBox.Left = m_iCenterDialogX - (m_CheckBox.Rect.Width >> 1);
            }
        }