adds tilting on slopes to suitable actor previews
This commit is contained in:
committed by
Gustas
parent
1a037c06bf
commit
00857df990
@@ -23,6 +23,12 @@ namespace OpenRA.Mods.Common
|
||||
: base(value) { }
|
||||
}
|
||||
|
||||
public class TerrainOrientationInit : ValueActorInit<WRot>, ISingleInstanceInit
|
||||
{
|
||||
public TerrainOrientationInit(WRot value)
|
||||
: base(value) { }
|
||||
}
|
||||
|
||||
public class CreationActivityDelayInit : ValueActorInit<int>, ISingleInstanceInit
|
||||
{
|
||||
public CreationActivityDelayInit(int value)
|
||||
|
||||
@@ -67,20 +67,32 @@ namespace OpenRA.Mods.Common.Graphics
|
||||
if (facingInfo == null)
|
||||
return () => WRot.None;
|
||||
|
||||
WAngle facing;
|
||||
|
||||
// Dynamic facing takes priority
|
||||
var dynamicInit = reference.GetOrDefault<DynamicFacingInit>();
|
||||
if (dynamicInit != null)
|
||||
{
|
||||
// TODO: Account for terrain slope
|
||||
var getFacing = dynamicInit.Value;
|
||||
return () => WRot.FromYaw(getFacing());
|
||||
facing = getFacing();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Fall back to initial actor facing if an Init isn't available
|
||||
var facingInit = reference.GetOrDefault<FacingInit>();
|
||||
var facing = facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing();
|
||||
var orientation = WRot.FromYaw(facing);
|
||||
return () => orientation;
|
||||
facing = facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing();
|
||||
}
|
||||
|
||||
var mobileInfo = Actor.TraitInfoOrDefault<MobileInfo>();
|
||||
var location = reference.GetOrDefault<LocationInit>();
|
||||
if (location == null || mobileInfo == null || mobileInfo.TerrainOrientationAdjustmentMargin.Length < 0)
|
||||
return () => WRot.FromYaw(facing);
|
||||
|
||||
var orientationInit = reference.GetOrDefault<TerrainOrientationInit>();
|
||||
var terrainOrientation = orientationInit != null ? orientationInit.Value : World.Map.TerrainOrientation(location.Value);
|
||||
var terrainAdjustedFacing = new WRot(new WVec(0, 0, 1024).Rotate(terrainOrientation), facing);
|
||||
|
||||
return () => terrainOrientation + terrainAdjustedFacing;
|
||||
}
|
||||
|
||||
public Func<WAngle> GetFacing()
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly TooltipInfoBase tooltip;
|
||||
IActorPreview[] previews;
|
||||
readonly ActorReference reference;
|
||||
readonly Action<CPos> onCellEntryChanged;
|
||||
readonly Dictionary<INotifyEditorPlacementInfo, object> editorData = new();
|
||||
|
||||
public EditorActorPreview(WorldRenderer worldRenderer, string id, ActorReference reference, PlayerReference owner)
|
||||
@@ -98,6 +99,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
SelectionBox = new SelectionBoxAnnotationRenderable(new WPos(CenterPosition.X, CenterPosition.Y, 8192),
|
||||
new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height), Color.White);
|
||||
|
||||
// TODO: updating all actors on the map is not very efficient.
|
||||
onCellEntryChanged = _ => GeneratePreviews();
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
@@ -134,12 +138,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
foreach (var notify in Info.TraitInfos<INotifyEditorPlacementInfo>())
|
||||
editorData[notify] = notify.AddedToEditor(this, worldRenderer.World);
|
||||
|
||||
// TODO: this should subscribe to ramp cell map as well.
|
||||
worldRenderer.World.Map.Height.CellEntryChanged += onCellEntryChanged;
|
||||
}
|
||||
|
||||
public void RemovedFromEditor()
|
||||
{
|
||||
foreach (var kv in editorData)
|
||||
kv.Key.RemovedFromEditor(this, worldRenderer.World, kv.Value);
|
||||
|
||||
worldRenderer.World.Map.Height.CellEntryChanged -= onCellEntryChanged;
|
||||
}
|
||||
|
||||
public void AddInit<T>(T init) where T : ActorInit
|
||||
|
||||
Reference in New Issue
Block a user