Пример #1
0
        public Window(XmlNode windowXml, GUI_Base parent, object owner)
            : base(windowXml, parent, owner)
        {
            images          = new string[5];
            imageDrawSpaces = new Rectangle[5];

            XmlNode imageNode = windowXml["Images"];

            if (imageNode != null)
            {
                for (int i = 0; i < c_ImageNodes.Length; i++)
                {
                    XmlNode currentImage = imageNode[c_ImageNodes[i]];
                    if (currentImage != null)
                    {
                        images[i] = LoadTextureFromXML(currentImage);
                        CreateDrawSpace((ImageNames)i);
                    }
                    else
                    {
                        images[i]          = string.Empty;
                        imageDrawSpaces[i] = new Rectangle(0, 0, 0, 0);
                    }
                }
            }
        }
        public static void ClearSelected(GUI_Base root)
        {
            int i = 0;

            XNA_GUI.GUIElements.GUI_Base slider = null;
            string test = string.Format(c_sliderName, i);

            if (test == null)
            {
                return;
            }
            while ((slider = root.GetChildByName(string.Format(c_sliderName, i))) != null)
            {
                root.RemoveChild(slider);
                GUI_Base cancelButton = root.GetChildByName(string.Format("Cancel Button {0}", i));
                root.RemoveChild(cancelButton);
                GUI_Base name = root.GetChildByName(string.Format("Label {0}", i));
                root.RemoveChild(name);

                i++;
            }

            s_root = null;

            TextLabel planetName   = (TextLabel)root.GetChildByName("Planet Name");
            TextLabel defenseLabel = (TextLabel)root.GetChildByName("Defense Fleets");
            TextLabel production   = (TextLabel)root.GetChildByName("Production");

            planetName.DisplayText   = "No Planet Selected";
            defenseLabel.DisplayText = "No Planet";
            production.DisplayText   = "Production: No Planet";
            s_previousSelected       = null;
        }
Пример #3
0
 /// <summary>
 /// Adds a new child element to this control.
 /// </summary>
 /// <param name="child">Class derived from GUI Base that falls within this control</param>
 public void AddChild(GUI_Base child)
 {
     if (childList.Contains(child) == false)
     {
         childList.Add(child);
     }
 }
Пример #4
0
        /// <summary>
        /// The main entry point for mouse informaiton to be passed to the GUI controls.
        /// The mouse state is typically passed to the GUI by the engine's update() function every frame;
        /// though there is no requirement to do so.  The GUI will only respond to input events using this
        /// function.
        /// </summary>
        /// <param name="mouse"></param>
        public virtual void HandleMouse(MouseState mouse)
        {
            foreach (GUI_Base c in childList)
            {
                if (c.PointIsIn(mouse.X, mouse.Y) == true)
                {
                    if (c != s_controlWithFocus)
                    {
                        c.MouseEnter(mouse);
                        if (s_controlWithFocus != null)
                        {
                            s_controlWithFocus.MouseExit(mouse);
                        }
                        s_controlWithFocus = c;
                    }
                    c.HandleMouse(mouse);
                    return;
                }
            }

            //if no child gets focus, child with focus must be set to null
            if (s_controlWithFocus != null)
            {
                s_controlWithFocus.MouseExit(mouse);
                s_controlWithFocus = null;
            }
            return;
        }
Пример #5
0
        public override void Resize(GUI_Base parent)
        {
            base.Resize(parent);

            //we'll also want to cacluate where to position the text in relation to the
            //upper left corner of the control
            if (fontName != null && fontName != String.Empty)
            {
                SpriteFont font = GetFont(fontName);
                textPaddingVertical = 0.5f * (sizePixel.Height - font.LineSpacing);
            }
        }
Пример #6
0
 /// <summary>
 /// repositions / resizes the window and its children.
 /// </summary>
 /// <param name="parent">The already resized parent of this window</param>
 public override void Resize(GUI_Base parent)
 {
     base.Resize(parent);
     if (images != null)
     {
         for (int i = 0; i < images.Length; i++)
         {
             if (images[i] != string.Empty)
             {
                 CreateDrawSpace((ImageNames)i);
             }
         }
     }
 }
