public void Start() { GameEvents.onVesselChange.Add(OnVesselChange); GameEvents.onSetSpeedMode.Add(OnSetSpeedMode); //GameEvents.OnGameSettingsApplied.Add(OnGameSettingsApplied); //GameEvents.OnGameSettingsWritten.Add(OnGameSettingsWritten); GameEvents.onGameUnpause.Add(OnGameUnpause); display = GameObject.FindObjectOfType <SpeedDisplay>(); settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); settings2 = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings2>(); if (settings.overrideFAR) { CreateFARReflections(); ToggleFARDisplay(); } display.textSpeed.enableWordWrapping = false; display.textTitle.enableWordWrapping = false; display.textTitle.fontSize = display.textTitle.fontSize / 1.15f; SetFinalName(FlightGlobals.speedDisplayMode); //Log("Font: "+display.textSpeed.font); // NotoSans-Regular SDF }
public void OnGameUnpause() { //Log("OnGameUnpause"); SetFinalName(FlightGlobals.speedDisplayMode); settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); ToggleFARDisplay(); }
public void Start() { //Log("OnStart()"); display = GameObject.FindObjectOfType <SpeedDisplay>(); settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); display.textSpeed.enableWordWrapping = false; display.textTitle.enableWordWrapping = false; display.textTitle.fontSize = display.textTitle.fontSize / 1.15f; }
public void Start() { GameEvents.onVesselChange.Add(onVesselChange); GameEvents.onSetSpeedMode.Add(onSetSpeedMode); GameEvents.OnGameSettingsApplied.Add(OnGameSettingsApplied); display = GameObject.FindObjectOfType <SpeedDisplay>(); settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); display.textSpeed.enableWordWrapping = false; display.textTitle.enableWordWrapping = false; display.textTitle.fontSize = display.textTitle.fontSize / 1.15f; SetFinalName(FlightGlobals.speedDisplayMode); //Log("Font: "+display.textSpeed.font); // NotoSans-Regular SDF }
public void LateUpdate() { if (display == null) { return; } if (FlightGlobals.ActiveVessel == null) { return; } if (settings == null) { settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); } //Log("{0:F1}, {1:F1}={2:F1}, {3:F1}, {4:F1}={5:F1}", // FlightGlobals.ActiveVessel.heightFromTerrain == FlightGlobals.ship_altitude - FlightGlobals.ActiveVessel.terrainAltitude, // FlightGlobals.ActiveVessel.heightFromTerrain, FlightGlobals.ship_altitude - FlightGlobals.ActiveVessel.terrainAltitude, // FlightGlobals.ship_altitude == FlightGlobals.ActiveVessel.altitude, FlightGlobals.ship_altitude, FlightGlobals.ActiveVessel.altitude); FlightGlobals.SpeedDisplayModes mode = FlightGlobals.speedDisplayMode; #region all VesselTypes and Situations //VesselType.Base; //Situations.LANDED //VesselType.Debris //Situations.SPLASHED //VesselType.EVA //Situations.PRELAUNCH //VesselType.Flag //Situations.FLYING //VesselType.Lander //Situations.SUB_ORBITAL //VesselType.Plane; //Situations.ORBITING //VesselType.Probe //Situations.ESCAPING //VesselType.Relay //Situations.DOCKED //VesselType.Rover //VesselType.Ship //VesselType.SpaceObject //VesselType.Station //VesselType.Unknown #endregion switch (mode) { case FlightGlobals.SpeedDisplayModes.Surface: string titleText; Vessel.Situations situation = FlightGlobals.ActiveVessel.situation; VesselType vesselType = FlightGlobals.ActiveVessel.vesselType; double spd = FlightGlobals.ship_srfSpeed; string srfSpeedText = spd.ToString("F1") + mps_s; switch (vesselType) { case VesselType.Plane: case VesselType.Rover: // Boat or Submarine if (situation == Vessel.Situations.SPLASHED) { // Submarine if (FlightGlobals.ActiveVessel.altitude < BoatSubmarineBorderAlt && settings.radar) { titleText = Surf3 + Formatter.Distance_short(AGL()) + " " + (spd * knTOms).ToString("F1") + kn_s; } // Boat else { titleText = Surf5 + (spd * knTOms).ToString("F1") + knots_s; } } // Plane (not LANDED) else if (vesselType == VesselType.Plane && situation != Vessel.Situations.LANDED && situation != Vessel.Situations.PRELAUNCH) { bool isATM = FlightGlobals.ActiveVessel.atmDensity > 0.0; //double speedIAS = FlightGlobals.ActiveVessel.indicatedAirSpeed; if (settings.radar) { double radar = FlightGlobals.ActiveVessel.radarAltitude; if (settings.aircraft == MachNum) { if (isATM) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf5 + Formatter.Distance_long(radar); } } else if (settings.aircraft == knots) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * knTOms).ToString("F1") + kn_s; } else if (settings.aircraft == kmph) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.aircraft == mph { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * mphTOms).ToString("F1") + mph_s; } } else { if (settings.aircraft == MachNum) { if (isATM) { titleText = Surf5 + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf_full; } } else if (settings.aircraft == knots) { titleText = Surf5 + (spd * knTOms).ToString("F1") + knots_s; } else if (settings.aircraft == kmph) { titleText = Surf5 + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.aircraft == mph { titleText = Surf5 + (spd * mphTOms).ToString("F1") + mph_s; } } if (settings.ias) { double speedIAS = 0; if (isLoadedFAR) { speedIAS = FAR_ActiveVesselIAS(); } else { speedIAS = FlightGlobals.ActiveVessel.indicatedAirSpeed; } if (speedIAS > 0) { srfSpeedText += " " + speedIAS.ToString("F1"); } } } // Rover (and LANDED Plane) // and rover-carrier if ksp detect them as rover else { if (settings.rover == kmph) { titleText = Surf5 + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.rover == mph { titleText = Surf5 + (spd * mphTOms).ToString("F1") + mph_s; } } // All mistake at ksp detecting vessel type can be fixed by // some additional checking (ex. altitude for rover-carrier) // but it make unclear to user, which values is showed up. break; case VesselType.EVA: titleText = Surf3 + (settings.radar ? RadarAltitudeEVA_str() : "") + FinalName; break; case VesselType.Flag: titleText = Surf3 + FinalName; break; // Other: Rocket, Lander, Base etc default: if (settings.radar) { titleText = Surf5 + Formatter.Distance_long(RadarAltitude()); } else { titleText = Surf_full; } break; } display.textTitle.text = titleText; display.textSpeed.text = srfSpeedText; break; case FlightGlobals.SpeedDisplayModes.Orbit: if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA && settings2.orbit_EVA) { display.textTitle.text = (settings2.orbit_ApPe && settings2.orbit_time ? "" : Orb) + FinalName; } else if (settings2.orbit_ApPe || settings2.orbit_time) { double SOI_MASL = FlightGlobals.getMainBody().sphereOfInfluence - FlightGlobals.getMainBody().Radius; bool Ap_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.ApA && FlightGlobals.ship_orbit.ApA < SOI_MASL; bool Pe_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.PeA && FlightGlobals.ship_orbit.PeA < SOI_MASL; if (settings2.orbit_ApPe) { string Ap = Formatter.Distance_k(FlightGlobals.ship_orbit.ApA); string Pe = Formatter.Distance_k(FlightGlobals.ship_orbit.PeA); string Apsises = String.Format("<color={0}>{1}</color> <color={2}>{3}</color>", Ap_ok ? "#00ff00ff" : "#00ff009f", Ap, Pe_ok ? "#00ff00ff" : "#00ff009f", Pe); string TimeApsis; bool Apsis_ok; if (settings2.orbit_time) { if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToAp, A_prefix); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToPe, P_prefix); } display.textTitle.text = String.Format("{0} <color={1}>{2}</color>", Apsises, Apsis_ok ? "#ffffffff" : "#ffffff9f", TimeApsis); } else { display.textTitle.text = Orb + Apsises; } } else if (settings2.orbit_time) { string TimeApsis; bool Apsis_ok; if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.TimeLong(FlightGlobals.ship_orbit.timeToAp, ApT_prefix); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.TimeLong(FlightGlobals.ship_orbit.timeToPe, PeT_prefix); } display.textTitle.text = String.Format("<color={0}>{1}</color>", Apsis_ok ? "#00ff00ff" : "#00ff009f", TimeApsis); } } else { display.textTitle.text = Orb_full; } display.textSpeed.text = FlightGlobals.ship_obtSpeed.ToString("F1") + mps_s; break; case FlightGlobals.SpeedDisplayModes.Target: #region all Target // 1.6.0 // ITargetable: // * CelestialBody // * FlightCoMTracker // * ModuleDockingNode // * PositionTarget: // * DirectionTarget // * Vessel #endregion ITargetable obj = FlightGlobals.fetch.VesselTarget; if (obj == null) { display.textTitle.text = NoTrg; return; } bool isMDN = obj is ModuleDockingNode; if (settings2.targetAngles && isMDN) { Vector3 angles = GetOrientationDeviation(obj); if (settings2.targetInteger) { display.textTitle.text = Trg + Formatter.Angle(angles.x, true, 5) + Formatter.Angle(angles.y, true, 5) + Formatter.Angle(angles.z, true, 5); } else { display.textTitle.text = Formatter.Angle(angles.x) + Formatter.Angle(angles.y) + Formatter.Angle(angles.z); } } else { string TargetAngle = ""; string distanceToTarget = ""; if (settings2.targetAngle && isMDN) { Vector3 angles = GetOrientationDeviation(obj); if (settings2.targetInteger) { TargetAngle = Formatter.Angle(angles.z, true, 5); } else { TargetAngle = Formatter.Angle(angles.z); } } if (settings2.targetDistance) { distanceToTarget = CalcTargetDistance(obj); } bool isAngleAndDistance = settings2.targetDistance && settings2.targetAngle && isMDN; if (settings2.targetName && !isAngleAndDistance) { if (Target != obj) { TargetName = CutName(Trg + distanceToTarget + TargetAngle, GetTargetName(obj)); Target = obj; } display.textTitle.text = Trg + distanceToTarget + TargetName + TargetAngle; } else { display.textTitle.text = Trg + distanceToTarget + " " + TargetAngle; // 2 spaces } } if (FlightGlobals.ship_tgtSpeed < 0.195) { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F2") + mps_s; } else { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F1") + mps_s; } break; } // need to be there, for every tick. Doesn't work in the Start() or onSetSpeedMode() display.textTitle.alignment = TMPro.TextAlignmentOptions.MidlineLeft; }