Object used to keep track of state when walking an AST tree (see UIScreen.WalkTree in Gonzo).
コード例 #1
0
        public UISlider(AddSliderNode Node, ParserState State, UIScreen Screen)
            : base(Screen)
        {
            Name = Node.Name;
            m_ID = Node.ID;
            Position = new Vector2(Node.SliderPosition.Numbers[0], Node.SliderPosition.Numbers[1]);

            if (!State.InSharedPropertiesGroup)
            {
                Image = m_Screen.GetImage(Node.Image);
                Image.Position = Position;
            }
            else
            {
                Image = m_Screen.GetImage(State.Image);
                Image.Position = Position;
            }

            if (Node.MinimumValue != null)
                m_Minimumvalue = (int)Node.MinimumValue;
            if (Node.MaximumValue != null)
                m_MaximumValue = (int)Node.MaximumValue;

            if (!State.InSharedPropertiesGroup)
            {
                m_Size = new Vector2(Node.Size.Numbers[0], Node.Size.Numbers[1]);
                m_Orientation = (SliderOrientation)Node.Orientation;
            }
            else
            {
                m_Size = State.Size;
                m_Orientation = (SliderOrientation)State.Orientation;
            }
        }
コード例 #2
0
        private float m_XScale = 1.0f; //Used to scale buttons to fit text.

        #endregion Fields

        #region Constructors

        public UIButton(AddButtonNode Node, ParserState State, UIScreen Screen)
            : base(Screen)
        {
            Name = Node.Name;
            m_ID = Node.ID;
            m_Screen = Screen;

            if (!State.InSharedPropertiesGroup)
            {
                if (Node.Image != null)
                {
                    Image = m_Screen.GetImage(Node.Image, false);
                    //Initialize to second frame in the image.
                    m_SourcePosition = new Vector2((Image.Texture.Width / (4)) * 2, 0.0f);

                    m_Size = new Vector2();
                    m_Size.X = (Image.Texture.Width) / (4);
                    m_Size.Y = Image.Texture.Height;

                    Position = new Vector2(Node.ButtonPosition.Numbers[0], Node.ButtonPosition.Numbers[1]) + m_Screen.Position;
                }
                else
                {
                    Image = new UIImage(FileManager.GetTexture((ulong)FileIDs.UIFileIDs.buttontiledialog), m_Screen);
                    //Initialize to second frame in the image.
                    m_SourcePosition = new Vector2((Image.Texture.Width / 4) * 2, 0.0f);

                    m_Size = new Vector2();
                    m_Size.X = (Image.Texture.Width) / (4);
                    m_Size.Y = Image.Texture.Height;

                    Position = new Vector2(Node.ButtonPosition.Numbers[0], Node.ButtonPosition.Numbers[1]) + m_Screen.Position;
                }
            }
            else
            {
                if (State.Image != "")
                {
                    Image = m_Screen.GetImage(State.Image, true);
                    //Initialize to second frame in the image.
                    m_SourcePosition = new Vector2((Image.Texture.Width / 4) * 2, 0.0f);

                    m_Size = new Vector2();
                    m_Size.X = Image.Texture.Width / 4;
                    m_Size.Y = Image.Texture.Height;

                    Position = new Vector2(Node.ButtonPosition.Numbers[0], Node.ButtonPosition.Numbers[1]) + m_Screen.Position;
                }
                else
                {
                    if (State.TextButton)
                    {
                        m_Text = State.Caption;
                        //Text buttons always use this image.
                        Image = new UIImage(FileManager.GetTexture((ulong)FileIDs.UIFileIDs.buttontiledialog), m_Screen);
                        //Initialize to second frame in the image.
                        m_SourcePosition = new Vector2((Image.Texture.Width / 4) * 2, 0.0f);

                        m_Size = new Vector2();
                        m_Size.X = Image.Texture.Width / 4;
                        m_Size.Y = Image.Texture.Height;
                    }
                    else
                    {
                        Image = m_Screen.GetImage(Node.Image, false);
                        //Initialize to second frame in the image.
                        m_SourcePosition = new Vector2((Image.Texture.Width / (4)) * 2, 0.0f);

                        m_Size = new Vector2();
                        m_Size.X = (Image.Texture.Width) / (4);
                        m_Size.Y = Image.Texture.Height;

                        Position = new Vector2(Node.ButtonPosition.Numbers[0], Node.ButtonPosition.Numbers[1]) + m_Screen.Position;
                    }

                    Position = new Vector2(Node.ButtonPosition.Numbers[0], Node.ButtonPosition.Numbers[1]) + m_Screen.Position;
                }

                if (State.Tooltip != "")
                    Tooltip = m_Screen.GetString(State.Tooltip);
            }

            if (Node.TextHighlighted != null)
                m_IsTextHighlighted = (Node.TextHighlighted == 1) ? true : false;

            if (Node.Font != null)
            {
                int FontSize = (int)Node.Font;

                switch (FontSize)
                {
                    case 9:
                        m_Font = Screen.Font9px;
                        break;
                    case 10:
                        m_Font = Screen.Font10px;
                        break;
                    case 12:
                        m_Font = Screen.Font12px;
                        break;
                    case 14:
                        m_Font = Screen.Font14px;
                        break;
                    case 16:
                        m_Font = Screen.Font16px;
                        break;
                }
            }
            else if(State.Font != 0)
            {
                switch (State.Font)
                {
                    case 9:
                        m_Font = Screen.Font9px;
                        break;
                    case 10:
                        m_Font = Screen.Font10px;
                        break;
                    case 12:
                        m_Font = Screen.Font12px;
                        break;
                    case 14:
                        m_Font = Screen.Font14px;
                        break;
                    case 16:
                        m_Font = Screen.Font16px;
                        break;
                    default:
                        m_Font = Screen.Font12px;
                        break;
                }
            }

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

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

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

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

            if (Node.TextButton != null)
                m_IsTextButton = (Node.TextButton == 1) ? true : false;
            else
                m_IsTextButton = m_IsTextButton = State.TextButton;

            if (m_IsTextButton)
            {
                if (Node.Text != string.Empty)
                    m_Text = m_Screen.GetString(Node.Text);
                else
                    m_Text = m_Screen.GetString(State.Caption);

                m_TextPosition = Position;

                if (m_Size.X != 0)
                    ScaleToText();
            }

            if (Node.Tooltip != "")
                Tooltip = m_Screen.GetString(Node.Tooltip);

            if (Node.Tracking != null)
                Tracking = (int)Node.Tracking;
        }
