Esempio n. 1
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var ri = info.Traits.Get<RenderSimpleInfo>();
            string image = null;
            if (ri.OverrideTheater != null)
                for (int i = 0; i < ri.OverrideTheater.Length; i++)
                    if (ri.OverrideTheater[i] == tileset.Id)
                        image = ri.OverrideImage[i];

            image = image ?? ri.Image ?? info.Name;
            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = FileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2 = new ShpReader(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
            }
        }
Esempio n. 2
0
        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, TileSet tileset, IPalette p)
        {
            var image = ResolveFilename(info.EditorSprite, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                // TODO: Do this properly
                var shp = new ShpTDSprite(s);
                var frame = shp.Frames.Last();

                var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    var q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < frame.Size.Width; i++)
                        for (var j = 0; j < frame.Size.Height; j++)
                            q[j * stride + i] = frame.Data[i + frame.Size.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count - 1 };
            }
        }
Esempio n. 3
0
        public static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p)
        {
            var template = ts.Templates[n];
            var tile = ts.Tiles[n];

            var bitmap = new Bitmap(ts.TileSize * template.Size.X, ts.TileSize * template.Size.Y);
            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            unsafe
            {
                int* q = (int*)data.Scan0.ToPointer();
                var stride = data.Stride >> 2;

                for (var u = 0; u < template.Size.X; u++)
                    for (var v = 0; v < template.Size.Y; v++)
                        if (tile.TileBitmapBytes[u + v * template.Size.X] != null)
                        {
                            var rawImage = tile.TileBitmapBytes[u + v * template.Size.X];
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = p.GetColor(rawImage[i + ts.TileSize * j]).ToArgb();
                        }
                        else
                        {
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = Color.Transparent.ToArgb();
                        }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Esempio n. 4
0
        static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var ri = info.Traits.Get<RenderSimpleInfo>();
            string image = null;
            if (ri.OverrideTheater != null)
                for (int i = 0; i < ri.OverrideTheater.Length; i++)
                    if (ri.OverrideTheater[i] == tileset.Id)
                        image = ri.OverrideImage[i];

            image = image ?? ri.Image ?? info.Name;
            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var frame = shp[0];

                var bitmap = new Bitmap(shp.Width, shp.Height);
                var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                unsafe
                {
                    int* q = (int*)data.Scan0.ToPointer();
                    var stride = data.Stride >> 2;

                    for (var i = 0; i < shp.Width; i++)
                        for (var j = 0; j < shp.Height; j++)
                            q[j * stride + i] = p.GetColor(frame.Image[i + shp.Width * j]).ToArgb();
                }

                bitmap.UnlockBits(data);
                return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
            }
        }
Esempio n. 5
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var image = RenderSimple.GetImage(info, tileset.Id);

            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp = new ShpReader(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = FileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2 = new ShpReader(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
 protected TerrainTemplatePreviewWidget(TerrainTemplatePreviewWidget other)
     : base(other)
 {
     worldRenderer = other.worldRenderer;
     tileset = other.worldRenderer.World.Map.Rules.TileSets[other.worldRenderer.World.Map.Tileset];
     Template = other.Template;
     GetScale = other.GetScale;
 }
Esempio n. 7
0
		public void Bind(Map m, TileSet ts, Palette p)
		{
			Map = m;
			TileSet = ts;
			Palette = p;
			Brush = null;
			Chunks.Clear();
		}
Esempio n. 8
0
		public void Bind(Map m, TileSet ts, Palette p)
		{
			Map = m;
			TileSet = ts;
			Palette = p;
			PlayerPalettes = null;
			Chunks.Clear();
			Tool = null;
		}
Esempio n. 9
0
        public TileSetRenderer(TileSet tileset, Size tileSize)
        {
            this.TileSet = tileset;
            this.TileSize = tileSize;

            templates = new Dictionary<ushort, List<byte[]>>();
            var r8cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8")));
            foreach (var t in TileSet.Templates)
                templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, r8cache, t.Value.Frames));
        }
Esempio n. 10
0
        public TileSetRenderer(TileSet tileset, Size tileSize)
        {
            this.TileSet = tileset;
            this.TileSize = tileSize;

            templates = new Dictionary<ushort, List<byte[]>>();
            var sourceCache = new Dictionary<string, ISpriteSource>();
            foreach (var t in TileSet.Templates)
                templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, sourceCache, t.Value.Frames));
        }
