Пример #1
0
        private static IEnumerable <string> GetLevelStrings(IGuiElement root, uint level)
        {
            List <string> results = new List <string>();

            StringBuilder thisLevel = new StringBuilder();

            for (uint i = 0; i < level; ++i)
            {
                thisLevel.Append("\t");
            }
            if (root == null)
            {
                thisLevel.Append("NULL");
                results.Add(thisLevel.ToString());
                return(results);
            }
            else
            {
                thisLevel.Append(root.Name);
                results.Add(thisLevel.ToString());
            }

            if (root is IGuiContainer)
            {
                IGuiContainer rootContainer = (IGuiContainer)root;
                foreach (IGuiElement child in rootContainer.Children)
                {
                    results.AddRange(GetLevelStrings(child, level + 1));
                }
            }

            return(results);
        }
Пример #2
0
        /// Traverse the heiarchy of IGuiContainers to find the specified path element
        public IGuiElement[] SelectElements(IGuiContainer root)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            List <IGuiElement> results    = new List <IGuiElement>();
            List <string>      toTraverse = new List <string>(mLocations);

            if (toTraverse.Count != 0)
            {
                if (toTraverse[0] == "**")
                {
                    toTraverse.RemoveAt(0);
                    foreach (IGuiContainer container in GetAllElementsOfType <IGuiContainer>(root))
                    {
                        if (container is IGuiElement)
                        {
                            results.AddRange(RecurseFindInContainer(container, toTraverse));
                        }
                    }
                }
                else
                {
                    results = RecurseFindInContainer(root, toTraverse);
                }
            }

            return(results.ToArray());
        }
Пример #3
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.ExternalSize.x, this.ExternalSize.y);

            if (this.Style != null)
            {
                if (mDropShadowEnabled)
                {
                    Rect shadowCoords = new Rect(coords);
                    shadowCoords.x += 1.0f;
                    shadowCoords.y += 1.0f;
                    Color     shadowColor = new Color(0.0f, 0.0f, 0.0f, 0.75f);
                    IGuiStyle shadowStyle = new GuiStyle(this.Style, "Shadow");
                    shadowStyle.Normal.TextColor = shadowColor;
                    shadowStyle.Hover.TextColor  = shadowColor;
                    shadowStyle.Active.TextColor = shadowColor;

                    GUI.Label(shadowCoords, mText, shadowStyle.GenerateUnityGuiStyle());
                }
                GUI.Label(coords, mText, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.Label(coords, mText);
            }
        }
Пример #4
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            if (Event.current.type == EventType.mouseDrag)
            {
                foreach (Action <Vector2> callback in mMouseDragCallbacks)
                {
                    callback(Event.current.mousePosition);
                }
            }

            GUIContent buttonContent = BuildButtonContent();

            Vector2   size          = this.Size;
            Rect      coords        = new Rect(position.x, position.y, size.x, size.y);
            bool      buttonClicked = false;
            IGuiStyle style         = this.GetButtonStyle();

            if (style != null)
            {
                GUIStyle style2 = style.GenerateUnityGuiStyle(this.Enabled);
                buttonClicked = GUI.RepeatButton(coords, buttonContent, style2);
            }
            else
            {
                buttonClicked = GUI.RepeatButton(coords, buttonContent);
            }

            if (buttonClicked && this.Enabled)
            {
                OnPressed();
            }
        }
Пример #5
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.ExternalSize.x, this.ExternalSize.y);

            if (mAnimationStartTime == null)
            {
                mAnimationStartTime = Time.time;
            }

            float timesPlayed   = Time.time - (float)mAnimationStartTime / mAnimationLength;
            float animationTime = mAnimationLength - ((timesPlayed - Mathf.Floor(timesPlayed)) * mAnimationLength);

            Frame currentFrame   = null;
            float totalFrameTime = 0.0f;

            foreach (Frame frame in mFrames)
            {
                totalFrameTime += frame.Time;
                if (totalFrameTime >= animationTime)
                {
                    currentFrame = frame;
                    break;
                }
            }
            if (this.Style != null)
            {
                GUI.Label(coords, currentFrame.Image, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.Label(coords, currentFrame.Image);
            }
        }
