Exemplo n.º 1
0
        public GUIComponentStyle(XElement element)
        {
            Sprites = new Dictionary <GUIComponent.ComponentState, List <UISprite> >();
            foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
            {
                Sprites[state] = new List <UISprite>();
            }

            ChildStyles = new Dictionary <string, GUIComponentStyle>();

            Padding = element.GetAttributeVector4("padding", Vector4.Zero);

            Vector4 colorVector = element.GetAttributeVector4("color", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));

            Color = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector = element.GetAttributeVector4("textcolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
            textColor   = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector = element.GetAttributeVector4("hovercolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            HoverColor  = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector   = element.GetAttributeVector4("selectedcolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            SelectedColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector  = element.GetAttributeVector4("pressedcolor", new Vector4(1, 1, 1, 1));
            PressedColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector  = element.GetAttributeVector4("outlinecolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            OutlineColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    UISprite newSprite = new UISprite(subElement);

                    GUIComponent.ComponentState spriteState = GUIComponent.ComponentState.None;
                    if (subElement.Attribute("state") != null)
                    {
                        string stateStr = subElement.GetAttributeString("state", "None");
                        Enum.TryParse(stateStr, out spriteState);
                        Sprites[spriteState].Add(newSprite);
                    }
                    else
                    {
                        foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
                        {
                            Sprites[state].Add(newSprite);
                        }
                    }
                    break;

                default:
                    ChildStyles.Add(subElement.Name.ToString().ToLowerInvariant(), new GUIComponentStyle(subElement));
                    break;
                }
            }
        }
Exemplo n.º 2
0
 public InventorySlot(Rectangle rect)
 {
     Rect         = rect;
     InteractRect = rect;
     InteractRect.Inflate(5, 5);
     State = GUIComponent.ComponentState.None;
     Color = Color.White * 0.4f;
 }
Exemplo n.º 3
0
        public InventorySlot(Rectangle rect)
        {
            Rect = rect;

            State = GUIComponent.ComponentState.None;

            Color = Color.White * 0.4f;
        }
Exemplo n.º 4
0
        public GUIComponentStyle(XElement element)
        {
            Sprites = new Dictionary <GUIComponent.ComponentState, List <UISprite> >();
            foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
            {
                Sprites[state] = new List <UISprite>();
            }

            ChildStyles = new Dictionary <string, GUIComponentStyle>();

            Padding = element.GetAttributeVector4("padding", Vector4.Zero);

            Vector4 colorVector = element.GetAttributeVector4("color", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));

            Color = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector = element.GetAttributeVector4("textcolor", new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
            textColor   = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector = element.GetAttributeVector4("hovercolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            HoverColor  = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector   = element.GetAttributeVector4("selectedcolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            SelectedColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            colorVector  = element.GetAttributeVector4("outlinecolor", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
            OutlineColor = new Color(colorVector.X, colorVector.Y, colorVector.Z, colorVector.W);

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    Sprite sprite         = new Sprite(subElement);
                    bool   maintainAspect = subElement.GetAttributeBool("maintainaspectratio", false);
                    bool   tile           = subElement.GetAttributeBool("tile", true);

                    string stateStr = subElement.GetAttributeString("state", "None");
                    GUIComponent.ComponentState spriteState = GUIComponent.ComponentState.None;
                    Enum.TryParse(stateStr, out spriteState);

                    UISprite newSprite = new UISprite(sprite, tile, maintainAspect);

                    Vector4 sliceVec = subElement.GetAttributeVector4("slice", Vector4.Zero);
                    if (sliceVec != Vector4.Zero)
                    {
                        Rectangle slice = new Rectangle((int)sliceVec.X, (int)sliceVec.Y, (int)(sliceVec.Z - sliceVec.X), (int)(sliceVec.W - sliceVec.Y));

                        newSprite.Slice = true;

                        newSprite.Slices = new Rectangle[9];

                        //top-left
                        newSprite.Slices[0] = new Rectangle(newSprite.Sprite.SourceRect.Location, slice.Location - newSprite.Sprite.SourceRect.Location);
                        //top-mid
                        newSprite.Slices[1] = new Rectangle(slice.Location.X, newSprite.Slices[0].Y, slice.Width, newSprite.Slices[0].Height);
                        //top-right
                        newSprite.Slices[2] = new Rectangle(slice.Right, newSprite.Slices[0].Y, newSprite.Sprite.SourceRect.Right - slice.Right, newSprite.Slices[0].Height);

                        //mid-left
                        newSprite.Slices[3] = new Rectangle(newSprite.Slices[0].X, slice.Y, newSprite.Slices[0].Width, slice.Height);
                        //center
                        newSprite.Slices[4] = slice;
                        //mid-right
                        newSprite.Slices[5] = new Rectangle(newSprite.Slices[2].X, slice.Y, newSprite.Slices[2].Width, slice.Height);

                        //bottom-left
                        newSprite.Slices[6] = new Rectangle(newSprite.Slices[0].X, slice.Bottom, newSprite.Slices[0].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
                        //bottom-mid
                        newSprite.Slices[7] = new Rectangle(newSprite.Slices[1].X, slice.Bottom, newSprite.Slices[1].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
                        //bottom-right
                        newSprite.Slices[8] = new Rectangle(newSprite.Slices[2].X, slice.Bottom, newSprite.Slices[2].Width, newSprite.Sprite.SourceRect.Bottom - slice.Bottom);
                    }

                    Sprites[spriteState].Add(newSprite);
                    break;

                default:
                    ChildStyles.Add(subElement.Name.ToString().ToLowerInvariant(), new GUIComponentStyle(subElement));
                    break;
                }
            }
        }
        public GUIComponentStyle(XElement element, GUIStyle style)
        {
            Name = element.Name.LocalName;

            Style   = style;
            Element = element;

            Sprites = new Dictionary <GUIComponent.ComponentState, List <UISprite> >();
            foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
            {
                Sprites[state] = new List <UISprite>();
            }

            ChildStyles = new Dictionary <string, GUIComponentStyle>();

            Padding = element.GetAttributeVector4("padding", Vector4.Zero);

            Color         = element.GetAttributeColor("color", Color.Transparent);
            HoverColor    = element.GetAttributeColor("hovercolor", Color);
            SelectedColor = element.GetAttributeColor("selectedcolor", Color);
            DisabledColor = element.GetAttributeColor("disabledcolor", Color);
            PressedColor  = element.GetAttributeColor("pressedcolor", Color);
            OutlineColor  = element.GetAttributeColor("outlinecolor", Color.Transparent);

            TextColor           = element.GetAttributeColor("textcolor", Color.Black);
            HoverTextColor      = element.GetAttributeColor("hovertextcolor", TextColor);
            DisabledTextColor   = element.GetAttributeColor("disabledtextcolor", TextColor);
            SelectedTextColor   = element.GetAttributeColor("selectedtextcolor", TextColor);
            SpriteCrossFadeTime = element.GetAttributeFloat("spritefadetime", SpriteCrossFadeTime);
            ColorCrossFadeTime  = element.GetAttributeFloat("colorfadetime", ColorCrossFadeTime);

            if (Enum.TryParse(element.GetAttributeString("colortransition", string.Empty), ignoreCase: true, out TransitionMode transition))
            {
                TransitionMode = transition;
            }
            if (Enum.TryParse(element.GetAttributeString("fallbackstate", GUIComponent.ComponentState.None.ToString()), ignoreCase: true, out SpriteFallBackState s))
            {
                FallBackState = s;
            }

            Font           = element.GetAttributeString("font", "");
            ForceUpperCase = element.GetAttributeBool("forceuppercase", false);

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    UISprite newSprite = new UISprite(subElement);

                    GUIComponent.ComponentState spriteState = GUIComponent.ComponentState.None;
                    if (subElement.Attribute("state") != null)
                    {
                        string stateStr = subElement.GetAttributeString("state", "None");
                        Enum.TryParse(stateStr, out spriteState);
                        Sprites[spriteState].Add(newSprite);
                        //use the same sprite for Hover and HoverSelected if latter is not specified
                        if (spriteState == GUIComponent.ComponentState.HoverSelected && !Sprites.ContainsKey(GUIComponent.ComponentState.HoverSelected))
                        {
                            Sprites[GUIComponent.ComponentState.HoverSelected].Add(newSprite);
                        }
                    }
                    else
                    {
                        foreach (GUIComponent.ComponentState state in Enum.GetValues(typeof(GUIComponent.ComponentState)))
                        {
                            Sprites[state].Add(newSprite);
                        }
                    }
                    break;

                case "size":
                    break;

                default:
                    string styleName = subElement.Name.ToString().ToLowerInvariant();
                    if (ChildStyles.ContainsKey(styleName))
                    {
                        DebugConsole.ThrowError("UI style \"" + element.Name.ToString() + "\" contains multiple child styles with the same name (\"" + styleName + "\")!");
                        ChildStyles[styleName] = new GUIComponentStyle(subElement, style);
                    }
                    else
                    {
                        ChildStyles.Add(styleName, new GUIComponentStyle(subElement, style));
                    }
                    break;
                }
            }

            GetSize(element);
        }
 public Sprite GetSprite(GUIComponent.ComponentState state)
 {
     return(Sprites.ContainsKey(state) ? Sprites[state]?.First()?.Sprite : null);
 }