예제 #1
0
        private void DrawTextfields(Screen screen, GameTime time)
        {
            //Draw field background
            int buttonW = (int)(_buttonWidth * 0.2f);
            Rectangle left = new Rectangle(_r[1, 0].X, _r[1, 0].Y, buttonW, _r[1, 0].Height);
            Rectangle center = new Rectangle(_r[1, 0].X + buttonW, _r[1, 0].Y, (_r[1, 0].Width * (_r.GetLength(1) + 1)) - (buttonW * 2), _r[1, 0].Height);
            Rectangle right = new Rectangle(_r[1, 0].X + center.Width + buttonW, _r[1, 0].Y, buttonW, _r[1, 0].Height);

            screen.AddSprite(true, _textureKeys[3], left, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[4], center, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[5], right, Vector2.Zero, 0, Color.White, 1, null, false);

            screen.AddText(_fontKey, _descriptionText, new Vector2(
                                                     _r[0, 0].X + buttonW,
                                                     (_r[0, 0].Y + (_textfield.Height / 2)) -
                                                     ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(_descriptionText).Y / 2),
                                                     Vector2.Zero, Vector2.One,
                                                     0, Color.White, 0);

            //this is the input string that is drawn
            //its the same as _inputText but with a few modifications
            string drawString = _inputText;
            //do the password thing
            if (_passwordMode)
            {
                int stars = drawString.Length - 0; if (stars < 0) stars = 0;
                string s = ""; for (int i = 0; i < stars; i++) s += "*";
            }
            //add the flashing indicator
            if (time.TotalGameTime.Milliseconds / 500 % 2 == 0) drawString += "|";
            //format the string so its not to long for the textfield
            while (((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).X > center.Width) drawString = drawString.Remove(0, 1);

            screen.AddText(_fontKey, drawString, new Vector2(
                                                     _r[1, 0].X + buttonW,
                                                     (_r[1, 0].Y + (_textfield.Height / 2)) -
                                                     ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).Y / 2),
                                                     Vector2.Zero, Vector2.One,
                                                     0, Color.White, 0);
        }
예제 #2
0
        public void Draw(Screen screen)
        {
            //Reset button state
            optionPressed = null;

            //Update every button and see if any is pressed
            for (int s = 0; s < optionsMenu.Count; s++)
            {
                Rectangle bound = optionsBound;
                Vector2 position = new Vector2((startPosition.X) - bound.Width / 2f, startPosition.Y + (s * (optionsBound.Height * spacing)));
                bound.X = (int)position.X;
                bound.Y = (int)position.Y;

                //Check what alignment we want on the button text
                float orginX;
                switch (align)
                {
                    case MenuAlign.Center:
                        orginX = ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(fontKey)).MeasureString(optionsMenu[s]).X / 2 - bound.Width / 2f;
                        break;
                    case MenuAlign.Right:
                        orginX = ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(fontKey)).MeasureString(optionsMenu[s]).X - bound.Width;
                        break;
                    default:
                        orginX = 0;
                        break;
                }

                //Add a draw of the button
                screen.AddText(fontKey, optionsMenu[s], position, new Vector2(orginX, 0), Vector2.One, 0, Color.White, 0);

                //check if any button was pressed
                if (Touch == null)
                    return;

                foreach (TouchLocation t in Touch)
                {
                    if (bound.Contains(t.Position))
                    {
                        optionPressed = optionsMenu[s];
                        break;
                    }
                    if (optionPressed != null)
                        break;
                }
            }
        }
예제 #3
0
        private void DrawButton(int x, int y, Screen screen)
        {
            int buttonW = (int)(_buttonWidth * 0.2f);
            Rectangle left = new Rectangle(
                _r[y,x].X,
                _r[y, x].Y,
                buttonW,
                _r[y, x].Height);

            Rectangle center = new Rectangle(
                _r[y, x].X + buttonW,
                _r[y, x].Y,
                _r[y, x].Width - (buttonW * 2),
                _r[y, x].Height);

            Rectangle right = new Rectangle(
                _r[y, x].X + _r[y, x].Width - buttonW,
                _r[y, x].Y,
                buttonW,
                _r[y, x].Height);

            screen.AddSprite(true, _textureKeys[0], left, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[1], center, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[2], right, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddText(_fontKey, _c[y, x], new Vector2(
                                              (_r[y, x].X + (_r[y, x].Width / 2)) -
                                              ((SpriteFont)
                                               screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).
                                                  MeasureString(_c[y, x]).X / 2,
                                              (_r[y, x].Y + (_r[y, x].Height / 2)) -
                                              ((SpriteFont)
                                               screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).
                                                  MeasureString(_c[y, x]).Y / 2),
                           Vector2.Zero, Vector2.One,
                           0, Color.White, 0);
        }