Пример #6
0
        public TextBlock(XmlAttributeCollection attributes, IGuiContainer parent)
            : base(attributes, parent)
        {
            Text       = attributes["Text"].ParseString();
            textAnchor = attributes["TextAnchor"].ParseVector2();

            SetText = setText;
        }
Пример #7
0
 public IGuiElement SelectSingleElement(IGuiContainer root)
 {
     // can be optimized if rewritten to not use SelectElements
     IGuiElement[] elements = SelectElements(root);
     if (elements.Length == 0)
     {
         return(null);
     }
     return(elements[0]);
 }
Пример #8
0
        public Button(XmlAttributeCollection attributes, IGuiContainer parent, Delegate clicked, object[] buttonParams)
            : base(attributes, parent)
        {
            hoverStyleName = attributes["Hover"].ParseString();

            if (clicked != null)
            {
                onClick          = clicked;
                buttonParameters = buttonParams;
            }
        }
Пример #9
0
        private List <IGuiElement> RecurseFindInContainer(IGuiContainer root, List <string> toTraverse)
        {
            /*Debug.Log
             * (
             *      "Scanning " + root.ContainerName + "\n" +
             *      Functionals.Reduce<string, string>
             *      (
             *              delegate(string a, string b)
             *              {
             *                      return a + "\n" + b;
             *              },
             *              toTraverse
             *      )
             * );*/

            List <IGuiElement> result = new List <IGuiElement>();

            // is this level the leaf of the path? (Base Case)
            if (toTraverse.Count == 1)
            {
                result.AddRange(GetAllMatchingChildrenInContainer(root, toTraverse[0]));
            }
            else if (toTraverse.Count > 1)
            {
                List <string> subPath = new List <string>(toTraverse);
                subPath.RemoveAt(0);

                if (toTraverse[0] == "..")
                {
                    if (root is IGuiElement)
                    {
                        // Instead of going down 1 level, we have to go up 1
                        IGuiElement rootElement = (IGuiElement)root;
                        if (rootElement.Parent != null && rootElement.Parent is IGuiContainer)
                        {
                            result.AddRange(RecurseFindInContainer((IGuiContainer)rootElement.Parent, subPath));
                        }
                    }
                }
                else
                {
                    foreach (IGuiElement child in root.Children)
                    {
                        if (child != null && (child is IGuiContainer) && NameMatches(child.Name, toTraverse[0]))
                        {
                            result.AddRange(RecurseFindInContainer((IGuiContainer)child, subPath));
                        }
                    }
                }
            }

            return(result);
        }
Пример #10
0
 public T SelectSingleElement <T>(IGuiContainer root) where T : IGuiElement
 {
     // can be optimized if rewritten to not use SelectElements
     foreach (IGuiElement element in SelectElements(root))
     {
         if (element is T)
         {
             return((T)element);
         }
     }
     return(default(T));
 }
Пример #11
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.ExternalSize.x, this.ExternalSize.y);

            if (this.Style != null)
            {
                GUI.Label(coords, mTexture, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.Label(coords, mTexture);
            }
        }
Пример #12
0
        IEnumerable <IGuiElement> GetAllMatchingChildrenInContainer(IGuiContainer container, string pattern)
        {
            List <IGuiElement> result = new List <IGuiElement>();

            foreach (IGuiElement child in container.Children)
            {
                if (child != null && NameMatches(child.Name, pattern))
                {
                    result.Add(child);
                }
            }

            return(result);
        }
Пример #13
0
        /// Select all elements with a given type
        /// TODO: BUG: Long paths are not workin' out so goodly.  FIGURE OUT LATER.  Work around, use
        /// shorter queries via lower level elements in the xml hierarchy. Le Pherg.
        public IEnumerable <T> SelectElements <T>(IGuiContainer root) where T : IGuiElement
        {
            List <T> results = new List <T>();

            foreach (IGuiElement element in this.SelectElements(root))
            {
                if (element is T)
                {
                    results.Add((T)element);
                }
            }

            return(results);
        }
