add dropdown in editor for choosing owner of new actors

This commit is contained in:
Chris Forbes
2011-10-31 18:41:38 +13:00
parent 7bc7fbc006
commit a060d99780
5 changed files with 217 additions and 151 deletions

View File

@@ -22,10 +22,8 @@ namespace OpenRA.Editor
public void Preview(Surface surface, SGraphics g) public void Preview(Surface surface, SGraphics g)
{ {
/* todo: include the player surface.DrawActor(g, surface.GetBrushLocation(), Actor,
* in the brush so we can color new buildings too */ surface.GetPaletteForPlayer(surface.NewActorOwner));
surface.DrawActor(g, surface.GetBrushLocation(), Actor, null);
} }
public void Apply(Surface surface) public void Apply(Surface surface)
@@ -33,7 +31,7 @@ namespace OpenRA.Editor
if (surface.Map.Actors.Value.Any(a => a.Value.Location() == surface.GetBrushLocation())) if (surface.Map.Actors.Value.Any(a => a.Value.Location() == surface.GetBrushLocation()))
return; return;
var owner = "Neutral"; var owner = surface.NewActorOwner;
var id = NextActorName(surface); var id = NextActorName(surface);
surface.Map.Actors.Value[id] = new ActorReference(Actor.Info.Name.ToLowerInvariant()) surface.Map.Actors.Value[id] = new ActorReference(Actor.Info.Name.ToLowerInvariant())
{ {

View File

@@ -47,7 +47,9 @@ namespace OpenRA.Editor
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.tilePalette = new System.Windows.Forms.FlowLayoutPanel(); this.tilePalette = new System.Windows.Forms.FlowLayoutPanel();
this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage();
this.panel1 = new System.Windows.Forms.Panel();
this.actorPalette = new System.Windows.Forms.FlowLayoutPanel(); this.actorPalette = new System.Windows.Forms.FlowLayoutPanel();
this.actorOwnerChooser = new System.Windows.Forms.ComboBox();
this.tabPage3 = new System.Windows.Forms.TabPage(); this.tabPage3 = new System.Windows.Forms.TabPage();
this.resourcePalette = new System.Windows.Forms.FlowLayoutPanel(); this.resourcePalette = new System.Windows.Forms.FlowLayoutPanel();
this.surface1 = new OpenRA.Editor.Surface(); this.surface1 = new OpenRA.Editor.Surface();
@@ -74,13 +76,13 @@ namespace OpenRA.Editor
this.resizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resizeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showActorNamesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showActorNamesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showGridToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showGridToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.fixOpenAreasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setupDefaultPlayersMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox(); this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel(); this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelFiller = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelFiller = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelMousePosition = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelMousePosition = new System.Windows.Forms.ToolStripStatusLabel();
this.fixOpenAreasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setupDefaultPlayersMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout(); this.splitContainer1.SuspendLayout();
@@ -91,6 +93,7 @@ namespace OpenRA.Editor
this.tabControl1.SuspendLayout(); this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout(); this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout(); this.tabPage2.SuspendLayout();
this.panel1.SuspendLayout();
this.tabPage3.SuspendLayout(); this.tabPage3.SuspendLayout();
this.splitContainer3.Panel1.SuspendLayout(); this.splitContainer3.Panel1.SuspendLayout();
this.splitContainer3.Panel2.SuspendLayout(); this.splitContainer3.Panel2.SuspendLayout();
@@ -184,7 +187,8 @@ namespace OpenRA.Editor
// //
// tabPage2 // tabPage2
// //
this.tabPage2.Controls.Add(this.actorPalette); this.tabPage2.Controls.Add(this.panel1);
this.tabPage2.Controls.Add(this.actorOwnerChooser);
this.tabPage2.Location = new System.Drawing.Point(4, 20); this.tabPage2.Location = new System.Drawing.Point(4, 20);
this.tabPage2.Name = "tabPage2"; this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
@@ -193,15 +197,37 @@ namespace OpenRA.Editor
this.tabPage2.Text = "Actors"; this.tabPage2.Text = "Actors";
this.tabPage2.UseVisualStyleBackColor = true; this.tabPage2.UseVisualStyleBackColor = true;
// //
// panel1
//
this.panel1.Controls.Add(this.actorPalette);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(3, 24);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(184, 525);
this.panel1.TabIndex = 4;
//
// actorPalette // actorPalette
// //
this.actorPalette.AutoScroll = true; this.actorPalette.AutoScroll = true;
this.actorPalette.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.actorPalette.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.actorPalette.Dock = System.Windows.Forms.DockStyle.Fill; this.actorPalette.Dock = System.Windows.Forms.DockStyle.Fill;
this.actorPalette.Location = new System.Drawing.Point(3, 3); this.actorPalette.Location = new System.Drawing.Point(0, 0);
this.actorPalette.Name = "actorPalette"; this.actorPalette.Name = "actorPalette";
this.actorPalette.Size = new System.Drawing.Size(184, 546); this.actorPalette.Size = new System.Drawing.Size(184, 525);
this.actorPalette.TabIndex = 2; this.actorPalette.TabIndex = 3;
//
// actorOwnerChooser
//
this.actorOwnerChooser.Dock = System.Windows.Forms.DockStyle.Top;
this.actorOwnerChooser.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.actorOwnerChooser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.actorOwnerChooser.FormattingEnabled = true;
this.actorOwnerChooser.Location = new System.Drawing.Point(3, 3);
this.actorOwnerChooser.Name = "actorOwnerChooser";
this.actorOwnerChooser.Size = new System.Drawing.Size(184, 21);
this.actorOwnerChooser.TabIndex = 3;
this.actorOwnerChooser.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.onDrawPlayerItem);
this.actorOwnerChooser.SelectionChangeCommitted += new System.EventHandler(this.onSelectOwner);
// //
// tabPage3 // tabPage3
// //
@@ -266,10 +292,10 @@ namespace OpenRA.Editor
// menuStrip1 // menuStrip1
// //
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem, this.fileToolStripMenuItem,
this.mapToolStripMenuItem, this.mapToolStripMenuItem,
this.toolStripComboBox1, this.toolStripComboBox1,
this.toolStripLabel1}); this.toolStripLabel1});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(985, 27); this.menuStrip1.Size = new System.Drawing.Size(985, 27);
@@ -279,16 +305,16 @@ namespace OpenRA.Editor
// fileToolStripMenuItem // fileToolStripMenuItem
// //
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.newToolStripMenuItem, this.newToolStripMenuItem,
this.toolStripSeparator1, this.toolStripSeparator1,
this.openToolStripMenuItem, this.openToolStripMenuItem,
this.saveToolStripMenuItem, this.saveToolStripMenuItem,
this.saveAsToolStripMenuItem, this.saveAsToolStripMenuItem,
this.toolStripSeparator2, this.toolStripSeparator2,
this.toolStripMenuItem1, this.toolStripMenuItem1,
this.mnuExport, this.mnuExport,
this.toolStripSeparator3, this.toolStripSeparator3,
this.exitToolStripMenuItem}); this.exitToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 23); this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 23);
this.fileToolStripMenuItem.Text = "&File"; this.fileToolStripMenuItem.Text = "&File";
@@ -340,8 +366,8 @@ namespace OpenRA.Editor
// toolStripMenuItem1 // toolStripMenuItem1
// //
this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.cCRedAlertMapToolStripMenuItem, this.cCRedAlertMapToolStripMenuItem,
this.bitmapToolStripMenuItem}); this.bitmapToolStripMenuItem});
this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(123, 22); this.toolStripMenuItem1.Size = new System.Drawing.Size(123, 22);
this.toolStripMenuItem1.Text = "&Import"; this.toolStripMenuItem1.Text = "&Import";
@@ -365,7 +391,7 @@ namespace OpenRA.Editor
// mnuExport // mnuExport
// //
this.mnuExport.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuExport.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuMinimapToPNG}); this.mnuMinimapToPNG});
this.mnuExport.Name = "mnuExport"; this.mnuExport.Name = "mnuExport";
this.mnuExport.Size = new System.Drawing.Size(123, 22); this.mnuExport.Size = new System.Drawing.Size(123, 22);
this.mnuExport.Text = "&Export"; this.mnuExport.Text = "&Export";
@@ -394,12 +420,12 @@ namespace OpenRA.Editor
// mapToolStripMenuItem // mapToolStripMenuItem
// //
this.mapToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mapToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.propertiesToolStripMenuItem, this.propertiesToolStripMenuItem,
this.resizeToolStripMenuItem, this.resizeToolStripMenuItem,
this.showActorNamesToolStripMenuItem, this.showActorNamesToolStripMenuItem,
this.showGridToolStripMenuItem, this.showGridToolStripMenuItem,
this.fixOpenAreasToolStripMenuItem, this.fixOpenAreasToolStripMenuItem,
this.setupDefaultPlayersMenuItem}); this.setupDefaultPlayersMenuItem});
this.mapToolStripMenuItem.Name = "mapToolStripMenuItem"; this.mapToolStripMenuItem.Name = "mapToolStripMenuItem";
this.mapToolStripMenuItem.Size = new System.Drawing.Size(43, 23); this.mapToolStripMenuItem.Size = new System.Drawing.Size(43, 23);
this.mapToolStripMenuItem.Text = "&Map"; this.mapToolStripMenuItem.Text = "&Map";
@@ -409,7 +435,7 @@ namespace OpenRA.Editor
this.propertiesToolStripMenuItem.Enabled = false; this.propertiesToolStripMenuItem.Enabled = false;
this.propertiesToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("propertiesToolStripMenuItem.Image"))); this.propertiesToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("propertiesToolStripMenuItem.Image")));
this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem"; this.propertiesToolStripMenuItem.Name = "propertiesToolStripMenuItem";
this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(175, 22); this.propertiesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.propertiesToolStripMenuItem.Text = "&Properties..."; this.propertiesToolStripMenuItem.Text = "&Properties...";
this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.PropertiesClicked); this.propertiesToolStripMenuItem.Click += new System.EventHandler(this.PropertiesClicked);
// //
@@ -418,24 +444,38 @@ namespace OpenRA.Editor
this.resizeToolStripMenuItem.Enabled = false; this.resizeToolStripMenuItem.Enabled = false;
this.resizeToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("resizeToolStripMenuItem.Image"))); this.resizeToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("resizeToolStripMenuItem.Image")));
this.resizeToolStripMenuItem.Name = "resizeToolStripMenuItem"; this.resizeToolStripMenuItem.Name = "resizeToolStripMenuItem";
this.resizeToolStripMenuItem.Size = new System.Drawing.Size(175, 22); this.resizeToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.resizeToolStripMenuItem.Text = "&Resize..."; this.resizeToolStripMenuItem.Text = "&Resize...";
this.resizeToolStripMenuItem.Click += new System.EventHandler(this.ResizeClicked); this.resizeToolStripMenuItem.Click += new System.EventHandler(this.ResizeClicked);
// //
// showActorNamesToolStripMenuItem // showActorNamesToolStripMenuItem
// //
this.showActorNamesToolStripMenuItem.Name = "showActorNamesToolStripMenuItem"; this.showActorNamesToolStripMenuItem.Name = "showActorNamesToolStripMenuItem";
this.showActorNamesToolStripMenuItem.Size = new System.Drawing.Size(175, 22); this.showActorNamesToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showActorNamesToolStripMenuItem.Text = "Show Actor &Names"; this.showActorNamesToolStripMenuItem.Text = "Show Actor &Names";
this.showActorNamesToolStripMenuItem.Click += new System.EventHandler(this.ShowActorNamesClicked); this.showActorNamesToolStripMenuItem.Click += new System.EventHandler(this.ShowActorNamesClicked);
// //
// showGridToolStripMenuItem // showGridToolStripMenuItem
// //
this.showGridToolStripMenuItem.Name = "showGridToolStripMenuItem"; this.showGridToolStripMenuItem.Name = "showGridToolStripMenuItem";
this.showGridToolStripMenuItem.Size = new System.Drawing.Size(175, 22); this.showGridToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.showGridToolStripMenuItem.Text = "Show &Grid"; this.showGridToolStripMenuItem.Text = "Show &Grid";
this.showGridToolStripMenuItem.Click += new System.EventHandler(this.ShowGridClicked); this.showGridToolStripMenuItem.Click += new System.EventHandler(this.ShowGridClicked);
// //
// fixOpenAreasToolStripMenuItem
//
this.fixOpenAreasToolStripMenuItem.Name = "fixOpenAreasToolStripMenuItem";
this.fixOpenAreasToolStripMenuItem.Size = new System.Drawing.Size(185, 22);
this.fixOpenAreasToolStripMenuItem.Text = "&Fix Open Areas";
this.fixOpenAreasToolStripMenuItem.Click += new System.EventHandler(this.FixOpenAreas);
//
// setupDefaultPlayersMenuItem
//
this.setupDefaultPlayersMenuItem.Name = "setupDefaultPlayersMenuItem";
this.setupDefaultPlayersMenuItem.Size = new System.Drawing.Size(185, 22);
this.setupDefaultPlayersMenuItem.Text = "&Setup Default Players";
this.setupDefaultPlayersMenuItem.Click += new System.EventHandler(this.SetupDefaultPlayers);
//
// toolStripComboBox1 // toolStripComboBox1
// //
this.toolStripComboBox1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.toolStripComboBox1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
@@ -453,8 +493,8 @@ namespace OpenRA.Editor
// statusStrip1 // statusStrip1
// //
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelFiller, this.toolStripStatusLabelFiller,
this.toolStripStatusLabelMousePosition}); this.toolStripStatusLabelMousePosition});
this.statusStrip1.Location = new System.Drawing.Point(0, 751); this.statusStrip1.Location = new System.Drawing.Point(0, 751);
this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(985, 22); this.statusStrip1.Size = new System.Drawing.Size(985, 22);
@@ -474,20 +514,6 @@ namespace OpenRA.Editor
this.toolStripStatusLabelMousePosition.Size = new System.Drawing.Size(22, 17); this.toolStripStatusLabelMousePosition.Size = new System.Drawing.Size(22, 17);
this.toolStripStatusLabelMousePosition.Text = "0,0"; this.toolStripStatusLabelMousePosition.Text = "0,0";
// //
// fixOpenAreasToolStripMenuItem
//
this.fixOpenAreasToolStripMenuItem.Name = "fixOpenAreasToolStripMenuItem";
this.fixOpenAreasToolStripMenuItem.Size = new System.Drawing.Size(175, 22);
this.fixOpenAreasToolStripMenuItem.Text = "&Fix Open Areas";
this.fixOpenAreasToolStripMenuItem.Click += new System.EventHandler(this.FixOpenAreas);
//
// setupDefaultPlayersMenuItem
//
this.setupDefaultPlayersMenuItem.Name = "setupDefaultPlayersMenuItem";
this.setupDefaultPlayersMenuItem.Size = new System.Drawing.Size(175, 22);
this.setupDefaultPlayersMenuItem.Text = "&Setup Default Players";
this.setupDefaultPlayersMenuItem.Click += new System.EventHandler(this.SetupDefaultPlayers);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -514,6 +540,7 @@ namespace OpenRA.Editor
this.tabControl1.ResumeLayout(false); this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false); this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false); this.tabPage2.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false); this.tabPage3.ResumeLayout(false);
this.splitContainer3.Panel1.ResumeLayout(false); this.splitContainer3.Panel1.ResumeLayout(false);
this.splitContainer3.Panel1.PerformLayout(); this.splitContainer3.Panel1.PerformLayout();
@@ -536,7 +563,6 @@ namespace OpenRA.Editor
private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.FlowLayoutPanel tilePalette; private System.Windows.Forms.FlowLayoutPanel tilePalette;
private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.FlowLayoutPanel actorPalette;
private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.FlowLayoutPanel resourcePalette; private System.Windows.Forms.FlowLayoutPanel resourcePalette;
private Surface surface1; private Surface surface1;
@@ -571,6 +597,9 @@ namespace OpenRA.Editor
private System.Windows.Forms.ToolStripMenuItem showGridToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem showGridToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem fixOpenAreasToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem fixOpenAreasToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem setupDefaultPlayersMenuItem; private System.Windows.Forms.ToolStripMenuItem setupDefaultPlayersMenuItem;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.FlowLayoutPanel actorPalette;
private System.Windows.Forms.ComboBox actorOwnerChooser;
} }
} }

