diff --git a/OpenRA.Editor/ActorTemplate.cs b/OpenRA.Editor/ActorTemplate.cs index 8a6f75e4b7..a49d474ecb 100644 --- a/OpenRA.Editor/ActorTemplate.cs +++ b/OpenRA.Editor/ActorTemplate.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; +using System.Drawing; using OpenRA.GameRules; -using System.Windows.Forms; +using OpenRA.Traits; namespace OpenRA.Editor { @@ -20,4 +16,10 @@ namespace OpenRA.Editor public Bitmap Bitmap; public ushort N; } + + class ResourceTemplate + { + public Bitmap Bitmap; + public ResourceTypeInfo Info; + } } diff --git a/OpenRA.Editor/Form1.Designer.cs b/OpenRA.Editor/Form1.Designer.cs index 6fe8ac9afb..7bfce9e9c9 100644 --- a/OpenRA.Editor/Form1.Designer.cs +++ b/OpenRA.Editor/Form1.Designer.cs @@ -36,12 +36,14 @@ this.tabPage1 = new System.Windows.Forms.TabPage(); this.tilePalette = new System.Windows.Forms.FlowLayoutPanel(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.surface1 = new OpenRA.Editor.Surface(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.tt = new System.Windows.Forms.ToolTip(this.components); this.actorPalette = new System.Windows.Forms.FlowLayoutPanel(); + this.surface1 = new OpenRA.Editor.Surface(); + this.tabPage3 = new System.Windows.Forms.TabPage(); + this.resourcePalette = new System.Windows.Forms.FlowLayoutPanel(); this.toolStripContainer1.ContentPanel.SuspendLayout(); this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); this.toolStripContainer1.SuspendLayout(); @@ -52,6 +54,7 @@ this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); this.toolStrip1.SuspendLayout(); + this.tabPage3.SuspendLayout(); this.SuspendLayout(); // // toolStripContainer1 @@ -94,6 +97,7 @@ this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Left; this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Controls.Add(this.tabPage3); this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; this.tabControl1.Location = new System.Drawing.Point(0, 0); this.tabControl1.Multiline = true; @@ -133,16 +137,6 @@ this.tabPage2.Text = "Actors"; this.tabPage2.UseVisualStyleBackColor = true; // - // surface1 - // - this.surface1.BackColor = System.Drawing.Color.Black; - this.surface1.Dock = System.Windows.Forms.DockStyle.Fill; - this.surface1.Location = new System.Drawing.Point(0, 0); - this.surface1.Name = "surface1"; - this.surface1.Size = new System.Drawing.Size(783, 680); - this.surface1.TabIndex = 2; - this.surface1.Text = "surface1"; - // // toolStrip1 // this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; @@ -184,6 +178,35 @@ this.actorPalette.Size = new System.Drawing.Size(165, 666); this.actorPalette.TabIndex = 2; // + // surface1 + // + this.surface1.BackColor = System.Drawing.Color.Black; + this.surface1.Dock = System.Windows.Forms.DockStyle.Fill; + this.surface1.Location = new System.Drawing.Point(0, 0); + this.surface1.Name = "surface1"; + this.surface1.Size = new System.Drawing.Size(783, 680); + this.surface1.TabIndex = 2; + this.surface1.Text = "surface1"; + // + // tabPage3 + // + this.tabPage3.Controls.Add(this.resourcePalette); + this.tabPage3.Location = new System.Drawing.Point(23, 4); + this.tabPage3.Name = "tabPage3"; + this.tabPage3.Size = new System.Drawing.Size(171, 672); + this.tabPage3.TabIndex = 2; + this.tabPage3.Text = "Resources"; + this.tabPage3.UseVisualStyleBackColor = true; + // + // resourcePalette + // + this.resourcePalette.AutoScroll = true; + this.resourcePalette.Dock = System.Windows.Forms.DockStyle.Fill; + this.resourcePalette.Location = new System.Drawing.Point(0, 0); + this.resourcePalette.Name = "resourcePalette"; + this.resourcePalette.Size = new System.Drawing.Size(171, 672); + this.resourcePalette.TabIndex = 3; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -205,6 +228,7 @@ this.tabPage2.ResumeLayout(false); this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); + this.tabPage3.ResumeLayout(false); this.ResumeLayout(false); } @@ -223,6 +247,8 @@ private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.ToolStripButton toolStripButton2; private System.Windows.Forms.FlowLayoutPanel actorPalette; + private System.Windows.Forms.TabPage tabPage3; + private System.Windows.Forms.FlowLayoutPanel resourcePalette; } } diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index 9c6cdf6d3f..0aab14df36 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -18,12 +18,14 @@ namespace OpenRA.Editor AppDomain.CurrentDomain.AssemblyResolve += FileSystem.ResolveAssembly; LocateGameRoot(); - LoadMap("cnc", "scm02ea"); + LoadMap("ra", "mjolnir"); } void LoadMap(string mod, string mapname) { tilePalette.Controls.Clear(); + actorPalette.Controls.Clear(); + resourcePalette.Controls.Clear(); var mods = new[] { mod }; @@ -110,6 +112,37 @@ namespace OpenRA.Editor } surface1.BindActorTemplates(actorTemplates); + + var resourceTemplates = new List(); + + foreach (var a in Rules.Info["world"].Traits.WithInterface()) + { + try + { + var template = RenderResourceType(a, tsinfo.First, 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); } void LocateGameRoot() @@ -195,6 +228,33 @@ namespace OpenRA.Editor } } + static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string ext, Palette p) + { + var image = info.SpriteNames[0]; + using (var s = FileSystem.OpenWithExts(image, "." + ext, ".shp")) + { + var shp = new ShpReader(s); + var frame = shp[shp.ImageCount - 1]; + + 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 ResourceTemplate { Bitmap = bitmap, Info = info }; + } + } + void ResizeClicked(object sender, EventArgs e) { using (var rd = new ResizeDialog()) diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 02953aaa88..6c11fe9bcc 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -18,6 +18,7 @@ namespace OpenRA.Editor public ActorTemplate Actor; Dictionary ActorTemplates = new Dictionary(); + Dictionary ResourceTemplates = new Dictionary(); public void Bind(Map m, TileSet ts, Palette p) { @@ -30,12 +31,18 @@ namespace OpenRA.Editor public void SetBrush(BrushTemplate brush) { Actor = null; Brush = brush; } public void SetActor(ActorTemplate actor) { Brush = null; Actor = actor; } + public void SetResource(ResourceTemplate resource) { Brush = null; Actor = null; /* todo */ } public void BindActorTemplates(IEnumerable templates) { ActorTemplates = templates.ToDictionary(a => a.Info.Name.ToLowerInvariant()); } + public void BindResourceTemplates(IEnumerable templates) + { + /* todo */ + } + Dictionary Chunks = new Dictionary(); public Surface()