Пример #14
0
        private List <Element> loadGuiNode(XmlNode node, IGuiContainer parent)
        {
            List <Element> elementChildren = new List <Element>(node.ChildNodes.Count);

            foreach (XmlNode childNode in node)
            {
                //The type of the element
                Type elementType = typeof(Element).Assembly.GetType(typeof(Element).Namespace + "." + childNode.Name);

                //Make an object array for the element's constructor argument. All element constructors have the attributes and the parent, so those are added first
                List <object> childArguments = new List <object>(2);
                childArguments.Add(childNode.Attributes);
                childArguments.Add(parent);

                //Currently no element needs extra arguments, in the future there will be a switch(childNode.Name) to add specific arguments to the object array
                switch (childNode.Name)
                {
                //Add the delegate and object arguments to the arguments of the element
                case "Button":
                    if (childNode.Attributes["Function"] == null)
                    {
                        childArguments.Add(null);
                        childArguments.Add(null);
                    }
                    else
                    {
                        object[] methodParams = getFunctionParameters(childNode.Attributes["Function"].Value);

                        childArguments.Add(getFunctionDelegate(childNode.Attributes["Function"].Value, methodParams));
                        childArguments.Add(methodParams);
                    }
                    break;
                }

                //Creates an element based on the childNode
                Element childElement = (Element)Activator.CreateInstance(elementType, childArguments.ToArray());

                //Adds this element to the children of the parent
                elementChildren.Add(childElement);

                //If this element is a container, iterate through its children as well
                if (childNode.HasChildNodes && childElement is IGuiContainer f)
                {
                    f.AddElements(loadGuiNode(childNode, f));
                }
            }

            return(elementChildren);
        }
Пример #15
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            string resultText = "";
            Rect   coords     = new Rect(position.x, position.y, this.Size.x, this.Size.y);

            if (Text == null)
            {
                Text = "";
            }

            if (mSingleLine)
            {
                if (this.Style != null)
                {
                    resultText = GUI.TextField(coords, Text, this.Style.GenerateUnityGuiStyle());
                }
                else
                {
                    resultText = GUI.TextField(coords, Text);
                }
            }
            else
            {
                if (this.Style != null)
                {
                    resultText = GUI.TextArea(coords, Text, this.Style.GenerateUnityGuiStyle());
                }
                else
                {
                    resultText = GUI.TextArea(coords, Text);
                }
            }

            if (mUserEditable)
            {
                bool textChanged = Text != resultText;
                Text = resultText;

                if (textChanged)
                {
                    foreach (Hangout.Shared.Action callback in mTextChangedCallbacks)
                    {
                        callback();
                    }
                }
            }
        }
Пример #16
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.Size.x, this.Size.y);
            Rect newCoords;

            if (this.Style != null)
            {
                newCoords = this.GuiWindowCall(this.WindowId, coords, DrawContents, "", this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                newCoords = this.GuiWindowCallNoStyle(this.WindowId, coords, DrawContents, "");
            }

            if (newCoords.x != coords.x || newCoords.y != coords.y)
            {
                container.UpdateChildPosition(this, new Vector2(newCoords.x, newCoords.y));
            }
        }
Пример #17
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.Size.x, this.Size.y);

            AutoLayoutUpdate();

            if (this.Style != null)
            {
                GUI.BeginGroup(coords, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.BeginGroup(coords);
            }

            try
            {
                //Draw the widgets in the GuiFrame.
                foreach (KeyValuePair <IWidget, IGuiPosition> widget in Widgets)
                {
                    if (widget.Key.Showing)
                    {
                        Vector2 widgetPosition = widget.Value.GetPosition(widget.Key);
                        widget.Key.Draw(this, widgetPosition);
                    }
                }

                //Draw only the active widgets in the grid.
                foreach (KeyValuePair <IWidget, IGuiPosition> widget in mActiveWidgets)
                {
                    if (widget.Key.Showing)
                    {
                        Vector2 widgetPosition = widget.Value.GetPosition(widget.Key);
                        widget.Key.Draw(this, widgetPosition);
                    }
                }
            }
            finally
            {
                GUI.EndGroup();
            }
        }
