Jump to content

Find all KSPFields and KSPEvents in a partmodule


Recommended Posts

Hi

I'm a little rusty after a few months away from any code, so I'm looking at Visual Studio and the KSP API like a 2 year old with a Rubiks cube. Trying to find a way to get a list of the items mentioned in the title to be able to disable their visibility in gui and flight. The disabling I'm fine with doing, but somewhere in the back of my mind there's a thing about BaseFields that I can't quite remember. Any pointers please?

Many thanks

Lo-Fi

Link to comment
Share on other sites

Thanks. Man, I'm rusty with this stuff...

FFR:


foreach (BaseField k in this.Fields) // foreach (KSPField k in this.Fields) will compile, but will give invalid cast error at runtime.
{
k.guiActive = false;
k.guiActiveEditor = false;
}
foreach (BaseAction a in this.Actions)
{
a.active = false;
}
foreach (BaseEvent e in this.Events)
{
e.active = false;
}

disables tweakables - both button and slider - along with any text displays in the RCM.

Link to comment
Share on other sites

One caution on using BaseAction.active = false is that while that hides it from the GUI, it also disables it.

While not a huge difference to the player, it can be a problem from a modding perspective. If you create another way of triggering the action and so you set the BaseAction.active = false to hide it from the GUI as you don't want the same action showing twice. The issue is that now your way of triggering the action will no longer do anything because since the BaseAction is not active, it will not execute when called.

I assume the same is true for Events, but I have not tested them.

For actions in your own mod under your control this is not a big deal, but if you start disabling actions in other peoples mods, that could be opening a very large can of worms.

D.

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...