Jump to content

DMagic

Members
  • Posts

    4,180
  • Joined

  • Last visited

Everything posted by DMagic

  1. 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.
  2. 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.
  3. @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.
  4. This section will cover how to replace the standard Unity Text elements with the fancy new TextMeshPro elements included with the latest version of KSP. Since we can’t add the KSP assemblies to Unity we won’t be able to directly add TMP elements to out Unity project, unless you happen to own the $95 TMP Asset. So instead we’ll have to use standard Text elements as placeholders then do all of the replacements from in-game. This turns out to be fairly simple, the only real issue is that we need some method for dynamically updating the text, or other properties from in-game. Section 1: Tagging Text Elements: Much like in the last part of the tutorial, the first step is to create a simple script that can be used to tag all of the Text elements that we wish to replace. Create a script in your Unity Assembly This script will also be used for updating the Text Field of the element whenever it needs changing A simple UnityEvent can be used to trigger then text change when needed Listeners can be added to this event to watch for text changes and update the Text Field public class TextHandler : MonoBehaviour { public class OnTextEvent : UnityEvent<string> { } private OnTextEvent _onTextUpdate = new OnTextEvent(); public UnityEvent<string> OnTextUpdate { get { return _onTextUpdate; } } } Section 2: Listening for Updates: To handle text updates the simplest method is to create an extension of the standard TMP Text Element with a few added methods. Create an extension class from the TextMeshProUGUI, this is the UI element used for text in KSP This element will be added to the same GameObject that our script is attached to We can grab a reference to our script and add a listener to its UnityEvent A simple method takes the argument from that UnityEvent and uses it to update the Text Field of the TMP Element public class BasicOrbitTextMeshProHolder : TextMeshProUGUI { private TextHandler _handler; new private void Awake() { base.Awake(); _handler = GetComponent<TextHandler>(); if (_handler == null) return; _handler.OnTextUpdate.AddListener(new UnityAction<string>(UpdateText)); } private void UpdateText(string t) { text = t; } } Store a reference to the TextHandler script in the Unity Assembly Invoke the UnityEvent whenever needed public class BasicOrbit_Module : MonoBehaviour { [SerializeField] private TextHandler m_Title = null; private IBasicModule moduleInterface; public void setModule(IBasicModule module) { if (module == null || m_Title == null) return; moduleInterface = module; m_Title.OnTextUpdate.Invoke(module.ModuleTitle + ":"); } } Section 3: Replacing Text Elements: The only tricky part to all of this is how we take the placeholder Text Element and replace it with the Text Mesh Pro Element. The method for this works similar to assigning style elements, covered in the last part. See the last part for how to load the Asset Bundle and process the prefabs during loading Once we have the prefabs we use the TextHandler tag to search for all of the Text Elements that need replacing We cache the properties from the placeholder Text Element to be used for creating the TMP Element Since a GameObject can only contain one UI element at a time we need to immediately destroy the Text Element after caching its properties Then create the new TMP Element and add it to the GameObject private void processTMP(GameObject obj) { TextHandler[] handlers = obj.GetComponentsInChildren<TextHandler>(true); if (handlers == null) return; for (int i = 0; i < handlers.Length; i++) TMProFromText(handlers[i]); } private void TMProFromText(TextHandler handler) { if (handler == null) return; //The TextHandler element should be attached only to objects with a Unity Text element //Note that the "[RequireComponent(typeof(Text))]" attribute cannot be attached to TextHandler since Unity will not allow the Text element to be removed Text text = handler.GetComponent<Text>(); if (text == null) return; //Cache all of the relevent information from the Text element string t = text.text; Color c = text.color; int i = text.fontSize; bool r = text.raycastTarget; FontStyles sty = getStyle(text.fontStyle); TextAlignmentOptions align = getAnchor(text.alignment); float spacing = text.lineSpacing; GameObject obj = text.gameObject; //The existing Text element must by destroyed since Unity will not allow two UI elements to be placed on the same GameObject MonoBehaviour.DestroyImmediate(text); BasicOrbitTextMeshProHolder tmp = obj.AddComponent<BasicOrbitTextMeshProHolder>(); //Populate the TextMeshPro fields with the cached data from the old Text element tmp.text = t; tmp.color = c; tmp.fontSize = i; tmp.raycastTarget = r; tmp.alignment = align; tmp.fontStyle = sty; tmp.lineSpacing = spacing; //Load the TMP Font from disk tmp.font = Resources.Load("Fonts/Calibri SDF", typeof(TMP_FontAsset)) as TMP_FontAsset; tmp.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow", typeof(Material)) as Material; tmp.enableWordWrapping = true; tmp.isOverlay = false; tmp.richText = true; } Different fonts are available and there is a TMP Font defined in the UISkinManager described in the last part There are two properties of the Text Element that don’t translate directly to Text Mesh Pro The Font Style and Text Alignment TMP does not have the bold - italic style and has more alignment options For these there are simple methods to convert to TMP private FontStyles getStyle(FontStyle style) { switch (style) { case FontStyle.Normal: return FontStyles.Normal; case FontStyle.Bold: return FontStyles.Bold; case FontStyle.Italic: return FontStyles.Italic; case FontStyle.BoldAndItalic: return FontStyles.Bold; default: return FontStyles.Normal; } } private TextAlignmentOptions getAnchor(TextAnchor anchor) { switch (anchor) { case TextAnchor.UpperLeft: return TextAlignmentOptions.TopLeft; case TextAnchor.UpperCenter: return TextAlignmentOptions.Top; case TextAnchor.UpperRight: return TextAlignmentOptions.TopRight; case TextAnchor.MiddleLeft: return TextAlignmentOptions.MidlineLeft; case TextAnchor.MiddleCenter: return TextAlignmentOptions.Midline; case TextAnchor.MiddleRight: return TextAlignmentOptions.MidlineRight; case TextAnchor.LowerLeft: return TextAlignmentOptions.BottomLeft; case TextAnchor.LowerCenter: return TextAlignmentOptions.Bottom; case TextAnchor.LowerRight: return TextAlignmentOptions.BottomRight; default: return TextAlignmentOptions.Center; } } That’s basically all there is to it. The result is much cleaner looking text that scales well and is readable in much smaller fonts. The only real problem areas are UI elements that require a standard Text Element, such as a Text Input Field. A custom input field will be required to handle these, or you can just leave them as standard Text, since they generally aren’t used as much. The full source code for the most complete version of the TextHandler and Text Mesh Pro extension (from Contracts Window +) are included below. Feel free to use the code directly. TMP Source Code:
  5. The MapNode has a protected Image component, MapNode.img. A lot of UI elements are either white or grey with the color added in later. To change that color you just need to set the color property of the Image: MapNode.img.color = ... Since that field is protected you might need to go through the hassle of manually accessing it with the GetComponent<Image> or GetComponent(s)InChildren<Image> methods. Sometimes Debug Stuff can be invaluable for figuring out the hierarchy of UI elements like this: As for why it's changing to the generic map object type, I'm guessing there is something wrong with the first argument of the Create method.
  6. 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.
  7. Version 7.3 is out; get it on Space Dock. It tightens up the spacing between contract parameters and no longer includes the settings file in the download package. This way your settings won't be erased every time a new update is released. The file will be generated as soon as you save with CW+ installed. The editor funds widget thing remains. I'm not entirely sure exactly what is going on with it, I know there are Unity bugs with using nested UI canvases, but I can't see what's really happening to the funds tumblers. It will have to remain as a known issue for now.
  8. Are you directly checking Alt, or are you using the Modifier key? GameSettings.MODIFIER_KEY.GetKey(false) @AVaughan The settings file is only generated when it's saved by KSP, which only happens if you turn on the "Use As Default" option when changing the settings from the stock panel. That way new downloads won't override any existing settings files, it also has the unfortunate side effect of hiding the only way to change the key shortcut.
  9. I tried Alt + M first, but that didn't turn out too well. It's possible to change the keyboard shortcut for Maneuver Node Evolved, but you have to do it in the settings file, since the stock setting panel doesn't offer any method to assign keys.
  10. Updates for Maneuver Node Evolved, KerbNet Controller, and Science Relay have been released. These fix errors with some of the sliders in the settings menu. The problem is specific to KSP 1.2.2, but the fixed versions should work fine in 1.2.1. Maneuver Node Evolved has a fix for the order of the Next/Previous orbit buttons, the Next Orbit button should no longer be displaced by the Previous Orbit button when the window is updated. As for the addition of more advanced maneuver features, I'm inclined to agree with @fourfa. That feels like something that is a little outside of the scope of this mod. It also has the potential for feature creep; there are several similar features that could be added: plane change, or minimal insertion orbit for instance. Science Relay has a fix for a bug when a transmission to another vessel is aborted; this bug prevented regular transmission to Kerbin if the transmission to another vessel was aborted or cancelled due to lack of EC.
  11. Did something happen to the float custom game parameter in 1.2.2? The following line works fine in 1.2.1, creating a slider in the settings menu that moved smoothly from 0.5 - 2.5 and displayed values from 50 - 250%. [GameParameters.CustomFloatParameterUI("Base Scale", minValue = 0.5f, maxValue = 2.5f, displayFormat = "P0", autoPersistance = true)] public float baseScale = 1.25f; But in 1.2.2 any attempt to change the slider causes this error: [EXC 01:29:50.877] FormatException: Unknown char System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) System.Single.Parse (System.String s) DifficultyOptionsMenu+<CreateDifficultWindow>c__AnonStorey15D.<>m__24B (Single v) UnityEngine.Events.InvokableCall`1[System.Single].Invoke (System.Object[] args) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) UnityEngine.Events.UnityEvent`1[System.Single].Invoke (Single arg0) UnityEngine.UI.Slider.Set (Single input, Boolean sendCallback) UnityEngine.UI.Slider.Set (Single input) UnityEngine.UI.Slider.set_value (Single value) DialogGUISlider.Update () DialogGUIBase.Update () DialogGUIVerticalLayout.Update () DialogGUIBase.Update () DialogGUIVerticalLayout.Update () DialogGUIBase.Update () DialogGUIBase.Update () DialogGUIVerticalLayout.Update () DialogGUIBase.Update () MultiOptionDialog.Update () PopupDialog.Update () The offending part seems to be the displayFormat = "P0". I have no idea why that would cause a problem. I tried setting the format to N0 and turning asPercentage to true, but then the slider only allowed for integer values (1 or 2), though it did display the percentage correctly. Is there something I'm missing? Do I have to set the stepCount to some specific value?
  12. @Esquire42 The latest update of Orbital Science includes a part upgrade to convert the antennas to relays.
  13. No new parts. Just additions to existing parts and a part upgrade package, which can be unlocked in the tech tree (the config for which can be found in the Resources folder if you want to change its tech node).
  14. Version 1.3.7 is out; get it on Space Dock. It should work fine on KSP 1.2.1 or 1.2.2. It fixes bugs with resetting experiments and fixing broken SIGINT dishes with EVA Kerbals, it will now look for the relevant experience skill rather than checking the Kerbal type. It also adds a ModuleDataTransmitter to the Soil Moisture experiments, which now works with the parts' animations. These are direct signal antennas, like the SIGINT dishes. The SIGINT antenna signal strength was made stronger. An upgrade package is available for all SIGINT and Soil Moisture parts that turns them into relay antennas and further boosts their signal strength.
  15. I imagine the idea was to preserves as much of the data transmitter code as possible, so that you could transmit two different types of science. Originally the other type of science triggered a callback when the transmission was complete (hence the name), but at some point it was changed to a game event which accomplished essentially the same thing, while allowing other things to listen for that transmission. This dual-use science transmission system has caused no end of problems with mods that fiddle with data transmission, like Remote Tech or Science Alert. But it can also be handy, because you can trick the transmitter into going through the motions and consuming EC without actually sending anything. For Science Relay I temporarily set the triggered flag when transmitting data between two vessels then change it back when the game event fires (the last argument in the event tells you if the transmission was successful, so it fires even if you run out of EC). I think the science value comes from the Celestial Body's recovered data multiplier (which is what basically all science that isn't tied to a specific situation uses, along with things like contract rewards). There is also a multiplier field in the M700 part config.
  16. The orbital survey (and science lab transmission) are using triggered data transmissions, that is, they set the Triggered flag in the Science Data to true. This bypasses the R&D center while still allowing for standard transmission through an antenna (extending the antenna, using EC). Adding science points to the R&D is handled separately for triggered transmissions. And they also fire a separate event: OnTriggeredDataTransmission.
  17. @Pointblank66 I don't see any way that Orbital Science would affect the antennas from BDB. None of the antennas have any of modules on them. The only thing that might cause a problem could be some error with an Orbital Science part that prevents other parts on the vessel from loading? Does this happen with any vessel? You do have a mod that's filling up your error log though. It looks like something that is meant for KSP 1.2. This line repeats over and over: MissingMethodException: Method not found: 'MapView.get_MapIsEnabled'. That field was changed from 1.1 to 1.2, causing that error if a mod is used in the wrong version. I can't tell where it comes from though.
  18. I actually didn't mess with mipmaps. My method was to take the planet textures and rescale them. It worked really well, even though there was some very odd behavior with planets that don't use color texture maps, like Kerbin. And changing mipmap settings wouldn't work with SCANsat anyway, because I needed an ability to scan specific areas of the surface, so I would have to combine different textures. The problem is that a significant amount of detail comes from the normal map, which don't work with this kind of combining textures, you end up with sharp seems. The other problem is that all of this texture swapping used a tremendous amount of memory, 100s of MBs (for each planet, and you have to consider situations where multiple planets and moons are visible) when refreshing.
  19. @sinpro There are technical reasons for why it's a bad idea to accept or cancel contracts while in the VAB. But you can always just wait until you are on the launch pad to accept part test contracts.
  20. Basic Orbit version 5.0 is out; get it on Space Dock. It should work on any version of KSP 1.2.x. It adds several readout modules to show the post maneuver node orbit parameters, these only apply to the first maneuver node. When using an EVA Kerbal or a vessel marked as a rover, there are several changes that will prevent flickering of the readout modules. This was particularly noticeable on low gravity planets where there were frequent transitions between the landed and sub-orbital states. Now it will only show the sub-orbital readouts when the vessel is more than a few meters above the surface. This behavior can be overruled by selecting the Always On toggles for the readout modules. It also fixes some bugs with showing the maneuver node panel with no target selected, and some potential bugs with impossible numbers.
  21. I updated Space Dock and CKAN to mark this compatible with KSP 1.2.2. Let me know if anyone runs into any problems. @NotAgain That Orbital Science scanner is a bit messy because it has two separate SCANsat modules, so you have to make sure to actually scan with both. The resource scanner part will only be available depending on your SCANsat resource scanning settings.
  22. This should be working fine in KSP 1.2.2, I updated Space Dock, which should hopefully update CKAN.
  23. @Snark I sympathize about GitHub's terrible release stats, but the info is available. You get either get directly from the GitHub API (search for download_count), or download a browser extension to show the data. Of course, you have to make a GitHub release for that to work, I'm not sure the info is available for just downloading files directly from the repo.
  24. Maneuver Node Evolved version 2.2 is out; get it on Space Dock. It is updated for KSP 1.2.2 and contains some fixes for snapping maneuver nodes to specific locations, along with error checking to prevent moving the node to an impossible location. It also has an option to turn off the connection lines between the windows and buttons, is some cases they can get a little weird and it might be annoying to have them on. And it fixes some text overflow problems. It is listed for AVC (and probably CKAN) as only supporting KSP 1.2.2; it should work fine in 1.2.1, there is just a minor problem when trying to save the settings file while creating a new game; the core aspects of the mod should be ok.
×
×
  • Create New...