root/Code/oMaE/oMaE/Widgets/RadioButton.cs @ 9

Revision 9, 2.2 KB (checked in by acarter, 2 years ago)

Refactored some of the Match minigame

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Microsoft.Xna.Framework;
6using Microsoft.Xna.Framework.Audio;
7using Microsoft.Xna.Framework.Content;
8using Microsoft.Xna.Framework.GamerServices;
9using Microsoft.Xna.Framework.Graphics;
10using Microsoft.Xna.Framework.Input;
11using Microsoft.Xna.Framework.Media;
12
13namespace oMaE.Widgets
14{
15    class RadioButton : GameObject
16    {
17        private RadioGroup Parent;
18        private Rectangle Location;
19        private String text;
20
21        public Vector2 Center { get { return new Vector2(Location.Center.X, Location.Center.Y); } }
22
23        public static Texture2D UnclickedImg, ClickedImg, Pixel;
24       
25        public RadioButton(Rectangle Location, String text, TextLocation textLocation, RadioGroup Parent)
26        {
27            this.Location = Location;
28            this.text = text;
29            this.Parent = Parent;
30        }
31        public override bool LoadContent(ContentManager Content)
32        {
33            UnclickedImg = Content.Load<Texture2D>("Interface/RadioButton_Unclicked");
34            ClickedImg = Content.Load<Texture2D>("Interface/RadioButton_Clicked");
35            return base.LoadContent(Content);
36        }
37        public void clear()
38        {
39            Updated |= Active;
40            Active = false;
41        }
42        public override void Update(GameState gamestate)
43        {
44            if (gamestate.CurrentMouseState.LeftButton == ButtonState.Pressed
45                    && gamestate.LastMouseState.LeftButton == ButtonState.Released
46                    && Location.Contains(gamestate.CurrentMouseState.X, gamestate.CurrentMouseState.Y))
47            {
48                Active = !Active;
49                Updated = true;
50                Parent.UpdateComponent(this);
51            }
52            else
53                Updated = false;
54            base.Update(gamestate);
55        }
56        public override void Draw(SpriteBatch spritebatch, GameState gamestate)
57        {
58            spritebatch.Begin();
59            spritebatch.Draw(Active ? ClickedImg : UnclickedImg, Location, Color.White);
60            spritebatch.End();
61        }
62    }
63}
Note: See TracBrowser for help on using the browser.