Пример #7
0
        public TextLabel(XmlNode TextLabelXml, GUI_Base parent, object owner)
            : base(TextLabelXml, parent, owner)
        {
            displayText = TextLabelXml["DisplayText"].InnerText;
            XmlNode background = TextLabelXml["BackgroundImage"];

            if (background != null)
            {
                backgroundImage = LoadTextureFromXML(background);
            }

            XmlNode fontInfo = TextLabelXml["Font"];

            if (fontInfo != null)
            {
                fontName = fontInfo.InnerText;
            }
            else
            {
                fontName = c_defaultFont;
            }

            XmlNode ImageColorInfo = TextLabelXml["ImageColor"];

            if (ImageColorInfo != null)
            {
                backgroundColor = this.ReadColor32(ImageColorInfo);
            }
            else
            {
                backgroundColor = Color.White;
            }

            XmlNode TextColorInfo = TextLabelXml["TextColor"];

            if (TextColorInfo != null)
            {
                textColor = ReadColor32(TextColorInfo);
            }
            else
            {
                textColor = Color.White;
            }

            LoadFont(fontName);
            Resize(parent);
        }
Пример #8
0
        public SliderBar(XmlNode sliderXml, GUI_Base parent, object owner)
            : base(sliderXml, parent, owner)
        {
            //Load in the Image for the slider and the bar
            XmlNode barImageXML    = sliderXml["SliderBarImage"];
            XmlNode sliderImageXML = sliderXml["SliderImage"];

            if (barImageXML != null)
            {
                backgroundImage = LoadTextureFromXML(barImageXML);
            }

            if (sliderImageXML != null)
            {
                sliderImage = LoadTextureFromXML(sliderImageXML);
            }

            //Load in the min, max and Starting values for the control.
            try
            {
                minValue     = Convert.ToInt32(sliderXml["MinValue"].InnerText);
                maxValue     = Convert.ToInt32(sliderXml["MaxValue"].InnerText);
                currentValue = Convert.ToInt32(sliderXml["InitialValue"].InnerText);
            }
            catch (NullReferenceException)
            {
                uint result = MessageBox(new IntPtr(0), string.Format("Error loading in slider values in {0}", controlName),
                                         "Error In slider XML", 0);
                minValue     = 0;
                maxValue     = 100;
                currentValue = 50;
            }

            sliderLength = Math.Abs(maxValue - minValue);
            XmlNode orientationXML = sliderXml["Orientation"];

            if (orientationXML != null && orientationXML.InnerText == "Vertical")
            {
                orientation = SliderOrientation.Vertical;
            }
            else
            {
                orientation = SliderOrientation.Horizontal;
            }
        }
