Fix crew monitor for rotated eyes (#11931)

This commit is contained in:
Leon Friedrich
2022-10-16 13:07:42 +13:00
committed by GitHub
parent c44f173f5e
commit 6e6ddc0cb8
5 changed files with 38 additions and 36 deletions

View File

@@ -16,6 +16,8 @@ public sealed class DirectionIcon : TextureRect
public static string StyleClassDirectionIconUnknown = "direction-icon-unknown"; // unknown direction / error
private Angle? _rotation;
private bool _snap;
float _minDistance;
public Angle? Rotation
{
@@ -33,29 +35,27 @@ public sealed class DirectionIcon : TextureRect
SetOnlyStyleClass(StyleClassDirectionIconUnknown);
}
public DirectionIcon(Direction direction) : this()
public DirectionIcon(bool snap = true, float minDistance = 0.1f) : this()
{
_snap = snap;
_minDistance = minDistance;
}
public void UpdateDirection(Direction direction)
{
Rotation = direction.ToAngle();
}
/// <summary>
/// Creates an icon with an arrow pointing in some direction.
/// </summary>
/// <param name="direction">The direction</param>
/// <param name="relativeAngle">The relative angle. This may be the players eye rotation, the grid rotation, or
/// maybe the world rotation of the entity that owns some BUI</param>
/// <param name="snap">If true, will snap the nearest cardinal or diagonal direction</param>
/// <param name="minDistance">If the distance is less than this, the arrow icon will be replaced by some other indicator</param>
public DirectionIcon(Vector2 direction, Angle relativeAngle, bool snap, float minDistance = 0.1f) : this()
public void UpdateDirection(Vector2 direction, Angle relativeAngle)
{
if (direction.EqualsApprox(Vector2.Zero, minDistance))
if (direction.EqualsApprox(Vector2.Zero, _minDistance))
{
SetOnlyStyleClass(StyleClassDirectionIconHere);
return;
}
var rotation = direction.ToWorldAngle() - relativeAngle;
Rotation = snap ? rotation.GetDir().ToAngle() : rotation;
Rotation = _snap ? rotation.GetDir().ToAngle() : rotation;
}
protected override void Draw(DrawingHandleScreen handle)