Use new IAutoRenderSize for determining actor render bounds

This commit is contained in:
reaperrr
2017-09-10 10:44:31 +02:00
committed by Pavel Penev
parent 2501a93b87
commit 56b6aabbb8
26 changed files with 158 additions and 3 deletions

View File

@@ -138,7 +138,7 @@ namespace OpenRA
Rectangle DetermineRenderBounds()
{
var size = TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
var size = TraitsImplementing<IAutoRenderSize>().Select(x => x.RenderSize(this)).FirstOrDefault(Exts.IsTraitEnabled);
var offset = -size / 2;
return new Rectangle(offset.X, offset.Y, size.X, size.Y);

View File

@@ -101,6 +101,9 @@ namespace OpenRA.Traits
public interface IAutoSelectionSizeInfo : ITraitInfoInterface { }
public interface IAutoSelectionSize { int2 SelectionSize(Actor self); }
public interface IAutoRenderSizeInfo : ITraitInfoInterface { }
public interface IAutoRenderSize { int2 RenderSize(Actor self); }
public interface IIssueOrder
{
IEnumerable<IOrderTargeter> Orders { get; }

View File

@@ -328,6 +328,7 @@
<Compile Include="Traits\Crushable.cs" />
<Compile Include="Traits\CustomSellValue.cs" />
<Compile Include="Traits\CustomSelectionSize.cs" />
<Compile Include="Traits\Render\CustomRenderSize.cs" />
<Compile Include="Traits\DamagedByTerrain.cs" />
<Compile Include="Traits\DeliversCash.cs" />
<Compile Include="Traits\DeliversExperience.cs" />
@@ -417,6 +418,7 @@
<Compile Include="Traits\BodyOrientation.cs" />
<Compile Include="Traits\QuantizeFacingsFromSequence.cs" />
<Compile Include="Traits\Render\AutoSelectionSize.cs" />
<Compile Include="Traits\Render\AutoRenderSize.cs" />
<Compile Include="Traits\Render\CashTricklerBar.cs" />
<Compile Include="Traits\Render\CustomTerrainDebugOverlay.cs" />
<Compile Include="Traits\Render\Hovers.cs" />

View File

@@ -0,0 +1,32 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Automatically calculates the screen map boundaries from the sprite size.")]
public class AutoRenderSizeInfo : ITraitInfo, Requires<RenderSpritesInfo>, IAutoRenderSizeInfo
{
public object Create(ActorInitializer init) { return new AutoRenderSize(this); }
}
public class AutoRenderSize : IAutoRenderSize
{
public AutoRenderSize(AutoRenderSizeInfo info) { }
public int2 RenderSize(Actor self)
{
var rs = self.Trait<RenderSprites>();
return rs.AutoRenderSize(self);
}
}
}

View File

@@ -0,0 +1,35 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Special case trait for actors that need to define targetable area and screen map bounds manually.")]
public class CustomRenderSizeInfo : ITraitInfo, IAutoRenderSizeInfo
{
[FieldLoader.Require]
public readonly int[] CustomBounds = null;
public object Create(ActorInitializer init) { return new CustomRenderSize(this); }
}
public class CustomRenderSize : IAutoRenderSize
{
readonly CustomRenderSizeInfo info;
public CustomRenderSize(CustomRenderSizeInfo info) { this.info = info; }
public int2 RenderSize(Actor self)
{
return new int2(info.CustomBounds[0], info.CustomBounds[1]);
}
}
}

View File

@@ -238,6 +238,12 @@ namespace OpenRA.Mods.Common.Traits.Render
// Required by WithSpriteBody and WithInfantryBody
public int2 AutoSelectionSize(Actor self)
{
return AutoRenderSize(self);
}
// Required by WithSpriteBody and WithInfantryBody
public int2 AutoRenderSize(Actor self)
{
return anims.Where(b => b.IsVisible
&& b.Animation.Animation.CurrentSequence != null)

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, IAutoSelectionSizeInfo
public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, IAutoSelectionSizeInfo, IAutoRenderSizeInfo
{
public readonly string Sequence = "idle";
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoSelectionSize
public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoSelectionSize, IAutoRenderSize
{
readonly int2 size;
@@ -61,5 +61,6 @@ namespace OpenRA.Mods.Common.Traits.Render
}
public int2 SelectionSize(Actor self) { return size; }
public int2 RenderSize(Actor self) { return size; }
}
}

View File

