private bool NudgeButtonClicked(GUIButton btn, object userdata) { if (!MaintainPos || !AutoPilot) { AutoPilot = true; posToMaintain = item.Submarine.WorldPosition; } MaintainPos = true; if (userdata is Vector2) { Sonar sonar = item.GetComponent <Sonar>(); Vector2 nudgeAmount = (Vector2)userdata; if (sonar != null) { nudgeAmount *= sonar == null ? 500.0f : 500.0f / sonar.Zoom; } PosToMaintain += nudgeAmount; } return(true); }
public override void OnItemLoaded() { sonar = item.GetComponent <Sonar>(); }
public void DrawHUD(SpriteBatch spriteBatch, Rectangle rect) { int width = rect.Width, height = rect.Height; int x = rect.X; int y = rect.Y; if (Voltage < MinVoltage) { return; } Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); Vector2 steeringOrigin = steerArea.Rect.Center.ToVector2(); if (!AutoPilot) { Vector2 unitSteeringInput = steeringInput / 100.0f; //map input from rectangle to circle Vector2 steeringInputPos = new Vector2( steeringInput.X * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.Y * unitSteeringInput.Y), -steeringInput.Y * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.X * unitSteeringInput.X)); steeringInputPos += steeringOrigin; if (steeringIndicator != null) { Vector2 dir = steeringInputPos - steeringOrigin; float angle = (float)Math.Atan2(dir.Y, dir.X); steeringIndicator.Draw(spriteBatch, steeringOrigin, Color.White, origin: steeringIndicator.Origin, rotate: angle, scale: new Vector2(dir.Length() / steeringIndicator.size.X, 1.0f)); } else { GUI.DrawLine(spriteBatch, steeringOrigin, steeringInputPos, Color.LightGray); GUI.DrawRectangle(spriteBatch, new Rectangle((int)steeringInputPos.X - 5, (int)steeringInputPos.Y - 5, 10, 10), Color.White); } if (velRect.Contains(PlayerInput.MousePosition)) { GUI.DrawRectangle(spriteBatch, new Rectangle((int)steeringInputPos.X - 4, (int)steeringInputPos.Y - 4, 8, 8), GUI.Style.Red, thickness: 2); } } else if (posToMaintain.HasValue && !LevelStartSelected && !LevelEndSelected) { Sonar sonar = item.GetComponent <Sonar>(); if (sonar != null && controlledSub != null) { Vector2 displayPosToMaintain = ((posToMaintain.Value - controlledSub.WorldPosition)) / sonar.Range * sonar.DisplayRadius * sonar.Zoom; displayPosToMaintain.Y = -displayPosToMaintain.Y; displayPosToMaintain = displayPosToMaintain.ClampLength(velRect.Width / 2); displayPosToMaintain = steerArea.Rect.Center.ToVector2() + displayPosToMaintain; Color crosshairColor = GUI.Style.Orange * (0.5f + ((float)Math.Sin(Timing.TotalTime * 5.0f) + 1.0f) / 4.0f); if (maintainPosIndicator != null) { maintainPosIndicator.Draw(spriteBatch, displayPosToMaintain, crosshairColor, scale: 0.5f * sonar.Zoom); } else { float crossHairSize = 8.0f; GUI.DrawLine(spriteBatch, displayPosToMaintain + Vector2.UnitY * crossHairSize, displayPosToMaintain - Vector2.UnitY * crossHairSize, crosshairColor, width: 3); GUI.DrawLine(spriteBatch, displayPosToMaintain + Vector2.UnitX * crossHairSize, displayPosToMaintain - Vector2.UnitX * crossHairSize, crosshairColor, width: 3); } if (maintainPosOriginIndicator != null) { maintainPosOriginIndicator.Draw(spriteBatch, steeringOrigin, GUI.Style.Orange, scale: 0.5f * sonar.Zoom); } else { GUI.DrawRectangle(spriteBatch, new Rectangle((int)steeringOrigin.X - 5, (int)steeringOrigin.Y - 5, 10, 10), GUI.Style.Orange); } } } //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 += steeringOrigin; if (steeringIndicator != null) { Vector2 dir = steeringPos - steeringOrigin; float angle = (float)Math.Atan2(dir.Y, dir.X); steeringIndicator.Draw(spriteBatch, steeringOrigin, Color.Gray, origin: steeringIndicator.Origin, rotate: angle, scale: new Vector2(dir.Length() / steeringIndicator.size.X, 0.7f)); } else { GUI.DrawLine(spriteBatch, steeringOrigin, steeringPos, Color.CadetBlue, 0, 2); } }
public void DrawHUD(SpriteBatch spriteBatch, Rectangle rect) { int width = rect.Width, height = rect.Height; int x = rect.X; int y = rect.Y; if (voltage < minVoltage && currPowerConsumption > 0.0f) { return; } Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40); GUI.DrawLine(spriteBatch, new Vector2(velRect.Center.X, velRect.Center.Y), new Vector2(velRect.Center.X + currVelocity.X, velRect.Center.Y - currVelocity.Y), Color.Gray); if (!AutoPilot) { Vector2 unitSteeringInput = steeringInput / 100.0f; //map input from rectangle to circle Vector2 steeringInputPos = new Vector2( steeringInput.X * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.Y * unitSteeringInput.Y), -steeringInput.Y * (float)Math.Sqrt(1.0f - 0.5f * unitSteeringInput.X * unitSteeringInput.X)); steeringInputPos.X += velRect.Center.X; steeringInputPos.Y += velRect.Center.Y; GUI.DrawLine(spriteBatch, new Vector2(velRect.Center.X, velRect.Center.Y), steeringInputPos, Color.LightGray); GUI.DrawRectangle(spriteBatch, new Rectangle((int)steeringInputPos.X - 5, (int)steeringInputPos.Y - 5, 10, 10), Color.White); //if (keyboardInput.Length() > 0 || Vector2.Distance(PlayerInput.MousePosition, new Vector2(velRect.Center.X, velRect.Center.Y)) < 200.0f) if (velRect.Contains(PlayerInput.MousePosition)) { GUI.DrawRectangle(spriteBatch, new Rectangle((int)steeringInputPos.X - 10, (int)steeringInputPos.Y - 10, 20, 20), Color.Red); } } else if (posToMaintain.HasValue && !LevelStartSelected && !LevelEndSelected) { Sonar sonar = item.GetComponent <Sonar>(); if (sonar != null && controlledSub != null) { Vector2 displayPosToMaintain = (posToMaintain.Value - controlledSub.WorldPosition) / sonar.Range * sonar.DisplayRadius; displayPosToMaintain.Y = -displayPosToMaintain.Y; displayPosToMaintain = displayPosToMaintain.ClampLength(velRect.Width * 0.45f); displayPosToMaintain = velRect.Center.ToVector2() + displayPosToMaintain; GUI.DrawRectangle(spriteBatch, new Rectangle((int)displayPosToMaintain.X - 5, (int)displayPosToMaintain.Y - 5, 10, 10), Color.Red); } } //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; GUI.DrawLine(spriteBatch, new Vector2(velRect.Center.X, velRect.Center.Y), steeringPos, Color.CadetBlue, 0, 2); }