Jump to content

GUI Question (dropdown menu and other)


Recommended Posts

Hey guys,

I am running at the time where I need to get a bit of a better GUI for my tool.

here is the current state:

BLOmiwY.png

I have three question at the moment:

To select the category I am using GUILayoutx.SelectionList(). That works well (except that the category enum are not ordered the same than the tabs in the editor). However I would like to add the icons to it. same icons that the editor ones. And I don't know where to get them from and how to put them in.

Second question:

I would like to make a dropdown list (one selection possible). And I don't know how to do it, every tutorial I have found on google use javascript! Any tips/info on that?

Last question:

Any way to have the description box with a word wrap?

Thanks in advance

Link to comment
Share on other sites

GUILayout.TextArea might be what you want. This is the first link in result google gave me for "unity dropdown". Haven't tried it, but looks promising... since it has a button that shows/hides some list/box/etc on click. Can't help on the last one, sry. I wish we could have a look with a proper debugger. But that would require Squad to release a Development Build with Script Debugging enabled (jop, just 2 Checkboxes) and share the about 3 files with us that are actually different. Any ideas how we could get squad to do so?

Link to comment
Share on other sites

Hey guys,

To select the category I am using GUILayoutx.SelectionList(). That works well (except that the category enum are not ordered the same than the tabs in the editor). However I would like to add the icons to it. same icons that the editor ones. And I don't know where to get them from and how to put them in.

When you open the game, everything that gets loaded is logged in KSP.log, including texture loads.

Take a look through that and see if you can pick out the images Squad is using for the icons and then just load them yourself.

Failing that, you could do some trickery with a screen shot I would think.

D.

Link to comment
Share on other sites

GUILayout.TextArea might be what you want.

I gonna have to look at it, I used a textfield.

This is the first link in result google gave me for "unity dropdown". Haven't tried it, but looks promising... since it has a button that shows/hides some list/box/etc on click.

Think I could have googled it and not just forum search it? errr no! thanks I will check that and see if it works.

I wish we could have a look with a proper debugger. But that would require Squad to release a Development Build with Script Debugging enabled (jop, just 2 Checkboxes) and share the about 3 files with us that are actually different. Any ideas how we could get squad to do so?

I don't know what could block Squad to do it. On top of my head, ideas would be, that they wait to be out of alpha or integrate a proper mod API, Since debugging would mean sharing decompiled source, it could be a copyright problem, or issue with the unity license.

When you open the game, everything that gets loaded is logged in KSP.log, including texture loads.

Take a look through that and see if you can pick out the images Squad is using for the icons and then just load them yourself.

So I guess no easy way. But I should be able to find that somewhere.

Do you know how I can set image to a button?

Link to comment
Share on other sites

I actually had to figure that out myself just recently. Credit to Kerbal Alarm Clock for being my reference for this.

This should get you going:


private Texture2D buttonTx = new Texture2D(30,40, TextureFormat.ARGB32, false); //declare the texture variable, 30pixels wide, 40 pixels high, standard RGB32 format, false on the end for no normal mapping, not needed for buttons.

public void Awake()
{
buttonTx = GameDatabase.Instance.GetTexture("/Name/Mod/Texture", false); //Load the texture from the GameData\Name\Mod\Texture.jpg file. Note the file extension is stripped, that would load Texture.jpg, Texture.png and Texture.bmp and probably others.
}

public void OnWindow() //inside your onwindow
{
GUI.skin.label.alignment = TextAnchor.MiddleCenter; //center the texture on the button
GUI.Button(new Rect(50, 100, 30, 40), texture2D) //display the button at 50,100 with a size of 30x40. I'm not sure what happens if the texture is bigger then the button. Texture being smaller then the button is fine.
}

And that's putting a picture on a button in a nutshell. Note that if you use .png, transparency works so it makes it look nicer.

D.

Link to comment
Share on other sites

I actually had to figure that out myself just recently. Credit to Kerbal Alarm Clock for being my reference for this.

...

And that's putting a picture on a button in a nutshell. Note that if you use .png, transparency works so it makes it look nicer.

Thanks Awesome Diazo (And Kerbal Alarm Clock too then I guess).

Link to comment
Share on other sites

Since debugging would mean sharing decompiled source, it could be a copyright problem, or issue with the unity license.

This is not true. You don't need game source at all unless you want to debug game code. I did slap my own dll on a pure .net game and could easily debug it with visual studio without the game source, even without debug symbols and while the game was a release. VS even was able to live-edit my dll code. It has to work without game code, just like you can debug your own app without having code to the .NET framework.