Пример #18
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.Size.x, this.Size.y);

            AutoLayoutUpdate();

            if (this.Style != null)
            {
                GUI.BeginGroup(coords, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.BeginGroup(coords);
            }

            try
            {
                // The copy here is so that child widgets can modify the list of widgets here if necessary
                IEnumerable <KeyValuePair <IWidget, IGuiPosition> > widgets = new List <KeyValuePair <IWidget, IGuiPosition> >(mWidgets);
                foreach (KeyValuePair <IWidget, IGuiPosition> widget in widgets)
                {
                    if (widget.Key.Showing)
                    {
                        Vector2 widgetPosition = widget.Value.GetPosition(widget.Key);
                        if (!mIgnoreModifyPosition.Contains(widget.Key))
                        {
                            foreach (Hangout.Shared.Func <Vector2, Vector2> modifyPositionCallback in mModifyWidgetPositionCallbacks)
                            {
                                widgetPosition = modifyPositionCallback(widgetPosition);
                            }
                        }
                        widget.Key.Draw(this, widgetPosition);
                    }
                }
            }
            finally
            {
                GUI.EndGroup();
            }
        }
Пример #19
0
        private static IEnumerable <T> GetAllElementsOfType <T>(IGuiContainer root)
        {
            List <T> results = new List <T>();

            if (root is T)
            {
                results.Add((T)root);
            }

            foreach (IGuiElement child in root.Children)
            {
                if (child is IGuiContainer)
                {
                    results.AddRange(GetAllElementsOfType <T>((IGuiContainer)child));
                }
                else if (child is T)
                {
                    results.Add((T)child);
                }
            }

            return(results);
        }
Пример #20
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            GUIContent buttonContent = BuildButtonContent();

            Vector2   size          = this.Size;
            Rect      coords        = new Rect(position.x, position.y, size.x, size.y);
            bool      buttonClicked = false;
            IGuiStyle style         = this.GetButtonStyle();

            if (style != null)
            {
                GUIStyle style2 = style.GenerateUnityGuiStyle(mEnabled);
                buttonClicked = GUI.Button(coords, buttonContent, style2);
            }
            else
            {
                buttonClicked = GUI.Button(coords, buttonContent);
            }

            if (buttonClicked && mEnabled)
            {
                OnPressed();
            }
        }
Пример #21
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.Size.x, this.Size.y);

            GUI.Box(coords, mEmptyGuiContent, Style.GenerateUnityGuiStyle());
        }
Пример #22
0
 public override void Draw(IGuiContainer parent, Vector2 size)
 {
     base.Draw(parent, size);
 }
Пример #23
0
 public override void Draw(IGuiContainer container, Vector2 position)
 {
     this.DrawContents(0);
 }
Пример #24
0
 public override void Draw(IGuiContainer parent, Vector2 position)
 {
     mButtonFrame.Draw(this, mButtonFramePosition.GetPosition(mButtonFrame));
     mContextFrame.Draw(this, mContextFramePosition.GetPosition(mContextFrame));
 }
Пример #25
0
 public override void Draw(IGuiContainer container, Vector2 position)
 {
     mTroughFrame.Draw(this, position);
 }
Пример #26
0
 public LineGraph(XmlAttributeCollection attributes, IGuiContainer parent)
     : base(attributes, parent)
 {
 }
Пример #27
0
 public abstract void Draw(IGuiContainer container, Vector2 position);
Пример #28
0
 public Frame(XmlAttributeCollection attributes, IGuiContainer parent)
     : base(attributes, parent)
 {
     Elements = new List <Element>();
 }
Пример #29
0
 public override void Draw(IGuiContainer parent, Vector2 position)
 {
     mProgressFrame.First.Draw(this, mProgressFrame.Second.GetPosition(mProgressFrame.First));
     mContextFrame.First.Draw(this, mContextFrame.Second.GetPosition(mContextFrame.First));
 }
Пример #30
0
 public override void Draw(IGuiContainer container, Vector2 position)
 {
     mTrough.Draw(container, position);
     mThumb.Draw(container, position + new Vector2(0.0f, Mathf.Lerp(0.0f, Size.y - mThumb.ExternalSize.y, this.Percent)));
 }