Esempio n. 1
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();
            int[] ShadowIndex = { 3, 4 };
            var   palette     = new Palette(FileSystem.Open(tileset.Palette), ShadowIndex);

            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 tc in tileset.Templates.GroupBy(t => t.Value.Category))
            {
                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 = 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. 2
0
        // this code is insanely stupid, and mostly my fault -- chrisf
        void PrepareMapResources(ModData modData, Map map)
        {
            Program.Rules = map.Rules;

            tileset         = Program.Rules.TileSets[map.Tileset];
            tilesetRenderer = new TileSetRenderer(tileset, modData.Manifest.TileSize);
            var shadowIndex = new int[] { 3, 4 };
            var palette     = new ImmutablePalette(GlobalFileSystem.Open(tileset.Palette), shadowIndex);

            // required for desert terrain in RA
            var playerPalette   = tileset.PlayerPalette ?? tileset.Palette;
            var shadowedPalette = new ImmutablePalette(GlobalFileSystem.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.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.Images[0], template.Id, template.Size.X, template.Size.Y));
                    }
                    catch { }
                }
            }

            var actorTemplates = new List <ActorTemplate>();

            foreach (var a in Program.Rules.Actors.Keys)
            {
                try
                {
                    var info = Program.Rules.Actors[a];
                    if (!info.Traits.Contains <ILegacyEditorRenderInfo>())
                    {
                        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 <ILegacyEditorRenderInfo>();

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

                    var race             = Program.Rules.Actors["world"].Traits.WithInterface <CountryInfo>().First().Race;
                    var sequenceProvider = Program.Rules.Sequences[tileset.Id];
                    var template         = RenderUtils.RenderActor(info, sequenceProvider, tileset, templatePalette, race);
                    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 Program.Rules.Actors["world"].Traits.WithInterface <ResourceTypeInfo>())
            {
                try
                {
                    var template = RenderUtils.RenderResourceType(a, tileset, 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.RenderMapPreview(tileset, 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();
        }
Esempio n. 3
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();
        }