So I'm pretty sure the only technical problem that prevents us from debugging is that an embedded mono environment has to provide some debug interface, and the common ksp release does not and modifying it to do so would require an unreasonable amount of work and most likely would be illegal anyway.

I tested a little bit on the AngryBots unity sample. Slapped an external DLL onto it and could easily debug it without requiring game code, once i checked "Development Build" and "Script Debugging" on the build config. Beside a bunch of symbol files, only 3 files were actually different: The launched executable, the managed dll (though it appears to just be some flags) and some "PlayerConnectionConfigFile" i have no idea what it is good for and does not exist in KSP anyway^^

(I actually had a non-standard environment, since i tried to get it running with VS via UnityVS, what apparently had some side on MonoDevelop as well. Might be worth to re-test it on a clear setup)

So yes, chances are good that all Squad has to do would be to enable two checkboxes, rebuild the game and share the created KSP.exe with interested modders.

Link to comment
Share on other sites

Here is how I draw textures on my icons:

https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.cs#L55

https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.cs#L89

I put it on a label, but you can use the GUIContent with anything including buttons.

Also, I did a drop-down menu for my TAC Fuel Balancer:

https://github.com/taraniselsu/TacFuelBalancer/blob/master/Source/MainWindow.cs#L185

https://github.com/taraniselsu/TacLib/blob/master/Source/PopupWindow.cs

It is based on the page that Faark linked to. It has some issues, but it seems to work well.

... This is the first link in result google gave me for "unity dropdown". Haven't tried it, but looks promising... since it has a button that shows/hides some list/box/etc on click. ...
Edited by TaranisElsu
typo
Link to comment
Share on other sites

This is not true. You don't need game source at all unless you want to debug game code. I did slap my own dll on a pure .net game and could easily debug it with visual studio without the game source, even without debug symbols and while the game was a release. VS even was able to live-edit my dll code. It has to work without game code, just like you can debug your own app without having code to the .NET framework.

So I'm pretty sure the only technical problem that prevents us from debugging is that an embedded mono environment has to provide some debug interface, and the common ksp release does not and modifying it to do so would require an unreasonable amount of work and most likely would be illegal anyway.

I tested a little bit on the AngryBots unity sample. Slapped an external DLL onto it and could easily debug it without requiring game code, once i checked "Development Build" and "Script Debugging" on the build config. Beside a bunch of symbol files, only 3 files were actually different: The launched executable, the managed dll (though it appears to just be some flags) and some "PlayerConnectionConfigFile" i have no idea what it is good for and does not exist in KSP anyway^^

(I actually had a non-standard environment, since i tried to get it running with VS via UnityVS, what apparently had some side on MonoDevelop as well. Might be worth to re-test it on a clear setup)

So yes, chances are good that all Squad has to do would be to enable two checkboxes, rebuild the game and share the created KSP.exe with interested modders.

Ok Interesting, I am kind of getting back to coding and completely learning C# (more the differences there is between C# and C++). If I get a chance, I will pop the question to the dev/Ted to know more about it.

Here is how I draw textures on my icons:

https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.cs#L55

https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.cs#L89

I put it on a label, but you can use the GUIContent with anything including buttons.

Also, I did a drop-down menu for my TAC Fuel Balancer:

https://github.com/taraniselsu/TacFuelBalancer/blob/master/Source/MainWindow.cs#L185

https://github.com/taraniselsu/TacLib/blob/master/Source/PopupWindow.cs

It is based on the page that Faark linked to. It has some issues, but it seems to work well.

Thanks Taranis, I will have a look at it; Cleaning a bit my code at the moment so it look like programming and not messing around with code.

Link to comment
Share on other sites

OK I got a curve ball for you, this is what I have in mind.

I am trying to set up as near to stock as possible (using the new KW Rocketry parts aswell for myself but there is a possibility of using pure stock aswell) multiple station parts. I would also like to setup 3.75m station parts aswell as 2.5m. Is it possible to have a scale function within your new gui?

As an example of what I have inmind here is my station.

D8EA6A8F3B8D5A13509B8DEEF984D4038B86BEC5

Link to comment
Share on other sites

The first release is a simple welding with just display data at first.

And then release a second version that will allow to change some value.

I am not sure it will be possible to change the scale value for each part however, since for just a few parts it would be ok, but it would become quite a mess with more parts.

Link to comment
Share on other sites

It's uploaded.

I managed to get the dropdown menu working (but it doesn't work very well with other gui items like the buttons)

I couldn't get the place where the icons are for the category so I used the dropdown menu.

Still need to work on the GUI to make it look better. Especially color wise.

hoQ7vMf.jpg

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