(021a3d977) Draw the steering indicator at the center of the sub, not at the center of the display. Change the color of the docking indicators when ready to dock
This commit is contained in:
@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
|
||||
};
|
||||
|
||||
private float prevDockingDist;
|
||||
|
||||
|
||||
public Vector2 DisplayOffset { get; private set; }
|
||||
|
||||
public float DisplayRadius { get; private set; }
|
||||
@@ -578,14 +578,14 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
size.Y = 0.0f;
|
||||
}
|
||||
GUI.DrawLine(spriteBatch, center + offset - size / 2, center + offset + size / 2, Color.LightGreen, width: (int)(zoom));
|
||||
GUI.DrawLine(spriteBatch, center + offset - size, center + offset + size, Color.LightGreen, width: (int)(zoom * 2.5f));
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDockingIndicator(SpriteBatch spriteBatch, Steering steering, ref Vector2 transducerCenter)
|
||||
{
|
||||
float scale = displayScale * zoom;
|
||||
|
||||
|
||||
Vector2 worldFocusPos = (steering.DockingSource.Item.WorldPosition + steering.DockingTarget.Item.WorldPosition) / 2.0f;
|
||||
worldFocusPos.X = steering.DockingTarget.Item.WorldPosition.X;
|
||||
|
||||
@@ -602,6 +602,9 @@ namespace Barotrauma.Items.Components
|
||||
System.Diagnostics.Debug.Assert(steering.DockingSource.IsHorizontal == steering.DockingTarget.IsHorizontal);
|
||||
Vector2 diff = steering.DockingTarget.Item.WorldPosition - steering.DockingSource.Item.WorldPosition;
|
||||
float dist = diff.Length();
|
||||
bool readyToDock =
|
||||
Math.Abs(diff.X) < steering.DockingTarget.DistanceTolerance.X &&
|
||||
Math.Abs(diff.Y) < steering.DockingTarget.DistanceTolerance.Y;
|
||||
|
||||
Vector2 dockingDir = sourcePortPos - targetPortPos;
|
||||
Vector2 normalizedDockingDir = Vector2.Normalize(dockingDir);
|
||||
@@ -617,7 +620,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
Color staticLineColor = Color.White * 0.8f;
|
||||
Color staticLineColor = Color.White * 0.5f;
|
||||
|
||||
float sector = MathHelper.ToRadians(MathHelper.Lerp(10.0f, 45.0f, MathHelper.Clamp(dist / steering.DockingAssistThreshold, 0.0f, 1.0f)));
|
||||
float sectorLength = DisplayRadius;
|
||||
@@ -626,7 +629,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Vector2 midNormal = new Vector2(-normalizedDockingDir.Y, normalizedDockingDir.X);
|
||||
|
||||
DrawLine(spriteBatch, targetPortPos, targetPortPos + normalizedDockingDir * midLength, staticLineColor, width: 2);
|
||||
DrawLine(spriteBatch, targetPortPos, targetPortPos + normalizedDockingDir * midLength, readyToDock ? Color.LightGreen : staticLineColor, width: 2);
|
||||
DrawLine(spriteBatch, targetPortPos,
|
||||
targetPortPos + MathUtils.RotatePoint(normalizedDockingDir, sector) * sectorLength, staticLineColor, width: 2);
|
||||
DrawLine(spriteBatch, targetPortPos,
|
||||
@@ -646,39 +649,13 @@ namespace Barotrauma.Items.Components
|
||||
Vector2.Dot(normalizedDockingDir, MathUtils.RotatePoint(normalizedDockingDir, indicatorSector)) <
|
||||
Vector2.Dot(normalizedDockingDir, Vector2.Normalize(dockingDir));
|
||||
|
||||
Color indicatorColor = withinSector ? Color.LightGreen * 0.9f : Color.Red * 0.9f;
|
||||
Color indicatorColor = withinSector ? Color.LightGreen * 0.8f : Color.Red * 0.8f;
|
||||
|
||||
DrawLine(spriteBatch, targetPortPos,
|
||||
targetPortPos + MathUtils.RotatePoint(normalizedDockingDir,indicatorSector) * indicatorSectorLength, indicatorColor, width: 2);
|
||||
DrawLine(spriteBatch, targetPortPos,
|
||||
targetPortPos + MathUtils.RotatePoint(normalizedDockingDir, -indicatorSector) * indicatorSectorLength, indicatorColor, width: 2);
|
||||
|
||||
/*if (steering.DockingSource.IsHorizontal)
|
||||
{
|
||||
if (yDist < steering.DockingSource.DistanceTolerance.Y)
|
||||
{
|
||||
DrawLine(spriteBatch, sourcePortPos, new Vector2(targetPortPos.X, sourcePortPos.Y), xColor, width: 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine(spriteBatch, sourcePortPos, new Vector2(midPos.X, sourcePortPos.Y), xColor, width: 3);
|
||||
DrawLine(spriteBatch, targetPortPos, new Vector2(midPos.X, targetPortPos.Y), xColor, width: 3);
|
||||
DrawLine(spriteBatch, new Vector2(midPos.X, sourcePortPos.Y), new Vector2(midPos.X, targetPortPos.Y), yColor, width: 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xDist < steering.DockingSource.DistanceTolerance.X)
|
||||
{
|
||||
DrawLine(spriteBatch, sourcePortPos, new Vector2(sourcePortPos.X, targetPortPos.Y), yColor, width: 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLine(spriteBatch, sourcePortPos, new Vector2(sourcePortPos.X, midPos.Y), yColor, width: 3);
|
||||
DrawLine(spriteBatch, targetPortPos, new Vector2(targetPortPos.X, midPos.Y), yColor, width: 3);
|
||||
DrawLine(spriteBatch, new Vector2(sourcePortPos.X, midPos.Y), new Vector2(targetPortPos.X, midPos.Y), xColor, width: 3);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
private void UpdateDisruptions(Vector2 pingSource, float worldPingRadius, float worldPrevPingRadius)
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private GUIComponent statusContainer, dockingContainer;
|
||||
|
||||
private GUIButton dockingButton;
|
||||
|
||||
private GUIFrame autoPilotControlsDisabler;
|
||||
|
||||
private GUIComponent steerArea;
|
||||
@@ -288,7 +290,7 @@ namespace Barotrauma.Items.Components
|
||||
{ MinSize = new Point(150, 0), AbsoluteOffset = new Point((int)(viewSize * 0.9f), 0) }, style: null);
|
||||
var paddedDockingContainer = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), dockingContainer.RectTransform, Anchor.Center), style: null);
|
||||
|
||||
var dockButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.3f), paddedDockingContainer.RectTransform, Anchor.Center), "Dock");
|
||||
dockingButton = new GUIButton(new RectTransform(new Vector2(0.3f, 0.3f), paddedDockingContainer.RectTransform, Anchor.Center), "Dock");
|
||||
|
||||
new GUIButton(new RectTransform(new Vector2(0.3f, 0.3f), paddedDockingContainer.RectTransform, Anchor.CenterLeft), "<")
|
||||
{
|
||||
@@ -383,16 +385,20 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 displaySubPos = ((posToMaintain.Value - sonar.DisplayOffset * sonar.Zoom - controlledSub.WorldPosition)) / sonar.Range * sonar.DisplayRadius * sonar.Zoom;
|
||||
displaySubPos.Y = -displaySubPos.Y;
|
||||
displaySubPos = displaySubPos.ClampLength(velRect.Width / 2);
|
||||
displaySubPos = velRect.Center.ToVector2() + displaySubPos;
|
||||
|
||||
//map velocity from rectangle to circle
|
||||
Vector2 unitTargetVel = targetVelocity / 100.0f;
|
||||
Vector2 steeringPos = new Vector2(
|
||||
targetVelocity.X * 0.9f * (float)Math.Sqrt(1.0f - 0.5f * unitTargetVel.Y * unitTargetVel.Y),
|
||||
-targetVelocity.Y * 0.9f * (float)Math.Sqrt(1.0f - 0.5f * unitTargetVel.X * unitTargetVel.X));
|
||||
steeringPos.X += velRect.Center.X;
|
||||
steeringPos.Y += velRect.Center.Y;
|
||||
steeringPos += displaySubPos;
|
||||
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(velRect.Center.X, velRect.Center.Y),
|
||||
displaySubPos,
|
||||
steeringPos,
|
||||
Color.CadetBlue, 0, 2);
|
||||
}
|
||||
@@ -466,6 +472,15 @@ namespace Barotrauma.Items.Components
|
||||
dockingContainer.Visible = DockingModeEnabled;
|
||||
statusContainer.Visible = !DockingModeEnabled;
|
||||
|
||||
if (DockingModeEnabled)
|
||||
{
|
||||
if (Math.Abs(DockingSource.Item.WorldPosition.X - DockingTarget.Item.WorldPosition.X) < DockingSource.DistanceTolerance.X &&
|
||||
Math.Abs(DockingSource.Item.WorldPosition.X - DockingTarget.Item.WorldPosition.X) < DockingSource.DistanceTolerance.X)
|
||||
{
|
||||
//TODO: flash docking button
|
||||
}
|
||||
}
|
||||
|
||||
autoPilotControlsDisabler.Visible = !AutoPilot;
|
||||
|
||||
if (voltage < minVoltage && currPowerConsumption > 0.0f)
|
||||
@@ -501,7 +516,19 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (Vector2.Distance(PlayerInput.MousePosition, steerArea.Rect.Center.ToVector2()) < steerArea.Rect.Width / 2)
|
||||
{
|
||||
if (PlayerInput.LeftButtonHeld())
|
||||
tipContainer.Visible = true;
|
||||
tipContainer.Text = noPowerTip;
|
||||
return;
|
||||
}
|
||||
|
||||
tipContainer.Visible = AutoPilot;
|
||||
if (AutoPilot)
|
||||
{
|
||||
if (maintainPos)
|
||||
{
|
||||
tipContainer.Text = autoPilotMaintainPosTip;
|
||||
}
|
||||
else if (LevelStartSelected)
|
||||
{
|
||||
Vector2 inputPos = PlayerInput.MousePosition - steerArea.Rect.Center.ToVector2();
|
||||
inputPos.Y = -inputPos.Y;
|
||||
@@ -567,8 +594,7 @@ namespace Barotrauma.Items.Components
|
||||
inputCumulation = 0;
|
||||
keyboardInput = Vector2.Zero;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float closestDist = DockingAssistThreshold * DockingAssistThreshold;
|
||||
DockingModeEnabled = false;
|
||||
DockingSource = null;
|
||||
|
||||
Reference in New Issue
Block a user