Account for cross-mod tile shapes in map previews.

This commit is contained in:
Paul Chote
2015-10-24 22:02:46 +01:00
parent c0f42904f0
commit be37717e6d
4 changed files with 16 additions and 15 deletions

View File

@@ -61,8 +61,6 @@ namespace OpenRA.Mods.Common.Widgets
readonly SpriteFont spawnFont;
readonly Color spawnColor, spawnContrastColor;
readonly int2 spawnLabelOffset;
readonly int cellWidth;
readonly TileShape shape;
public Func<MapPreview> Preview = () => null;
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
@@ -83,9 +81,6 @@ namespace OpenRA.Mods.Common.Widgets
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
shape = Game.ModData.Manifest.Get<MapGrid>().Type;
cellWidth = shape == TileShape.Diamond ? 2 : 1;
}
protected MapPreviewWidget(MapPreviewWidget other)
@@ -107,9 +102,6 @@ namespace OpenRA.Mods.Common.Widgets
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
shape = other.shape;
cellWidth = other.cellWidth;
}
public override Widget Clone() { return new MapPreviewWidget(this); }
@@ -138,10 +130,11 @@ namespace OpenRA.Mods.Common.Widgets
tooltipContainer.Value.RemoveTooltip();
}
public int2 ConvertToPreview(CPos cell)
public int2 ConvertToPreview(CPos cell, TileShape gridType)
{
var preview = Preview();
var point = cell.ToMPos(shape);
var point = cell.ToMPos(gridType);
var cellWidth = gridType == TileShape.Diamond ? 2 : 1;
var dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left));
var dy = (int)(previewScale * (point.V - preview.Bounds.Top));
@@ -180,10 +173,11 @@ namespace OpenRA.Mods.Common.Widgets
var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);
var spawnPoints = preview.SpawnPoints;
var gridType = preview.GridType;
foreach (var p in spawnPoints)
{
var owned = colors.ContainsKey(p);
var pos = ConvertToPreview(p);
var pos = ConvertToPreview(p, gridType);
var sprite = owned ? spawnClaimed : spawnUnclaimed;
var offset = new int2(sprite.Bounds.Width, sprite.Bounds.Height) / 2;