Ejemplo n.º 1
0
        void MapList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (MapList.SelectedItems.Count == 1)
            {
                txtNew.Text = MapList.SelectedItems[0].Text;
                txtNew.Tag  = MapList.SelectedItems[0].Tag;

                var map = new Map(txtNew.Tag as string);
                txtTitle.Text   = map.Title;
                txtAuthor.Text  = map.Author;
                txtTheater.Text = map.Tileset;
                txtDesc.Text    = map.Description;
                pbMinimap.Image = null;

                try
                {
                    pbMinimap.Image = Minimap.AddStaticResources(map, Minimap.TerrainBitmap(map, true));
                }
                catch (Exception ed)
                {
                    Console.WriteLine("No map preview image found: {0}", ed.ToString());
                }
                finally { }
            }
        }
Ejemplo n.º 2
0
        void MapList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (MapList.SelectedItems.Count == 1)
            {
                NewText.Text = MapList.SelectedItems[0].Text;
                NewText.Tag  = MapList.SelectedItems[0].Tag;

                var map = new Map(NewText.Tag as string);
                TitleText.Text   = map.Title;
                AuthorText.Text  = map.Author;
                TheaterText.Text = map.Tileset;
                DescTxt.Text     = map.Description;
                MiniMapBox.Image = null;

                try
                {
                    MiniMapBox.Image = Minimap.AddStaticResources(map, Minimap.TerrainBitmap(map, true));
                }
                catch (Exception ed)
                {
                    Console.WriteLine("No map preview image found: {0}", ed);
                }
            }
        }
Ejemplo n.º 3
0
 void OnMapChanged()
 {
     MakeDirty();
     pmMiniMap.Image = Minimap.AddStaticResources(surface1.Map, Minimap.TerrainBitmap(surface1.Map, true));
     cashToolStripStatusLabel.Text = CalculateTotalResource().ToString();
 }
Ejemplo n.º 4
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);

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

            surface1.Bind(map, tileset, palette, PlayerPalette);
            // construct the palette of tiles
            var palettes = new[] { tilePalette, actorPalette, resourcePalette };

            foreach (var p in palettes)
            {
                p.Visible = false; p.SuspendLayout();
            }

            string[] 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 = 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 TemplatePalette = PlayerPalette;
                    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, PlayerPalette);
                    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;
            toolStripMenuItemProperties.Enabled = true;
            resizeToolStripMenuItem.Enabled     = true;
            toolStripMenuItemResize.Enabled     = true;
            saveToolStripMenuItem.Enabled       = true;
            toolStripMenuItemSave.Enabled       = true;
            saveAsToolStripMenuItem.Enabled     = true;
            mnuMinimapToPNG.Enabled             = true; // TODO: what is this VB naming bullshit doing here?

            PopulateActorOwnerChooser();
        }
Ejemplo n.º 5
0
 void OnMapChanged()
 {
     MakeDirty();
     pmMiniMap.Image = Minimap.AddStaticResources(surface1.Map, Minimap.TerrainBitmap(surface1.Map, true));
 }
Ejemplo n.º 6
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();
        }