Add MapGrid class

MapGrid is a mod Manifest field which includes (and thus makes redundant) TileSize, TileShape, SubCells info and MaximumTerrainHeight.
This commit is contained in:
Pavel Penev
2015-09-14 01:55:00 +03:00
parent 699a7f8227
commit 642468ce0c
28 changed files with 164 additions and 157 deletions

View File

@@ -48,7 +48,8 @@ namespace OpenRA.Mods.Common.Widgets
preview.IsVisible = () => editorWidget.CurrentBrush == this;
preview.Template = world.TileSet.Templates.First(t => t.Value.Id == template).Value;
bounds = worldRenderer.Theater.TemplateBounds(preview.Template, Game.ModData.Manifest.TileSize, world.Map.TileShape);
var grid = world.Map.Grid;
bounds = worldRenderer.Theater.TemplateBounds(preview.Template, grid.TileSize, grid.Type);
// The preview widget may be rendered by the higher-level code before it is ticked.
// Force a manual tick to ensure the bounds are set correctly for this first draw.
@@ -106,7 +107,7 @@ namespace OpenRA.Mods.Common.Widgets
continue;
mapTiles[c] = new TerrainTile(Template, index);
mapHeight[c] = (byte)(baseHeight + template[index].Height).Clamp(0, map.MaximumTerrainHeight);
mapHeight[c] = (byte)(baseHeight + template[index].Height).Clamp(0, map.Grid.MaximumTerrainHeight);
}
}
}

View File

