Convert Waypoints to actors

This commit is contained in:
Paul Chote
2011-02-11 20:32:13 +13:00
parent 4a7be2e0c8
commit b134ba41f4
17 changed files with 114 additions and 146 deletions

View File

@@ -33,8 +33,4 @@ namespace OpenRA.Editor
public ResourceTypeInfo Info;
public int Value;
}
class WaypointTemplate
{
}
}

View File

@@ -416,15 +416,6 @@
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(139, 6);
//
// spawnpointsToolStripMenuItem
//
this.spawnpointsToolStripMenuItem.Enabled = false;
this.spawnpointsToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("spawnpointsToolStripMenuItem.Image")));
this.spawnpointsToolStripMenuItem.Name = "spawnpointsToolStripMenuItem";
this.spawnpointsToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
this.spawnpointsToolStripMenuItem.Text = "&Spawnpoints";
this.spawnpointsToolStripMenuItem.Click += new System.EventHandler(this.SpawnPointsClicked);
//
// toolsToolStripMenuItem
//
this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {

View File

@@ -347,7 +347,6 @@ namespace OpenRA.Editor
}
}
void SpawnPointsClicked(object sender, EventArgs e) { surface1.SetTool(new WaypointTool(new WaypointTemplate())); }
void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = true; }
void Form1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) surface1.IsPanning = false; }

View File

@@ -156,14 +156,19 @@ namespace OpenRA.Editor
foreach (var p in Players)
LoadPlayer(file, p, (legacyMapFormat == IniMapFormat.RedAlert));
var wp = file.GetSection("Waypoints")
var wps = file.GetSection("Waypoints")
.Where(kv => int.Parse(kv.Value) > 0)
.Select(kv => Pair.New(int.Parse(kv.Key),
LocationFromMapOffset(int.Parse(kv.Value), MapSize)))
.ToArray();
foreach (var kv in wp)
Map.Waypoints.Add("spawn" + kv.First, kv.Second);
// Add waypoint actors
foreach( var kv in wps )
{
var a = new ActorReference("mpspawn");
a.Add(new LocationInit(kv.Second));
Map.Actors.Add("spawn" + kv.First, a);
}
}
static int2 LocationFromMapOffset(int offset, int mapSize)

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -137,7 +137,6 @@
<Compile Include="Surface.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="WaypointTool.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -166,9 +166,6 @@ namespace OpenRA.Editor
}
}
var k = Map.Waypoints.FirstOrDefault(a => a.Value == BrushLocation);
if (k.Key != null) Map.Waypoints.Remove(k.Key);
AfterChange();
}
@@ -345,12 +342,6 @@ namespace OpenRA.Editor
DrawActor(e.Graphics, ar.Value.Location(), ActorTemplates[ar.Value.Type],
GetPaletteForActor(ar.Value));
foreach (var wp in Map.Waypoints)
e.Graphics.DrawRectangle(Pens.LimeGreen,
TileSet.TileSize * wp.Value.X * Zoom + Offset.X + 4,
TileSet.TileSize * wp.Value.Y * Zoom + Offset.Y + 4,
(TileSet.TileSize - 8) * Zoom, (TileSet.TileSize - 8) * Zoom);
if (Tool != null)
Tool.Preview(this, e.Graphics);

View File

@@ -1,51 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System.Drawing;
using System.Linq;
using SGraphics = System.Drawing.Graphics;
namespace OpenRA.Editor
{
class WaypointTool : ITool
{
WaypointTemplate Waypoint;
public WaypointTool(WaypointTemplate waypoint) { Waypoint = waypoint; }
public void Apply(Surface surface)
{
var k = surface.Map.Waypoints.FirstOrDefault(a => a.Value == surface.GetBrushLocation());
if (k.Key != null) surface.Map.Waypoints.Remove(k.Key);
surface.Map.Waypoints.Add(NextWpid(surface), surface.GetBrushLocation());
}
public void Preview(Surface surface, SGraphics g)
{
g.DrawRectangle(Pens.LimeGreen,
surface.TileSet.TileSize * surface.GetBrushLocation().X * surface.Zoom + surface.GetOffset().X + 4,
surface.TileSet.TileSize * surface.GetBrushLocation().Y * surface.Zoom + surface.GetOffset().Y + 4,
(surface.TileSet.TileSize - 8) * surface.Zoom, (surface.TileSet.TileSize - 8) * surface.Zoom);
}
public string NextWpid(Surface surface)
{
int wpid = 0;
for (; ; )
{
var a = "wp{0}".F(wpid++);
if (!surface.Map.Waypoints.ContainsKey(a))
return a;
}
}
}
}