Account for cross-mod tile shapes in map previews.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public sealed class MapCache : IEnumerable<MapPreview>, IDisposable
|
public sealed class MapCache : IEnumerable<MapPreview>, IDisposable
|
||||||
{
|
{
|
||||||
public static readonly MapPreview UnknownMap = new MapPreview(null, null);
|
public static readonly MapPreview UnknownMap = new MapPreview(null, TileShape.Rectangle, null);
|
||||||
readonly Cache<string, MapPreview> previews;
|
readonly Cache<string, MapPreview> previews;
|
||||||
readonly ModData modData;
|
readonly ModData modData;
|
||||||
readonly SheetBuilder sheetBuilder;
|
readonly SheetBuilder sheetBuilder;
|
||||||
@@ -35,7 +35,9 @@ namespace OpenRA
|
|||||||
public MapCache(ModData modData)
|
public MapCache(ModData modData)
|
||||||
{
|
{
|
||||||
this.modData = modData;
|
this.modData = modData;
|
||||||
previews = new Cache<string, MapPreview>(uid => new MapPreview(uid, this));
|
|
||||||
|
var gridType = Exts.Lazy(() => modData.Manifest.Get<MapGrid>().Type);
|
||||||
|
previews = new Cache<string, MapPreview>(uid => new MapPreview(uid, gridType.Value, this));
|
||||||
sheetBuilder = new SheetBuilder(SheetType.BGRA);
|
sheetBuilder = new SheetBuilder(SheetType.BGRA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ namespace OpenRA
|
|||||||
public readonly int players;
|
public readonly int players;
|
||||||
public readonly Rectangle bounds;
|
public readonly Rectangle bounds;
|
||||||
public readonly int[] spawnpoints = { };
|
public readonly int[] spawnpoints = { };
|
||||||
|
public readonly TileShape map_grid_type;
|
||||||
public readonly string minimap;
|
public readonly string minimap;
|
||||||
public readonly bool downloading;
|
public readonly bool downloading;
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,7 @@ namespace OpenRA
|
|||||||
public string Author { get; private set; }
|
public string Author { get; private set; }
|
||||||
public int PlayerCount { get; private set; }
|
public int PlayerCount { get; private set; }
|
||||||
public CPos[] SpawnPoints { get; private set; }
|
public CPos[] SpawnPoints { get; private set; }
|
||||||
|
public TileShape GridType { get; private set; }
|
||||||
public Rectangle Bounds { get; private set; }
|
public Rectangle Bounds { get; private set; }
|
||||||
public Bitmap CustomPreview { get; private set; }
|
public Bitmap CustomPreview { get; private set; }
|
||||||
public Map Map { get; private set; }
|
public Map Map { get; private set; }
|
||||||
@@ -97,7 +99,7 @@ namespace OpenRA
|
|||||||
generatingMinimap = false;
|
generatingMinimap = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapPreview(string uid, MapCache cache)
|
public MapPreview(string uid, TileShape gridType, MapCache cache)
|
||||||
{
|
{
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
Uid = uid;
|
Uid = uid;
|
||||||
@@ -107,6 +109,7 @@ namespace OpenRA
|
|||||||
PlayerCount = 0;
|
PlayerCount = 0;
|
||||||
Bounds = Rectangle.Empty;
|
Bounds = Rectangle.Empty;
|
||||||
SpawnPoints = NoSpawns;
|
SpawnPoints = NoSpawns;
|
||||||
|
GridType = gridType;
|
||||||
Status = MapStatus.Unavailable;
|
Status = MapStatus.Unavailable;
|
||||||
Class = MapClassification.Unknown;
|
Class = MapClassification.Unknown;
|
||||||
}
|
}
|
||||||
@@ -120,6 +123,7 @@ namespace OpenRA
|
|||||||
Author = m.Author;
|
Author = m.Author;
|
||||||
Bounds = m.Bounds;
|
Bounds = m.Bounds;
|
||||||
SpawnPoints = m.SpawnPoints.Value;
|
SpawnPoints = m.SpawnPoints.Value;
|
||||||
|
GridType = m.Grid.Type;
|
||||||
CustomPreview = m.CustomPreview;
|
CustomPreview = m.CustomPreview;
|
||||||
Status = MapStatus.Available;
|
Status = MapStatus.Available;
|
||||||
Class = classification;
|
Class = classification;
|
||||||
@@ -179,6 +183,7 @@ namespace OpenRA
|
|||||||
for (var j = 0; j < r.spawnpoints.Length; j += 2)
|
for (var j = 0; j < r.spawnpoints.Length; j += 2)
|
||||||
spawns[j / 2] = new CPos(r.spawnpoints[j], r.spawnpoints[j + 1]);
|
spawns[j / 2] = new CPos(r.spawnpoints[j], r.spawnpoints[j + 1]);
|
||||||
SpawnPoints = spawns;
|
SpawnPoints = spawns;
|
||||||
|
GridType = r.map_grid_type;
|
||||||
|
|
||||||
CustomPreview = new Bitmap(new MemoryStream(Convert.FromBase64String(r.minimap)));
|
CustomPreview = new Bitmap(new MemoryStream(Convert.FromBase64String(r.minimap)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var spawnSize = new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").Bounds.Size);
|
var spawnSize = new float2(ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed").Bounds.Size);
|
||||||
var selectedSpawn = preview.SpawnPoints
|
var selectedSpawn = preview.SpawnPoints
|
||||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp), i))
|
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(sp, preview.GridType), i))
|
||||||
.Where(a => ((a.First - mi.Location).ToFloat2() / spawnSize * 2).LengthSquared <= 1)
|
.Where(a => ((a.First - mi.Location).ToFloat2() / spawnSize * 2).LengthSquared <= 1)
|
||||||
.Select(a => a.Second + 1)
|
.Select(a => a.Second + 1)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
readonly SpriteFont spawnFont;
|
readonly SpriteFont spawnFont;
|
||||||
readonly Color spawnColor, spawnContrastColor;
|
readonly Color spawnColor, spawnContrastColor;
|
||||||
readonly int2 spawnLabelOffset;
|
readonly int2 spawnLabelOffset;
|
||||||
readonly int cellWidth;
|
|
||||||
readonly TileShape shape;
|
|
||||||
|
|
||||||
public Func<MapPreview> Preview = () => null;
|
public Func<MapPreview> Preview = () => null;
|
||||||
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
|
public Func<Dictionary<CPos, SpawnOccupant>> SpawnOccupants = () => new Dictionary<CPos, SpawnOccupant>();
|
||||||
@@ -83,9 +81,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
||||||
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
||||||
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
||||||
|
|
||||||
shape = Game.ModData.Manifest.Get<MapGrid>().Type;
|
|
||||||
cellWidth = shape == TileShape.Diamond ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MapPreviewWidget(MapPreviewWidget other)
|
protected MapPreviewWidget(MapPreviewWidget other)
|
||||||
@@ -107,9 +102,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
spawnColor = ChromeMetrics.Get<Color>("SpawnColor");
|
||||||
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
|
||||||
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
|
||||||
|
|
||||||
shape = other.shape;
|
|
||||||
cellWidth = other.cellWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||||
@@ -138,10 +130,11 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
tooltipContainer.Value.RemoveTooltip();
|
tooltipContainer.Value.RemoveTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 ConvertToPreview(CPos cell)
|
public int2 ConvertToPreview(CPos cell, TileShape gridType)
|
||||||
{
|
{
|
||||||
var preview = Preview();
|
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 dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left));
|
||||||
var dy = (int)(previewScale * (point.V - preview.Bounds.Top));
|
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 colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);
|
||||||
|
|
||||||
var spawnPoints = preview.SpawnPoints;
|
var spawnPoints = preview.SpawnPoints;
|
||||||
|
var gridType = preview.GridType;
|
||||||
foreach (var p in spawnPoints)
|
foreach (var p in spawnPoints)
|
||||||
{
|
{
|
||||||
var owned = colors.ContainsKey(p);
|
var owned = colors.ContainsKey(p);
|
||||||
var pos = ConvertToPreview(p);
|
var pos = ConvertToPreview(p, gridType);
|
||||||
var sprite = owned ? spawnClaimed : spawnUnclaimed;
|
var sprite = owned ? spawnClaimed : spawnUnclaimed;
|
||||||
var offset = new int2(sprite.Bounds.Width, sprite.Bounds.Height) / 2;
|
var offset = new int2(sprite.Bounds.Width, sprite.Bounds.Height) / 2;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user