override public void WindowGUI(int windowID) { base.preWindowGUI(windowID); base.WindowGUI(windowID); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ComboBox.Box((int)warpTarget, warpTargetStrings, this); if (warpTarget == WarpTarget.Time) { GUILayout.Label("Warp for: ", GUILayout.ExpandWidth(true)); timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) { GUILayout.Label("You need a target"); } else { GuiUtils.SimpleTextBox("Phase Angle:", phaseAngle, "º", 60); } } if (!warping) { GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); } if (warping) { if (GUILayout.Button("Abort")) { this.onAbord(); } } if (warping) { GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); } if (this.isStarted() && !this.isExecuted() && this.startTime > 0) { GUILayout.Label(" waiting " + this.spendTime + "s"); } base.postWindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) { warping = true; } } GUILayout.EndHorizontal(); if (warping) { GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); } GUILayout.EndVertical(); GUI.DragWindow(); }
private void LockOntoWarpTarget() { if (_currentState == State.WarpStandby) { CancelWarpLock(); } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { WarpTarget target = hit.collider.gameObject.GetComponent <WarpTarget>(); if (target == null) { return; } LockMovement(true); warpManager.Destination = target.Position; StartCoroutine(RotateTowards(target.Position)); _currentState = State.WarpStandby; } }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label1"), GUILayout.ExpandWidth(false));//"Warp to: " warpTarget = (WarpTarget)GuiUtils.ComboBox.Box((int)warpTarget, warpTargetStrings, this); GUILayout.EndHorizontal(); if (warpTarget == WarpTarget.Time) { GUILayout.BeginHorizontal(); GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label2"), GUILayout.ExpandWidth(true));//"Warp for: " timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); GUILayout.EndHorizontal(); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) { GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label3"));//"You need a target" } else { GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_WarpHelper_label4"), phaseAngle, "º", 60);//"Phase Angle:" } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_WarpHelper_label5"), leadTime, "");//"Lead time: " if (warping) { if (GUILayout.Button(Localizer.Format("#MechJeb_WarpHelper_button1")))//"Abort" { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button(Localizer.Format("#MechJeb_WarpHelper_button2")))//"Warp" { warping = true; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) { targetUT = orbit.NextApoapsisTime(vesselState.time); } break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { targetUT = orbit.EndUT; } break; case WarpTarget.Node: if (vessel.patchedConicsUnlocked() && vessel.patchedConicSolver.maneuverNodes.Any()) { targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; } break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.TargetOrbit.referenceBody == orbit.referenceBody) { reference = orbit; // we orbit arround the same body } else { reference = orbit.referenceBody.orbit; } // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.TargetOrbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.TargetOrbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) { angleDigff -= 360; } if (angleDigff < 0 && angleChangePerSec < 0) { angleDigff += 360; } double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; case WarpTarget.AtmosphericEntry: try { targetUT = OrbitExtensions.NextTimeOfRadius(vessel.orbit, vesselState.time, vesselState.mainBody.Radius + vesselState.mainBody.RealMaxAtmosphereAltitude()); } catch { warping = false; } break; case WarpTarget.SuicideBurn: try { targetUT = OrbitExtensions.SuicideBurnCountdown(orbit, vesselState, vessel) + vesselState.time; } catch { warping = false; } break; default: targetUT = vesselState.time; break; } } } GUILayout.EndHorizontal(); core.warp.useQuickWarpInfoItem(); if (warping) { GUILayout.Label(Localizer.Format("#MechJeb_WarpHelper_label6") + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); //"Warping to " } core.warp.ControlWarpButton(); GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); if (warpTarget == WarpTarget.Time) { GUILayout.BeginHorizontal(); GUILayout.Label("Warp for: ", GUILayout.ExpandWidth(true)); timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); GUILayout.EndHorizontal(); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) { GUILayout.Label("You need a target"); } else { GuiUtils.SimpleTextBox("Phase Angle:", phaseAngle, "º", 60); } } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) { warping = true; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) { targetUT = orbit.NextApoapsisTime(vesselState.time); } break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) { targetUT = orbit.EndUT; } break; case WarpTarget.Node: if (vessel.patchedConicSolver.maneuverNodes.Any()) { targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; } break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.Orbit.referenceBody == orbit.referenceBody) { reference = orbit; // we orbit arround the same body } else { reference = orbit.referenceBody.orbit; } // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.Orbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.Orbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) { angleDigff -= 360; } if (angleDigff < 0 && angleChangePerSec < 0) { angleDigff += 360; } double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; default: targetUT = vesselState.time; break; } } } GUILayout.EndHorizontal(); if (warping) { GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); } GUILayout.EndVertical(); base.WindowGUI(windowID); }
void LateUpdate() { resetPool(); if (!GameManager.instance.IsMenuOpen) { // POSITION OBJECTIVE ARROWS AND INDICATORS Vector3[] waypoints = GameManager.questManager.GetActiveQuestObjectiveTargets(); if (waypoints != null) { foreach (Vector3 waypoint in waypoints) { Vector3 targetPosition = Camera.main.WorldToScreenPoint(waypoint); // If the target is onscreen show the onscreen indicator if (targetPosition.z > 0f && targetPosition.x >= 0f && targetPosition.x <= Screen.width && targetPosition.y >= 0f && targetPosition.y <= Screen.height) { if (targetPosition.z > 500f) { ObjectiveIndicator indicatorImage = getObjectiveIcon(); indicatorImage.GetComponent <RectTransform>().anchoredPosition = new Vector3(targetPosition.x, targetPosition.y, 0f); indicatorImage.SetDistance(Vector3.Distance(waypoint, GameManager.playerTransform.position)); } } else { PositionArrowIndicator(targetPosition, ArrowType.waypoint); } } } // POSITION ENEMY ARROWS AND BOXES var enemies = GameManager.instance.TargetableObjects.Where(t => t.Allegiance == Enums.Allegiance.Enemy); foreach (TargetableObject obj in enemies) { if (GameManager.playerTransform != null) { if (Vector3.Distance(obj.transform.position, GameManager.playerTransform.position) < 500f) { Vector3 targetPosition = Camera.main.WorldToScreenPoint(obj.transform.position); // If the target is onscreen show the onscreen indicator & health bar if (targetPosition.z > 0f && targetPosition.x >= 0f && targetPosition.x <= Screen.width && targetPosition.y >= 0f && targetPosition.y <= Screen.height) { TargetIndicator box = getBoxIndicator(); box.anchoredPosition = new Vector3(targetPosition.x, targetPosition.y, 0f); box.healthBarFillAmount = (float)obj.GetComponent <HealthController>().Health / (float)obj.GetComponent <HealthController>().MaxHealth; float multiplier = (maxAlpha - minAlpha) / alphaThreshold; float currentAlpha = maxAlpha; box.healthBarVisible = false; if (targetPosition.z < alphaThreshold) { box.healthBarVisible = true; currentAlpha = minAlpha + (targetPosition.z * multiplier); } box.boxAlpha = currentAlpha / 255f; //Vector3 lead = CalculateLead(player.transform.position, obj.transform.position, projectileSpeed * 1.5f, obj.gameObject.GetComponent<Rigidbody>().velocity, player.GetComponent<Rigidbody>().velocity); //box.trajectory.rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(lead) - screenCenter; } else // Offscreen - show directional arrow { if (waypoints == null || !OverlapsWaypoint(waypoints, obj.transform.position)) { PositionArrowIndicator(targetPosition, ArrowType.enemy); } } } } } // Warp target indicators _warpIndicatorInstance.gameObject.SetActive(false); if (GameManager.instance.IsCursorVisible) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; int layerMask = 1 << 2; layerMask = ~layerMask; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { WarpTarget target = hit.collider.gameObject.GetComponent <WarpTarget>(); if (target != null) { _warpIndicatorInstance.gameObject.SetActive(true); _warpIndicatorInstance.SetDestinationName(target.TargetName); // Works with sphere colliders Vector3 centerPosition = Camera.main.WorldToScreenPoint(target.Bounds.center); float diffPosition = Camera.main.WorldToScreenPoint(target.Bounds.max).y - centerPosition.y; Vector3 topPosition = centerPosition + new Vector3(0f, diffPosition * 0.8f, 0f); _warpIndicatorInstance.SetNamePosition(topPosition); // Disable entry point indicator if it is currently overlapping an objective marker if (waypoints == null || !OverlapsWaypoint(waypoints, target.Position)) { _warpIndicatorInstance.SetEntryPointPosition(target.Position); } else { _warpIndicatorInstance.DisableEntryPoint(); } } } } } cleanPool(); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); if (warpTarget == WarpTarget.Time) { GUILayout.BeginHorizontal(); GUILayout.Label("Warp for: ", GUILayout.ExpandWidth(true)); timeOffset.text = GUILayout.TextField(timeOffset.text, GUILayout.Width(100)); GUILayout.EndHorizontal(); } else if (warpTarget == WarpTarget.PhaseAngleT) { // I wonder if I should check for target that don't make sense if (!core.target.NormalTargetExists) GUILayout.Label("You need a target"); else GuiUtils.SimpleTextBox("Phase Angle:", phaseAngle, "º", 60); } GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) { warping = true; switch (warpTarget) { case WarpTarget.Periapsis: targetUT = orbit.NextPeriapsisTime(vesselState.time); break; case WarpTarget.Apoapsis: if (orbit.eccentricity < 1) targetUT = orbit.NextApoapsisTime(vesselState.time); break; case WarpTarget.SoI: if (orbit.patchEndTransition != Orbit.PatchTransitionType.FINAL) targetUT = orbit.EndUT; break; case WarpTarget.Node: if (vessel.patchedConicSolver.maneuverNodes.Any()) targetUT = vessel.patchedConicSolver.maneuverNodes[0].UT; break; case WarpTarget.Time: targetUT = vesselState.time + timeOffset; break; case WarpTarget.PhaseAngleT: if (core.target.NormalTargetExists) { Orbit reference; if (core.target.Orbit.referenceBody == orbit.referenceBody) reference = orbit; // we orbit arround the same body else reference = orbit.referenceBody.orbit; // From Kerbal Alarm Clock double angleChangePerSec = (360 / core.target.Orbit.period) - (360 / reference.period); double currentAngle = reference.PhaseAngle(core.target.Orbit, vesselState.time); double angleDigff = currentAngle - phaseAngle; if (angleDigff > 0 && angleChangePerSec > 0) angleDigff -= 360; if (angleDigff < 0 && angleChangePerSec < 0) angleDigff += 360; double TimeToTarget = Math.Floor(Math.Abs(angleDigff / angleChangePerSec)); targetUT = vesselState.time + TimeToTarget; } break; default: targetUT = vesselState.time; break; } } } GUILayout.EndHorizontal(); if (warping) GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); GUILayout.EndVertical(); base.WindowGUI(windowID); }
protected override void WindowGUI(int windowID) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Warp to: ", GUILayout.ExpandWidth(false)); warpTarget = (WarpTarget)GuiUtils.ArrowSelector((int)warpTarget, numWarpTargets, warpTargetStrings[(int)warpTarget]); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.SimpleTextBox("Lead time: ", leadTime, ""); if (warping) { if (GUILayout.Button("Abort")) { warping = false; core.warp.MinimumWarp(true); } } else { if (GUILayout.Button("Warp")) warping = true; } GUILayout.EndHorizontal(); if (warping) GUILayout.Label("Warping to " + (leadTime > 0 ? GuiUtils.TimeToDHMS(leadTime) + " before " : "") + warpTargetStrings[(int)warpTarget] + "."); GUILayout.EndVertical(); GUI.DragWindow(); }