Jump to content

Updating the "auto pilot UI"


Recommended Posts

I'm having an odd problem that I cannot seem to figure out to solve. Maybe someone knows where to look...

I've build this:

20141227_215928.small.jpg

As you can see, I have quite a few switches and buttons.

Now, I want to right most 6 switches to control the auto-pilot mode.

Which I can do with:


FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.[mode]);

When I do this, the ships acts as if it has the proper autopilot mode. However, the GUI keeps showing the old mode (stability assist) and I cannot seem to find a way to force an update to that part of the GUI.

I can find that there is a class called "VesselAutopilotUI", which has references to an array of RUIToggleButtons, so I assume this is what handles this part of the GUI. However, I cannot seem to find a way to get a reference to the instance of this VesselAutopilotUI. (Which is most likely my lack of unity knowledge)

Anyone got a tip?

Link to comment
Share on other sites

I had to solve this also for my Actions Everywhere mod as I do exactly what you are doing, expect with action groups.

if (this.part.vessel.Autopilot.CanSetMode(VesselAutopilot.AutopilotMode.Normal)) //can you set this autopilot mode?
{
this.part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); //enable SAS
this.part.vessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Normal); //set our desired mode
setSASUI(3); //jump to next method
}

public void setSASUI(int mode)
{
RUIToggleButton[] SASbtns = FindObjectOfType<VesselAutopilotUI>().modeButtons; //find the UI object on screen
SASbtns.ElementAt<RUIToggleButton>(mode).SetTrue(true, true); //set our mode, note it takes the mode as an int, generally top to bottom, left to right, as seen on the screen. Maneuver node being the exception, it is 9
}

Hope that helps.

D.

Link to comment
Share on other sites

That helps a lot! "FindObjectOfType" really helps in this case.

Note that you can cast a "VesselAutopilot.AutopilotMode" to an int to get the proper index.

Making your code:


if (this.part.vessel.Autopilot.CanSetMode(VesselAutopilot.AutopilotMode.Normal)) //can you set this autopilot mode?
{
this.part.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); //enable SAS
this.part.vessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Normal); //set our desired mode
setSASUI(VesselAutopilot.AutopilotMode.Normal); //jump to next method
}

public void setSASUI(VesselAutopilot.AutopilotMode mode)
{
RUIToggleButton[] SASbtns = FindObjectOfType<VesselAutopilotUI>().modeButtons; //find the UI object on screen
SASbtns.ElementAt<RUIToggleButton>((int)mode).SetTrue(true, true); //set our mode, note it takes the mode as an int, generally top to bottom, left to right, as seen on the screen. Maneuver node being the exception, it is 9
}

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...