@@ -106,8 +106,7 @@ namespace OpenRA.Mods.Common.Graphics
{
var groundPos = voxel.pos - new WVec(0, 0, wr.World.Map.DistanceAboveTerrain(voxel.pos).Length);
var ts = Game.ModData.Manifest.TileSize;
var groundZ = ts.Height * (groundPos.Z - voxel.pos.Z) / 1024f;
var groundZ = wr.World.Map.Grid.TileSize.Height * (groundPos.Z - voxel.pos.Z) / 1024f;
var pxOrigin = wr.ScreenPosition(voxel.pos);
var shadowOrigin = pxOrigin - groundZ * (new float2(renderProxy.ShadowDirection, 1));

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Pathfinder
CellLayer<CellInfo>.CreateInstance(
mpos => new CellInfo(int.MaxValue, int.MaxValue, mpos.ToCPos(map), CellStatus.Unvisited),
new Size(map.MapSize.X, map.MapSize.Y),
map.TileShape);
map.Grid.Type);
}
public PooledCellInfoLayer Get()

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var pr in Players.Players.Values)
wr.UpdatePalettesForPlayer(pr.Name, pr.Color, false);
var ts = Game.ModData.Manifest.TileSize;
var ts = world.Map.Grid.TileSize;
var width = world.Map.MapSize.X * ts.Width;
var height = world.Map.MapSize.Y * ts.Height;
screenMap = new SpatiallyPartitioned<EditorActorPreview>(width, height, info.BinSize);

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
internal static void ConvertPxToRange(ref string input, int scaleMult, int scaleDiv)
{
var value = Exts.ParseIntegerInvariant(input);
var ts = Game.ModData.Manifest.TileSize;
var ts = Game.ModData.Manifest.Get<MapGrid>().TileSize;
var world = value * 1024 * scaleMult / (scaleDiv * ts.Height);
var cells = world / 1024;
var subcells = world - 1024 * cells;
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
internal static void ConvertInt2ToWVec(ref string input)
{
var offset = FieldLoader.GetValue<int2>("(value)", input);
var ts = Game.ModData.Manifest.TileSize;
var ts = Game.ModData.Manifest.Get<MapGrid>().TileSize;
var world = new WVec(offset.X * 1024 / ts.Width, offset.Y * 1024 / ts.Height, 0);
input = world.ToString();
}

View File

@@ -67,12 +67,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var frame = sequence.Frames != null ? sequence.Frames.Last() : resource.MaxDensity - 1;
layerPreview.GetSprite = () => sequence.GetSprite(frame);
var tileWidth = Game.ModData.Manifest.TileSize.Width;
var tileHeight = Game.ModData.Manifest.TileSize.Height;
layerPreview.Bounds.Width = tileWidth;
layerPreview.Bounds.Height = tileHeight;
newResourcePreviewTemplate.Bounds.Width = tileWidth + (layerPreview.Bounds.X * 2);
newResourcePreviewTemplate.Bounds.Height = tileHeight + (layerPreview.Bounds.Y * 2);
var tileSize = Game.ModData.Manifest.Get<MapGrid>().TileSize;
layerPreview.Bounds.Width = tileSize.Width;
layerPreview.Bounds.Height = tileSize.Height;
newResourcePreviewTemplate.Bounds.Width = tileSize.Width + (layerPreview.Bounds.X * 2);
newResourcePreviewTemplate.Bounds.Height = tileSize.Height + (layerPreview.Bounds.Y * 2);
newResourcePreviewTemplate.IsVisible = () => true;
newResourcePreviewTemplate.GetTooltipText = () => resource.Name;

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
width = Math.Max(2, width);
height = Math.Max(2, height);
var maxTerrainHeight = Game.ModData.Manifest.MaximumTerrainHeight;
var maxTerrainHeight = world.Map.Grid.MaximumTerrainHeight;
var tileset = modRules.TileSets[tilesetDropDown.Text];
var map = new Map(tileset, width + 2, height + maxTerrainHeight + 2);

View File

@@ -68,7 +68,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var preview = item.Get<TerrainTemplatePreviewWidget>("TILE_PREVIEW");
var template = tileset.Templates[tileId];
var bounds = worldRenderer.Theater.TemplateBounds(template, Game.ModData.Manifest.TileSize, worldRenderer.World.Map.TileShape);
var grid = worldRenderer.World.Map.Grid;
var bounds = worldRenderer.Theater.TemplateBounds(template, grid.TileSize, grid.Type);
// Scale templates to fit within the panel
var scale = 1f;

View File

@@ -62,6 +62,7 @@ namespace OpenRA.Mods.Common.Widgets
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,7 +84,8 @@ namespace OpenRA.Mods.Common.Widgets
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
cellWidth = Game.ModData.Manifest.TileShape == TileShape.Diamond ? 2 : 1;
shape = Game.ModData.Manifest.Get<MapGrid>().Type;
cellWidth = shape == TileShape.Diamond ? 2 : 1;
}
protected MapPreviewWidget(MapPreviewWidget other)
@@ -106,6 +108,7 @@ namespace OpenRA.Mods.Common.Widgets
spawnContrastColor = ChromeMetrics.Get<Color>("SpawnContrastColor");
spawnLabelOffset = ChromeMetrics.Get<int2>("SpawnLabelOffset");
shape = other.shape;
cellWidth = other.cellWidth;
}
@@ -138,8 +141,7 @@ namespace OpenRA.Mods.Common.Widgets
public int2 ConvertToPreview(CPos cell)
{
var preview = Preview();
var tileShape = Game.ModData.Manifest.TileShape;
var point = cell.ToMPos(tileShape);
var point = cell.ToMPos(shape);
var dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left));
var dy = (int)(previewScale * (point.V - preview.Bounds.Top));

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets
this.worldRenderer = worldRenderer;
radarPings = world.WorldActor.TraitOrDefault<RadarPings>();
isDiamond = world.Map.TileShape == TileShape.Diamond;
isDiamond = world.Map.Grid.Type == TileShape.Diamond;
cellWidth = isDiamond ? 2 : 1;
previewWidth = world.Map.MapSize.X;
previewHeight = world.Map.MapSize.Y;
@@ -379,7 +379,7 @@ namespace OpenRA.Mods.Common.Widgets
if (!world.Map.Contains(cell.First))
continue;
var uv = cell.First.ToMPos(world.Map.TileShape);
var uv = cell.First.ToMPos(world.Map.Grid.Type);
var color = cell.Second.ToArgb();
if (isDiamond)
{

View File

@@ -41,8 +41,9 @@ namespace OpenRA.Mods.Common.Widgets
if (template == null)
return;
var ts = Game.ModData.Manifest.TileSize;
var shape = Game.ModData.Manifest.TileShape;
var grid = Game.ModData.Manifest.Get<MapGrid>();
var ts = grid.TileSize;
var shape = grid.Type;
bounds = worldRenderer.Theater.TemplateBounds(template, ts, shape);
}
}
@@ -70,8 +71,9 @@ namespace OpenRA.Mods.Common.Widgets
if (template == null)
return;
var ts = Game.ModData.Manifest.TileSize;
var shape = Game.ModData.Manifest.TileShape;
var grid = Game.ModData.Manifest.Get<MapGrid>();
var ts = grid.TileSize;
var shape = grid.Type;
var scale = GetScale();
var sb = new Rectangle((int)(scale * bounds.X), (int)(scale * bounds.Y), (int)(scale * bounds.Width), (int)(scale * bounds.Height));