Jump to content

HALP needed, Orion mod updatings


Recommended Posts

Due to being able to spot red squiggly lines and follow some guesswork when the temperature variables in KSP changed, I've stumbled into being the nominated code maintainer for Nyrath's USAFOrion.  While I'm perfectly at home with modelling parts, I find myself a bit lost in this C# stuff the modules are written in.

Part of the problem is that, instead of needing to update from 1.0 to 1.1 code, the code is actually dependent on some libraries from the dawn of time.  I suspect KSP 0.25, as the UI elements never worked in 0.90 onwards (or was that 0.80, I forget).  And now, there's no available source code for the 3rd party libraries that the source code I have is dependent on.

So, I'd LIKE to clear out all the UI components of the code and rewrite them.  The UI is pretty much completely new in 1.1 anyway, and all it needs is a window with some buttons.  "How hard could that be?" he said...

Initially, I really wanted to do this all myself.  I wanted to wrap my head around how C# worked, and how the orion code worked, so I could maintain it properly.  But, I find every time I look at stuff, I get lost incredibly easy.  I can't figure out what calls to make or how to find variables to use from KSP libraries.  I don't know what half the compile errors are suggesting and so on.  I can follow the logic of the code just fine.  I just never know which bits come from where.

If you want to take a gander at the source before mentioning anything, it's at https://github.com/cerebrate/USAFOrion

I'm happy with any level of assistance at this stage.

 

Link to comment
Share on other sites

I might be missing something here, but is there something specific you're asking about? It's somewhat difficult to advise with no topic/examples :confused:. I somewhat understand this is about UI, but after that...

A few questions also. I assume you want to make UI elements with the new Unity UI (create in the editor and just link up in code)? Do you have an example window you want to recreate (something relatively simple with just text, buttons, etc) we can start with?

Edited by Crzyrndm
Link to comment
Share on other sites

5 minutes ago, Crzyrndm said:

I might be missing something here, but is there something specific you're asking about? It's somewhat difficult to advise with no topic/examples :confused:. I somewhat understand this is about UI, but after that...

A few questions also. I assume you want to make UI elements with the new Unity UI (create in the editor and just link up in code)? Do you have an example window you want to recreate (something relatively simple with just text, buttons, etc) we can start with?

At this stage I'm just asking for general assistance, so no specifics.  More like all of the code.

I actually just meant that I thought all of the coded UI had changed linkings.  I could be wrong.  But either way, I've actually never seen the UI.  But it'd be a list of pulse unit sizes, with either a toggle button or an on and an off button each.  So, for example;

--------------------

10kT    [toggle]

5kT     [toggle]

1.5kT  [toggle]

-------------------

 

Link to comment
Share on other sites

Ok, this might actually be easier with the new UI in some respects, but I'll show the pure code way too.

Code only (inside a part module)

// an attribute for part modules which makes this a toggle in the right click window
[KSPField(guiName = "Visible", guiActiveEditor = false, guiActive = true),
            UI_Toggle(affectSymCounterparts = UI_Scene.Flight, scene = UI_Scene.Flight, enabledText = "Visible", disabledText = "Hidden")]
bool visible;

Rect window;
OnGUI() // special unity function for code GUI
{
  if (visible
  {
    window = GUILayout.Window(this.getInstanceID(), window, drawWindow, "title");
  }
}

void drawWindow(int id) // the name of the function is the third parameter above
{
  	GUILayout.Label("I'm a text object");
    if (GUILayout.Button("I'm a button"))
    {
      // the button was clicked **in this frame**
    }
    string text = GUILayout.TextField("I'm a text input box");
    
    int selected = 1;
    selected = GUILayout.SelectionGrid(selected, new string[] {"1", "2", "3", "4"}, 2); // A 2 x 2 grid of buttons, returns the index of the selected button
}

For your basic window, I would recommend using probably a label for a header and then a selection grid with all your power options. If selected changes (oldSelected != selected), you update the engine power or w/e this thing does


New UI

In Unity, have a setup something like the following (http://imgur.com/a/RcmEB). Setup the window colour, text, options etc exactly as you want it (This bit is a lot easier than the old way if you want something that looks a bit better than the default...)

Then you need to export it. For that you need to have part tools installed in Unity

Add the canvas and its children to a prefab and set that prefab to be in a bundle. At the top next to File, Edit, etc, there will be a dropdown "KSPAssets", in there select asset compiler and update -> build your bundle. Find the .ksp file and drop it into GameData. Now we head into code.

in your part module you will need to load the prefab from the assetbundle. I'll use one of my plugins as as example here (with its own ultra simple UI)

Start the bundle load process: https://github.com/Crzyrndm/FilterExtension/blob/master/FilterExtension/Settings.cs#L35 -> https://github.com/Crzyrndm/FilterExtension/blob/master/FilterExtension/Settings.cs#L44
Replace the file address in the using statement as appropriate and use the correct asset name in the loop. Otherwise you can copy that function almost 100%;

Next we need to create an instance of that UI: https://github.com/Crzyrndm/FilterExtension/blob/master/FilterExtension/Settings.cs#L121
While this may look complex, all its doing is instantiating a n instance, and then finding those objects in the unity hierachy by name and type (toggles and text input in my case, a dropdown for you)

Notice the "AddListener" calls. Those setup the function in my code that gets called for an event (value changed: https://github.com/Crzyrndm/FilterExtension/blob/master/FilterExtension/Settings.cs#L140)
From there, it's just a matter of responding to the event: https://github.com/Crzyrndm/FilterExtension/blob/master/FilterExtension/Settings.cs#L173
Note that a dropdown onvalue changed will give you an integer parameter corresponding to the selected index which you can then convert to a power setting

 

Edited by Crzyrndm
Link to comment
Share on other sites

And I've discovered,

which led me to

https://github.com/evilC/TacLib

Which would be that ancient code I didn't have source for.  :-)  Could never find TacLib, only TacLibGUI, probably because it's not actually TaranisElsu's.  This _should_ bypass a lot of the need for rewriting stuff.

Also, I've decided to do some less ambitious projects to warm up to this.  My main problem is that I just lept in too deep to start with.  So, I'm going to code up my "if you have a spare wheel, you don't need an engineer to fix your flat" code.  Which should be simpler.  At the very least, it'll be from scratch and thus easier to understand for me.  It may end up a horrible unsupportable mess, but it'll be MY horrible unsupportable mess.  :-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...