コード例 #3
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, ref ParseResult Result)
        {
            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);
                Result.Elements.Add(ImgNode.Name, Img);
                break;

            case NodeType.DefineString:     //Defines a string with a name.
                DefineStringNode StrNode = (DefineStringNode)UINode.GetNode(node);
                Result.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, Result, m_Screen);
                Result.Elements.Add(ButtonNode.Name, Btn);

                break;

            case NodeType.AddText:
                AddTextNode TextNode = (AddTextNode)UINode.GetNode(node);
                UILabel     Lbl      = new UILabel(TextNode, Result, m_Screen);
                Result.Elements.Add(TextNode.Name, Lbl);
                break;

            case NodeType.AddTextEdit:
                AddTextEditNode TextEditNode = (AddTextEditNode)UINode.GetNode(node);
                UITextEdit2     Txt          = new UITextEdit2(TextEditNode, State, m_Screen);
                Result.Elements.Add(TextEditNode.Name, Txt);
                break;

            case NodeType.AddSlider:
                AddSliderNode SliderNode = (AddSliderNode)UINode.GetNode(node);
                UISlider      Slider     = new UISlider(SliderNode, State, m_Screen);
                Result.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);
                Result.Controls.Add(ControlPropsNode.Control, Ctrl);

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

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

                        Result.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    = "";
                State.Size       = new Vector2(0, 0);
                State.Alignment  = 0;
                State.Font       = 0;
                //TODO: Reset more?
                break;
            }

            foreach (AstNode child in node.ChildNodes)
            {
                WalkTree(State, child, ref Result);
            }
        }
コード例 #4
0
        public UILabel(AddTextNode Node, ParserState State, UIScreen Screen)
            : base(Screen)
        {
            Name = Node.Name;
            m_ID = Node.ID;
            Position = new Vector2(Node.TextPosition.Numbers[0], Node.TextPosition.Numbers[1]) + Screen.Position;

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

            if (Node.Color != null)
            {
                m_TextColor = new Color();
                m_TextColor.A = 255; //Ignore opacity, The Sims Online doesn't support transparent text.
                m_TextColor.R = (byte)Node.Color.Numbers[0];
                m_TextColor.G = (byte)Node.Color.Numbers[1];
                m_TextColor.B = (byte)Node.Color.Numbers[2];
            }
            else
            {
                m_TextColor = State.Color;
                m_TextColor.A = 255; //Ignore opacity, The Sims Online doesn't support transparent text.
            }

            if (Node.Alignment != 0)
                m_Alignment = Node.Alignment;
            else
                m_Alignment = (TextAlignment)State.Alignment;

            int Font = 0;
            if (Node.Font != null)
            {
                if (Node.Font != 0)
                    Font = (int)Node.Font;
            }
            else
                Font = State.Font;

            switch (Font)
            {
                    case 7:
                        m_Font = Screen.Font10px; //TODO: Fixme.
                    break;
                    case 9:
                    m_Font = Screen.Font9px;
                        break;
                    case 10:
                        m_Font = Screen.Font10px;
                        break;
                    case 12:
                        m_Font = Screen.Font12px;
                        break;
                    case 14:
                        m_Font = Screen.Font14px;
                        break;
                    case 16:
                        m_Font = Screen.Font16px;
                        break;
            }

            if (Node.Text != "")
                Caption = m_Screen.GetString(Node.Text);
            else
            {
                if(State.Caption != "")
                    //Sometimes labels will not have pre-defined text, as they will hold text
                    //generated in-game.
                    Caption = m_Screen.GetString(State.Caption);
            }

            AlignText();
        }