@@ -1234,6 +1234,25 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
// Split Selection- and RenderSize
if (engineVersion < 20171115)
{
var autoSelSize = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("AutoSelectionSize", StringComparison.Ordinal));
if (autoSelSize != null)
node.Value.Nodes.Add(new MiniYamlNode("AutoRenderSize", ""));
var customSelSize = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("CustomSelectionSize", StringComparison.Ordinal));
if (customSelSize != null)
{
var bounds = customSelSize.Value.Nodes.FirstOrDefault(n => n.Key == "CustomBounds");
var customRenderSize = new MiniYamlNode("CustomRenderSize", "");
if (bounds != null)
customRenderSize.Value.Nodes.Add(bounds);
node.Value.Nodes.Add(customRenderSize);
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}

View File

@@ -417,6 +417,8 @@ BRIDGE1:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 0,2
CustomRenderSize:
CustomBounds: 96,96
BRIDGE2:
Inherits: ^Bridge
@@ -434,6 +436,8 @@ BRIDGE2:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 2,2
CustomRenderSize:
CustomBounds: 120,120
BRIDGE3:
Inherits: ^Bridge
@@ -451,6 +455,8 @@ BRIDGE3:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 1,2
CustomRenderSize:
CustomBounds: 144,120
BRIDGE4:
Inherits: ^Bridge
@@ -468,6 +474,8 @@ BRIDGE4:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 3,2
CustomRenderSize:
CustomBounds: 144,96
BRIDGEHUT:
AlwaysVisible:
@@ -479,6 +487,8 @@ BRIDGEHUT:
LegacyBridgeHut:
Targetable:
TargetTypes: BridgeHut, C4
CustomRenderSize:
CustomBounds: 48,48
C1:
Inherits: ^CivInfantry

View File

@@ -13,6 +13,7 @@
QuantizeFacingsFromSequence:
AutoSelectionSize:
RenderSprites:
AutoRenderSize:
^1x1Shape:
HitShape:

View File

@@ -134,3 +134,4 @@ FLARE:
AutoSelectionSize:
EditorTilesetFilter:
Categories: System
AutoRenderSize:

View File

@@ -243,6 +243,7 @@ SILO:
SelectionDecorations:
VisualBounds: 49,30
-AcceptsDeliveredCash:
AutoRenderSize:
PYLE:
Inherits: ^BaseBuilding
@@ -814,6 +815,7 @@ SAM:
Amount: -20
BodyOrientation:
UseClassicFacingFudge: True
AutoRenderSize:
OBLI:
Inherits: ^Defense

View File

@@ -88,6 +88,7 @@ tile475:
BodyOrientation:
QuantizedFacings: 1
AutoSelectionSize:
AutoRenderSize:
# Placed after the sietch is destroyed so that the cliff is still unpassable
invisibleBlocker:

View File

@@ -63,6 +63,7 @@ spicebloom:
Radius: 512
EditorTilesetFilter:
Categories: System
AutoRenderSize:
sandworm:
Inherits@1: ^SpriteActor

View File

@@ -13,6 +13,7 @@
QuantizeFacingsFromSequence:
AutoSelectionSize:
RenderSprites:
AutoRenderSize:
^GainsExperience:
GainsExperience:

View File

@@ -138,6 +138,8 @@ crate:
CustomBounds: 20,20
EditorTilesetFilter:
Categories: System
CustomRenderSize:
CustomBounds: 20,20
mpspawn:
EditorOnlyTooltip:

View File

@@ -22,6 +22,7 @@ TRAN.Extraction:
AutoSelectionSize:
RenderSprites:
Image: tran
AutoRenderSize:
TRAN.Insertion:
Inherits: TRAN.Extraction
@@ -31,6 +32,7 @@ TRAN.Insertion:
AutoSelectionSize:
RenderSprites:
Image: tran
AutoRenderSize:
EINSTEIN:
Passenger:

View File