Esempio n. 11
0
		public void Bind(Map m, TileSet ts, TileSetRenderer tsr, Palette p, Palette pp)
		{
			Map = m;
			TileSet = ts;
			TileSetRenderer = tsr;
			Palette = p;
			PlayerPalette = pp;
			playerPalettes = null;
			Chunks.Clear();
			currentTool = null;
		}
Esempio n. 12
0
        public static ActorTemplate RenderActor(ActorInfo info, SequenceProvider sequenceProvider, TileSet tileset, IPalette p, string race)
        {
            var image = info.Traits.Get<ILegacyEditorRenderInfo>().EditorImage(info, sequenceProvider, race);
            image = ResolveFilename(image, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                var shp = new ShpTDSprite(s);
                var bitmap = RenderShp(shp, p);

                return new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
                };
            }
        }
Esempio n. 13
0
        public Theater(TileSet tileset)
        {
            var allocated = false;
            Func<Sheet> allocate = () =>
            {
                if (allocated)
                    throw new SheetOverflowException("Terrain sheet overflow. Try increasing the tileset SheetSize parameter.");
                allocated = true;

                return new Sheet(new Size(tileset.SheetSize, tileset.SheetSize));
            };

            var r8Cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8")));
            templates = new Dictionary<ushort, Sprite[]>();
            sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);
            foreach (var t in tileset.Templates)
                templates.Add(t.Value.Id, LoadTemplate(t.Value.Image, tileset.Extensions, r8Cache, t.Value.Frames));

            // 1x1px transparent tile
            missingTile = sheetBuilder.Add(new byte[1], new Size(1, 1));
        }
