Ejemplo n.º 1
0
        public override void Draw(SpriteBatch sb)
        {
            Vector2 position = this.position;

            if (parent != null)
            {
                position += this.parent.position;
            }
            this.rectangle = new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y);
            Texture2D tex   = this.texture;
            Color     color = Color.White;

            if (new Rectangle(Main.mouseX, Main.mouseY, 1, 1).Intersects(this.rectangle))
            {
                Main.player[Main.myPlayer].mouseInterface = true;
                this.hover = true;
                if (this.texture != null && this.textureH != null)
                {
                    tex = this.textureH;
                }
                else
                {
                    color = Color.LightGray;
                }
                if (!flag)
                {
                    if (UIParameters.mouseState.LeftButton == ButtonState.Pressed && UIParameters.mouseRect.Intersects(new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y)))
                    {
                        if (this.texture != null && this.textureC != null)
                        {
                            tex = this.textureC;
                        }
                        else
                        {
                            color = new Color(167, 167, 167, 255);
                        }
                    }
                    if (UIParameters.LeftMouseClick(new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y)))
                    {
                        this.Function();
                    }
                }
                else
                {
                    if (UIParameters.mouseState.LeftButton != ButtonState.Pressed)
                    {
                        flag = false;
                    }
                }
            }
            else
            {
                flag = (UIParameters.mouseState.LeftButton == ButtonState.Pressed);
            }

            if (tex == null)
            {
                BaseTextureDrawing.DrawRectangleBox(sb, color, Color.Black, this.rectangle, 1);
            }
            else
            {
                sb.Draw(tex, this.rectangle, color);
            }
            base.Draw(sb);
        }
Ejemplo n.º 2
0
        public override void Draw(SpriteBatch sb)
        {
            Vector2 position = this.position;

            if (parent != null)
            {
                position += this.parent.position;
            }
            this.rectangle = new Rectangle((int)position.X, (int)position.Y, (int)this.size.X, (int)this.size.Y);
            if (UIParameters.LeftMouseClick(this.rectangle))
            {
                if (this.selected)
                {
                    this.selected   = false;
                    Main.blockInput = false;
                }
                else
                {
                    this.selected   = true;
                    Main.blockInput = true;
                }
            }
            if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.selected   = false;
                Main.blockInput = false;
            }
            if (this.selected)
            {
                Main.blockInput = true;
                Microsoft.Xna.Framework.Input.Keys[] oldPressed = UIParameters.oldState.GetPressedKeys();
                Microsoft.Xna.Framework.Input.Keys[] newPressed = UIParameters.newState.GetPressedKeys();
                bool shift    = false;
                bool capsLock = false;
                bool numLock  = false;
                if (this.text.Length > 0 && UIParameters.oldState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Back) && UIParameters.newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Back))
                {
                    if (UIParameters.backSpace == 0)
                    {
                        this.text = this.text.Remove(this.text.Length - 1);
                        UIParameters.backSpace = 9;
                    }
                    UIParameters.backSpace--;
                    goto End;
                }
                else
                {
                    UIParameters.backSpace = 0;
                }
                if ((UIParameters.oldState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift) && UIParameters.newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) || (UIParameters.oldState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift) && UIParameters.newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightShift)))
                {
                    shift = true;
                }
                if (Control.IsKeyLocked(System.Windows.Forms.Keys.CapsLock))
                {
                    capsLock = true;
                }
                if (Control.IsKeyLocked(System.Windows.Forms.Keys.NumLock))
                {
                    numLock = true;
                }
                for (int i = 0; i < newPressed.Length; i++)
                {
                    if (newPressed[i] == Microsoft.Xna.Framework.Input.Keys.Back)
                    {
                        goto Skip;
                    }
                    bool flag = true;
                    for (int k = 0; k < oldPressed.Length; k++)
                    {
                        if (newPressed[i] == oldPressed[k])
                        {
                            flag = false;
                        }
                    }
                    if (this.font.MeasureString(this.text).X >= this.size.X - 12)
                    {
                        flag = false;
                    }
                    if (flag)
                    {
                        this.text += UIParameters.TranslateChar(newPressed[i], shift, capsLock, numLock);
                    }
                    Skip :;
                }
                End :;
            }
            BaseTextureDrawing.DrawRectangleBox(sb, Color.DarkGray, Color.White, this.rectangle, 2);
            sb.DrawString(this.font, this.text + NeedsEnd(), position + new Vector2(2), Color.Black);
            base.Draw(sb);
        }