View File

@@ -16,6 +16,7 @@ using System.Windows.Forms;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
using System.Drawing;
namespace OpenRA.Editor namespace OpenRA.Editor
{ {
@@ -233,6 +234,11 @@ namespace OpenRA.Editor
saveToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true;
saveAsToolStripMenuItem.Enabled = true; saveAsToolStripMenuItem.Enabled = true;
mnuMinimapToPNG.Enabled = true; // todo: what is this VB naming bullshit doing here? mnuMinimapToPNG.Enabled = true; // todo: what is this VB naming bullshit doing here?
actorOwnerChooser.Items.Clear();
actorOwnerChooser.Items.AddRange(map.Players.Values.ToArray());
actorOwnerChooser.SelectedIndex = 0;
surface1.NewActorOwner = (actorOwnerChooser.SelectedItem as PlayerReference).Name;
} }
void ResizeClicked(object sender, EventArgs e) void ResizeClicked(object sender, EventArgs e)
@@ -456,5 +462,29 @@ namespace OpenRA.Editor
surface1.Chunks.Clear(); surface1.Chunks.Clear();
surface1.Invalidate(); surface1.Invalidate();
} }
void onDrawPlayerItem(object sender, DrawItemEventArgs e)
{
// color block
var player = e.Index >= 0 ? (PlayerReference)(sender as ComboBox).Items[e.Index] : null;
e.DrawBackground();
e.DrawFocusRectangle();
if (player == null)
return;
var color = player.ColorRamp.GetColor(0);
using( var brush = new SolidBrush(color) )
e.Graphics.FillRectangle( brush, e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Height + 6, e.Bounds.Height - 4 );
using( var foreBrush = new SolidBrush(e.ForeColor) )
e.Graphics.DrawString( player.Name, e.Font, foreBrush, e.Bounds.Left + e.Bounds.Height + 12, e.Bounds.Top );
}
void onSelectOwner(object sender, EventArgs e)
{
var player = actorOwnerChooser.SelectedItem as PlayerReference;
surface1.NewActorOwner = player.Name;
}
} }
} }

