Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpeedUnitAnnex compatibility #32

Closed
yalov opened this issue Mar 17, 2019 · 17 comments
Closed

SpeedUnitAnnex compatibility #32

yalov opened this issue Mar 17, 2019 · 17 comments

Comments

@yalov
Copy link

yalov commented Mar 17, 2019

SpeedUnitAnnex (SUA) changes lines on the navball panel, so in the Surface Mode it looks like this:

both FAR and SUA make this, but FAR somehow wins:

UI.textTitle.text = caption;
UI.textSpeed.text = velString;

Anyway, looks like all this navball-panel-speed-units-feature can be passed to SUA.
SUA for the planes has main speedometer (m/s), secondary speedometer (mach or knots or km/h or mph) and disabled by default IAS (m/s)

I have found the feature settings in the FAR: FAR toolbar - Fit Settings - Air Spd.
All these units and IAS already in the SUA. (does EAS makes sense without FAR?)

left panel on that image (surface speed: 915.9 m/s, Mach 3.0, IAS: 12.5 m/s, AGL 23.2 km):

So
possibility1: deleting some code in the AirspeedSettingsGUI and making FAR suggesting SUA
possibility2: I could make SUA overriding FAR (without any changes in the FAR) on the Navball panel, any idea how?

UPD.
possibility3: FAR detects SUA and disables FAR's navball-panel-text

@dkavolis
Copy link
Owner

I could expose a method to toggle FAR speed display to FARAPI. You would then have to look for if FAR has been loaded and disable its speed display.

@yalov
Copy link
Author

yalov commented Mar 17, 2019

Will I need to copy FARAPI.cs to my repo, similar to KAC_Wrapper ?

@dkavolis
Copy link
Owner

dkavolis commented Mar 17, 2019

No, you load the method by reflection. Check how MechJeb does it https://github.com/MuMech/MechJeb2/blob/0d49eac5f938aabe5271de98b73b9563b802ff78/MechJeb2/VesselState.cs

@yalov
Copy link
Author

yalov commented Mar 17, 2019

ok, I will figure this out

@dkavolis
Copy link
Owner

You can try out #33

/// <summary>
/// Toggle or enable/disable FAR speed display.
/// </summary>
/// <param name="v">Vessel to toggle or enable/disable speed display for</param>
/// <param name="enabled">Enable/disable the speed display, null value toggles the speed display</param>
/// <returns>Success/failure of toggling or enabling/disabling the speed display</returns>
public static bool ToggleAirspeedDisplay(Vessel v, bool? enabled = null)
{
FlightGUI gui = VesselFlightInfo(v);
if (gui != null)
{
AirspeedSettingsGUI airspeedSettingsGUI = gui.airSpeedGUI;
if (airspeedSettingsGUI != null)
{
if (enabled == null)
{
airspeedSettingsGUI.enabled = !airspeedSettingsGUI.enabled;
}
else
{
airspeedSettingsGUI.enabled = (bool)enabled;
}
return true;
}
}
return false;
}

@yalov
Copy link
Author

yalov commented Mar 18, 2019

I created FARReflection in the Start() of KSPAddon and was trying to call ToggleAirspeedDisplay right after that in the Start(), but it was returning failure of toggling.
Same thing happens for FARReflection placed in the constructor of KSPAddon and ToggleAirspeedDisplay placed in the start.

Then I called ToggleAirspeedDisplay() in some later GameEvents like OnGameUnpause() and OnSetSpeedMode(), and it works ok, after manual un-pausing or SpeedMode changes.

Is there some near-start-time Method or GameEvent, where it will be working?

@dkavolis
Copy link
Owner

The airspeed display is attached to FlightGUI which is a vessel module so you will need to toggle it at the start of every flight scene/vessel load. I've added a global option to make things easier

