UIElement is the base class for all UI related elements (UIButton, UIControl, UIDialog, UIImage, UILabel, UISlider, UITextEdit).
示例#1
0
        /// <summary>
        /// Centers this dialog around a UIElement (UIImage, UILabel or similar).
        /// </summary>
        /// <param name="Element">The element to center around.</param>
        /// <param name="OffsetX">Offset on the X-axis when centering.</param>
        /// <param name="OffsetY">Offset on the Y-axis when centering.</param>
        public void CenterAround(UIElement Element, int OffsetX, int OffsetY)
        {
            Vector2 TopLeft = Element.Position;

            this.Position = new Vector2(OffsetX + TopLeft.X + ((Element.Size.X - m_Size.X) / 2),
                OffsetY + TopLeft.Y + ((Element.Size.Y - m_Size.Y) / 2));

            if(m_HasExitBtn)
            {
                m_CloseBtnBack.Position = Position + new Vector2(Image.Slicer.Width - m_CloseBtnBack.Texture.Width, 0);
                m_CloseButton.Position = Position + new Vector2(Image.Slicer.Width - (m_CloseButton.Image.Texture.Width / 2.5f), 9f);
            }
        }
示例#2
0
        uint[] PixelData = new uint[1]; // Delare an Array of 1 just to store data for one pixel

        #endregion Fields

        #region Constructors

        public UIElement(string Name, Vector2 Position, Vector2 Size, UIScreen Screen, UIElement Parent = null)
        {
            this.Name = Name;
            m_Size = Size;

            if (Parent != null)
            {
                m_Parent = Parent;
                m_Position += Parent.m_Position;
            }
            else
                m_Position = Position;

            m_Screen = Screen;
        }
示例#3
0
        /// <summary>
        /// Constructs a new UIButton instance.
        /// </summary>
        /// <param name="Name">Name of button.</param>
        /// <param name="Tex">Texture used to display this button.</param>
        /// <param name="Position">Button's position.</param>
        /// <param name="Screen">This button's screen.</param>
        public UIButton(string Name, Texture2D Tex, Vector2 Pos, UIScreen Screen, UIElement Parent = null)
            : base(Screen, Parent)
        {
            base.Name = Name;
            Position = Pos;

            Image = new UIImage(Tex, Screen, null);
            Image.Position = new Vector2(Pos.X, Pos.Y);
            //Initialize to second frame in the image.
            m_SourcePosition = new Vector2((Tex.Width / 4) * 2, 0.0f);

            m_Size = new Vector2();
            m_Size.X = Tex.Width / 4;
            m_Size.Y = Tex.Height;
        }
示例#4
0
        /// <summary>
        /// Constructs a new UIImage instance.
        /// </summary>
        /// <param name="Tex">Texture to create image from.</param>
        /// <param name="Screen">UIScreen instance.</param>
        /// <param name="Parent">Parent of this UIImage instance, may be null.</param>
        public UIImage(Texture2D Tex, UIScreen Screen, UIElement Parent = null)
            : base(Screen, Parent)
        {
            Texture = Tex;

            m_Loaded = true;
        }
示例#5
0
        /// <summary>
        /// Constructs a UIElement from a Screen instance and an optional UIElement that acts as a parent.
        /// </summary>
        /// <param name="Screen">A Screen instance.</param>
        /// <param name="Parent">(Optional) UIElement that acts as a parent.</param>
        /// <param name="Path"> (Optional) Path to a UI script that will create this UI element.</param>
        public UIElement(UIScreen Screen, UIElement Parent = null, string Path = "")
        {
            m_Screen = Screen;

            if (Parent != null)
                m_Parent = Parent;
        }
