Merge pull request #8430 from pchote/editor-cordon
Display and support editing the area outside the map bounds
This commit is contained in:
@@ -36,6 +36,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
readonly CVec locationOffset;
|
||||
readonly WVec previewOffset;
|
||||
readonly PlayerReference owner;
|
||||
readonly CVec[] footprint;
|
||||
|
||||
int facing = 92;
|
||||
|
||||
@@ -67,6 +68,14 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
td.Add(new RaceInit(owner.Race));
|
||||
preview.SetPreview(actor, td);
|
||||
|
||||
var ios = actor.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
if (ios != null)
|
||||
footprint = ios.OccupiedCells(actor, CPos.Zero)
|
||||
.Select(c => c.Key - CPos.Zero)
|
||||
.ToArray();
|
||||
else
|
||||
footprint = new CVec[0];
|
||||
|
||||
// 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.
|
||||
Tick();
|
||||
@@ -85,8 +94,12 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
}
|
||||
|
||||
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
|
||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down && world.Map.Contains(cell))
|
||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
// Check the actor is inside the map
|
||||
if (!footprint.All(c => world.Map.MapTiles.Value.Contains(cell + locationOffset + c)))
|
||||
return true;
|
||||
|
||||
var newActorReference = new ActorReference(Actor.Name);
|
||||
newActorReference.Add(new OwnerInit(owner.Name));
|
||||
|
||||
|
||||
@@ -65,10 +65,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var underCursor = editorLayer.PreviewsAt(worldRenderer.Viewport.ViewToWorldPx(mi.Location))
|
||||
.FirstOrDefault();
|
||||
|
||||
var mapResources = world.Map.MapResources.Value;
|
||||
ResourceType type;
|
||||
if (underCursor != null)
|
||||
editorWidget.SetTooltip(underCursor.Tooltip);
|
||||
else if (world.Map.Contains(cell) && resources.TryGetValue(world.Map.MapResources.Value[cell].Type, out type))
|
||||
else if (mapResources.Contains(cell) && resources.TryGetValue(mapResources[cell].Type, out type))
|
||||
editorWidget.SetTooltip(type.Info.Name);
|
||||
else
|
||||
editorWidget.SetTooltip(null);
|
||||
@@ -84,8 +85,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (underCursor != null)
|
||||
editorLayer.Remove(underCursor);
|
||||
|
||||
if (world.Map.MapResources.Value[cell].Type != 0)
|
||||
world.Map.MapResources.Value[cell] = new ResourceTile();
|
||||
if (mapResources.Contains(cell) && mapResources[cell].Type != 0)
|
||||
mapResources[cell] = new ResourceTile();
|
||||
}
|
||||
else if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
|
||||
{
|
||||
|
||||
@@ -82,7 +82,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
public bool AllowResourceAt(CPos cell)
|
||||
{
|
||||
if (!world.Map.Contains(cell))
|
||||
var mapResources = world.Map.MapResources.Value;
|
||||
if (!mapResources.Contains(cell))
|
||||
return false;
|
||||
|
||||
var tile = world.Map.MapTiles.Value[cell];
|
||||
@@ -92,7 +93,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
var terrainType = world.TileSet.TerrainInfo[tileInfo.TerrainType];
|
||||
|
||||
if (world.Map.MapResources.Value[cell].Type == ResourceType.ResourceType)
|
||||
if (mapResources[cell].Type == ResourceType.ResourceType)
|
||||
return false;
|
||||
|
||||
if (!ResourceType.AllowedTerrainTypes.Contains(terrainType.Type))
|
||||
|
||||
@@ -79,6 +79,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
return true;
|
||||
|
||||
var map = world.Map;
|
||||
var mapTiles = map.MapTiles.Value;
|
||||
var mapHeight = map.MapHeight.Value;
|
||||
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
|
||||
|
||||
if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Move)
|
||||
@@ -87,7 +89,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var rules = map.Rules;
|
||||
var tileset = rules.TileSets[map.Tileset];
|
||||
var template = tileset.Templates[Template];
|
||||
var baseHeight = map.Contains(cell) ? map.MapHeight.Value[cell] : (byte)0;
|
||||
var baseHeight = mapHeight.Contains(cell) ? mapHeight[cell] : (byte)0;
|
||||
if (mi.Event == MouseInputEvent.Move && PlacementOverlapsSameTemplate(template, cell))
|
||||
return true;
|
||||
|
||||
@@ -100,11 +102,11 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var index = template.PickAny ? (byte)Game.CosmeticRandom.Next(0, template.TilesCount) : (byte)i;
|
||||
var c = cell + new CVec(x, y);
|
||||
if (!map.Contains(c))
|
||||
if (!mapTiles.Contains(c))
|
||||
continue;
|
||||
|
||||
map.MapTiles.Value[c] = new TerrainTile(Template, index);
|
||||
map.MapHeight.Value[c] = (byte)(baseHeight + template[index].Height).Clamp(0, world.TileSet.MaxGroundHeight);
|
||||
mapTiles[c] = new TerrainTile(Template, index);
|
||||
mapHeight[c] = (byte)(baseHeight + template[index].Height).Clamp(0, world.TileSet.MaxGroundHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +117,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
bool PlacementOverlapsSameTemplate(TerrainTemplateInfo template, CPos cell)
|
||||
{
|
||||
var map = world.Map;
|
||||
var mapTiles = map.MapTiles.Value;
|
||||
var i = 0;
|
||||
for (var y = 0; y < template.Size.Y; y++)
|
||||
{
|
||||
@@ -123,7 +126,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (template.Contains(i) && template[i] != null)
|
||||
{
|
||||
var c = cell + new CVec(x, y);
|
||||
if (map.Contains(c) && map.MapTiles.Value[c].Type == template.Id)
|
||||
if (mapTiles.Contains(c) && mapTiles[c].Type == template.Id)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,11 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// so we must also touch all the neighbouring tiles
|
||||
Dirty.Add(cell);
|
||||
foreach (var d in CVec.Directions)
|
||||
{
|
||||
var c = cell + d;
|
||||
if (Map.Contains(c))
|
||||
Dirty.Add(c);
|
||||
}
|
||||
Dirty.Add(cell + d);
|
||||
}
|
||||
|
||||
protected virtual string ChooseRandomVariant(ResourceType t)
|
||||
@@ -103,10 +99,16 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Set density based on the number of neighboring resources
|
||||
var adjacent = 0;
|
||||
var type = Tiles[c].Type;
|
||||
var resources = Map.MapResources.Value;
|
||||
for (var u = -1; u < 2; u++)
|
||||
{
|
||||
for (var v = -1; v < 2; v++)
|
||||
if (Map.MapResources.Value[c + new CVec(u, v)].Type == type.Info.ResourceType)
|
||||
{
|
||||
var cell = c + new CVec(u, v);
|
||||
if (resources.Contains(cell) && resources[cell].Type == type.Info.ResourceType)
|
||||
adjacent++;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.Max(int2.Lerp(0, type.Info.MaxDensity, adjacent, 9), 1);
|
||||
}
|
||||
@@ -139,7 +141,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return;
|
||||
|
||||
foreach (var c in Dirty)
|
||||
Tiles[c] = UpdateDirtyTile(c);
|
||||
if (Tiles.Contains(c))
|
||||
Tiles[c] = UpdateDirtyTile(c);
|
||||
|
||||
Dirty.Clear();
|
||||
|
||||
|
||||
@@ -50,9 +50,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var sum = 0;
|
||||
for (var u = -1; u < 2; u++)
|
||||
{
|
||||
for (var v = -1; v < 2; v++)
|
||||
if (content[cell + new CVec(u, v)].Type == t)
|
||||
{
|
||||
var c = cell + new CVec(u, v);
|
||||
if (content.Contains(c) && content[c].Type == t)
|
||||
++sum;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
DirtyCells(map.AllCells);
|
||||
visibleUnderShroud = map.Contains;
|
||||
|
||||
// All tiles are visible in the editor
|
||||
if (w.Type == WorldType.Editor)
|
||||
visibleUnderShroud = _ => true;
|
||||
else
|
||||
visibleUnderShroud = map.Contains;
|
||||
|
||||
visibleUnderFog = map.Contains;
|
||||
|
||||
var shroudSheet = shroudSprites[0].Sheet;
|
||||
|
||||
Reference in New Issue
Block a user