Jump to content

fatcargo

Members
  • Posts

    393
  • Joined

  • Last visited

Everything posted by fatcargo

  1. I'm starting to seriously doubt myself, i need sleep... Anyway i (mistakenly ?) thought that docking ports do not have as strong connection as editor-built parts. I tried looking at KAS sources to learn more but i am tired. I'll look at it later. Is there a somewhat comprehensive list of unity3d joint types mapped to KSP vanilla/modded parts ?
  2. Correct, but i used Konstrucion ports merely to demonstrate part of my idea, not as desired effect. I'll try to explain this ... EXAMPLE : Imagine this scenario where Konstruction ports were never invented, instead RoverDude made a plugin that allows player to arbitrarily connect any part to any vessel in flight. Player would be able to simply use its vessel in orbit to get close enough to derelict Mk1 Command Pod, right click on it and use a new option "Join to my vessel". The pod (and its Kerbal inhabitant) would be instanly added to ship. The newly attached pod would have no visible connection to player's vessel. Of course, this scenario makes no sense. But when you add a part such as Konstruction port, and a rule that docked craft can join to your vessel using only these ports, then the whole idea of joining craft/parts in flight starts to make sense. Same with my idea : join AND RELEASE parts in flight that are connected via Unity3D FixedJoint connection (this is used when building crafts in VAB/SPH), used via separate part that introduces this functionality into the game.
  3. Bingo! But with one important caveat : once connected, there is no way to separate joined parts. And as far as game logic regarding Konstruction ports is concerned, this is ok. What i am proposing is a feature that allows the same part connection that is reverisble (ie a part can be detached). Problem is how and when to determine which part needs to be disconnected. In KAS, this is achieved by letting player target the part using an ingame-avatar representation of himeslf/herself in game - a Kerbal Engineer on EVA using tools. If attempting to just plainly add option to every part that can be detached in flight without any representing entity, player will be confused by this inconsistency. Thus, there must be a separate part that will introduce such functionality with its rules that will make it consistent with rest of game logic. A sort of Konstrucion port with detach action. All above considering a detachable parts without Kerbal, a fully automatic operation. Same as not needing a Kerbal to dock/undock two vessels with docking ports.
  4. I'll try to reply with least stress/impact on work : i was asking if it would be possible to add part(s) that perform same function as Engineer on EVA. A type of port/connector (or better yet a pair of such ports) that can attach part to vessel in flight with connection that is of equal type and strength as any other part normally built in editor. Such connection would be autostrut/KJR compatible. If such connection would be implemented, it would not matter if (for example) a resource container was added in VAB/SPH or in flight. In both cases, resource container would be connected to vessel the same way. All without EVA Engineer, just parts and vessels. It could VISUALLY look like a docking port or a hooking clamp for securing payload. If this is added to KAS, it would enable "payload reintegration" to vessels for example a unmanned truck but without wobbling associated with claws, magnets or docking ports.
  5. A question about reintegrating payloads into craft's body/frame : is there a separate plugin from other addon or a functionality within KAS to dock/attach part to craft as it if was added in VAB/SPH, WITHOUT Engineer on EVA ? Something like weldable ports from Konstruction, but separable again ?
  6. Idea : synchronized winches. When dealing with bulky loads, it may be needed to perform winching operations from multiple points. But only simple start/stop/speed synchronization toggle from winch UI. Anything more complicated and it will turn into Infernal Robotics (which is, sadly, badly out of date). It may be possible to make a auto-sync function that allows player to manipulate loads by having all synced winches working as one (there is YT video about it, can't remember the link). In simpler version (one i recommend implementing, if this idea is accepted) player is responsible for positioning of winches. Lots of trial and error, but that's the name of the game.
  7. While i was reading your code i realized that i already worked with lambdas in other part of my plugin. I tried too hard to make all-in-one solution for anyone to use, in my case i actually won't have problems to using refs inside anonymous functions. As for adding more triggers/listeners, i added a if- getcomponent-return line to prevent just that
  8. Here is the newest iteration, i adapted code from this post on unity answers site public DialogGUISlider CreateJogShuttle() { bool isDragging = false; float val = 0f; return new DialogGUISlider( setValue: () => { return isDragging ? val : 5f; }, // this one. can't set any ref or out parameters here min: 0f, max: 10f, wholeNumbers: true, width: 200, height: 10, setCallback: (float f) => { val = f; }) { OnUpdate = () => { //commented out for testing purposes //test_slider.OnUpdate = () => { }; //longwinded but reliable, good enough for my tests if (test_slider.slider.GetComponent<EventTrigger>()?.triggers.Exists(e => e.eventID == EventTriggerType.BeginDrag || e.eventID == EventTriggerType.EndDrag) ?? false) return; EventTrigger sliderEvent = test_slider.slider.gameObject.AddComponent<EventTrigger>(); EventTrigger.Entry sliderOnEndDrag = new EventTrigger.Entry(); sliderOnEndDrag.eventID = EventTriggerType.EndDrag; sliderOnEndDrag.callback.AddListener((e) => { Debug.Log("OnEndDrag\n"); isDragging = false; }); sliderEvent.triggers.Add(sliderOnEndDrag); EventTrigger.Entry sliderOnBegindDrag = new EventTrigger.Entry(); sliderOnBegindDrag.eventID = EventTriggerType.BeginDrag; sliderOnBegindDrag.callback.AddListener((e) => { Debug.Log("OnBeginDrag\n"); isDragging = true; }); sliderEvent.triggers.Add(sliderOnBegindDrag); } }; } Note that "isDragging" is updated by two event handlers, so it properly resets slider thumb. Also i used "slider" field instead of "uItem". @xEvilReeperx thanks for the example, i'll give it a try.
  9. Not-so-good-news-update : i made some more tests and used different approach. I want to make a function to create a jog-shuttle type of slider. I need test how it performs when called multiple times because it uses some local variables (it should be ok), but i also wanted to bind output value of slider to a float variable passed by reference, so the whole thing stays neatly inside a single function. Guess what ? "out" and "ref" variables can't be used inside anonymous functions, which is how all callbacks are implemented for slider events. Sigh... what now ? I'll keep picking at this but feel free to chime in. If all else fails, after i post the example code, whoever wants to use it will have to use class-level variables in callbacks to get usable values ... yuck. Read this stackoverflow post if insterested.
  10. @maja : Thanks for the example code ! It helped me construct a working example. uItem field is indeed the right way to obtain handle to GameObject for DialogGUI element, i just used it wrong. NOTE : uItem field appears to be valid only after PopupDialog.SpawnPopupDialog() is called. Kudos for clever way of disabling further calls to Update by assigning an empty code block. However, i noticed that when calling PopupDialog.SpawnPopupDialog() multiple times, DialogGUISlider.Update() stays disabled (so for anyone trying this - if there is a problem with code not running correctly, this may be one of the reasons). @DMagic : Thanks for the idea to call default events from my custom handlers, though i still have to check logic and flow of code. Example code is working i just need to make a more robust solution. Namely, there will be multiple sliders and i need to know which one fired the event. PointerEventData contains source object fields that i can use, but not all fields are valid for all types of events, some of them are null (i've got a few NREs when experimenting). Once i clean the code i'll post what i did.
  11. I've run into another problem : i want to use DialogGUISlider as a jog-shuttle control. Why ? I need a precise control over a potentially large range of values within a single UI element. The problem is that available functional callbacks for setValue and actionCallback do not provide required event handling, and i need events that fire when slider thumb is clicked-and-held-down and when it is released. I've found almost a direct example in sources of BetterManeuvering and JanitorsCloset. For start i need to know if i can attach a additional listener(s) directly to DialogGUISlider to capture events using DialogGUISlider.uiItem.gameObject.AddComponent and also what events i need to define/use to capture inputs. I found two approaches : - BetterManeuvering defines events it needs and hooks into PopupDialogController (its listener is a basic MonoBehaviour) - JanitorsCloset completely replaces default event handlers with its own (its listener inherits from MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler and IPointerExitHandler) DebugStuff could find references to thumb and container components of DialogGUISlider inside PopDialog window, so it should be possible to intercept messages for those specific event targets. I'll try to roll my own event installer/listener ofcourse but i'd like some advice on doing this properly. EDIT : I was wrong to try using DialogGUISlider.uiItem, its null at runtime...
  12. Ohhh i think i solved it ! When using 9-slice UI Sprite, few things need to be done : 1. Image to be loaded as texture needs to have small enough corners (usually rounded) so that rendering engine can use it on smaller elements (like the before mentioned scrollbar thumb) 2. For proper display image needs to have alpha channel, otherwise all pixels will fill up the UI element box and it won't look good 3. Border parameter needs to reflect actual size in pixels for borders (though you can put fractionals too, its a float so tweak it your liking) 4. Pixels Per Unit parameter works ok at value of 100, if lower the displayed image will degrade Note that if corners needs to be shown with soft(er) edges, try adding/setting anti-aliasing in image processing software (also, the below code example does it's own smoothing which really isn't sufficient on it's own). public int pixelsPerUnit = 100; // best to keep it at 100 public uint extrude = 0; //don't know what this does, 0 is ok //these are the magic stuff needed for 9-slice to work public float border_left = 8f; // choose how many pixels from image edge need to be allocated for border / corner public float border_bottom = 8f; public float border_right = 8f; public float border_top = 8f; public Sprite ImageSprite(string imagePath) { Texture2D imageTexture = GameDatabase.Instance.GetTexture(imagePath, false); // load image imageTexture.filterMode = FilterMode.Trilinear; // try smoothing, not overly spectacular imageTexture.wrapMode = TextureWrapMode.Clamp; // not sure this is required imageTexture.Apply(); return Sprite.Create( imageTexture, new Rect(0, 0, imageTexture.width, imageTexture.height), new Vector2(0.5f, 0.5f), // pivot aka center of sprite pixelsPerUnit, extrude, SpriteMeshType.Tight, new Vector4(border_left, border_bottom, border_right, border_top) // important stuff ); } Ahh yes the SpriteMeshType.Tight tells what to do with empty space around texture, if using entire image this has no effect. PS: As so many times before, i was actually fighting my own stupidity - while tinkering with input values for borders i forgot to properly transfer parameters and it ended up using (1,1,1,1), so i spent couple of days staring at the screen like a statue for two hours.
  13. Just as i considered texture rescaling to be resolved, i stumbled upon something interesting and it just bugs me. I have made a function that loads image, then "stretches" it by creating a new texture of desired size, copies all four corners, then copies all borders between corners and finally fills in the center. Not the most elegant (or short) function, but it does the job. Then, i tried the same for thumb button on DialogGUIScrollList and found that, depending on given content, thumb size changes. This in turn deforms the loaded image. Ofcourse i wanted to use OnResize event, but that d*mn thing triggers even with plain scrolling user action. Too expensive, too bulky and will most likely attract a Kraken with that many memory reallocations / garbage collections. So, i yet again i turned to KSP built-in style HighLogic.UISkin.verticalScrollbarThumb . I assigned it to DialogGUIScrollList UIStyle and lo and behold - it rescaled button with no extra code, all rounded corners perfectly preserved, it even has a simple gradient. So, i tried to copy the entire UIStyle and after some tests found that this specific resizing type is built inside Sprite itself. I used HighLogic.UISkin.verticalScrollbarThumb.normal.background (which is a KSP built-in Sprite) in my own UIStyle and there was the smoking gun. So what is bugging me now, is how i can replicate same behaviour in my custom Sprite. There are parameters for Sprite.Create() as mentioned on this Unity3D help page public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsPerUnit, uint extrude, SpriteMeshType meshType, Vector4 border); I'm out of my depth here. Are there any ides how to this ? This stackoverflow post demonstrates pretty much exactly what i'm trying to do (sans putting the texture in 3D space). Another example is at Unity3D docs GUI Texture (Legacy UI Component) Ahh one more thing : it appears to be referenced as "9-slice" UI image (found at this post from answers.unity.com, reading it now and trying that solution ! Will respond tomorrow).
  14. Found solution for this, though in hindsight it is not what i'm after. I'll have to enforce PNGs to have required width and height. If anyone still wishes to do texture resizing, source is available in this stackexchange post . Note that is quite crude for larger scaling factors, but for minor pixel-by-pixel adjustments it works ok.
  15. I can't solve UI Texture2D rescaling problem. I have an image glyph in PNG format that i want to load and then rescale to fit a specific constraints for plugin code to work on it. Problem is that at every time i try, KSP (or to be more precise - Unity3D under the hood) refuses or outright quietly fails to resize a texture. Debug log either shows "can't resize a compressed texture" or texture dimensions drop to 0 (!?) after resize. I've searched and found that apparently Texture2D.Resize() method does NOT rescale a texture, it only changes the Color[] array size. If the above is true, this is ... ridiculous. Anyway, here is a snippet of troublesome code: Texture2D sourceTexture = GameDatabase.Instance.GetTexture(imagePath, false); sourceTexture.Resize(10, 15, TextureFormat.DXT1, false); // trying to bypass compressed texture resize failure warning sourceTexture.Resize(10, 15); // does not work for me sourceTexture.Apply(); Note that, resizing dimensions 10 and 15 are purely for demonstration purposes. Failing above, i could enforce failure if loaded PNG is not within constraints. Barring the Resize() problem, my code nicely loads and manipulates the PNG for display in UI, there are no problems for now.
  16. Found it. Thanks ! I copied code from SettingsWindowView .cs and i found what i missed : DialogGUIVerticalLayout was added to box element with all parameters. So it worked !
  17. I was away for several days. I searched at github for "SettingsWindowView" and " DialogGUIBox", neither has been found.
  18. Originally, while i was learning about UI there were two competing approaches with KSP Assets and DialogGUI. First i tried creating an asset as per instructions but have given up, then i tried DialogGUI which worked. My confusion arised when i thought that panel object used in UI design inside unity editor had an equivalent method in C# and i mistakenly associated it to DialogGUIBox. I was wrong. Anyway, i've got all i need from various coding experiments and have continued development.
  19. Thanks ! I suspected this might be the case, which leaves DialogGUIBox() in questionable usability - if used on it's own, its functionality could have been duplicated with label with no text for example. Then again, it could be similar to DialogGUISpace(), just with added box for visibility. It is odd that it accepts any UI elements at all .
  20. I should consider this topic "official" discussion for DialogGUI, though i did separate posts and i'm willing to change to this topic only to keep all related problems and solutions in one spot (even though this is offically "necroposting"). So, i've got the problem with DialogGUIBox. I think this element is used for grouping other basic UI elements such as labels, buttons, sliders etc... Assuming above is correct, i can't properly set positions of UI elements inside box. When i add two labels, they appear waaay in upper left corner, far outside popupdialog window, and label text is vertically aligned. I tried placing box inside horizontal layout, tried to add content sizer as first element... nothing helps. So, does anyone have a working example of using box as container for other elements (again, if that is a proper use of box) ? Maybe a dumbed-down-hello-world style example ?
  21. Solved it ! My custom UISkinDef style was incomplete ! Here is what is needed to specifically customize scrollview. When i first started tinkering with styles, i ignored these fields since i already had slider-related fields, i never associated scrollbar stuff with scrollview. Thus the point of confusion. CAMSkin.verticalScrollbarUpButton = buttonStyle; CAMSkin.verticalScrollbarThumb = buttonStyle; CAMSkin.verticalScrollbarDownButton = buttonStyle; CAMSkin.verticalScrollbar = windowStyle; CAMSkin.horizontalScrollbarThumb = buttonStyle; CAMSkin.horizontalScrollbarRightButton = buttonStyle; CAMSkin.horizontalScrollbarLeftButton = buttonStyle; CAMSkin.horizontalScrollbar = windowStyle; This raises an interesting issue : when creating a new style, not all fields are initialized to values from HighLogic.UISkin (and it should, as fallback/default) , which looks odd to me.
  22. Thanks for the idea ! I'm not really after the class members listing, but their VALUES. So i did some digging and found a dump-values-of-all-members-inside-class over on stackoverflow. What i did was -write that function -assign a HighLogic.UISkin.scrollView to a public variable -set a convenient breakpoint -then compile/copy dll/run ksp -run debugger, run into breakpoint -in immediate window i called that function and got all values This way i can dissect how that (working) UISkinDef class is setup so i can clone it and try to modify until it looks that way i want to (or until it breaks ). Though now when i look at values my SolidColorFill() may be not correct. Here is some more code. This is what i use to create backgrounds/fills for various UI elements. public Sprite SolidColorFill(Color color) { Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false); tex.SetPixel(1, 1, color); tex.Apply(); return Sprite.Create( tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f), tex.width ); } As it can be seen, it is copy from github sources, two functions mushed into one. And this is a dump from "HighLogic.UISkin.scrollView" (some editing done to make it more legible): //Type: UIStyle //Fields: System.String name = scrollview UIStyleState normal = UIStyleState UIStyleState active = UIStyleState UIStyleState highlight = UIStyleState UIStyleState disabled = UIStyleState UnityEngine.Font font = System.Int32 fontSize = 0 UnityEngine.FontStyle fontStyle = Normal System.Boolean wordWrap = False System.Boolean richText = True UnityEngine.TextAnchor alignment = UpperLeft UnityEngine.TextClipping clipping = Clip System.Single lineHeight = 13 System.Boolean stretchHeight = False System.Boolean stretchWidth = True System.Single fixedHeight = 0 System.Single fixedWidth = 0 //Type: UIStyleState //Fields: UnityEngine.Sprite background = rect_round_down_dark_veryTransparent //(UnityEngine.Sprite) UnityEngine.Color textColor = RGBA(0.000, 0.000, 0.000, 1.000) The function used to dump data is from C# Variable description function . I have removed some of the "\r" carriage returns. Note that when this is used in immediate window, it will escape \n newlines before printing, so it won't be a newline-formatted printout, rather a unbroken string. But it still beats manually exploring all members and doing copy/paste into text editor. public static string DisplayObjectInfo(System.Object o) { StringBuilder sb = new StringBuilder(); // Include the type of the object System.Type type = o.GetType(); sb.Append("Type: " + type.Name); // Include information for each Field sb.Append('\n' + "Fields:"); System.Reflection.FieldInfo[] fi = type.GetFields(); if (fi.Length > 0) { foreach (FieldInfo f in fi) { sb.Append('\n' + " " + f.ToString() + " = " + f.GetValue(o)); } } else sb.Append('\n' + " None"); // Include information for each Property sb.Append('\n'+ "Properties:"); System.Reflection.PropertyInfo[] pi = type.GetProperties(); if (pi.Length > 0) { foreach (PropertyInfo p in pi) { sb.Append('\n' + " " + p.ToString() + " = " + p.GetValue(o, null)); } } else sb.Append('\n' + " None"); return sb.ToString(); }
  23. Ok here it is. https://imgur.com/8UO8tda Note white box on right side of scroll view. Off-topic : this is for my animation partmodule, i'm trying to expand B9 pack with new components. But the development is horribly slow due to real-life commitments.
  24. I am trying to make a UI for my partmodule using DialogGUI and need to fit a long list of UI elements inside window. Sorry to bug people but im paging @HebaruSan, @DMagic, @MOARdV, @malkuth and others. If anyone has some time please respond. DialogGUIScrollList (and a mandatory DialogGUIContentSizer) are used for this. When opening a window, scrollbar of right side of scroll view has white thumb and a white body. The scroll view content itself also appears to have default style (grayish box with round corners). To me it appears that scroll view has no style defined, so some of its elements either revert to hard-coded fail-safe defaults or take values from builtin style (HighLogic.UISkin). Is this a problem with my style ? Here is what i used to set my UISkinDef.scrollView. Please note that some values may by wildly off - its on purpose, for testing only. //note that i did not used static class to define/initialize variables and methods, //because i've had NREs when trying to use styles from static class on slider UI elements scrollViewStyleState.background = SolidColorFill(Color.yellow); scrollViewStyleState.textColor = Color.red; scrollViewStyle.fixedHeight = 1f; scrollViewStyle.stretchWidth = true; scrollViewStyle.stretchHeight = true; scrollViewStyle.lineHeight = 20f; scrollViewStyle.clipping = TextClipping.Clip; scrollViewStyle.alignment = TextAnchor.MiddleCenter; scrollViewStyle.richText = false; scrollViewStyle.wordWrap = false; scrollViewStyle.fontStyle = FontStyle.Normal; scrollViewStyle.fontSize = 20; scrollViewStyle.font = UISkinManager.defaultSkin.font; scrollViewStyle.disabled = scrollViewStyleState; scrollViewStyle.highlight = scrollViewStyleState; scrollViewStyle.active = scrollViewStyleState; scrollViewStyle.normal = scrollViewStyleState; scrollViewStyle.fixedWidth = 20f; //MultiOptionDialog is supplied with this new DialogGUIVerticalLayout( new DialogGUIScrollList(new Vector2(400f, 150f), new Vector2(350f, 140f), false, true, new DialogGUIVerticalLayout( new DialogGUIContentSizer(UnityEngine.UI.ContentSizeFitter.FitMode.Unconstrained, UnityEngine.UI.ContentSizeFitter.FitMode.PreferredSize, true), //UI elements such as labels, sliders, buttons etc new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test"), new DialogGUILabel("label test") )//vertical layout - scroll )//scroll list )// vertical layout - main I don't know which of these is wrong, though i'm concerned that one-style-covers-all approach to using same styling structure for all types of UI elements may be too rough (for example what effect would text color have on scrollview ?)
  25. Does "PAW" refer to Part Action Window Sorter-Outer ? While i tinkered with my code, i used following flags (this was done with stock part menus) : guiActive = true guiActiveEditor = true externalToEVAOnly = false guiActiveUnfocused = true //this one ? unfocusedRange = 1 //not directly relevant, though it wouldn't surprise me if KSP freaks out on large values Though i tested this by launching two probe cores separated with docking ports and batteries, then cheating them into orbit and then decoupling them. As distance grew, beyond 1m range, menu item for other vessel vanished. Note that distance is measured from part's stack attachment node (most likely first one in part.cfg, part i work with has only one).
×
×
  • Create New...