/// <summary>
/// Toggle or enable/disable FAR speed display.
/// </summary>
/// <param name="v">Vessel to toggle or enable/disable speed display for</param>
/// <param name="globally">whether to apply the state to all FAR speed displays</param>
/// <param name="enabled">Enable/disable the speed display, null value toggles the speed display</param>
/// <returns>Success/failure of toggling or enabling/disabling the speed display</returns>
public static bool ToggleAirspeedDisplay(Vessel v, bool globally = false, bool? enabled = null)
{
if (globally)
{
if (enabled == null)
{
AirspeedSettingsGUI.allEnabled = !AirspeedSettingsGUI.allEnabled;
}
else
{
AirspeedSettingsGUI.allEnabled = (bool)enabled;
}
return true;
}
FlightGUI gui = VesselFlightInfo(v);
if (gui != null)
{
AirspeedSettingsGUI airspeedSettingsGUI = gui.airSpeedGUI;
if (airspeedSettingsGUI != null)
{
if (enabled == null)
{
airspeedSettingsGUI.enabled = !airspeedSettingsGUI.enabled;
}
else
{
airspeedSettingsGUI.enabled = (bool)enabled;
}
return true;
}
}
return false;
}

@yalov
Copy link
Author

yalov commented Mar 19, 2019

global version doesn't use Vessel, so maybe
ToggleAirspeedDisplay(Vessel? v = null, bool? enabled = null)
and v == null means globally?

@dkavolis
Copy link
Owner

Done, Vessel is already nullable so no need for ?. I've switched v and enabled around since global change by default might be more useful.

/// <summary>
/// Toggle or enable/disable FAR speed display.
/// </summary>
/// <param name="enabled">Enable/disable the speed display, null value toggles the speed display</param>
/// <param name="v">Vessel to toggle or enable/disable speed display for, null to apply <paramref name="enabled"/> globally</param>
/// <returns>Success/failure of toggling or enabling/disabling the speed display</returns>
public static bool ToggleAirspeedDisplay(bool? enabled = null, Vessel v = null)
{
if (v == null)
{
if (enabled == null)
{
AirspeedSettingsGUI.allEnabled = !AirspeedSettingsGUI.allEnabled;
}
else
{
AirspeedSettingsGUI.allEnabled = (bool) enabled;
}
return true;
}
FlightGUI gui = VesselFlightInfo(v);
if (gui != null)
{
AirspeedSettingsGUI airspeedSettingsGUI = gui.airSpeedGUI;
if (airspeedSettingsGUI != null)
{
if (enabled == null)
{
airspeedSettingsGUI.enabled = !airspeedSettingsGUI.enabled;
}
else
{
airspeedSettingsGUI.enabled = (bool) enabled;
}
return true;
}
}
return false;
}

@yalov
Copy link
Author

yalov commented Mar 19, 2019

ok, I think it works

@dkavolis
Copy link
Owner

Merged #33

@yalov
Copy link
Author

yalov commented Mar 21, 2019

Another one, looks like FlightGlobals.ActiveVessel.indicatedAirSpeed doesn't shows right value with FAR.
Could you also add IAS for the current vessel? And maybe also EAS... for the future.

@dkavolis
Copy link
Owner

dkavolis commented Mar 21, 2019

FAR calculates IAS and EAS in AirspeedSettingsGUI. I can expose them in FARAPI.

@dkavolis dkavolis reopened this Mar 21, 2019
@dkavolis
Copy link
Owner

Try out #34

public static double ActiveVesselIAS()
{
return VesselIAS(FlightGlobals.ActiveVessel);
}
public static double VesselIAS(Vessel vessel)
{
return VesselFlightInfo(vessel)?.airSpeedGUI?.CalculateIAS() ?? 0;
}
public static double ActiveVesselEAS()
{
return VesselEAS(FlightGlobals.ActiveVessel);
}
public static double VesselEAS(Vessel vessel)
{
return VesselFlightInfo(vessel)?.airSpeedGUI?.CalculateEAS() ?? 0;
}

@yalov
Copy link
Author

yalov commented Mar 21, 2019

thanks, it works.

when are you planning on making full release?

@dkavolis
Copy link
Owner

Merged #34

I don't know about a full release. If I changed the versioning to incrementing revision number without changing the name I could do more frequent releases if there were any changes.

@yalov
Copy link
Author

yalov commented Mar 25, 2019

that would be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants