示例#1
0
        private void GenerateWallVertices(XElement rootElement)
        {
            List <Vector2> points = new List <Vector2>();

            var wallPrefabs =
                MapEntityPrefab.list.FindAll(mp => (mp is StructurePrefab) && ((StructurePrefab)mp).HasBody);

            foreach (XElement element in rootElement.Elements())
            {
                if (element.Name != "Structure")
                {
                    continue;
                }

                string name = ToolBox.GetAttributeString(element, "name", "");
                if (!wallPrefabs.Any(wp => wp.Name == name))
                {
                    continue;
                }

                var rect = ToolBox.GetAttributeVector4(element, "rect", Vector4.Zero);

                points.Add(new Vector2(rect.X, rect.Y));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y));
                points.Add(new Vector2(rect.X, rect.Y - rect.W));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y - rect.W));
            }

            wallVertices = MathUtils.GiftWrap(points);
        }
示例#2
0
        public Sprite(XElement element, string path = "", string file = "")
        {
            if (file == "")
            {
                file = ToolBox.GetAttributeString(element, "texture", "");
            }

            if (file == "")
            {
                DebugConsole.ThrowError("Sprite " + element + " doesn't have a texture specified!");
                return;
            }

            if (!string.IsNullOrEmpty(path))
            {
                if (!path.EndsWith("/"))
                {
                    path += "/";
                }
            }

            this.file = path + file;

            texture = LoadTexture(this.file);

            if (texture == null)
            {
                return;
            }

            Vector4 sourceVector = ToolBox.GetAttributeVector4(element, "sourcerect", Vector4.Zero);

            if (sourceVector.Z == 0.0f)
            {
                sourceVector.Z = texture.Width;
            }
            if (sourceVector.W == 0.0f)
            {
                sourceVector.W = texture.Height;
            }

            sourceRect = new Rectangle(
                (int)sourceVector.X, (int)sourceVector.Y,
                (int)sourceVector.Z, (int)sourceVector.W);

            origin   = ToolBox.GetAttributeVector2(element, "origin", new Vector2(0.5f, 0.5f));
            origin.X = origin.X * sourceRect.Width;
            origin.Y = origin.Y * sourceRect.Height;

            size    = ToolBox.GetAttributeVector2(element, "size", Vector2.One);
            size.X *= sourceRect.Width;
            size.Y *= sourceRect.Height;

            Depth = ToolBox.GetAttributeFloat(element, "depth", 0.0f);

            list.Add(this);
        }
示例#3
0
        private Order(XElement orderElement)
        {
            Name      = ToolBox.GetAttributeString(orderElement, "name", "Name not found");
            DoingText = ToolBox.GetAttributeString(orderElement, "doingtext", "");

            string targetItemName = ToolBox.GetAttributeString(orderElement, "targetitemtype", "");

            if (!string.IsNullOrWhiteSpace(targetItemName))
            {
                try
                {
                    ItemComponentType = Type.GetType("Barotrauma.Items.Components." + targetItemName, true, true);
                }

                catch (Exception e)
                {
                    DebugConsole.ThrowError("Error in " + ConfigFile + ", item component type " + targetItemName + " not found", e);
                }
            }

            ItemName = ToolBox.GetAttributeString(orderElement, "targetitemname", "");

            Color = new Color(ToolBox.GetAttributeVector4(orderElement, "color", new Vector4(1.0f, 1.0f, 1.0f, 1.0f)));

            UseController = ToolBox.GetAttributeBool(orderElement, "usecontroller", false);

            string optionStr = ToolBox.GetAttributeString(orderElement, "options", "");

            if (string.IsNullOrWhiteSpace(optionStr))
            {
                Options = new string[0];
            }
            else
            {
                Options = optionStr.Split(',');

                for (int i = 0; i < Options.Length; i++)
                {
                    Options[i] = Options[i].Trim();
                }
            }



            foreach (XElement subElement in orderElement.Elements())
            {
                if (subElement.Name.ToString().ToLowerInvariant() != "sprite")
                {
                    continue;
                }
                SymbolSprite = new Sprite(subElement);
                break;
            }
        }
示例#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 = ToolBox.GetAttributeVector4(element, "padding", Vector4.Zero);

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

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

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

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

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

            colorVector  = ToolBox.GetAttributeVector4(element, "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 = ToolBox.GetAttributeBool(subElement, "maintainaspectratio", false);
                    bool   tile           = ToolBox.GetAttributeBool(subElement, "tile", true);

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

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

                    Vector4 sliceVec = ToolBox.GetAttributeVector4(subElement, "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;
                }
            }
        }