Пример #1
0
        private static String DumpPalette(String Path)
        {
            var palette        = TextureTool.ExtractPaletteFromDirectoryRecursive(Path);
            var paletteTexture = TextureTool.Texture2DFromMemoryTexture(DwarfGame.GuiSkin.Device, TextureTool.MemoryTextureFromPalette(palette));

            paletteTexture.SaveAsPng(System.IO.File.OpenWrite("palette.png"), paletteTexture.Width, paletteTexture.Height);
            return("Dumped.");
        }
Пример #2
0
 public OverworldMap()
 {
     BiomeBlend = TextureTool.MemoryTextureFromTexture2D(AssetManager.GetContentTexture("World\\biome-blend"));
     if (BiomeBlend == null || BiomeBlend.Width != VoxelConstants.ChunkSizeX || BiomeBlend.Height != VoxelConstants.ChunkSizeZ)
     {
         BiomeBlend = new MemoryTexture(VoxelConstants.ChunkSizeX, VoxelConstants.ChunkSizeZ);
     }
 }
Пример #3
0
        public static List <PhotoshopLayer> LoadPSD(System.IO.FileStream Stream)
        {
            var psd = new PhotoshopFile.PsdFile(Stream, new PhotoshopFile.LoadContext());
            var r   = new List <PhotoshopLayer>();

            foreach (var layer in psd.Layers)
            {
                var entry = new PhotoshopLayer();
                entry.LayerName = layer.Name;

                // Need to expand the PSD layer to the size of the image as transparent rows/columns are trimmed off in PSD.
                entry.Data = new MemoryTexture(psd.ColumnCount, psd.RowCount);
                TextureTool.Blit(PSDLayerToMemoryTexture(layer), new Rectangle(0, 0, layer.Rect.Width, layer.Rect.Height), entry.Data, new Point(layer.Rect.X, layer.Rect.Y));

                r.Add(entry);
            }

            return(r);
        }
        private static MemoryTexture _GetResourceTexture(GraphicsDevice Device, ResourceType.GuiGraphic Graphic)
        {
            MemoryTexture r        = null;
            var           rawAsset = AssetManager.GetContentTexture(Graphic.AssetPath);

            if (Graphic.Palette != "None" && DwarfSprites.LayerLibrary.FindPalette(Graphic.Palette).HasValue(out var palette))
            {
                r = TextureTool.CropAndColorSprite(Device, rawAsset, Graphic.FrameSize, Graphic.Frame, DwarfSprites.LayerLibrary.BasePalette.CachedPalette, palette.CachedPalette);
            }
            else
            {
                r = TextureTool.CropSprite(Device, rawAsset, Graphic.FrameSize, Graphic.Frame);
            }

            if (Graphic.NextLayer != null)
            {
                TextureTool.AlphaBlit(_GetResourceTexture(Device, Graphic.NextLayer), new Rectangle(0, 0, Graphic.NextLayer.FrameSize.X, Graphic.NextLayer.FrameSize.Y),
                                      r, new Point(0, 0));
            }
            return(r);
        }
Пример #5
0
        private int[,] CellMap; // Todo: Reconstruct on deserialize; do not save!

        public CellSet(String Filename)
        {
            var texture    = AssetManager.GetContentTexture(Filename);
            var rawTexture = TextureTool.MemoryTextureFromTexture2D(texture);

            var cells = new Dictionary <Color, Rectangle>();

            for (var x = 0; x < rawTexture.Width; ++x)
            {
                for (var y = 0; y < rawTexture.Height; ++y)
                {
                    var c = rawTexture.Data[rawTexture.Index(x, y)];
                    if (!cells.ContainsKey(c))
                    {
                        cells.Add(c, new Rectangle(x, y, 1, 1));
                    }
                    else
                    {
                        var r = cells[c];
                        if (x >= r.X + r.Width)
                        {
                            r = new Rectangle(r.X, r.Y, x - r.X + 1, r.Height);
                        }
                        if (y >= r.Y + r.Height)
                        {
                            r = new Rectangle(r.X, r.Y, r.Width, y - r.Y + 1);
                        }
                        cells[c] = r;
                    }
                }
            }

            Cells = cells.Values.Select(r => new ColonyCell {
                Bounds = r
            }).ToList();

            InitializeCellMap();
        }
 public static Texture2D GetResourceTexture(GraphicsDevice Device, ResourceType.GuiGraphic Graphic)
 {
     return(TextureTool.Texture2DFromMemoryTexture(Device, _GetResourceTexture(Device, Graphic)));
 }
Пример #7
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            if (Resource.Gui_NewStyle)
            {
                var       sheetName          = String.Format("{0}&{1}-{2}&{3}", Resource.Gui_Graphic.AssetPath, Resource.Gui_Graphic.Frame.X, Resource.Gui_Graphic.Frame.Y, Resource.Gui_Palette);
                var       tiledInstanceGroup = Manager.World.Renderer.InstanceRenderer.GetCombinedTiledInstance();
                Texture2D fixedTex           = null;
                if (!tiledInstanceGroup.DoesInstanceSheetExist(sheetName))
                {
                    if (DwarfSprites.LayerLibrary.FindPalette(Resource.Gui_Palette).HasValue(out var palette))
                    {
                        fixedTex = TextureTool.CropAndColorSprite(manager.World.Renderer.GraphicsDevice, AssetManager.GetContentTexture(Resource.Gui_Graphic.AssetPath),
                                                                  Resource.Gui_Graphic.FrameSize, Resource.Gui_Graphic.Frame, DwarfSprites.LayerLibrary.BasePalette.CachedPalette, palette.CachedPalette);
                    }
                }

                var sheet = new SpriteSheet(fixedTex)
                {
                    FrameWidth  = Resource.Gui_Graphic.FrameSize.X,
                    FrameHeight = Resource.Gui_Graphic.FrameSize.Y,
                    AssetName   = sheetName
                };

                var sprite = AddChild(new SimpleBobber(Manager, "Sprite", Matrix.CreateTranslation(Vector3.UnitY * 0.25f), sheet, Point.Zero, 0.15f,
                                                       MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)) as Tinter;
                sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                sprite.LightRamp      = Resource.Tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
            else
            {
                var compositeLayers = Resource.CompositeLayers;
                var tint            = Resource.Tint;

                Tinter sprite = null;

                // Minor optimization for single layer resources.
                if (compositeLayers.Count == 1)
                {
                    var layer = compositeLayers[0];
                    sprite = AddChild(new SimpleBobber(Manager, "Sprite",
                                                       Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                       new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                                                       layer.Frame, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = SimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                    sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                }
                else
                {
                    var layers = new List <LayeredSimpleSprite.Layer>();

                    foreach (var layer in compositeLayers)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                            Frame = layer.Frame
                        });
                    }

                    sprite = AddChild(new LayeredBobber(Manager, "Sprite",
                                                        Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f),
                                                        layers, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                }

                sprite.LightRamp = tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
        }