Esempio n. 14
0
        public static Bitmap RenderTemplate(TileSet ts, ushort n, Palette p)
        {
            var template = ts.Templates[n];
            var tile = ts.Tiles[n];

            var bitmap = new Bitmap(ts.TileSize * template.Size.X, ts.TileSize * template.Size.Y,
                PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                byte* q = (byte*)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                    for (var v = 0; v < template.Size.Y; v++)
                        if (tile.TileBitmapBytes[u + v * template.Size.X] != null)
                        {
                            var rawImage = tile.TileBitmapBytes[u + v * template.Size.X];
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = rawImage[i + ts.TileSize * j];
                        }
                        else
                        {
                            for (var i = 0; i < ts.TileSize; i++)
                                for (var j = 0; j < ts.TileSize; j++)
                                    q[(v * ts.TileSize + j) * stride + u * ts.TileSize + i] = 0;
                        }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
Esempio n. 15
0
		void IntializeTilePreview(Widget widget, WorldRenderer worldRenderer, TileSet tileset, string category)
		{
			panel.RemoveChildren();

			var tileIds = tileset.Templates
				.Where(t => t.Value.Category == category)
				.Select(t => t.Value.Id);

			foreach (var t in tileIds)
			{
				var tileId = t;
				var item = ScrollItemWidget.Setup(itemTemplate,
					() => { var brush = editor.CurrentBrush as EditorTileBrush; return brush != null && brush.Template == tileId; },
					() => editor.SetBrush(new EditorTileBrush(editor, tileId, worldRenderer)));

				var preview = item.Get<TerrainTemplatePreviewWidget>("TILE_PREVIEW");
				var template = tileset.Templates[tileId];
				var grid = worldRenderer.World.Map.Grid;
				var bounds = worldRenderer.Theater.TemplateBounds(template, grid.TileSize, grid.Type);

				// Scale templates to fit within the panel
				var scale = 1f;
				while (scale * bounds.Width > itemTemplate.Bounds.Width)
					scale /= 2;

				preview.Template = template;
				preview.GetScale = () => scale;
				preview.Bounds.Width = (int)(scale * bounds.Width);
				preview.Bounds.Height = (int)(scale * bounds.Height);

				item.Bounds.Width = preview.Bounds.Width + 2 * preview.Bounds.X;
				item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;
				item.IsVisible = () => true;
				item.GetTooltipText = () => tileId.ToString();

				panel.AddChild(item);
			}
		}
Esempio n. 16
0
        // this code is insanely stupid, and mostly my fault -- chrisf
        void PrepareMapResources(Manifest manifest, Map map)
        {
            Rules.LoadRules(manifest, map);
            tileset = Rules.TileSets[map.Tileset];
            tileset.LoadTiles();
            var palette = new Palette(FileSystem.Open(tileset.Palette), true);

            surface1.Bind(map, tileset, palette);
            // construct the palette of tiles
            var palettes = new[] { tilePalette, actorPalette, resourcePalette };
            foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); }
            foreach (var t in tileset.Templates)
            {
                try
                {
                    var bitmap = tileset.RenderTemplate((ushort)t.Key, palette);
                    var ibox = new PictureBox
                    {
                        Image = bitmap,
                        Width = bitmap.Width / 2,
                        Height = bitmap.Height / 2,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key };
                    ibox.Click += (_, e) => surface1.SetTool(new BrushTool(brushTemplate));

                    var template = t.Value;
                    tilePalette.Controls.Add(ibox);
                    tt.SetToolTip(ibox,
                        "{1}:{0} ({2}x{3})".F(
                        template.Image,
                        template.Id,
                        template.Size.X,
                        template.Size.Y));
                }
                catch { }
            }

            var actorTemplates = new List<ActorTemplate>();

            foreach (var a in Rules.Info.Keys)
            {
                try
                {
                    var info = Rules.Info[a];
                    if (!info.Traits.Contains<RenderSimpleInfo>()) continue;

                    var etf = info.Traits.GetOrDefault<EditorTilesetFilterInfo>();
                    if (etf != null && etf.ExcludeTilesets != null
                        && etf.ExcludeTilesets.Contains(tileset.Id)) continue;
                    if (etf != null && etf.RequireTilesets != null
                        && !etf.RequireTilesets.Contains(tileset.Id)) continue;

                    var template = RenderUtils.RenderActor(info, tileset, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = 32,
                        Height = 32,
                        SizeMode = PictureBoxSizeMode.Zoom,
                        BorderStyle = BorderStyle.FixedSingle
                    };

                    ibox.Click += (_, e) => surface1.SetTool(new ActorTool(template));

                    actorPalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}".F(
                        info.Name));

                    actorTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindActorTemplates(actorTemplates);

            var resourceTemplates = new List<ResourceTemplate>();

            foreach (var a in Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>())
            {
                try
                {
                    var template = RenderUtils.RenderResourceType(a, tileset.Extensions, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = 32,
                        Height = 32,
                        SizeMode = PictureBoxSizeMode.Zoom,
                        BorderStyle = BorderStyle.FixedSingle
                    };

                    ibox.Click += (_, e) => surface1.SetTool(new ResourceTool(template));

                    resourcePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}:{1}cr".F(
                        template.Info.Name,
                        template.Info.ValuePerUnit));

                    resourceTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindResourceTemplates(resourceTemplates);

            foreach (var p in palettes)
            {
                p.Visible = true;
                p.ResumeLayout();
            }

            pmMiniMap.Image = Minimap.AddStaticResources(surface1.Map, Minimap.TerrainBitmap(surface1.Map, true));

            propertiesToolStripMenuItem.Enabled = true;
            resizeToolStripMenuItem.Enabled = true;
            saveToolStripMenuItem.Enabled = true;
            saveAsToolStripMenuItem.Enabled = true;
            mnuMinimapToPNG.Enabled = true;	// todo: what is this VB naming bullshit doing here?

            PopulateActorOwnerChooser();
        }
Esempio n. 17
0
        void ExportClicked(object sender, EventArgs e)
        {
            var dir = Path.Combine(Path.GetDirectoryName(srcfile), "output");
            Directory.CreateDirectory(dir);

            // Create a Tileset definition
            // Todo: Pull this info from the gui
            var tilesetFile = "tileset-arrakis.yaml";
            var mixFile = "arrakis.mix";
            var tileset = new TileSet()
            {
                Name = "Arrakis",
                Id = "ARRAKIS",
                Palette = "arrakis.pal",
                Extensions = new string[] {".arr", ".shp"}
            };

            // List of files to add to the mix file
            List<string> fileList = new List<string>();

            // Export palette (use the embedded palette)
            var p = surface1.Image.Palette.Entries.ToList();
            fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));

            // Export tile artwork
            foreach (var t in surface1.Templates)
                fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tileset.Extensions.First(), dir));

            // Add the terraintypes
            // Todo: add support for multiple/different terraintypes
            var terraintype = new TerrainTypeInfo()
            {
                Type = "clear",
                Buildable = true,
                AcceptSmudge = true,
                IsWater = false,
                Color = Color.White
            };
            tileset.Terrain.Add("clear", terraintype);

            // Add the templates
            ushort cur = 0;
            foreach (var tp in surface1.Templates)
            {
                var template = new TileTemplate()
                {
                    Id = cur,
                    Image = "t{0:00}".F(cur),
                    Size = new int2(tp.Width,tp.Height),
                };

                // Todo: add support for different terraintypes
                // Todo: restrict cells? this doesn't work: .Where( c => surface1.TerrainTypes[c.Key.X, c.Key.Y] != 0 )
                foreach (var t in tp.Cells)
                    template.Tiles.Add((byte)((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top)), "clear");

                tileset.Templates.Add(cur, template);
                cur++;
            }

            tileset.Save(Path.Combine(dir, tilesetFile));
            PackageWriter.CreateMix(Path.Combine(dir, mixFile),fileList);

            // Cleanup
            foreach (var file in fileList)
                File.Delete(file);

            Console.WriteLine("Finished export");
        }
