Jump to content

KSP Plugin Framework - Plugin Examples and Structure v1.1 (Apr 6)


Recommended Posts

https://ksppluginframework.codeplex.com/SourceControl/latest#Examples/PersistingData/DictionaryTest.cs

Have you verified that this code to store Dictionaries in ConfigNodeStorage still works recently? I'm trying to do *exactly* this, and while I get no errors on save or load, my .cfg file is empty (Just has the parent scope)

Been a long time since I looked at that code, but from recollection it was a test to see what would and wouldn't store, so I dont know if Dictionaries ever did store - same as how you still can't store/restore a Vector2 or Vector3d types directly. Last time I tried to store a Dictionary.

If you look here - https://github.com/TriggerAu/AlternateResourcePanel/blob/master/AlternateResourcePanel/Settings.cs#L116-134 you can see how I am using a dictionary in the ARP mod, but storing as a list - and using the ToDictionary() method to load the stored list into the dictionary thats used in the mod.

Hope that helps

Link to comment
Share on other sites

Been a long time since I looked at that code, but from recollection it was a test to see what would and wouldn't store, so I dont know if Dictionaries ever did store - same as how you still can't store/restore a Vector2 or Vector3d types directly. Last time I tried to store a Dictionary.

If you look here - https://github.com/TriggerAu/AlternateResourcePanel/blob/master/AlternateResourcePanel/Settings.cs#L116-134 you can see how I am using a dictionary in the ARP mod, but storing as a list - and using the ToDictionary() method to load the stored list into the dictionary thats used in the mod.

Hope that helps

Ok so lists store ok? Wonder how that looks in the file. I could also pack a string, but I kind of want the file to be easily editable by people.

Link to comment
Share on other sites

Ok so lists store ok? Wonder how that looks in the file. I could also pack a string, but I kind of want the file to be easily editable by people.

If you are storing other objects then its pretty easy to read. KAC stores the alarms as a list in the save file, so it looks just like the vessel list in the save file too - using that confignodestorage class

Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

The simplest method would be to simply change your class to inherit from the MonoBehaviourExtended class instead of Monobehaviour and you can then use the OnGuiEvery and OnGuiOnce methods there to replicate the behaviour. That said if you are going to have a lot of windows it "may" be worth changing the way you do your windows to use the MonoBehaviourWindow as well. In KAC when I transitioned I used the first method for the existing windows and then all new stuff uses the MBW classes because there was soo much code to change.

Mind you when we go to Unity5 I have absolutely no idea what that will mean yet. So short answer is look at how much code you have, cheapest way will be MBE, longer model MBW, and I'd decide based on existing code and what functionality you are looking to use - ie if you want a bunch of the Window code, or to use the drop downs then add that to your consideration.

If you want to share which project you are thinking about I'm happy to have a browse of the source on GitHub, etc and see if I can give some specific advice

Link to comment
Share on other sites

The simplest method would be to simply change your class to inherit from the MonoBehaviourExtended class instead of Monobehaviour and you can then use the OnGuiEvery and OnGuiOnce methods there to replicate the behaviour. That said if you are going to have a lot of windows it "may" be worth changing the way you do your windows to use the MonoBehaviourWindow as well. In KAC when I transitioned I used the first method for the existing windows and then all new stuff uses the MBW classes because there was soo much code to change.

Mind you when we go to Unity5 I have absolutely no idea what that will mean yet. So short answer is look at how much code you have, cheapest way will be MBE, longer model MBW, and I'd decide based on existing code and what functionality you are looking to use - ie if you want a bunch of the Window code, or to use the drop downs then add that to your consideration.

If you want to share which project you are thinking about I'm happy to have a browse of the source on GitHub, etc and see if I can give some specific advice

For now, it's the CraftImport mod. It really only has two windows, one of which is reused for multiple windows depending on the situation.

Thanks

LGG

Link to comment
Share on other sites

The simplest method would be to simply change your class to inherit from the MonoBehaviourExtended class instead of Monobehaviour and you can then use the OnGuiEvery and OnGuiOnce methods there to replicate the behaviour. That said if you are going to have a lot of windows it "may" be worth changing the way you do your windows to use the MonoBehaviourWindow as well. In KAC when I transitioned I used the first method for the existing windows and then all new stuff uses the MBW classes because there was soo much code to change.

Mind you when we go to Unity5 I have absolutely no idea what that will mean yet. So short answer is look at how much code you have, cheapest way will be MBE, longer model MBW, and I'd decide based on existing code and what functionality you are looking to use - ie if you want a bunch of the Window code, or to use the drop downs then add that to your consideration.

If you want to share which project you are thinking about I'm happy to have a browse of the source on GitHub, etc and see if I can give some specific advice

So, the main class should inherit from MonoBehaviousExtended, and secondary classes should inherit the MonoBehaviourWindow?

Also, I'm going to be starting to write a new mod, and figure this would be a good way to learn this. So, all I'll need (for now) will be the ability to display a window using GUILayout stuff, and then I'll be registering a function to be called when a ship is launched.

Do you have a minimal sample with a window I can look at?

Thanks

Link to comment
Share on other sites

You can draw a UI using either MBE or MBW (MBW inherits from MBE).

The difference is that MBE should really on be used if you are using OnGUI directly.

Most KSP mods add their window to the KSP RenderManager, which handles things like hiding the window (so don't use it if you want, for example, to draw something on top of the R&D or Mission Control UI) and I think some drawing order functions. MBW uses the RenderManager and has some helper methods for drawing complex UIs, making sure everything is run in the correct order, tooltips, clamping the window to the screen edges, etc...

But only use MBW for a class that actually draws the window.

Link to comment
Share on other sites

  • 1 month later...
It does not use this framework at all, but as an example of loading toolbar buttons, [url=https://github.com/SirDiazo/AGExt/blob/master/AGExt/Editor.cs#L418]I do so here.[/url]

The link goes to the IF statement where I decide whether to load my button into either Blizzy's or the stock toolbar, you should be able to backtrack my reference from there.

Let me know if you need more details.

D.
Link to comment
Share on other sites

[quote name='Diazo']It does not use this framework at all, but as an example of loading toolbar buttons, [URL="https://github.com/SirDiazo/AGExt/blob/master/AGExt/Editor.cs#L418"]I do so here.[/URL]

The link goes to the IF statement where I decide whether to load my button into either Blizzy's or the stock toolbar, you should be able to backtrack my reference from there.

Let me know if you need more details.

D.[/QUOTE]

Oh, i'm already loading buttons, was just wondering how it worked with the framework.


LGG
Link to comment
Share on other sites

  • 1 month later...
  • 5 months later...

I couldn't find them either, even by using some google dorks, which means they have probably entirely disappeared from the forum.

I resorted using the wayback machine [ https://web.archive.org ]  (please note that all links below are external to this forum and go to web.archive.org) :

(Also note that you might have to click the "latest" button once on web archive)

Edited by neitsa
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...