removed editor -> ra dep; added EditorAppearance for inconvenient bits that the editor must have _some_ understanding of, but can't see

This commit is contained in:
Chris Forbes
2010-11-06 14:51:13 +13:00
parent 9a2cdcde11
commit 13d76f8e9c
9 changed files with 54 additions and 22 deletions

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Editor
{
public Bitmap Bitmap;
public ActorInfo Info;
public bool Centered;
public EditorAppearanceInfo Appearance;
}
class BrushTemplate

View File

@@ -145,10 +145,6 @@
<Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project>
<Name>OpenRA.Game</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Mods.RA\OpenRA.Mods.RA.csproj">
<Project>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</Project>
<Name>OpenRA.Mods.RA</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="OpenRA.Editor.Icon.ico" />

View File

@@ -13,7 +13,6 @@ using System.Drawing;
using System.Drawing.Imaging;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Editor
{
@@ -122,7 +121,12 @@ namespace OpenRA.Editor
}
catch { }
return new ActorTemplate { Bitmap = bitmap, Info = info, Centered = !info.Traits.Contains<BuildingInfo>() };
return new ActorTemplate
{
Bitmap = bitmap,
Info = info,
Appearance = info.Traits.GetOrDefault<EditorAppearanceInfo>()
};
}
}

View File

@@ -413,10 +413,12 @@ namespace OpenRA.Editor
void DrawActor(System.Drawing.Graphics g, int2 p, ActorTemplate t, ColorPalette cp)
{
float OffsetX = t.Centered ? t.Bitmap.Width / 2 - TileSet.TileSize / 2 : 0;
var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft;
float OffsetX = centered ? t.Bitmap.Width / 2 - TileSet.TileSize / 2 : 0;
float DrawX = TileSet.TileSize * p.X * Zoom + Offset.X - OffsetX;
float OffsetY = t.Centered ? t.Bitmap.Height / 2 - TileSet.TileSize / 2 : 0;
float OffsetY = centered ? t.Bitmap.Height / 2 - TileSet.TileSize / 2 : 0;
float DrawY = TileSet.TileSize * p.Y * Zoom + Offset.Y - OffsetY;
float width = t.Bitmap.Width * Zoom;
@@ -447,10 +449,12 @@ namespace OpenRA.Editor
void DrawActorBorder(System.Drawing.Graphics g, int2 p, ActorTemplate t)
{
float OffsetX = t.Centered ? t.Bitmap.Width / 2 - TileSet.TileSize / 2 : 0;
var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft;
float OffsetX = centered ? t.Bitmap.Width / 2 - TileSet.TileSize / 2 : 0;
float DrawX = TileSet.TileSize * p.X * Zoom + Offset.X - OffsetX;
float OffsetY = t.Centered ? t.Bitmap.Height / 2 - TileSet.TileSize / 2 : 0;
float OffsetY = centered ? t.Bitmap.Height / 2 - TileSet.TileSize / 2 : 0;
float DrawY = TileSet.TileSize * p.Y * Zoom + Offset.Y - OffsetY;
g.DrawRectangle(CordonPen,

View File

@@ -66,21 +66,21 @@ namespace OpenRA
var ret = new List<ITraitInfo>();
var t = Traits.WithInterface<ITraitInfo>().ToList();
int index = 0;
while( t.Count != 0 )
while (t.Count != 0)
{
if( index >= t.Count )
throw new InvalidOperationException( "Trait prerequisites not satisfied (or prerequisite loop) Actor={0} Unresolved={1}".F(
Name, string.Join( ",", t.Select( x => x.GetType().Name ).ToArray())));
var prereqs = PrerequisitesOf( t[ index ] );
if( prereqs.Count == 0 || prereqs.All( n => ret.Any( x => x.GetType() == n || x.GetType().IsSubclassOf( n ) ) ) )
var prereqs = PrerequisitesOf(t[index]);
var unsatisfied = prereqs.Where(n => !ret.Any(x => x.GetType() == n || x.GetType().IsSubclassOf(n)));
if (!unsatisfied.Any())
{
ret.Add( t[ index ] );
t.RemoveAt( index );
ret.Add(t[index]);
t.RemoveAt(index);
index = 0;
}
else
++index;
else if (++index >= t.Count)
throw new InvalidOperationException("Trait prerequisites not satisfied (or prerequisite loop) Actor={0} Unresolved={1} Missing={2}".F(
Name,
string.Join(",", t.Select(x => x.GetType().Name).ToArray()),
string.Join(",", unsatisfied.Select(x => x.Name).ToArray())));
}
return ret;

View File

@@ -211,6 +211,7 @@
<Compile Include="Server\IServerExtension.cs" />
<Compile Include="Server\NullServerExtension.cs" />
<Compile Include="Traits\BaseBuilding.cs" />
<Compile Include="Traits\EditorAppearance.cs" />
<Compile Include="Traits\ValidateOrder.cs" />
<Compile Include="Traits\Scale.cs" />
<Compile Include="TraitDictionary.cs" />

View File

@@ -0,0 +1,19 @@
#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
namespace OpenRA.Traits
{
public class EditorAppearanceInfo : TraitInfo<EditorAppearance>
{
public readonly bool RelativeToTopLeft = false;
}
public class EditorAppearance { }
}

View File

@@ -205,6 +205,8 @@
Notification: nodcapt1.aud
ActorLostNotification:
Notification: strclost.aud
EditorAppearance:
RelativeToTopLeft: yes
^CivBuilding:
Inherits: ^Building
@@ -254,6 +256,8 @@
HasMakeAnimation: false
Palette: terrain
GivesExperience:
EditorAppearance:
RelativeToTopLeft: yes
^Tree:
Tooltip:

View File

@@ -139,6 +139,8 @@
FrozenUnderFog:
CaptureNotification:
Notification: strucap1.aud
EditorAppearance:
RelativeToTopLeft: yes
^Wall:
AppearsOnRadar:
@@ -163,6 +165,8 @@
HasMakeAnimation: false
Palette: terrain
GivesExperience:
EditorAppearance:
RelativeToTopLeft: yes
^CivBuilding:
Inherits: ^Building