Esempio n. 18
0
 public static void Initialize( TileSet tileset )
 {
     exts = tileset.Extensions;
     sprites = new Cache<string, Sprite[]>( LoadSprites );
 }
Esempio n. 19
0
        public SequenceCache(ModData modData, TileSet tileSet)
        {
            this.modData = modData;

            spriteLoader = Exts.Lazy(() => new SpriteLoader(tileSet.Extensions, new SheetBuilder(SheetType.Indexed)));
        }
Esempio n. 20
0
        public void Export(string OutputDir)
        {
            var dir = Path.Combine(Path.GetDirectoryName(srcfile), Platform.SupportDir+OutputDir);
            Directory.CreateDirectory(dir);
            var tilesetName = txtTilesetName.Text;
            var tilesetID = txtID.Text;
            var tilesetPalette = txtPal.Text;
            var tilesetExt = txtExt.Text;

            if (tilesetName.Length < 1) { tilesetName = "Temperat"; }
            if (tilesetID.Length < 1) { tilesetID = "TEMPERAT"; }
            if (tilesetPalette.Length < 1) { tilesetPalette = "temperat"; }
            if (tilesetExt.Length < 1) { tilesetExt = ".tem,.shp"; }
            // Create a Tileset definition
            // TODO: Pull this info from the GUI
            var tilesetFile = "";
            //var mixFile = "";
            tilesetFile = tilesetName.ToLower();
            if (tilesetFile.Length < 8)
            {
                tilesetFile = tilesetName.ToLower() + ".yaml";
                //mixFile = tilesetName.ToLower() + ".mix";
            }
            else
            {
                tilesetFile = tilesetName.ToLower().Substring(0, 8) + ".yaml";
                //mixFile = tilesetName.ToLower().Substring(0, 8) + ".mix";
            }

            string[] Ext = tilesetExt.Split(',');
            var tileset = new TileSet()
            {
                Name = tilesetName,
                Id = tilesetID.ToUpper(),
                TileSize = size,
                Palette = tilesetPalette.ToLower(),
                Extensions = new string[] { Ext[0], Ext[1] }
            };

            // List of files to add to the mix file
            List<string> fileList = new List<string>();

            // Export palette (use the embedded palette)
            var p = surface1.Image.Palette.Entries.ToList();
            fileList.Add(ExportPalette(p, Path.Combine(dir, tileset.Palette)));

            // Export tile artwork
            foreach (var t in surface1.Templates)
                fileList.Add(ExportTemplate(t, surface1.Templates.IndexOf(t), tileset.Extensions.First(), dir));

            // Add the terraintypes
            foreach (var tt in TerrainType)
            {
                tileset.Terrain.Add(tt.Type, tt);
            }

            // Add the templates
            ushort cur = 0;
            foreach (var tp in surface1.Templates)
            {
                var template = new TileTemplate()
                {
                    Id = cur,
                    Image = "{0}{1:00}".F(txtTilesetName.Text, cur),
                    Size = new int2(tp.Width,tp.Height),
                };

                foreach (var t in tp.Cells)
                {
                    string ttype = "Clear";
                    ttype = TerrainType[surface1.TerrainTypes[t.Key.X, t.Key.Y]].Type;
                    var idx = ((t.Key.X - tp.Left) + tp.Width * (t.Key.Y - tp.Top));
                    template.Tiles.Add((byte)idx, ttype);
                }

                tileset.Templates.Add(cur, template);
                cur++;
            }

            tileset.Save(Path.Combine(dir, tilesetFile));
            //throw new NotImplementedException("NotI");
            //PackageWriter.CreateMix(Path.Combine(dir, mixFile),fileList);

            // Cleanup
            //foreach (var file in fileList)
                //File.Delete(file);

            Console.WriteLine("Finished export");
        }