@@ -320,6 +320,8 @@ BARL:
-Demolishable:
EditorTilesetFilter:
Categories: Decoration
CustomRenderSize:
CustomBounds: 24,24
BRL3:
Inherits: ^TechBuilding
@@ -344,6 +346,8 @@ BRL3:
-Demolishable:
EditorTilesetFilter:
Categories: Decoration
CustomRenderSize:
CustomBounds: 24,24
AMMOBOX1:
Inherits: ^AmmoBox
@@ -491,6 +495,8 @@ BRIDGE1:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 0,1
CustomRenderSize:
CustomBounds: 120,72
BRIDGE2:
Inherits: ^Bridge
@@ -509,6 +515,8 @@ BRIDGE2:
FreeActor@south:
Actor: bridgehut
SpawnOffset: 2,1
CustomRenderSize:
CustomBounds: 120,48
SBRIDGE1:
Inherits: ^Bridge
@@ -527,6 +535,8 @@ SBRIDGE1:
FreeActor@south:
Actor: bridgehut.small
SpawnOffset: 1,1
CustomRenderSize:
CustomBounds: 72,48
SBRIDGE2:
Inherits: ^Bridge
@@ -545,6 +555,8 @@ SBRIDGE2:
FreeActor@east:
Actor: bridgehut.small
SpawnOffset: 1,1
CustomRenderSize:
CustomBounds: 48,72
SBRIDGE3:
Inherits: ^Bridge

View File

@@ -12,6 +12,7 @@
QuantizeFacingsFromSequence:
AutoSelectionSize:
RenderSprites:
AutoRenderSize:
^1x1Shape:
HitShape:
@@ -786,6 +787,8 @@
Type: Light
EditorTilesetFilter:
Categories: Decoration
CustomRenderSize:
CustomBounds: 24,24
^CivBuilding:
Inherits: ^TechBuilding
@@ -974,6 +977,8 @@
ScriptTriggers:
BodyOrientation:
QuantizedFacings: 1
CustomRenderSize:
CustomBounds: 96,48
^Rock:
Inherits@1: ^SpriteActor

View File

@@ -201,6 +201,7 @@ FLARE:
AutoSelectionSize:
EditorTilesetFilter:
Categories: Decoration
AutoRenderSize:
MINE:
Inherits@1: ^SpriteActor

View File

@@ -381,3 +381,4 @@ HUNTER:
HitShape:
EditorTilesetFilter:
Categories: System
AutoRenderSize:

View File

@@ -34,6 +34,7 @@ CABHUT:
Name: Bridge
EditorTilesetFilter:
Categories: Bridge
AutoRenderSize:
^LowBridge:
Inherits: ^LowBridgeRamp
@@ -81,6 +82,8 @@ LOBRDG_A_D:
BOffset: 1,1
CustomSelectionSize:
CustomBounds: 96, 48
CustomRenderSize:
CustomBounds: 96, 48
LOBRDG_B:
Inherits: ^LowBridge
@@ -117,6 +120,8 @@ LOBRDG_B_D:
BOffset: -1,1
CustomSelectionSize:
CustomBounds: 96, 48
CustomRenderSize:
CustomBounds: 96, 48
LOBRDG_R_SE:
Inherits: ^LowBridgeRamp
@@ -177,6 +182,8 @@ LOBRDG_R_SW:
CustomBounds: 96, 144
EditorTilesetFilter:
Categories: Bridge
CustomRenderSize:
CustomBounds: 96, 144
BRIDGE1:
Inherits: ^ElevatedBridgePlaceholder

View File

@@ -15,6 +15,7 @@
QuantizeFacingsFromSequence:
AutoSelectionSize:
RenderSprites:
AutoRenderSize:
^GainsExperience:
GainsExperience:
@@ -431,6 +432,8 @@
CustomBounds: 24,24
EditorTilesetFilter:
Categories: System
CustomRenderSize:
CustomBounds: 24,24
^Wall:
Inherits@1: ^SpriteActor
@@ -1099,6 +1102,7 @@
TerrainType: Rail
EditorTilesetFilter:
Categories: Railway
AutoRenderSize:
^Tunnel:
RenderSprites:
@@ -1118,6 +1122,8 @@
Dimensions: 3, 3
EditorTilesetFilter:
Categories: Tunnel
CustomRenderSize:
CustomBounds: 144, 144
^Gate:
Inherits: ^Building

View File

@@ -188,6 +188,7 @@ JUMPJET.Husk:
FallbackSequence: die-splash
EditorTilesetFilter:
Categories: Husk
AutoRenderSize:
GHOST:
Inherits: ^Soldier

View File

@@ -129,6 +129,8 @@ NAFNCE:
Weapons: SmallDebris
Pieces: 0, 1
Range: 2c0, 5c0
CustomRenderSize:
CustomBounds: 48, 24
NALASR:
Inherits: ^Defense

View File

@@ -118,6 +118,7 @@ VEINHOLE:
AutoSelectionSize:
EditorTilesetFilter:
Categories: Resource spawn
AutoRenderSize:
^TibFlora:
Inherits: ^Tree