Пример #9
0
        /// <summary>
        /// Recalculates the existing client size of this control based on the new size of the parent.
        /// </summary>
        /// <param name="parent"></param>
        public virtual void Resize(GUI_Base parent)
        {
            SizeF  parentSize = parent.sizePixel;
            PointF parentPos  = parent.PositionPixels;

            sizePixel.Width  = sizePercent.Width * parentSize.Width;
            sizePixel.Height = SizePercent.Height * parentSize.Height;

            posPixel.X = parentPos.X + posPercent.X * parentSize.Width;
            posPixel.Y = parentPos.Y + parentSize.Height * posPercent.Y;

            drawSapce = new Microsoft.Xna.Framework.Rectangle((int)posPixel.X, (int)posPixel.Y,
                                                              (int)sizePixel.Width, (int)sizePixel.Height);

            foreach (GUI_Base child in childList)
            {
                child.Resize(this);
            }
        }
        /// <summary>
        /// Update the info for the selected. This updates production / defense information  in the GUI as well as
        /// updates the planet's depolyment route distrobutions.
        /// </summary>
        /// <param name="root">Root GUI elemtn that contains all the sliderbars for the deployment routes</param>
        /// <param name="viewing">The player viewing this information the screen.  The player's access to
        /// to the planet is determined by the its access level</param>
        public static void Update(XNA_GUI.GUIElements.GUI_Base root, Player viewing)
        {
            if (s_previousSelected == null)
            {
                return;
            }
            TextLabel planetName   = (TextLabel)root.GetChildByName("Planet Name");
            TextLabel defenseLabel = (TextLabel)root.GetChildByName("Defense Fleets");
            TextLabel production   = (TextLabel)root.GetChildByName("Production");

            planetName.DisplayText   = s_previousSelected.Name;
            defenseLabel.DisplayText = "Deffense Fleets: " + s_previousSelected.DefenseFleets.ToString();

            if (viewing.CanSeePlanet(s_previousSelected))
            {
                production.DisplayText = string.Format("Production: {0} per min", (int)s_previousSelected.Production);
            }
            else
            {
                production.DisplayText = "No Data Available";
            }

            //store the depolyment route distrobutions;
            SliderBar    s      = null;
            int          index  = 0;
            List <float> routes = s_previousSelected.DispatchRates;

            while ((s = (SliderBar)root.GetChildByName(string.Format(c_sliderName, index))) != null)
            {
                routes[index] = (float)s.CurrentValue / (float)s.MaxValue;
                index++;
            }

            s_previousSelected.NormalizeRoutes();

            index = 0;
            while ((s = (SliderBar)root.GetChildByName(string.Format(c_sliderName, index))) != null)
            {
                s.CurrentValue = (int)(s_previousSelected.DispatchRates[index] * s.MaxValue);
                index++;
            }
        }
Пример #11
0
        protected void LoadChildren(XmlNode parentNode, object owner)
        {
            foreach (XmlNode node in parentNode.ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    object [] parameters = new object[3];
                    parameters[0] = node;
                    parameters[1] = this;
                    parameters[2] = owner;

                    string asmName = "XNA_GUI.GUIElements." + node.Name;
                    Type   t       = Type.GetType(asmName);
                    if (t != null)
                    {
                        GUI_Base child = (GUI_Base)Activator.CreateInstance(t, parameters);
                        //GUI_Base child = (GUI_Base)Activator.CreateInstance((Type)s_controlTypes[node.Name], parameters);
                        AddChild(child);
                    }
                }
            }
        }
Пример #12
0
        public GUI_Base(XmlNode GUIControlXml, GUI_Base parent, object owner)
        {
            controlName  = GUIControlXml.Attributes["Name"].Value;
            parentObject = parent;
            //Read in the size and position from the XML Node
            ReadSize(GUIControlXml);
            ReadPosition(GUIControlXml);

            if (parent != null)
            {
                Resize(parent);
            }
            else
            {
                sizePixel.Height = sizePercent.Height * s_graphics.PreferredBackBufferHeight;
                sizePixel.Width  = sizePercent.Width * s_graphics.PreferredBackBufferWidth;
                posPixel.X       = posPercent.X * s_graphics.PreferredBackBufferWidth;
                posPixel.Y       = posPercent.Y * s_graphics.PreferredBackBufferHeight;
                drawSapce        = new Microsoft.Xna.Framework.Rectangle((int)posPixel.X, (int)posPixel.Y,
                                                                         (int)sizePixel.Width, (int)sizePixel.Height);
            }

            LoadChildren(GUIControlXml, owner);
        }
