Ezriilc Posted June 23, 2013 Share Posted June 23, 2013 I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it.I don't really know the first thing about it, but the GUI is what I'm interested in as well. HyperEdit is a non-part plugin that uses the UnityEngine.GUILayout class to generate its buttons and whatnot. The new official repository for HyperEdit source code is here: https://github.com/swifthawk/hyperedit (see Window.cs for GUILayout stuff)I hope this helps. Good luck! Quote Link to comment Share on other sites More sharing options...
MoonHeadJohn Posted June 23, 2013 Share Posted June 23, 2013 I don't really know the first thing about it, but the GUI is what I'm interested in as well. HyperEdit is a non-part plugin that uses the UnityEngine.GUILayout class to generate its buttons and whatnot. The new official repository for HyperEdit source code is here: https://github.com/swifthawk/hyperedit (see Window.cs for GUILayout stuff)I hope this helps. Good luck! Oh I'm okay with creating some of the buttons using the following:m_dfltButtonStyle = new GUIStyle(HighLogic.Skin.button)Does hyper edit use a similar feature to minimise the window or is it always visible? Never used it myself. Quote Link to comment Share on other sites More sharing options...
Ezriilc Posted June 23, 2013 Share Posted June 23, 2013 Oh I'm okay with creating some of the buttons using the following:m_dfltButtonStyle = new GUIStyle(HighLogic.Skin.button)Does hyper edit use a similar feature to minimise the window or is it always visible? Never used it myself.No, HyperEdit is activated by pressing Alt + h on the keyboard.As for that code, I have no idea. I'm still very new to C# and Unity, and I'm not fluent in the code yet. But it should be easy to do what you want. If nothing else, you could trigger keystrokes like Alt + TAB or even the Windows key, on a button click. Just have the button load with the view instead of waiting for the hotkey (Alt + h). Suggestion: make the button drag-able, transparent, and persistent between restarts. Quote Link to comment Share on other sites More sharing options...
aftokinito Posted June 24, 2013 Share Posted June 24, 2013 How do I get the CelestialBody component of a GameObject (a planet)?I'm trying this right now:GameObject reference = GameObject.Find("Tylo");GameObject newPlanet = (GameObject)GameObject.Instantiate(reference);Component celestialComponent = newPlanet.GetComponent("Celestial Body");CelestialBody celBody = (CelestialBody)celestialComponent.GetComponent("CelestialBody");Unfortunately the last two lines do not seem to work.EDIT:The quote is showing "Ce lestialBody" for some reason but it's properly written on the code. Quote Link to comment Share on other sites More sharing options...
Ezriilc Posted June 24, 2013 Share Posted June 24, 2013 The quote is showing "Ce lestialBody" for some reason but it's properly written on the code.That may actually not be the forum here causing that; you may have some hidden or non-standard character in your code that is translating to a whitespace here. I highly recommend you find out what is causing that, as I strongly suspect that that is why it's not working for you. I could easily be wrong, but that's my hunch. << ["His hunches ARE good..."] Quote Link to comment Share on other sites More sharing options...
TaranisElsu Posted June 24, 2013 Share Posted June 24, 2013 I'm currently trying to get my head around the GUI stuff provided by the KSP API, and I've set myself the task of getting a small button icon working in the bottom left portion of the screen which opens and minimises the window when pressed. Like those you see with Chatterer and ISA MapSat.Would someone be able to describe how to go about doing this or point me in the right direction? I've been trawling over the source code for both plugins but having a bit of trouble trying to understand it.Here is how I created an icon like that: https://github.com/taraniselsu/TacLib/blob/master/Source/Icon.csIt is used here: https://github.com/taraniselsu/TacFuelBalancer/blob/Release2.0/Source/FuelBalanceController.cs#L37 Quote Link to comment Share on other sites More sharing options...
aftokinito Posted June 24, 2013 Share Posted June 24, 2013 How do I print the list of all the components of a GameObject?I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones. Quote Link to comment Share on other sites More sharing options...
Ezriilc Posted June 24, 2013 Share Posted June 24, 2013 How do I print the list of all the components of a GameObject?I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones.I don't know if there's a built-in function to do that, but you should be able to iterate through it's children. Did you check with Unity? http://Docs.Unity3d.com/Documentation/ScriptReference/GameObject.html Quote Link to comment Share on other sites More sharing options...
aftokinito Posted June 24, 2013 Share Posted June 24, 2013 (edited) I don't know if there's a built-in function to do that, but you should be able to iterate through it's children. Did you check with Unity? http://Docs.Unity3d.com/Documentation/ScriptReference/GameObject.htmlI was looking for a snippet, I know I have to iterate through the children but Unity is so confusing.If I try to get the children of CelestialBody I get the children of the GameObject instead and same for the other 3.EDIT:NVM, found it.It looks like you have to iterate the transform, not the GameObject. Edited June 24, 2013 by aftokinito Quote Link to comment Share on other sites More sharing options...
LaydeeDem Posted June 27, 2013 Share Posted June 27, 2013 Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it. Quote Link to comment Share on other sites More sharing options...
PrivateFlip Posted June 28, 2013 Share Posted June 28, 2013 (edited) I have a part in a vessel. How do I get the position of the part in relation to the vessel just like vessel.LocalCom or vessel.angularMomentum but for a part. I have been looking for this for well over two hour. Looked in the source code of some mods, the KSP.API. It seems so stupidly simple, but I just can't find it.EDIT: The answer was given in the development thread of my mod by ZRM:I work in the vessel.transform space. Just transform positions with vessel.transform.InverseTransformPoint and directions with vessel.transform.InverseTransformDirection. If you do this with both engine positions/directions, the COM and the user input via the vessel.ReferenceTransform (the command module reference frame), everything is in the same coordinate space for solving the system. If you really want everything in a constant frame, use vessel.ReferenceTransform. Edited July 1, 2013 by PrivateFlip Question Answered Quote Link to comment Share on other sites More sharing options...
LaydeeDem Posted June 29, 2013 Share Posted June 29, 2013 Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it.No one? Where's all the helpful plugin devs when you need them? Quote Link to comment Share on other sites More sharing options...
Ezriilc Posted June 30, 2013 Share Posted June 30, 2013 Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it.I honestly have no clue, just heard of Unity, and know almost no C#, but since you're still waiting for a reply, and I'm interested, I'm going to investigate. Don't expect much. :| Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 1, 2013 Share Posted July 1, 2013 How do I get the CelestialBody component of a GameObject (a planet)?I'm trying this right now:Use the generics version:CelestialBody aCBComponent = planet.GetComponent<CelestialBody>();How do I print the list of all the components of a GameObject?I want to see all the components (Including the PQS mods) of a planet so I can learn how are they assembled.I know how to print CelestialBody, OrbitDriver, OrbitRenderer and UnityEngine.Transform but I'm not sure where are the other ones.They all derive from component, so you can use something like: foreach(Component aComponent in aTransform.gameObject.GetComponents<Component>()){ print(aComponent.GetType());}Does anyone know how the Space Center buildings are spawned? I know it's using PQSCity but I don't know the specifics behind it.http://forum.kerbalspaceprogram.com/showthread.php/26858-Adding-new-buildings-runways(easter egg spoilers):http://forum.kerbalspaceprogram.com/showthread.php/28857-Space-Center-Game-Objects-%28WARNING-SPOILERS%29 Quote Link to comment Share on other sites More sharing options...
EnhancedCookie Posted July 4, 2013 Share Posted July 4, 2013 Hi !I am thinking of making a "bailout" plugin, where, by the press of a key, all of the kerbals in the active vessel would all go on EVA, and I was wondering where to find an event related to going on EVA. Does anyone have an idea ? Quote Link to comment Share on other sites More sharing options...
LePwnerer Posted July 6, 2013 Share Posted July 6, 2013 k i was lurking around for hours but didn't find an answer to my problem. i want to make a plugin which doesn't need any part to function and runs as soon as the game starts or as soon as a vessel is on the launchpad.thx to anyone helping me with this Quote Link to comment Share on other sites More sharing options...
LePwnerer Posted July 6, 2013 Share Posted July 6, 2013 ok. hi everyone. i was lurking around since hours and still haven't found a solution to my problem.basically i want to make a "plugin" that doesn't need a part with it. also it should run as soon as a vessel is on the launchpad.thx for helpgreetings LePwnerer Quote Link to comment Share on other sites More sharing options...
Zyrac Posted July 6, 2013 Share Posted July 6, 2013 Hi guys. I was wondering if anyone can help me out here. I've got an add-on that can be used gather samples from the various celestial bodies. I'm trying to make a change to the plugin so that the sampling unit deactivates when it finishes gathering samples, but what I've got at the moment doesn't seem to be working and I'm not sure why. If anyone can help me out, that would be great. Here's an example of a bit of the code that is supposed to make it deactivate on filling up. (Unit capacity is 10)case "Moho" :if (this.part.RequestResource("MohoSamples", -1 * TimeWarp.deltaTime) != 10) { UnitActive = true;}else{ UnitActive = false; UnitStatus = "Unit Inactive"; SampleRequested = "Not Sampling";} this.part.RequestResource("ElectricCharge", 0.025 * TimeWarp.deltaTime); break; Quote Link to comment Share on other sites More sharing options...
Kreuzung Posted July 6, 2013 Share Posted July 6, 2013 RequestResource should return by which amount the resource level has changed, so if you want to check if the resource level hasn't yet reached the maximum, you should use > 0. Not sure about this, been a while since I touched the resource system for the last time. Quote Link to comment Share on other sites More sharing options...
Zyrac Posted July 6, 2013 Share Posted July 6, 2013 RequestResource should return by which amount the resource level has changed, so if you want to check if the resource level hasn't yet reached the maximum, you should use > 0. Not sure about this, been a while since I touched the resource system for the last time.Ok, thanks. I'll try that. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 6, 2013 Share Posted July 6, 2013 basically i want to make a "plugin" that doesn't need a part with it. also it should run as soon as a vessel is on the launchpad.Use the [KSPAddon] attribute on a monobehaviour subclass, it does have arguments as to which scene it will run in - you probably want the flight scene. Quote Link to comment Share on other sites More sharing options...
MrFailSauce Posted July 8, 2013 Share Posted July 8, 2013 Can anyone post some example code on how to make a right click menu?Maybe one that displays one line of information and a toggle? (e.g. activate button)I went through a bunch of forums and googling and the wiki and couldn't seem to find any good examples.Are there KSP classes to build these menus or is this done with unity? I figure I could probably figure out from the unity docs, but if there is a standard way I'd rather use it so that I can match the the look and feel of other KSP menus. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 9, 2013 Share Posted July 9, 2013 The sticky explains it in detail, but basically the lines with buttons are methods tagged with the [KSPEvent] attribute and the lines without buttons are fields tagged with the KSPField attribute with the guiActive property set to true. Quote Link to comment Share on other sites More sharing options...
MrFailSauce Posted July 9, 2013 Share Posted July 9, 2013 The sticky explains it in detail, but basically the lines with buttons are methods tagged with the [KSPEvent] attribute and the lines without buttons are fields tagged with the KSPField attribute with the guiActive property set to true.Thanks! I'll try that tonight.Which sticky? Can you link it for me? Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 9, 2013 Share Posted July 9, 2013 http://forum.kerbalspaceprogram.com/showthread.php/7529-Plugin-Posting-Rules-And-Official-Documentation?p=156430&viewfull=1#post156430 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.