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) { }
|
: base(value) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TerrainOrientationInit : ValueActorInit<WRot>, ISingleInstanceInit
|
||||||
|
{
|
||||||
|
public TerrainOrientationInit(WRot value)
|
||||||
|
: base(value) { }
|
||||||
|
}
|
||||||
|
|
||||||
public class CreationActivityDelayInit : ValueActorInit<int>, ISingleInstanceInit
|
public class CreationActivityDelayInit : ValueActorInit<int>, ISingleInstanceInit
|
||||||
{
|
{
|
||||||
public CreationActivityDelayInit(int value)
|
public CreationActivityDelayInit(int value)
|
||||||
|
|||||||
@@ -67,20 +67,32 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
if (facingInfo == null)
|
if (facingInfo == null)
|
||||||
return () => WRot.None;
|
return () => WRot.None;
|
||||||
|
|
||||||
|
WAngle facing;
|
||||||
|
|
||||||
// Dynamic facing takes priority
|
// Dynamic facing takes priority
|
||||||
var dynamicInit = reference.GetOrDefault<DynamicFacingInit>();
|
var dynamicInit = reference.GetOrDefault<DynamicFacingInit>();
|
||||||
if (dynamicInit != null)
|
if (dynamicInit != null)
|
||||||
{
|
{
|
||||||
// TODO: Account for terrain slope
|
|
||||||
var getFacing = dynamicInit.Value;
|
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>();
|
||||||
|
facing = facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to initial actor facing if an Init isn't available
|
var mobileInfo = Actor.TraitInfoOrDefault<MobileInfo>();
|
||||||
var facingInit = reference.GetOrDefault<FacingInit>();
|
var location = reference.GetOrDefault<LocationInit>();
|
||||||
var facing = facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing();
|
if (location == null || mobileInfo == null || mobileInfo.TerrainOrientationAdjustmentMargin.Length < 0)
|
||||||
var orientation = WRot.FromYaw(facing);
|
return () => WRot.FromYaw(facing);
|
||||||
return () => orientation;
|
|
||||||
|
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()
|
public Func<WAngle> GetFacing()
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly TooltipInfoBase tooltip;
|
readonly TooltipInfoBase tooltip;
|
||||||
IActorPreview[] previews;
|
IActorPreview[] previews;
|
||||||
readonly ActorReference reference;
|
readonly ActorReference reference;
|
||||||
|
readonly Action<CPos> onCellEntryChanged;
|
||||||
readonly Dictionary<INotifyEditorPlacementInfo, object> editorData = new();
|
readonly Dictionary<INotifyEditorPlacementInfo, object> editorData = new();
|
||||||
|
|
||||||
public EditorActorPreview(WorldRenderer worldRenderer, string id, ActorReference reference, PlayerReference owner)
|
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),
|
SelectionBox = new SelectionBoxAnnotationRenderable(new WPos(CenterPosition.X, CenterPosition.Y, 8192),
|
||||||
new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height), Color.White);
|
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()
|
public void Tick()
|
||||||
@@ -134,12 +138,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
foreach (var notify in Info.TraitInfos<INotifyEditorPlacementInfo>())
|
foreach (var notify in Info.TraitInfos<INotifyEditorPlacementInfo>())
|
||||||
editorData[notify] = notify.AddedToEditor(this, worldRenderer.World);
|
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()
|
public void RemovedFromEditor()
|
||||||
{
|
{
|
||||||
foreach (var kv in editorData)
|
foreach (var kv in editorData)
|
||||||
kv.Key.RemovedFromEditor(this, worldRenderer.World, kv.Value);
|
kv.Key.RemovedFromEditor(this, worldRenderer.World, kv.Value);
|
||||||
|
|
||||||
|
worldRenderer.World.Map.Height.CellEntryChanged -= onCellEntryChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddInit<T>(T init) where T : ActorInit
|
public void AddInit<T>(T init) where T : ActorInit
|
||||||
|
|||||||
Reference in New Issue
Block a user