コード例 #1
0
        public override void Initialize(Game game)
        {
            Root.ReturnedMessageBoxResult = MessageBoxResult.Awaiting;


            // Total width and height and X and Y
            Rectangle bounds = Primitives.GetMultiLineTextBounds(Text, new Rectangle(0, 0, 700, 400), Skin.Font);

            Height   = bounds.Height + 106;
            Width    = bounds.Width + 65;
            TopLeftX = Root.ScreenWidth / 2 - Width / 2;
            TopLeftY = Root.ScreenHeight / 2 - Height / 2;

            // Arranging buttons
            int  numbuttons     = 0;
            bool doOKButton     = false;
            bool doYesButton    = false;
            bool doNoButton     = false;
            bool doCancelButton = false;

            if (ButtonsType == MessageBoxButtons.OK)
            {
                numbuttons = 1; doOKButton = true;
            }
            if (ButtonsType == MessageBoxButtons.OKCancel)
            {
                numbuttons = 2; doOKButton = true; doCancelButton = true;
            }
            if (ButtonsType == MessageBoxButtons.YesNo)
            {
                numbuttons = 2; doYesButton = true; doNoButton = true;
            }
            if (ButtonsType == MessageBoxButtons.YesNoCancel)
            {
                numbuttons = 3; doYesButton = true; doNoButton = true; doCancelButton = true;
            }
            int buttonwidth = 140;
            int buttonspace = 20;

            if (Width < numbuttons * (buttonwidth + buttonspace) + 100)
            {
                Width = numbuttons * (buttonwidth + buttonspace) + 100;
            }
            int buttonheight = 40;
            int buttony      = TopLeftY + Height - 10 - buttonheight;
            int x            = TopLeftX + Width / 2 - (int)(((buttonwidth + buttonspace) * (numbuttons)) - buttonspace) / 2;

            if (doOKButton)
            {
                Button b = new Button("OK", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += new Action <Button>(button_Click);
                Buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doYesButton)
            {
                Button b = new Button("Yes", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += new Action <Button>(button_Click);
                Buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doNoButton)
            {
                Button b = new Button("No", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += new Action <Button>(button_Click);
                Buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doCancelButton)
            {
                Button b = new Button("Cancel", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += new Action <Button>(button_Click);
                Buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            base.Initialize(game);
        }
コード例 #2
0
        /// <summary>
        /// Initializes the MessageBoxPhase. Sets its bounds and creates its buttons.
        /// </summary>
        protected internal override void Initialize(Game game)
        {
            Root.ReturnedMessageBoxResult = MessageBoxResult.Awaiting;

            // Total width and height and X and Y
            Rectangle bounds = Primitives.GetMultiLineTextBounds(Text, new Rectangle(0, 0, 700, 400), FontFamily.Normal);

            Height   = 500;
            Width    = 1000;
            TopLeftX = Root.ScreenWidth / 2 - Width / 2;
            TopLeftY = Root.ScreenHeight / 2 - Height / 2;

            // Arranging buttons
            int       numbuttons     = 0;
            bool      doOKButton     = false;
            bool      doYesButton    = false;
            bool      doNoButton     = false;
            bool      doCancelButton = false;
            const int buttonheight   = 40;
            int       buttony        = TopLeftY + Height - 10 - buttonheight;

            if (ButtonsType == MessageBoxButtons.OK)
            {
                numbuttons = 1; doOKButton = true;
            }
            if (ButtonsType == MessageBoxButtons.OKCancel)
            {
                numbuttons = 2; doOKButton = true; doCancelButton = true;
            }

            if (ButtonsType == MessageBoxButtons.InputOKCancel)
            {
                numbuttons = 2; doOKButton = true; doCancelButton = true;
                textbox    = new Textbox("", new Rectangle(TopLeftX + 10, buttony - 50, Width - 20, 40));
            }
            if (ButtonsType == MessageBoxButtons.YesNo)
            {
                numbuttons = 2; doYesButton = true; doNoButton = true;
            }
            if (ButtonsType == MessageBoxButtons.YesNoCancel)
            {
                numbuttons = 3; doYesButton = true; doNoButton = true; doCancelButton = true;
            }
            const int buttonwidth = 140;
            const int buttonspace = 20;

            if (Width < numbuttons * (buttonwidth + buttonspace) + 100)
            {
                Width = numbuttons * (buttonwidth + buttonspace) + 100;
            }
            int x = TopLeftX + Width / 2 - (((buttonwidth + buttonspace) * (numbuttons)) - buttonspace) / 2;

            if (doOKButton)
            {
                Button b = new Button("OK", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += button_Click;
                buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doYesButton)
            {
                Button b = new Button("Yes", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += button_Click;
                buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doNoButton)
            {
                Button b = new Button("No", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += button_Click;
                buttons.Add(b);
                x += buttonwidth + buttonspace;
            }
            if (doCancelButton)
            {
                Button b = new Button("Cancel", new Rectangle(x, buttony, buttonwidth, buttonheight));
                b.Click += button_Click;
                buttons.Add(b);
            }
            base.Initialize(game);
        }