Jump to content

[RESOLVED] Keeping a context menu button down


Recommended Posts

When you right click on an engine, it has the option to Enable and Disable the Gimbal. The neat thing is, that when you disable it, the button remains pressed. How can I accomplish this myself?

Edited by FreeThinker
Link to comment
Share on other sites

Using KSPEvent, that happens automatically where you use a type of BOOL.

To do it manually would require an IF statement to check which type of button to display before your IF(GUI.Button....) line.

D.

Link to comment
Share on other sites

Using KSPEvent, that happens automatically where you use a type of BOOL.

To do it manually would require an IF statement to check which type of button to display before your IF(GUI.Button....) line.

D.

Sorry, could you give a short example?

Link to comment
Share on other sites

I'm not sure what you are asking for.

If you are using a KSPEvent, it's the standard [KSPEvent] tag you put before the object.

Hmm, actually I'm not sure if I meant KSPField now. KSPEvents are for methods, you can't have a type BOOL of those.


[KSPField(GUIActive = true)]
public bool myVal;

Should work. (Once you fix the GUIActive syntax, wrote that from memory.)

If you mean on your own button, something like:


If(showAsButtonUp)
{
GUICurrentStyle = GUIButtonUpStyle
}
else
{
GUICurrentStyle = GUIButtonDownStyle
}
If(GUI.Button(rect,string,GUICurrentStyle) //use values as per your usage scenario, then the GUIStyle value is the GUICurrentStyle from the previous IF statement.
{
//do stuff on button click
}

Hope that answers your question,

D.

Link to comment
Share on other sites

Sorry, I guess I wan not clear. I need to change the button of an KSPEvent

I got the following existing code


[KSPField(isPersistant = true, guiActive = false, guiActiveEditor = true, guiName = "Is Propellant")]
public bool isPropellant = true;

[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "Switch Propellant Mode"]
public void SwitchIsPropellant()
{
isPropellant = !isPropellant;
}

public void Update()
{
Events["SwitchIsPropellant"].guiName = isPropellant ? "Lock as Propellant Source" : "Unlock as Propellant Source";
Events["SwitchIsPropellant"].active = controlledResources.Any(r => part.Resources.Contains(r));
}

now I need to force the SwitchIsPropellant event (button) to remain pressed while inactive

Link to comment
Share on other sites

Alright, contrary to my first post, I don't think that is possible on a KSPEvent, only on KSPFields.

What you can do however is change the text string, so instead of being "Switch Propellant Mode!", you can have the text display which mode you are in.

You can do this via the string object found at this.Events["SwitchIsPropellant"].guiName

Best I can offer,

D.

Link to comment
Share on other sites

  • 2 weeks later...
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...