Example #1
0
        public UnlockButton(Color unlockColor, Color affordableColor, Color lockColor, Image image, UnlockButtonPressed pressFunction, UnlockButtonPressed unlockFunction, UnlockButtonPressed overFunction)
        {
            this.Active = true;

            this.Position = new Vector2();
            this.status = WindowButtonState.Normal;

            Texture2D texture = OGE.Content.Load<Texture2D>(@"Graphics\Entities\WindowGraphics\UnlockButtons");
            normalImage = new Image(texture, new Rectangle(0, 0, texture.Width, texture.Height / 2));
            selectedImage = new Image(texture, new Rectangle(0, texture.Height / 2, texture.Width, texture.Height / 2));
            normalImage.CenterOrigin();
            selectedImage.CenterOrigin();

            this.unlockColor = unlockColor;
            this.affordableColor = affordableColor;
            this.lockColor = lockColor;

            this.frontImage = image;
            this.frontImage.CenterOrigin();

            this.pressFunctions = new List<UnlockButtonPressed>();
            this.pressFunctions.Add(pressFunction);

            this.lockFunctions = new List<UnlockButtonPressed>();
            this.lockFunctions.Add(unlockFunction);

            this.overFunctions = new List<UnlockButtonPressed>();
            this.overFunctions.Add(overFunction);

            collision = new Rectangle(-normalImage.OriginX, -normalImage.OriginY, normalImage.Width, normalImage.Height);
        }
Example #2
0
        // hepler function
        protected virtual void OnWindowButtonStateChange(WindowButtonState state, WindowButton button)
        {
            switch (state)
            {
            case WindowButtonState.Normal:
                button.Visibility = Visibility.Visible;
                button.IsEnabled  = true;
                break;

            case WindowButtonState.Disabled:
                button.Visibility = Visibility.Visible;
                button.IsEnabled  = false;
                break;

            case WindowButtonState.None:
                button.Visibility = Visibility.Collapsed;
                break;
            }
        }
Example #3
0
        public Button(Color color, string text, ButtonPressed pressedFunction)
        {
            this.Active = true;

            this.Position = new Vector2();
            this.status = WindowButtonState.Normal;

            Texture2D texture = OGE.Content.Load<Texture2D>(@"Graphics\Entities\WindowGraphics\Buttons");
            normalImage = new Image(texture, new Rectangle(0, 0, texture.Width, texture.Height / 2));
            overImage = new Image(texture, new Rectangle(0, texture.Height / 2, texture.Width, texture.Height / 2));
            normalImage.CenterOrigin();
            overImage.CenterOrigin();

            this.color = color;
            this.TintColor = color;
            this.text = new Text(text, FontSize.Medium);
            this.text.OriginX = this.text.Width / 2;
            this.text.OriginY = this.text.Height / 2;
            this.pressedFunction = new List<ButtonPressed>();
            this.pressedFunction.Add(pressedFunction);

            collision = new Rectangle(-normalImage.OriginX, -normalImage.OriginY, normalImage.Width, normalImage.Height);
        }
Example #4
0
        // hepler function
        protected virtual void OnWindowButtonStateChange(WindowButtonState state, WindowButton button)
        {
            switch (state)
            {
                case WindowButtonState.Normal:
                    button.Visibility = Visibility.Visible;
                    button.IsEnabled = true;
                    break;

                case WindowButtonState.Disabled:
                    button.Visibility = Visibility.Visible;
                    button.IsEnabled = false;
                    break;

                case WindowButtonState.None:
                    button.Visibility = Visibility.Collapsed;
                    break;
            }
        }
Example #5
0
        public void Update(GameTime gameTime)
        {
            if (!Active)
            {
                status = WindowButtonState.Normal;
                return;
            }

            Vector2 mouseVector = Input.GetMousePosition(OGE.HUDCamera);
            Point mousePoint = new Point((int)mouseVector.X, (int)mouseVector.Y);
            Rectangle test = new Rectangle((int)(Position.X + collision.X), (int)(Position.Y + collision.Y),
                collision.Width, collision.Height);

            if (test.Contains(mousePoint))
            {
                status = WindowButtonState.Over;
                if (Input.CheckLeftMouseButton() == GameButtonState.Pressed)
                {
                    foreach (ButtonPressed pressed in pressedFunction)
                    {
                        if (pressed != null)
                        {
                            pressed();
                        }
                    }
                }
            }
            else
            {
                status = WindowButtonState.Normal;
            }
        }
Example #6
0
        public void Update(GameTime gameTime)
        {
            if (!Active)
            {
                status = WindowButtonState.Normal;
                Selected = false;
                return;
            }

            Vector2 mouseVector = Input.GetMousePosition(OGE.HUDCamera);
            Point mousePoint = new Point((int)mouseVector.X, (int)mouseVector.Y);
            Rectangle test = new Rectangle((int)(Position.X + collision.X), (int)(Position.Y + collision.Y),
                collision.Width, collision.Height);

            if (test.Contains(mousePoint))
            {
                status = WindowButtonState.Over;
                foreach (UnlockButtonPressed pressed in overFunctions)
                {
                    if (pressed != null)
                    {
                        pressed(ButtonNumber, ButtonType);
                    }
                }

                if (Input.CheckLeftMouseButton() == GameButtonState.Pressed)
                {
                    if (!Locked)
                    {
                        foreach (UnlockButtonPressed pressed in pressFunctions)
                        {
                            if (pressed != null)
                            {
                                pressed(ButtonNumber, ButtonType);
                            }
                        }
                    }
                    else
                    {
                        foreach (UnlockButtonPressed pressed in lockFunctions)
                        {
                            if (pressed != null)
                            {
                                pressed(ButtonNumber, ButtonType);
                            }
                        }
                    }
                }
            }
            else
            {
                status = WindowButtonState.Normal;
            }

            if (Selected)
            {
                normalImage.Scale = 0.75f;
                selectedImage.Scale = 0.75f;
                frontImage.Scale = 0.75f;
            }
            else
            {
                normalImage.Scale = 1f;
                selectedImage.Scale = 1f;
                frontImage.Scale = 1f;
            }

            if (Locked)
            {
                if (!Affordable)
                {
                    normalImage.TintColor = lockColor;
                    selectedImage.TintColor = lockColor;
                    frontImage.TintColor = lockColor;
                }
                else
                {
                    normalImage.TintColor = affordableColor;
                    selectedImage.TintColor = affordableColor;
                    frontImage.TintColor = affordableColor;
                }
            }
            else
            {
                normalImage.TintColor = unlockColor;
                selectedImage.TintColor = unlockColor;
                frontImage.TintColor = unlockColor;
            }
        }