public void Init(Manifest m, Dictionary<string, string> info)
 {
     var sheet = new Sheet("mods/modchooser/chrome.png");
     var res = Game.Renderer.Resolution;
     bounds = new Rectangle(0, 0, res.Width, res.Height);
     sprite = new Sprite(sheet, new Rectangle(0,0,1024,480), TextureChannel.Alpha);
 }
Beispiel #2
0
        public FileExtractor(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("usage: FileExtractor mod[,mod]* filename");
                return;
            }

            var mods = args[0].Split(',');
            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest( manifest );

            try
            {
                var readStream = FileSystem.Open(args[1]);
                var writeStream = new FileStream(args[1], FileMode.OpenOrCreate, FileAccess.Write);

                WriteOutFile(readStream, writeStream);

            }
            catch (FileNotFoundException)
            {
                Console.WriteLine(String.Format("No Such File {0}", args[1]));
            }
        }
Beispiel #3
0
        public static void LoadFromManifest(Manifest manifest)
        {
            UnmountAll();
            foreach (var dir in manifest.Folders)
                Mount(dir);

            foreach (var pkg in manifest.Packages)
                Mount(pkg.Key, pkg.Value);
        }
        public void Init(Manifest m, Dictionary<string, string> info)
        {
            this.info = info;

            // Avoid standard loading mechanisms so we
            // can display the loadscreen as early as possible
            r = Game.Renderer;
            if (r == null)
                return;

            messages = info["Text"].Split(',');
            var s = new Sheet(info["Image"]);
            logo = new Sprite(s, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha);
            stripe = new Sprite(s, new Rectangle(256, 0, 256, 256), TextureChannel.Alpha);
            stripeRect = new Rectangle(0, r.Resolution.Height / 2 - 128, r.Resolution.Width, 256);
            logoPos = new float2(r.Resolution.Width / 2 - 128, r.Resolution.Height / 2 - 128);
        }
        // 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();
        }
Beispiel #6
0
        public static void ExtractFiles(string[] args)
        {
            var mod = args[1];
            var files = args.Skip(2);

            var manifest = new Manifest(mod);
            GlobalFileSystem.LoadFromManifest(manifest);

            foreach (var f in files)
            {
                var src = GlobalFileSystem.Open(f);
                if (src == null)
                    throw new InvalidOperationException("File not found: {0}".F(f));
                var data = src.ReadAllBytes();
                File.WriteAllBytes(f, data);
                Console.WriteLine(f + " saved.");
            }
        }
Beispiel #7
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 static void ConvertTmpToPng(string[] args)
        {
            var mods = args[1].Split(',');
            var theater = args[2];
            var templateNames = args.Skip(3);

            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest(manifest);

            var tileset = manifest.TileSets.Select( a => new TileSet(a) )
                .FirstOrDefault( ts => ts.Name == theater );

            if (tileset == null)
                throw new InvalidOperationException("No theater named '{0}'".F(theater));

            tileset.LoadTiles();
            var palette = new Palette(FileSystem.Open(tileset.Palette), true);

            foreach( var templateName in templateNames )
            {
                var template = tileset.Templates.FirstOrDefault(tt => tt.Value.Image == templateName);
                if (template.Value == null)
                    throw new InvalidOperationException("No such template '{0}'".F(templateName));

                using( var image = tileset.RenderTemplate(template.Value.Id, palette) )
                    image.Save( Path.ChangeExtension( templateName, ".png" ) );
            }
        }
Beispiel #9
0
 public void Init(Manifest m, Dictionary<string, string> info)
 {
 }
Beispiel #10
0
        static void Main( string[] args )
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length != 3)
            {
                MessageBox.Show( "usage: SequenceEditor mod[,mod]* sequences-file.xml palette.pal");
                return;
            }

            var mods = args[0].Split(',');
            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest( manifest );

            XmlFilename = args[1];
            Doc = new XmlDocument();
            Doc.Load(XmlFilename);

            var tempPal = new Palette(FileSystem.Open(args[2]), true);
            Pal = tempPal;

            UnitName = GetTextForm.GetString("Unit to edit?", "e1");
            if (string.IsNullOrEmpty(UnitName))
                return;

            LoadAndResolve(UnitName);

            var xpath = string.Format("//unit[@name=\"{0}\"]/sequence", UnitName);
            foreach (XmlElement e in Doc.SelectNodes(xpath))
            {
                if (e.HasAttribute("src"))
                    LoadAndResolve(e.GetAttribute("src"));
                Sequences[e.GetAttribute("name")] = new Sequence(e);
            }

            Application.Run(new Form1());
        }
Beispiel #11
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(); }
        }
Beispiel #12
0
        public static void ExtractFiles(string[] args)
        {
            var mods = args[1].Split(',');
            var files = args.Skip(2);

            var manifest = new Manifest(mods);
            FileSystem.LoadFromManifest(manifest);

            foreach (var f in files)
            {
                if (f == "--userdir")
                    break;

                var src = FileSystem.Open(f);
                if (src == null)
                    throw new InvalidOperationException("File not found: {0}".F(f));
                var data = src.ReadAllBytes();
                var output = args.Contains("--userdir") ? Platform.SupportDir + f : f;
                File.WriteAllBytes(output, data);
                Console.WriteLine(output + " saved.");
            }
        }
Beispiel #13
0
        public void Init(Manifest m, Dictionary<string, string> info)
        {
            loadInfo = info;

            // Avoid standard loading mechanisms so we
            // can display loadscreen as early as possible
            r = Game.Renderer;
            if (r == null) return;

            var s = new Sheet("mods/cnc/uibits/chrome.png");
            var res = r.Resolution;
            bounds = new Rectangle(0, 0, res.Width, res.Height);

            ss = new[]
            {
                new Sprite(s, new Rectangle(161, 128, 62, 33), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(161, 223, 62, 33), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(128, 161, 33, 62), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(223, 161, 33, 62), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(128, 128, 33, 33), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(223, 128, 33, 33), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(128, 223, 33, 33), TextureChannel.Alpha),
                new Sprite(s, new Rectangle(223, 223, 33, 33), TextureChannel.Alpha)
            };

            nodLogo = new Sprite(s, new Rectangle(0, 256, 256, 256), TextureChannel.Alpha);
            gdiLogo = new Sprite(s, new Rectangle(256, 256, 256, 256), TextureChannel.Alpha);
            evaLogo = new Sprite(s, new Rectangle(256, 64, 128, 64), TextureChannel.Alpha);
            nodPos = new float2(bounds.Width / 2 - 384, bounds.Height / 2 - 128);
            gdiPos = new float2(bounds.Width / 2 + 128, bounds.Height / 2 - 128);
            evaPos = new float2(bounds.Width - 43 - 128, 43);

            brightBlock = new Sprite(s, new Rectangle(320, 0, 16, 35), TextureChannel.Alpha);
            dimBlock = new Sprite(s, new Rectangle(336, 0, 16, 35), TextureChannel.Alpha);

            versionText = m.Mod.Version;
        }