Пример #13
0
        public Button(XmlNode buttonXml, GUI_Base parent, object owner)
            : base(buttonXml, parent, owner)
        {
            XmlNode fontXml = buttonXml["Font"];

            if (fontXml != null)
            {
                fontName = fontXml.InnerText;
            }
            else   //if no font is specified, assign the default.
            {
                fontName = "ArialFont";
            }

            buttonImages = new string[3];
            XmlNode images = buttonXml["Images"];

            if (images != null)
            {
                LoadImages(images);
            }
            else
            {
                LoadDefaultImages();
            }

            buttonText = buttonXml["DisplayText"].InnerText;

            XmlNode BackgroundColor = buttonXml["BackgroundColor"];
            XmlNode TextColor       = buttonXml["TextColor"];

            if (BackgroundColor == null)
            {
                backgroundColor = Color.White;
            }
            else
            {
                backgroundColor = ReadColor32(BackgroundColor);
            }

            if (TextColor == null)
            {
                textColor = Color.White;
            }
            else
            {
                textColor = ReadColor32(TextColor);
            }


            //use reflection to find the function from owner that is the call back function.
            XmlNode clickFn = buttonXml["OnClick"];

            if (clickFn != null)
            {
                string     functionName = clickFn.InnerText;
                Type       t            = owner.GetType();
                MethodInfo m            = t.GetMethod(functionName);
                if (m != null)  // just in case the method we're looking for does not exist.
                {
                    onClickFunction = (GUI_BUTTONCLICK)Delegate.CreateDelegate(typeof(GUI_BUTTONCLICK), owner, m.Name, true);
                }
                else
                {
                    onClickFunction = null;
                }
            }
        }
Пример #14
0
 public MainMenuScreen(string GuiFilename, GraphicsDevice drawDevice)
     : base(drawDevice)
 {
     guiControl = XNA_GUI.GUIElements.GUI_Base.LoadLayout(GuiFilename, this);
 }
Пример #15
0
 public Frame(XmlNode FrameXml, GUI_Base parent, object owner)
     : base(FrameXml, parent, owner)
 {
     texture = resoursePath + texture;
     LoadTexutureFromFile(texture);
 }
Пример #16
0
 /// <summary>
 /// Removes and existing child control.
 /// </summary>
 /// <param name="child">Control that needs to be removed</param>
 public void RemoveChild(GUI_Base child)
 {
     childList.Remove(child);
 }
Пример #17
0
        public ListBox(XmlNode listBoXml, GUI_Base parent, object owner)
            : base(listBoXml, parent, owner)
        {
            scrollIndex    = 0;
            selected       = -1;
            scrollable     = false;
            leftButtonDown = false;

            XmlNode listBoxFrameXml     = listBoXml["BorderImage"];
            XmlNode listBoxItemImageXml = listBoXml["ItemBackgroundImage"];

            if (listBoxFrameXml != null)
            {
                borderTexture = LoadTextureFromXML(listBoxFrameXml);
            }
            if (listBoxItemImageXml != null)
            {
                itemTexture = LoadTextureFromXML(listBoxItemImageXml);
            }


            XmlNode selectedColorXml = listBoXml["SelectedColor"];

            selectedColor = ReadColor32(selectedColorXml);
            itemNames     = new List <string>(1);

            foreach (XmlNode c in listBoXml.ChildNodes)
            {
                if (c.NodeType == XmlNodeType.Element && c.Name == "ListItem")
                {
                    itemNames.Add(c.InnerText);
                }
            }

            XmlNode fontXml = listBoXml["Font"];

            if (fontXml == null)
            {
                fontName = "ArialFont";
            }
            else
            {
                fontName = fontXml.InnerText;
            }

            LoadFont(fontName);

            SpriteFont font          = GetFont(fontName);
            int        minItemHeight = font.LineSpacing + 4;

            int maxItemsWithoutScroll = (int)(sizePixel.Height / (float)minItemHeight);

            if (itemNames.Count > maxItemsWithoutScroll)
            {
                //implement a scrolling list box to accomidate

                itemHeight  = (int)Math.Floor((double)(sizePixel.Height / (float)maxItemsWithoutScroll));
                itemsToDraw = maxItemsWithoutScroll;
                scrollable  = true;
                CreateScrollButtons();
            }
            else
            {
                itemHeight  = (int)(sizePixel.Height / (float)itemNames.Count);
                itemsToDraw = itemNames.Count;
            }
        }