DMagic Posted December 15, 2016 Share Posted December 15, 2016 Another option for a somewhat simpler UI setup is covered by Maneuver Node Evolved. It basically uses an assembly for Unity just to handle storing references to objects. It also makes replacing the standard text objects with text mesh pro a lot simpler. All of the button listeners and methods are assigned manually in the other assembly. Since the UI is fairly simple, and its elements are fixed and don't change there isn't really any need for the more complex methods described in my tutorial. Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 15, 2016 Share Posted December 15, 2016 For now, I'm going to stick with a single assembly and making the calls to the asset bundle in code directly. There are only 3 object in this assetbundle so it's simpler to do it that way and it also helps me with learning how to do this at all. Once I move on to replacing the UI in my existing mods, a hybrid linked reference as Maneuver Node Evolved uses will probable be the way I go. Almost everything in my GUI's links to KSP objects somehow so what I could do in a dedicated GUI assembly is actually very limited as that assembly can't refer to KSP's Assembly-Csharp and so would be almost useless to me. However, that brings up the Text Mesh Pro issue, I did see the thread about it in the (now locked) 1.2 pre-release sub-forum, but is there anything more recent (forum thread or example mod code) on how to get that working? D. Quote Link to comment Share on other sites More sharing options...
DMagic Posted December 15, 2016 Share Posted December 15, 2016 @Diazo I got inspired seeing a few different posts about UI: Even without a separate assembly it should be fairly simple to replace the standard text elements. Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 15, 2016 Share Posted December 15, 2016 Alright, will try that out tonight and give some feedback. (On mobile at the moment.) Thanks for all the great info. D. Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 15, 2016 Share Posted December 15, 2016 (edited) Okay, I'm missing something that I'm pretty sure is obvious. This has nothing to do with my previous question about assetbundles. All I'm trying to do is attach another piece of text to the Altimeter to show which mode it is in. Start() { _tumbler = UnityEngine.Object.FindObjectOfType<KSP.UI.Screens.Flight.AltitudeTumbler>(); tumblerText = _tumbler.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText.text = "ASL"; tumblerText.color = Color.green; tumblerText.alignment = TMPro.TextAlignmentOptions.Center; tumblerText.fontSize = 14; tumblerText.fontStyle = TMPro.FontStyles.Bold; tumblerText.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; } Update() { tumblerText.rectTransform.anchoredPosition = tumblerText.rectTransform.anchoredPosition + new Vector2(0, -0.1f); } This works and spawns the text "ASL" in the middle of the altimeter in the Start() method and slowly descends the screen in the Update() method. The issue is that the black numbers from the Altimeter come along as well and I don't know why. My first though was that you can't have two TMPro instances on the same game object so: Start() { _tumbler = UnityEngine.Object.FindObjectOfType<KSP.UI.Screens.Flight.AltitudeTumbler>(); GameObject temp = new GameObject(); temp.transform.parent = _tumbler.transform; tumblerText = temp.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText = _tumbler.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText.text = "ASL"; tumblerText.color = Color.green; tumblerText.alignment = TMPro.TextAlignmentOptions.Center; tumblerText.fontSize = 14; tumblerText.fontStyle = TMPro.FontStyles.Bold; tumblerText.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; } Update() { tumblerText.rectTransform.anchoredPosition = tumblerText.rectTransform.anchoredPosition + new Vector2(0, -0.1f); } This worked to spawn the text "ASL" in the middle of the screen, but the altimiter numbers were just flat out gone. I assume they got shifted off screen somehow, but I don't know where. What am I missing? Just adding a piece of text should be easy but I don't know where I'm going wrong.. D. There is also a .bounds and .textbounds property that looks interesting, but they don't behave as expected. There documentation on this TMPro stuff somehwere? Edited December 15, 2016 by Diazo Quote Link to comment Share on other sites More sharing options...
DMagic Posted December 15, 2016 Share Posted December 15, 2016 In the first instance your text is attached to the same GameObject as the tumblers (which I don't think are text, they are something like 3d meshes, since they rotate as you would expect a tumbler to) which means they share a Transform/RectTransform. In the second instance it looks like you're adding the TMP object twice, first to the temp GameObject, then to the tumbler, you are probably wanting to add the temp GameObject as a child of the tumbler object. You might also want to just try skipping the tumbler altogether and adding the GameObject directly to the screen messages canvas, or maybe just the main canvas. Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 16, 2016 Share Posted December 16, 2016 (edited) This is turning into a real mess on me here. Fixing up the code to make a new gameObject that I make a child of the Altimeter UI is the farthest I've gotten so far. However, as soon as I attach that new gameObject to the Altimeter UI, the black altimeter numbers still disapear. Oddly enough, the altimeter numbers still disapear when I attach my text to the Atmopheric Pressure Gauge instead. My best guess at the moment is that when I make the new gameObject it gets automatically added to the Flight scene, NOT the UI Canvas and when I try to make a parent/child relationship across those two things it is what is causing my issue. Will keep poking at it, this is something that would really make my life easier if I can figure it out. D. Edited December 16, 2016 by Diazo Quote Link to comment Share on other sites More sharing options...
sarbian Posted December 16, 2016 Share Posted December 16, 2016 6 minutes ago, Diazo said: My best guess at the moment is that when I make the new gameObject it gets automatically added to the Flight scene, NOT the UI Canvas and when I try to make a parent/child relationship across those two things it is what is causing my issue. Will keep poking at it, this is something that would really make my life easier if I can figure it out. Just throwing ideas a few ideas to try out : add a RectTransform component and use that for parenting and moving since it s an UI object. parent with Transform.SetParent.html with the 2nd arg set to false. Quote Link to comment Share on other sites More sharing options...
DMagic Posted December 16, 2016 Share Posted December 16, 2016 The same thing happens to the Funds tumbler in the editor whenever Contracts Window + is opened, the numbers just disappear. But it doesn't happen in any other scene. I could never figure out what was happening, nothing about the position of the tumbler changed. So maybe there is just something weird about them or some bugs. Quote Link to comment Share on other sites More sharing options...
Eldrad_Ulthran Posted December 17, 2016 Share Posted December 17, 2016 https://www.dropbox.com/sh/k6f3a9bky48g7l8/AAD9MLXra7AltGLpXGlNzwFma?dl=0 My kopernicus planet pack. as soon as I f12 to it All hell gets loose. Done in ksp 1.2.1. Please help! Quote Link to comment Share on other sites More sharing options...
nightingale Posted December 17, 2016 Share Posted December 17, 2016 27 minutes ago, DMagic said: The same thing happens to the Funds tumbler in the editor whenever Contracts Window + is opened, the numbers just disappear. But it doesn't happen in any other scene. I could never figure out what was happening, nothing about the position of the tumbler changed. So maybe there is just something weird about them or some bugs. We had some fun times with layer/mask issues similar to this in 1.2. My guess is you've got a ScrollView in Contracts Window+, which is implemented with a mask (which is just setting the stencil bit). Because the tumblers also use the stencil bit, the two can interfere with each other. You can get it to stop doing that by either: Moving Contract Window + to another layer (by parenting it to a different canvas), picking one that is drawn later than the tumblers (which are on the Main layer/canvas). Playing around with z-coordinates. What you'd want to do is move the stuff under the viewport object away from the camera (+'ve z) so that they are drawn first (at least, I think that was what fixed it - going by memory). Quote Link to comment Share on other sites More sharing options...
Wjolcz Posted December 17, 2016 Share Posted December 17, 2016 I want to mod the stock ISRU parts to make them convert intake air into xenon. Is that doable? Where and how do I start? Quote Link to comment Share on other sites More sharing options...
Faile Posted December 17, 2016 Share Posted December 17, 2016 5 minutes ago, Veeltch said: I want to mod the stock ISRU parts to make them convert intake air into xenon. Is that doable? Where and how do I start? Start here: Look at what's in the .cfg file and use this for help: http://wiki.kerbalspaceprogram.com/wiki/CFG_File_Documentation Quote Link to comment Share on other sites More sharing options...
Wjolcz Posted December 17, 2016 Share Posted December 17, 2016 1 hour ago, Faile said: Start here: Look at what's in the .cfg file and use this for help: http://wiki.kerbalspaceprogram.com/wiki/CFG_File_Documentation Done! Thanks a ton! The ISRU now converts IntakeAir and EC into XenonGas. Now, I want to do something more complicated. I want to be able to harvest IntakeAir from all the atmospheres except for Kerbin. How I understand it: If I change the "checkForOxygen = true" to "false" the intakes will be able to collect IntakeAir, but it will also make jet engines work on Eve and Duna. And I don't want that. I want jets to work on Kerbin and Laythe and use all the atmospheres to turn IntakeAir into XenonGas (except for Kerbin). Uhhhh... It's complicated if I want to make it balanced somehow. Quote Link to comment Share on other sites More sharing options...
Marzl Posted December 17, 2016 Share Posted December 17, 2016 1 hour ago, Veeltch said: Done! Thanks a ton! The ISRU now converts IntakeAir and EC into XenonGas. Now, I want to do something more complicated. I want to be able to harvest IntakeAir from all the atmospheres except for Kerbin. How I understand it: If I change the "checkForOxygen = true" to "false" the intakes will be able to collect IntakeAir, but it will also make jet engines work on Eve and Duna. And I don't want that. I want jets to work on Kerbin and Laythe and use all the atmospheres to turn IntakeAir into XenonGas (except for Kerbin). Uhhhh... It's complicated if I want to make it balanced somehow. You need to define a new atmospheric resource for each of the other planets. Then you need a ModuleResourceHarvester module (in your ISRU or intake or whatever part) to harvest that new resource. Then you can convert this new resource instead of IntakeAir to XenonGas. I think Kerbonite does more or less exactly that, you may wan´t to take a look at this mod. ModuleResourceHarvester requires an animation to activate, at least that was the case for 1.1. Quote Link to comment Share on other sites More sharing options...
DMagic Posted December 17, 2016 Share Posted December 17, 2016 9 hours ago, nightingale said: We had some fun times with layer/mask issues similar to this in 1.2. My guess is you've got a ScrollView in Contracts Window+, which is implemented with a mask (which is just setting the stencil bit). Because the tumblers also use the stencil bit, the two can interfere with each other. You can get it to stop doing that by either: Moving Contract Window + to another layer (by parenting it to a different canvas), picking one that is drawn later than the tumblers (which are on the Main layer/canvas). Playing around with z-coordinates. What you'd want to do is move the stuff under the viewport object away from the camera (+'ve z) so that they are drawn first (at least, I think that was what fixed it - going by memory). Putting on a different canvas seems to work; moving the z-position didn't seem to help, but I didn't try too much. Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 17, 2016 Share Posted December 17, 2016 (edited) @nightingale Thanks for the info, I'll have to mess with the z-position some more. As this text is attached to altimeter, I need it to move when the altimeter does to show the Recover Vessel button. That means I need to put it on the same canvas. (I think, have not actually confirmed the exact number of the available canvases.) Could I just add my own Canvas? I'm still figuring this new UI out and that might be the simplest option. It is a strange issue though, I didn't notice previously, but both the Altimeter and Stage Count tumblers lose their text when this happens. D. Edited December 17, 2016 by Diazo Quote Link to comment Share on other sites More sharing options...
DMagic Posted December 17, 2016 Share Posted December 17, 2016 (edited) Check UIMasterController in KSP.UI for the available canvases. Adding your own canvas is possible, but can be tricky. You can also add your canvas to another canvas, but I wouldn't do that, there are apparently some Unity bugs with nested canvases. But if you need your UI to move with the altimeter it will have to be a child of that and can't be on a separate canvas, or you will have to constantly update its position. Text Mesh Pro objects are Unity MaskableGraphics, so maybe there is some property that can be set to keep them from screwing with other masks. Also, lots of TMP documentation here: http://digitalnativestudios.com/textmeshpro/docs/ Edited December 17, 2016 by DMagic Quote Link to comment Share on other sites More sharing options...
Diazo Posted December 18, 2016 Share Posted December 18, 2016 Of all the stupid things, it turns out that all I have to do is set the .localPostion on the gameObject with the text I'm trying to add to Vector.Zero and everything works. Apparently the defaults are what screw things up, so despite everything looking somewhat in the right place on-screen, the Vector3 positions of the transforms behind the scenes were screwy somehow. So the following works, note I'm using the HundredThousands tumbler (the leftmost 0), not the entire tumbler gameObject as my parent. lhGUIgo = new GameObject("LHGUI"); //lhGUIgo.layer = 5; //not sure this is required anymore lhGUIrect = lhGUIgo.AddComponent<RectTransform>(); lhGUIrect.SetParent(lhGUIgo.transform, false); tumblerASLtext = lhGUIgo.AddComponent<TMPro.TextMeshProUGUI>(); lhGUIgo.transform.SetParent(_tumbler.transform.GetChild(0).gameObject.GetComponent<RectTransform>()); tumblerASLtext.transform.localPosition = new Vector3(.5f,-.7f,0); //CRITICAL, set this because defaults block tumbler number rendering tumblerASLtext.text = "ASL"; tumblerASLtext.color = Color.green; tumblerASLtext.alignment = TMPro.TextAlignmentOptions.Center; tumblerASLtext.fontSize = 14; tumblerASLtext.fontStyle = TMPro.FontStyles.Bold; tumblerASLtext.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; So a lot of frustration for a simple answer. D. Quote Link to comment Share on other sites More sharing options...
RockyTV Posted December 21, 2016 Share Posted December 21, 2016 Is there a way I can debug KSP to show me detailed information about exceptions (e.g. what line of what file threw the exception)? Quote Link to comment Share on other sites More sharing options...
sarbian Posted December 21, 2016 Share Posted December 21, 2016 17 minutes ago, RockyTV said: Is there a way I can debug KSP to show me detailed information about exceptions (e.g. what line of what file threw the exception)? Yes Quote Link to comment Share on other sites More sharing options...
RockyTV Posted December 21, 2016 Share Posted December 21, 2016 (edited) 2 minutes ago, sarbian said: Yes Wasn't there a dev mode patcher that would patch some stuff in the assembly so, for example, the following message get_realtimeSinceStartup can only be called from the main thread would then be ignored and allow my addon to run perfectly fine? Is there a version of it for 1.2.2? Edited December 21, 2016 by RockyTV Quote Link to comment Share on other sites More sharing options...
sarbian Posted December 21, 2016 Share Posted December 21, 2016 (edited) 4 minutes ago, RockyTV said: Wasn't there a dev mode patcher that would patch some stuff in the assembly so, for example, the following message get_realtimeSinceStartup can only be called from the main thread would then be ignored and allow my addon to run perfectly fine? Is there a version of it for 1.2.2? That patcher is not required anymore. The game should not generate such message now. If you have then they most likely come from a mod that should fix its code. Edited December 21, 2016 by sarbian Quote Link to comment Share on other sites More sharing options...
RockyTV Posted December 21, 2016 Share Posted December 21, 2016 16 minutes ago, sarbian said: That patcher is not required anymore. The game should not generate such message now. If you have then they most likely come from a mod that should fix its code. Okay... uh, so what's a good replacement for Time.realtimeSinceStartup? In DMP we have some code that depends on it (connection logic is one of them). Quote Link to comment Share on other sites More sharing options...
sarbian Posted December 21, 2016 Share Posted December 21, 2016 (edited) There is no need for a replacement. Your code must NEVER call a Unity method from a constructor. That s all. Edit : those message only show up in Dev mode but they are important. Your code may behave strangely in "normal" mode if you ignore them Edited December 21, 2016 by sarbian 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.