View File

@@ -38,6 +38,8 @@ namespace OpenRA.Editor
public bool ShowActorNames; public bool ShowActorNames;
public bool ShowGrid; public bool ShowGrid;
public string NewActorOwner;
public event Action AfterChange = () => { }; public event Action AfterChange = () => { };
public event Action<string> MousePositionChanged = _ => { }; public event Action<string> MousePositionChanged = _ => { };
@@ -302,7 +304,7 @@ namespace OpenRA.Editor
t.Bitmap.Width * Zoom, t.Bitmap.Height * Zoom); t.Bitmap.Width * Zoom, t.Bitmap.Height * Zoom);
} }
ColorPalette GetPaletteForPlayer(string name) ColorPalette GetPaletteForPlayerInner(string name)
{ {
var pr = Map.Players[name]; var pr = Map.Players[name];
var pcpi = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>(); var pcpi = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>();
@@ -312,16 +314,21 @@ namespace OpenRA.Editor
Cache<string, ColorPalette> PlayerPalettes; Cache<string, ColorPalette> PlayerPalettes;
ColorPalette GetPaletteForActor(ActorReference ar) public ColorPalette GetPaletteForPlayer(string player)
{ {
if (PlayerPalettes == null) if (PlayerPalettes == null)
PlayerPalettes = new Cache<string, ColorPalette>(GetPaletteForPlayer); PlayerPalettes = new Cache<string, ColorPalette>(GetPaletteForPlayerInner);
return PlayerPalettes[player];
}
ColorPalette GetPaletteForActor(ActorReference ar)
{
var ownerInit = ar.InitDict.GetOrDefault<OwnerInit>(); var ownerInit = ar.InitDict.GetOrDefault<OwnerInit>();
if (ownerInit == null) if (ownerInit == null)
return null; return null;
return PlayerPalettes[ownerInit.PlayerName]; return GetPaletteForPlayer(ownerInit.PlayerName);
} }
protected override void OnPaint(PaintEventArgs e) protected override void OnPaint(PaintEventArgs e)

View File

@@ -42,5 +42,7 @@ namespace OpenRA.FileFormats
public PlayerReference() {} public PlayerReference() {}
public PlayerReference(MiniYaml my) { FieldLoader.Load(this, my); } public PlayerReference(MiniYaml my) { FieldLoader.Load(this, my); }
public override string ToString() { return Name; }
} }
} }