示例#6
0
        /// <summary>
        /// Walks a generated AST (Abstract Syntax Tree) and creates the elements of this UIScreen.
        /// </summary>
        /// <param name="State">A ParserState instance.</param>
        /// <param name="node">The root node of the AST.</param>
        private void WalkTree(UIParser.ParserState State, AstNode node)
        {
            NodeType NType = (NodeType)Enum.Parse(typeof(NodeType), node.ToString(), true);

            switch (NType)
            {
                case NodeType.DefineImage: //Defines an image and loads a texture for it.
                    DefineImageNode ImgNode = (DefineImageNode)UINode.GetNode(node);
                    UIImage Img = new UIImage(ImgNode, m_Screen);
                    Elements.Add(ImgNode.Name, Img);
                    break;
                case NodeType.DefineString: //Defines a string with a name.
                    DefineStringNode StrNode = (DefineStringNode)UINode.GetNode(node);
                    Strings.Add(StrNode.Name, StringManager.StrTable(State.CurrentStringTable)[StrNode.StrIndex]);
                    break;
                case NodeType.AddButton: //Defines a button.
                    AddButtonNode ButtonNode = (AddButtonNode)UINode.GetNode(node);
                    UIButton Btn = new UIButton(ButtonNode, State, m_Screen);
                    Elements.Add(ButtonNode.Name, Btn);

                    break;
                case NodeType.AddText:
                    AddTextNode TextNode = (AddTextNode)UINode.GetNode(node);
                    UILabel Lbl = new UILabel(TextNode, State, m_Screen);
                    Elements.Add(TextNode.Name, Lbl);
                    break;
                case NodeType.AddTextEdit:
                    AddTextEditNode TextEditNode = (AddTextEditNode)UINode.GetNode(node);
                    UITextEdit Txt = new UITextEdit(TextEditNode, State, m_Screen);
                    Elements.Add(TextEditNode.Name, Txt);
                    break;
                case NodeType.AddSlider:
                    AddSliderNode SliderNode = (AddSliderNode)UINode.GetNode(node);
                    UISlider Slider = new UISlider(SliderNode, State, m_Screen);
                    Elements.Add(SliderNode.Name, Slider);
                    break;
                case NodeType.SetSharedProperties: //Assigns a bunch of shared properties to declarations following the statement.
                    State.InSharedPropertiesGroup = true;
                    SetSharedPropsNode SharedPropsNode = (SetSharedPropsNode)UINode.GetNode(node);

                    if (SharedPropsNode.StringTable != null)
                        State.CurrentStringTable = (int)SharedPropsNode.StringTable;

                    if (SharedPropsNode.ControlPosition != null)
                    {
                        State.Position[0] = SharedPropsNode.ControlPosition.Numbers[0];
                        State.Position[1] = SharedPropsNode.ControlPosition.Numbers[1];
                        break;
                    }

                    if (SharedPropsNode.Color != null)
                    {
                        State.Color = new Color();
                        State.Color.R = (byte)SharedPropsNode.Color.Numbers[0];
                        State.Color.G = (byte)SharedPropsNode.Color.Numbers[1];
                        State.Color.B = (byte)SharedPropsNode.Color.Numbers[2];
                    }

                    if (SharedPropsNode.TextColor != null)
                    {
                        State.TextColor = new Color();
                        State.TextColor.R = (byte)SharedPropsNode.TextColor.Numbers[0];
                        State.TextColor.G = (byte)SharedPropsNode.TextColor.Numbers[1];
                        State.TextColor.B = (byte)SharedPropsNode.TextColor.Numbers[2];
                    }

                    if (SharedPropsNode.TextColorSelected != null)
                    {
                        State.TextColorSelected = new Color();
                        State.TextColorSelected.R = (byte)SharedPropsNode.TextColorSelected.Numbers[0];
                        State.TextColorSelected.G = (byte)SharedPropsNode.TextColorSelected.Numbers[1];
                        State.TextColorSelected.B = (byte)SharedPropsNode.TextColorSelected.Numbers[2];
                    }

                    if (SharedPropsNode.TextColorHighlighted != null)
                    {
                        State.TextColorHighlighted = new Color();
                        State.TextColorHighlighted.R = (byte)SharedPropsNode.TextColorHighlighted.Numbers[0];
                        State.TextColorHighlighted.G = (byte)SharedPropsNode.TextColorHighlighted.Numbers[1];
                        State.TextColorHighlighted.B = (byte)SharedPropsNode.TextColorHighlighted.Numbers[2];
                    }

                    if (SharedPropsNode.TextColorDisabled != null)
                    {
                        State.TextColorDisabled = new Color();
                        State.TextColorDisabled.R = (byte)SharedPropsNode.TextColorDisabled.Numbers[0];
                        State.TextColorDisabled.G = (byte)SharedPropsNode.TextColorDisabled.Numbers[1];
                        State.TextColorDisabled.B = (byte)SharedPropsNode.TextColorDisabled.Numbers[2];
                    }

                    if (SharedPropsNode.BackColor != null)
                    {
                        State.BackColor = new Color();
                        State.BackColor.R = (byte)SharedPropsNode.BackColor.Numbers[0];
                        State.BackColor.G = (byte)SharedPropsNode.BackColor.Numbers[1];
                        State.BackColor.B = (byte)SharedPropsNode.BackColor.Numbers[2];
                    }

                    if (SharedPropsNode.CursorColor != null)
                    {
                        State.CursorColor = new Color();
                        State.CursorColor.R = (byte)SharedPropsNode.CursorColor.Numbers[0];
                        State.CursorColor.G = (byte)SharedPropsNode.CursorColor.Numbers[1];
                        State.CursorColor.B = (byte)SharedPropsNode.CursorColor.Numbers[2];
                    }

                    if (SharedPropsNode.TextButton)
                        State.TextButton = true;

                    if (SharedPropsNode.Opaque != null)
                        State.IsOpaque = (SharedPropsNode.Opaque == 1) ? true : false;

                    if (SharedPropsNode.Transparent != null)
                        State.IsTransparent = (SharedPropsNode.Transparent == 1) ? true : false;

                    if (SharedPropsNode.Alignment != null)
                        State.Alignment = (int)SharedPropsNode.Alignment;

                    if (SharedPropsNode.Image != "")
                        State.Image = SharedPropsNode.Image;

                    if (SharedPropsNode.Tooltip != "")
                        State.Tooltip = SharedPropsNode.Tooltip;

                    if (SharedPropsNode.Text != "")
                        State.Caption = SharedPropsNode.Text;

                    if (SharedPropsNode.Size != null)
                        State.Size = new Vector2(SharedPropsNode.Size.Numbers[0], SharedPropsNode.Size.Numbers[1]);

                    if (SharedPropsNode.Orientation != null)
                        State.Orientation = (int)SharedPropsNode.Orientation;

                    if (SharedPropsNode.Font != null)
                        State.Font = (int)SharedPropsNode.Font;

                    if (SharedPropsNode.Opaque != null)
                        State.Opaque = (int)SharedPropsNode.Opaque;

                    break;
                case NodeType.SetControlProperties: //Sets a bunch of properties to a specified control.
                    SetControlPropsNode ControlPropsNode = (SetControlPropsNode)UINode.GetNode(node);

                    UIControl Ctrl = new UIControl(ControlPropsNode, m_Screen, State);
                    Controls.Add(ControlPropsNode.Control, Ctrl);

                    if (State.InSharedPropertiesGroup)
                    {
                        UIElement Test = new UIElement(m_Screen, null);
                        //Script implicitly created an object... :\
                        if (!Elements.TryGetValue(ControlPropsNode.Control, out Test))
                        {
                            Elements.Add(ControlPropsNode.Control, new UIElement(m_Screen, null));

                            if (Ctrl.Image != null)
                                Elements[ControlPropsNode.Control].Image = new UIImage(Ctrl.Image);

                            Elements[ControlPropsNode.Control].Position = Ctrl.Position;
                        }
                    }

                    break;
                case NodeType.End:
                    State.InSharedPropertiesGroup = false;
                    State.Image = ""; //Reset
                    State.TextButton = false; //Reset
                    State.Color = new Color();
                    State.Caption = "";
                    //TODO: Reset more?
                    break;
            }

            foreach (AstNode child in node.ChildNodes)
                WalkTree(State, child);
        }
示例#7
0
        /// <summary>
        /// A new UIElement was clicked on and is ready to receive keyboard input.
        /// </summary>
        public void OverrideFocus(UIElement Element)
        {
            if(Element.ListensToKeyboard)
            {
                foreach (KeyValuePair<string, UIElement> KVP in m_Walker.Elements)
                    KVP.Value.HasFocus = false;

                m_Walker.Elements[Element.Name].HasFocus = true;
            }
        }