Jump to content

Right click menus and resource consumption


Recommended Posts

Hi, I'm creating a custom plugin and I want to know how to create a toggle button on a part's right click menu, a simple 'on/off' button that the user can click on to activate the next part of my code. I also want to output (display) things onto a part's context menu.

I also want to know how to get resource consumption and production on a vessel, and store that value as a variable to work on later. I have very little experience with modding in general, let alone ksp modding, so a simple guide will be more useful.

Thanks. 

Link to comment
Share on other sites

2 hours ago, HebaruSan said:

Basically you need two C# attributes on a public bool, KSPField and UI_Toggle. An example:

https://github.com/HebaruSan/SmartTank/blob/791600cbd6ab7ab6fda2a0d64feb96455bf3e6a4/src/DiameterMatcher.cs#L63-L74

In that example, could I change 'UI_Scene.Editor' to UI_Scene.Flight', as I need the button on a part right-click menu during flight.

Link to comment
Share on other sites

27 minutes ago, Aniruddh said:

In that example, could I change 'UI_Scene.Editor' to UI_Scene.Flight', as I need the button on a part right-click menu during flight.

Yup, that's what that parameter is for. That link was to a mod that only has a UI in the VAB/SPH.

Link to comment
Share on other sites

13 hours ago, wasml said:

Unfortunately the Squad code is not publicly available but the API is listed here.

Thanks for the reply. Yes, I looked at that earlier and it is not very intuitive for complete beginners to ksp code. There is also so much in that API that it is hard to search through I think.

EDIT: Okay, I found this method on the API:

this.vessel.Parts[n].Resources.GetFlowing(EChash, false)

Does this give EC production per second? If so, how do I use it?

Edited by Aniruddh
Found something
Link to comment
Share on other sites

Your best bet would be to look at the code for a mod that does something similar - Nertea's Dynamic Battery Storage is one that comes to mind. The API mentioned above and other modder's code are the really the only documentation available. That and asking or looking for similar questions on this forum.

Link to comment
Share on other sites

On 7/25/2020 at 11:16 AM, Aniruddh said:

Yes, I looked at that earlier and it is not very intuitive for complete beginners to ksp code. There is also so much in that API that it is hard to search through I think.

Welcome to the wonderful world of KSP modding :D

What I tend to do in these cases, is find something that looks like it does what I want to do, then search it on Github to see how other modders have used it.

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