Esempio n. 21
0
        // this code is insanely stupid, and mostly my fault -- chrisf
        void PrepareMapResources(Manifest manifest, Map map)
        {
            Rules.LoadRules(manifest, map);
            tileset = Rules.TileSets[map.Tileset];
            tilesetRenderer = new TileSetRenderer(tileset, new Size(manifest.TileSize, manifest.TileSize));
            var shadowIndex = new int[] { 3, 4 };
            var palette = new Palette(FileSystem.Open(tileset.Palette), shadowIndex);

            // required for desert terrain in RA
            var playerPalette = tileset.PlayerPalette ?? tileset.Palette;
            var shadowedPalette = new Palette(FileSystem.Open(playerPalette), shadowIndex);

            surface1.Bind(map, tileset, tilesetRenderer, palette, shadowedPalette);

            // construct the palette of tiles
            var palettes = new[] { tilePalette, actorPalette, resourcePalette };
            foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); }

            var templateOrder = tileset.EditorTemplateOrder ?? new string[] { };
            foreach (var tc in tileset.Templates.GroupBy(t => t.Value.Category).OrderBy(t => templateOrder.ToList().IndexOf(t.Key)))
            {
                var category = tc.Key ?? "(Uncategorized)";
                var categoryHeader = new Label
                {
                    BackColor = SystemColors.Highlight,
                    ForeColor = SystemColors.HighlightText,
                    Text = category,
                    AutoSize = false,
                    Height = 24,
                    TextAlign = ContentAlignment.MiddleLeft,
                    Width = tilePalette.ClientSize.Width,
                };

                // hook this manually, anchoring inside FlowLayoutPanel is flaky.
                tilePalette.Resize += (_, e) => categoryHeader.Width = tilePalette.ClientSize.Width;

                if (tilePalette.Controls.Count > 0)
                    tilePalette.SetFlowBreak(
                        tilePalette.Controls[tilePalette.Controls.Count - 1], true);
                tilePalette.Controls.Add(categoryHeader);

                foreach (var t in tc)
                {
                    try
                    {
                        var bitmap = tilesetRenderer.RenderTemplate((ushort)t.Key, palette);
                        var ibox = new PictureBox
                        {
                            Image = bitmap,
                            Width = bitmap.Width / 2,
                            Height = bitmap.Height / 2,
                            SizeMode = PictureBoxSizeMode.StretchImage
                        };

                        var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key };
                        ibox.Click += (_, e) => surface1.SetTool(new BrushTool(brushTemplate));

                        var template = t.Value;
                        tilePalette.Controls.Add(ibox);
                        tt.SetToolTip(ibox, "{1}:{0} ({2}x{3})".F(template.Image, template.Id, template.Size.X, template.Size.Y));
                    }
                    catch { }
                }
            }

            var actorTemplates = new List<ActorTemplate>();

            foreach (var a in Rules.Info.Keys)
            {
                try
                {
                    var info = Rules.Info[a];
                    if (!info.Traits.Contains<RenderSimpleInfo>()) continue;

                    var etf = info.Traits.GetOrDefault<EditorTilesetFilterInfo>();
                    if (etf != null && etf.ExcludeTilesets != null
                        && etf.ExcludeTilesets.Contains(tileset.Id)) continue;
                    if (etf != null && etf.RequireTilesets != null
                        && !etf.RequireTilesets.Contains(tileset.Id)) continue;

                    var templatePalette = shadowedPalette;
                    var rsi = info.Traits.GetOrDefault<RenderSimpleInfo>();

                    // exception for desert buildings
                    if (rsi != null && rsi.Palette != null && rsi.Palette.Contains("terrain"))
                        templatePalette = palette;

                    var template = RenderUtils.RenderActor(info, tileset, templatePalette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = 32,
                        Height = 32,
                        SizeMode = PictureBoxSizeMode.Zoom,
                        BorderStyle = BorderStyle.FixedSingle
                    };

                    ibox.Click += (_, e) => surface1.SetTool(new ActorTool(template));

                    actorPalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox, "{0}".F(info.Name));

                    actorTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindActorTemplates(actorTemplates);

            var resourceTemplates = new List<ResourceTemplate>();

            foreach (var a in Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>())
            {
                try
                {
                    var template = RenderUtils.RenderResourceType(a, tileset.Extensions, shadowedPalette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = 32,
                        Height = 32,
                        SizeMode = PictureBoxSizeMode.Zoom,
                        BorderStyle = BorderStyle.FixedSingle
                    };

                    ibox.Click += (_, e) => surface1.SetTool(new ResourceTool(template));

                    resourcePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox, "{0}:{1}cr".F(template.Info.Name, template.Info.ValuePerUnit));

                    resourceTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindResourceTemplates(resourceTemplates);

            foreach (var p in palettes)
            {
                p.Visible = true;
                p.ResumeLayout();
            }

            miniMapBox.Image = Minimap.AddStaticResources(surface1.Map, Minimap.TerrainBitmap(surface1.Map, true));

            propertiesToolStripMenuItem.Enabled = true;
            toolStripMenuItemProperties.Enabled = true;
            resizeToolStripMenuItem.Enabled = true;
            toolStripMenuItemResize.Enabled = true;
            saveToolStripMenuItem.Enabled = true;
            toolStripMenuItemSave.Enabled = true;
            saveAsToolStripMenuItem.Enabled = true;
            miniMapToPng.Enabled = true;

            PopulateActorOwnerChooser();
        }
 public TerrainTemplatePreviewWidget(WorldRenderer worldRenderer, World world)
 {
     this.worldRenderer = worldRenderer;
     tileset = world.Map.Rules.TileSets[world.Map.Tileset];
 }
Esempio n. 23
0
        void PrepareMapResources(Manifest manifest, Map map)
        {
            Rules.LoadRules(manifest, map);
            tileset = Rules.TileSets[map.Theater];
            tileset.LoadTiles();
            var palette = new Palette(FileSystem.Open(tileset.Palette), true);

            surface1.Bind(map, tileset, palette);

            // construct the palette of tiles
            var palettes = new[] { tilePalette, actorPalette, resourcePalette };
            foreach (var p in palettes) { p.Visible = false; p.SuspendLayout(); }

            foreach (var t in tileset.Templates)
            {
                try
                {
                    var bitmap = RenderTemplate(tileset, (ushort)t.Key, palette);
                    var ibox = new PictureBox
                    {
                        Image = bitmap,
                        Width = bitmap.Width / 2,
                        Height = bitmap.Height / 2,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    var brushTemplate = new BrushTemplate { Bitmap = bitmap, N = t.Key };
                    ibox.Click += (_, e) => surface1.SetBrush(brushTemplate);

                    var template = t.Value;
                    tilePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{1}:{0} ({2}x{3})".F(
                        template.Image,
                        template.Id,
                        template.Size.X,
                        template.Size.Y));
                }
                catch { }
            }

            var actorTemplates = new List<ActorTemplate>();

            foreach (var a in Rules.Info.Keys)
            {
                try
                {
                    var info = Rules.Info[a];
                    if( !info.Traits.Contains<RenderSimpleInfo>() ) continue;
                    var template = RenderActor(info, tileset, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = template.Bitmap.Width / 2,
                        Height = template.Bitmap.Height / 2,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    ibox.Click += (_, e) => surface1.SetActor(template);

                    actorPalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}:{1}".F(
                        info.Name,
                        info.Category));

                    actorTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindActorTemplates(actorTemplates);

            var resourceTemplates = new List<ResourceTemplate>();

            foreach (var a in Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>())
            {
                try
                {
                    var template = RenderResourceType(a, tileset.Extensions, palette);
                    var ibox = new PictureBox
                    {
                        Image = template.Bitmap,
                        Width = template.Bitmap.Width,
                        Height = template.Bitmap.Height,
                        SizeMode = PictureBoxSizeMode.StretchImage
                    };

                    ibox.Click += (_, e) => surface1.SetResource(template);

                    resourcePalette.Controls.Add(ibox);

                    tt.SetToolTip(ibox,
                        "{0}:{1}cr".F(
                        template.Info.Name,
                        template.Info.ValuePerUnit));

                    resourceTemplates.Add(template);
                }
                catch { }
            }

            surface1.BindResourceTemplates(resourceTemplates);

            foreach (var p in palettes) { p.Visible = true; p.ResumeLayout(); }
        }
Esempio n. 24
0
        static string ResolveFilename(string name, TileSet tileSet)
        {
            var ssl = Game.ModData.SpriteSequenceLoader as TilesetSpecificSpriteSequenceLoader;
            var extensions = ssl != null ? new[] { ssl.TilesetExtensions[tileSet.Id], ssl.DefaultSpriteExtension }.Append(LegacyExtensions) :
                LegacyExtensions.AsEnumerable();

            foreach (var e in extensions)
                if (GlobalFileSystem.Exists(name + e))
                    return name + e;

            return name;
        }