#UITK for KSP 2
1 messages · Page 4 of 1
yeah and people wont be as inclined to use them
oh and (hopefully) last question, why are they internal?
cuz they arent suposed to be used in code
I'm guessing the game will still be able to find them since it uses reflection
they just expose them to the UIBuilder
yeah
i think the selector is public tho? or not?
the exposed ones should stay internal to avoid u using them since they are empty classes
yeah change it 
i dont remember why i didnt make it abstract tbh, but sure
alright, package seems to be working fine
ahhhhh what the fuck
I'm slowly going insane trying to make this work in a reasonable way
nevermind lmao, it was because I was loading the assembly with the custom controls before registering the Harmony patch for Shader.Find

Version 1.3 is now released, featuring:
- Configuration of UI scaling
- Selector custom control and support for many native controls hidden in the Builder
- API to disable dragging on an element, and disabled dragging on TextField by default
- UitkForKsp2.Controls Unity package for easy development of UITK UIs - install using Unity Package Manager from the following Git URL: https://github.com/jan-bures/UitkForKsp2.Controls.git
huh
@stuck jasper wasn't it possible to have it in the same git?
why the UITKforKsp2.Controls?
also sorry if i woke u up 
Having a Unity solution within another C# solution didn't seem like the best idea
oh yeah ur using an actual solution, makes sense yea
Instead I made the Unity project, inside it the package, made the package its own Git repo, made it a git submodule of the Unity project, and a submodule of the UitkForKsp2 solution within its own project
oh yeah wtf that works greatly
So now I can update the package from the Unity project, push those changes, and then pull them with one command into UitkForKsp2 and press build, and it's done
Seemed like the best way to go about it
who did stuff.
@stuck jasper is it a dependecy for uitk?
you know full well "who did stuff", if you wanna say "munix you fucked up, fix the package", just say it lol
munix you fucked up, fix the package
seems that 1.3.0 isn't on CKAN yet
no clue why that would happen, it is on SpaceDock
alright, I've finally started work on proper docs for this
and in preparation for that, I'm now preparing a new template type in SpaceWarp.Template for a UI mod
also I moved the relevant repositories from my personal GH profile to an organization:
https://github.com/UitkForKsp2
mostly to be able to use uitkforksp2.github.io for the docs
That reminds me, I'm likely going to have to use KSP2Community.github.io/PatchManager for the patch manager docs
yeah, but I think that's fine for the KSP2 Community mods
we could even make a landing page with links to all the docs for the mods there
I moved the assets for UitkForKsp2 from a regular bundle to addressables, that way when a modder installs the Unity package into their project and builds regular bundles, they will no longer get a rogue copy of the kerbalui bundle
plus I also restructured the UitkForKsp2 project to be more similar to how I did LFO, eliminating the need for a separate 3rd repo just for the Unity project
I'm finally done with the UITK template for SpaceWarp.Template, and I think I did a pretty good job with it, but I'll release it tomorrow, since it's almost 6am and I'm dying

Is there a specific reason the struct is named "MoveOptions" and not "DragOptions"?
Maybe you could also add CenterByDefault to WindowOptions?
I don't know how many subdomains we can add to kerbal.wiki but a uitk.kerbal.wiki redirect to the docs would be pretty nice imo
I mean we own kerbal.wiki as a domain (or at least shadow does)
I dont see how subdomaining it more would be an issue
Yeah, I don't think that's limited in any way
Not particularly, it was actually named DraggingOptions at first, but MoveOptions just sounded better to me
Sure, that's not a bad idea
Though I'll also need to fix these positioning methods, since they only work if you change the geometry of the window after they're called (so for example when display is changed from none to flex)
I can't really think of a use case where you'd want a window to be showing up automatically on game start, instead of being hidden at first, but I'd still like the methods to be more consistent
(actually I can think of one, the SpaceWarp version checker automatically shows up on first launch of the game)
What I'm always doing is creating a window when the tray toggle is activated and destroying it when the window is closed. So in essence I always want to show the window when it's created, no? Or I misunderstood what you're saying.
Also, Micro Engineer has a system that saves window(s) state on each open/close and on each window move/drag, so that it can automatically open whenever Flight, Map or OAB scenes are loaded. So whatever user did last before he closed the game, that's what the window state will be when a new session is loaded.
To be pedantic about this (sorry 🙂 ), windows can be moved by dragging, but they can also be moved without dragging (some game event or any other user action that makes the window move its position).
What MoveOptions are setting are the dragging parameters - IsMovingEnabled actually determines if a window can be dragged by the user.
I'm not sure how exactly you handle the displaying/hiding of windows, but usually it's done with rootElement.style.display = DisplayStyle.None or DisplayStyle.Flex
While what I mean by creating the window is calling Window.Create
(You should add window.Hide and window.Show extension functions to UITKForKSP2 in that case)
Which most mods do somewhere like in OnInitialized, so as soon as the game is loaded
I don't hide the window. When it's closed, I destroy it GameObject.Destroy(document);
It makes sense in your use case where you're updating the window every frame
DisplayStyle.None/Flex I'm using only for foldouts and some other special cases, but never to hide the entire window
You don't want it to keep updating in the background
Exactly
But even then I feel like using something like gameObject.SetActive(true/false) and handling the starting/stopping of the UI updates in OnEnable/OnDisable might be slightly better, because that way the entire UI doesn't have to be recreated each time
Of course, that's just a minor suggestion
I suppose the performance overhead of recreating the UI is not big enough to be noticeable, though
And yeah, this makes sense, though I can't really change it now that it's released, but I'll take it into consideration for 3.0.0
I found it much easier to recreate the UI because ME's window geometry can change a lot. Windows can pop in and out frequently and I didn't want to handle each case. And recreation is done only with user action, never in an Update() or similar, so the overhead isn't noticeable.
But in any case, what I'm just trying to convey here is that I have a need for the window to show immediately when it's created. It's (probably) not a problem if you want to change that behavior if I can get that functionality with an additional command I'll run when creating a window.
Oh no I wasn't talking about changing that
If someone wants their window to he hidden when created, they can just use display: hidden as the default style for their root element, or change it from code right as the window is created
But what I meant is that currently when you call Window.Create(), and then call rootElement.CenterByDefault() or rootElement.SetDefaultPosition(), nothing actually happens, the window will be (usually) in the top left corner of the screen
And only when you first change the geometry of the window, it will get centered/positioned
Alright, got it, thanks
So for example if the window has display:hidden and you change it to display:flex, it will get positioned correctly, but if it start with display:flex, and you're not manipulating its geometry in any way, then it just stays in the corner
The repositioning is currently done in OnGeometryChanged because the UI may not be fully created in the same tick where you call Window.Create, and if it is created in time but your UI is hidden by default, it still won't work properly, because it can't calculate the center position of the window when the window visually doesn't exist
So I'll need to work around that to somehow trigger OnGeometryChanged when the window is fully created, but its geometry is not being manipulated
It probably won't help, but what I've done in Orbital Survey is that I create the window in a SceneController, then add a MainGuiController component. On OnEnable of that component I'm setting up the positioning. Micro Engineer has a different system, HUMANS also different, I'm changing things each time 🙂
actually now I'm looking into the code for the SpaceWarp version checking dialog, and it seems it works there without any workarounds
but for the UITK template I made yesterday, it doesn't work
interesting
var avcDialogUxml = AssetManager.GetAsset<VisualTreeAsset>( $"{SpaceWarpPlugin.ModGuid}/avcdialog/ui/avcdialog/avcdialog.uxml");
var avcDialog = Window.CreateFromUxml(avcDialogUxml, "Space Warp AVC Dialog", ui.transform, true);
var avcDialogController = avcDialog.gameObject.AddComponent<AvcDialogController>();
avcDialogController.Module = VersionChecking.Instance;
// AvcDialogController.Awake:
var document = GetComponent<UIDocument>();
document.EnableLocalization();
var container = document.rootVisualElement;
container[0].CenterByDefault();
vs.
var myFirstWindowUxml = AssetManager.GetAsset<VisualTreeAsset>($"{ModGuid}/SpaceWarpModUI_ui/ui/myfirstwindow/myfirstwindow.uxml");
var windowOptions = new WindowOptions
{
WindowId = "SpaceWarpModUI_MyFirstWindow",
Parent = null,
IsHidingEnabled = true,
MoveOptions = new MoveOptions
{
IsMovingEnabled = true,
CheckScreenBounds = true
}
};
var myFirstWindow = Window.Create(windowOptions, myFirstWindowUxml);
var rootElement = myFirstWindow.rootVisualElement;
rootElement.CenterByDefault();
I feel like if the first one centers the window correctly, the second one should as well, but that is not the case
theoretically it could be the document.EnableLocalization(); call in the first snippet that makes it work, actually
since the localization component updates the text of elements
and that probably fires the OnGeometryChanged event
In the first case you're calling CenterByDefault for the first element in the root and in the second case on the root itself?
actually it does that in Awake, which should go through before the CenterByDefault method is called
I'm not sure
that's... a good point lmao
I'll try that
I'm blind
yeah that was the issue
nice
since the root is the TemplateContainer that doesn't change in size at all
it needs to target the actual root VisualElement
which is its first child
thanks!
and yeah that is a good idea
and now, big sigh, forum thread for this
though I might just wait until I have the documentation ready
Just light a fire under your ass by making the forum post like me
lmao I guess it will be one way to motivate me
So I'm thinking about updating the template uss to make drop downs better match the default game, if you haven't already done that as part of the update
If you mean the dropdown tray that pops up when the control is clicked, a while ago I desperately tried to find a selector to hide the big ugly checkmark. My conclusion was that it could only be done from the theme, since that selector is not accessible from individual mod uss files.
So, go for it! It would be nice to have a style that is more appropriate. It would be even better if the theme could somehow expose those selectors so mods could override it with their settings.
To help you out, check this: #🔴mod-dev message
Yeah, I think I should be able to change the background color to something more like the stock controls at least. The default drop down text that's not part of the drop-down list is also the same color as the background, at least for me, so I wanna fix that too. Right now I've been using html like color codes the override the color, but it feels like a bit of a hack.
Creating a new custom dropdown control is next up on my to-do list for UitkForKsp2
But yeah, the default one could also use some extra styling, I've been kinda putting it off but I really need to add styles for all the controls that are new in 2022.3.5
Here's my attempt at making the controls a little more consistent with each other and the base game
Dropdown text color fixed too
Looks nice
looks great, thanks for doing this!
By the way, whats the reason for the seperate KerbalUI and UitkForKsp2 uss themes?
well, mostly just for the sake of organization
KerbalUI is the theme for the native controls, and the UitkForKsp2 USS contains styles for custom controls
Ah, okay. I was curious, since most of the settings were in KerbalUI, but I had to override a setting in UitkForKsp2 in order to get the labels to all line up
oh, that's weird, what was it?
.unity-popup-field .unity-text-element {
-unity-text-align: middle-left;
margin-right: 0;
}
I had to change that -unity-text-align from top-center to middle-left
oh yeah I suppose this was in that file because some controls were experimental in 2020.3.33 and Lux wrote a wrapper for them to be displayed in the UI builder
and so they were technically custom elements and their styles probably ended up in the UitkForKsp2 file
I'll need to do some general refactoring of the stylesheets and controls, it's a mess
and a lot of it is not needed anymore in the new Unity version
plus I wanted to start laying down a framework for the support of multiple different themes, at first simply as a per-window choice for the modders using them, as something like an overrideable USS variable or a class on the root element, and later possibly even as a user-configurable global setting
I've only tested it in the unity scene, so I don't feel comfortable pushing my changes just yet, but I've forked the repo and made a commit at https://github.com/coldrifting/UitkForKsp2.Controls/, if you're interested in seeing the changes
will do when I get the chance, thanks
Multiple themes sounds cool, btw
just wanted to clarify some of the choices I made, for example the text boxes are based on this:
omg why
though in hindsight, it would probably be better to do what you did and make the controls look more consistent with each other rather than trying to perfectly match the game
there are a lot of choices made in the game's UI design lol
wait thats in the games ui
yes
@trail stag please fix. I cannot unsee.
Eww
another fun one right in the same window is the save button
this is the active (currently clicking on it) state
lmao
thats not good.
Thats ... very slughtly off center isnt it or are my eyes playing tricks
not sure, but the disappearing text feels like the bigger problem here lmao
2px out
I knew it
lol
I think they should push 0.2.0.0 back a bit for this

We should file a bug report
heres the fixed save button
honestly, I think I might put together a whole forum post with feedback regarding all of the UI inconsistencies
it'll probably be more useful than whining here
Yeah I can somehow notice the 2px difference
and it's something that's been annoying me since 0.1.0
file
Move the x right a bit
since it signifies the place where text is written, and the x is beyond that point
added some line ends
Thr gap between the x and the line end should equal the gap between the x and the border
So either shrink one or grow the other
Thats my opinion tho
its the same
wait you mean 1 sec
and there are many more outside of it
yeah that looks good
this mostly seems like they kept old uis
(My last suggestion would be make the x bigger maybe
I wouldn't even say that, it's more like literally every single window they made is made from scratch, independently on all others
can't explain why every single one would have a different style for buttons, for dropdowns, for toggles, etc
like, just make a centralized library of UI controls that you reuse for god's sake

Looks nice, just needs a higher res x, which i wont have you do
UITK
Just fucking use UITK
Ooo
@ Dakota forget what I said about hiring us for modding, just hire me for UI smh
But they have access to UITK, and if they want to make it easier, then they should use it
plus we could use their themes and such if they did
maybe I should just go for one of the design roles.
including the supporting systems, not just the UI itself
to be fair that's more so about the actual UI/UX as a whole functionally, while what I'm more concerned about are the various styles
I don't know how to put it well
(plus it is closed)
To the forum then: https://forum.kerbalspaceprogram.com/topic/221025-ui-ux-feedback-megathread/
Hello friends! A couple weeks ago I asked you all what are the top 10 requests you have for KSP2 and your responses have been tremendously helpful. I've had multiple meetings with the team going over your requests and now I'm back with another question! Our UI / UX team is curious what specific c...
I can't remember, does the text box also turn green when you select it? That was the thing that bugged me the most
Eww lol
I'm putting together all the references of inconsistencies I can find, and will 1) make a post/thread about it on the forums, 2) use it to try to make a somewhat coherent style for UitkForKsp2
Great idea
I think my biggest beef with the UI is the non native Scaling of pixel graphics. Hence the mod I'm working on
yeah, it will be awesome to have that
here is what I came up with - basically just dumped it all into Figma, categorized and saved to PDF for easier panning around/zooming
the list is not comprehensive, and many of the styles are replicated among many different UIs
but I did attempt to get at least one of each style of the main types of controls
here's the source
~30 different button types

(and the PDF is already outdated lol, I forgot to check the Wing Shape window and of course it had a differently colored toggle)
well, now that I have this, next up will be taking a look at the KerbalUI theme, and UitkForKsp 3.0
I'll probably do a couple of pre-releases so that people have the time to update their mods, and I can help out with some pull requests during that time, since I'm the asshole who wants to break compatibility, not them 
but hopefully 3.x will stick around for a longer time
the current API is not very different from the days of like version 0.4
so it really needs some updates, it definitely hasn't aged and scaled well
it will probably take some time before I get that done, but then, finally the docs
I decided it's useless to write extensive documentation for the current version if I'm going to be changing a lot of stuff
Sounds great! Better to get radical changes out of the way while the modding community is relatively small anyways IMO
BTW what resolution did you take those screenshots at? Because if it's not 1080p there's probably gonna be some artifacts. I think I noticed some on one of the PAM toggles.
Can you create a new "KerbalUI2" theme and leave "KerbalUI" as is? I'm not keen on updating all my mods tbh
that won't be that easy to do, since to have more concurrent themes, I'd have to create multiple PanelSettings, and an API to control which UI Documents are created in which
what I can do is make the old styles available with some class on the root element, like <VisualElement class="root theme-legacy">...</VisualElement>
is that good enough?
yep, it was 1080p
Uhhh theres got to be a better way than multiple panel settings
well, yeah, the alternative I suggested
Yeah but in general
themes are inherently linked to PanelSettings
so you can either swap out the theme globally, or make different styles accessible through different classes
or, make more panels
those are the only options I can think of
Hmm, could you not basically make the theme nothing, and dynamically apply the USS to a document when its created
Or is there some stuff that has to be in a theme
not really, no, there is no real need for a theme, though I feel like it's nice to have a sensible default
but applying USS dynamically sounds a bit like overkill, when you can just add a class to the root element
It doesnt sound like overkill to me tbh but I getcha I suppose
the issue with the dynamic approach is I'm not sure how easy it would be to do, you might have to recursively traverse the document tree and apply the styles to all elements in it
I suppose I can look into it, but I don't think it will be as simple as changing a property on the root element
Is there not a stylesheet property on the VisualDocument?
ah yeah you're right, element.styleSheets.Swap(...) might do the trick
good to know, adding support for the user settings of themes should be much easier with that
Also, this may have been the cause of the reflektor offsetting issue
I'll take a look at it in UE
nope that's not it, the two objects with UIDocuments are next to each other, and parentUI is null on both
If you'll stick with your original idea, what would I need to do exactly? Just add a theme-legacy class to the root and that's it?
yeah
the other option is what Cheese suggested, adding some sort of an API to change styles when creating the window in C#
like adding an enum with the existing themes and then adding a parameter to WindowOptions for that
That'd be sweet
I'll probably do that, then
@dense bison finally took the time to look at your changes, and the dropdowns look great!
however, this is why I couldn't just style Toggle without adding a class to it, because it is automatically created inside some other controls like the foldout
resulting in this
Thanks! Ah that's too bad. I was hoping to avoid custom controls
Fixed the foldout. Are you aware of any other classes that have the toggle?
not aware of anything else
though it might be used for the TreeView/MultiColumnTreeView
if I had to guess
it's hard to test since you have to generate the content of these dynamically
Hmm, I was messing with treeview a lot before I switched refektor to use a list and I didn't see one anywhere. I think it's only there if you add it
I was guessing because of this page in the docs
Right, you have to use code to make that though, it doesn't come like that
yeah, that's what I meant by saying it has to be generated dynamically
In any case, here's the uss for the foldout fix
.unity-foldout > .unity-foldout__toggle > .unity-base-field__input {
min-width: 100%;
max-width: 100%;
}
.unity-foldout > .unity-foldout__toggle > .unity-base-field__input > .unity-toggle__checkmark,
.unity-foldout:hover > .unity-foldout__toggle > .unity-base-field__input > .unity-toggle__checkmark,
.unity-foldout:active > .unity-foldout__toggle > .unity-base-field__input > .unity-toggle__checkmark,
.unity-foldout:inactive > .unity-foldout__toggle > .unity-base-field__input > .unity-toggle__checkmark {
-unity-background-image-tint-color: #d5dfff;
border-width: 0px;
background-color: transparent;
background-image: resource(arrow-right);
max-width: 24px;
height: 24px;
}
.unity-foldout:checked > .unity-foldout__toggle > .unity-base-field__input > .unity-toggle__checkmark {
background-image: resource(arrow-down);
top: 1px;
right: 1px;
}
ahh, the arrows are in resources, of course
Yeah, took me a bit to figure that one out
to be fair it wouldn't work in KSP pre-0.1.5 since it didn't have UITK built-in, so I'm giving myself a free pass
lmao
but it's nice that we have it now, thanks
another thing is I'm not sure whether to make the one we have now the default for the toggle, or the more traditional checkbox one
(they look similar to the radio buttons but they are in fact checkboxes)
Ah. I think those look a lot like radio buttons, so they probably shouldn't be toggles. I don't think it should be just a checkbox either though. I do like the current one, though I'm not sure if I like how it's offset to one side
I wouldn't mind the PAW toggle either though
That's probably harder to write USS for though
hm?
I think it's offset to the side in the Mods window on the main menu
Not sure if it is everywhere. I did change it to be centered in the USS i wrote
then it's most likely due to scaling
Oof. KSP2 scaling strikes again lol
yeah, the scaling of elements with 1px wide stuff like borders and text is just bad
yeaah
that's the issue with trying to display 1.3333px wide borders and paddings
lmao
makes sense
Oh yeah, you're right
only looks good in 4K
Let me see if maybe I can fix that
Yeah, 4K is double pixel scale, so it should be fine
yeah
By the way, if you change .unity-text-field to .unity-base-text-field you'll also style the float, int, long, and double input fields with the same selector
yep, already did that
Sweet
Actually could you please send me the full foldout USS? I still seem to be having some issues
first the background was green for one of the visual elements so I fixed that, but still having padding/margin issues and don't feel like investigating right now when you have it correctly
😆
ah, then I see we had a similar idea lol
you have top: -4px; and I "fixed" it with margin-top: -5px;
Ah, yeah I was trying to make the arrow appear to pivot around the center
how I wish we had something like SCSS for Unity

.unity-foldout {
background-color: #2e3540;
border-radius: 6px;
border-width: 2px;
border-color: #354051;
color: #c0c7d5;
> .unity-foldout__toggle {
color: #d6e0ff;
margin: 2px;
border-radius: 6px;
padding: 0;
&:hover {
background-color: #3f4487;
}
&:checked,
&:active {
background-color: #4b50b0;
}
.unity-text-element {
padding: 0;
margin: 2px;
color: #ffffff;
}
// ...
}
}
something like this would be so much easier to read (and write)
Yeah css can get ugly real fast
and meanwhile I'm planning to duplicate every single selector to support themes

e.g.
.theme-default .unity-foldout > .unity-foldout__toggle,
.root .unity-foldout.theme-default > .unity-foldout__toggle {
/* ... */
}
so that there's both a default style for the theme, and a way for windows with other themes to use the controls from other themes
Crazy idea, but maybe we could generate uss from a template?
hmmm
hmmmmmmm
I'm willing to give this a try
Interesting, nice that there's a package for it
yeah, I like the idea a lot
I'll head to bed now but I'll definitely take a look at it tomorrow
💤
thanks for all the help by the way!
NP. It's something I'm interested in, so I def want to help if I can.
woah I just discovered this completely randomly lol
Oh cool!
might have to add some sort of an indicator to make it obvious
Oh, forgot that SCSS has variables. Nice.
yeah, though I've been using the native CSS/USS ones with no issues
Ah, I forgot that default css has that, ha
for example
I definitely want to use them more often, for stuff like common colors, etc.
the stylesheet is a hot mess right now
Yeah, it's really easy to just add one thing, and then one more thing, etc, and suddenly your central rules aren't as central as you'd like
indeed
another reason why I'm glad I'm doing what's probably going to be almost a full rewrite of both the styles and the code
hindsight is 20/20
Hey, refactoring is FUN
honestly, it's some of the most fun I have when coding
seeing your old stuff and knowing exactly how you want to improve it is great
I get so much satisfaction from completing a refactoring and cleaning up the code. It's like cleaning for me
Yeah, this package is great. Looks like you can still edit and have it refresh in real time
Damn, I can hear people outside my apartment leaving for work
That's how I know it's really time for bed lmao
Oof, you're in europe right? I'm on night shift, so my schedule is already all f'd up
Haha yeah, almost 6am
Just woke up a few hours ago
Damn thats cool
Yeah, I'll try it out in a bit
If it works well, I might start using it for all my UITK projects
USS selectors get stupidly long and ugly really fast
Imagine patch manager without the nested selectors
Oh god
I dont think it would actually work as you need the variables from outer selectors
So it's still a bit incomplete, but I've been working on converting the KerbalUI theme to SCSS
Feel free to steal anything from here if you want
Thats much nicer lol
having variables like that is like please
By the way from my testing it seems that the SCSS addon doesn't like // comments inside block comments
Just always use /* comments */ tbh
Nice
ahhh this is annoying
I wish USS had @font-face
so that I could define new fonts and then reference them with their name
being unable to do that really sucks when using imports
since I define variables for font assets like $font-regular: url('../../Theme/Fonts/JetBrainsMono/JetBrainsMono-Regular SDF.asset'); in one file, but the variable is only evaluated in the file inside which I import the definitions
so for example having a folder structure like
- Theme
- Fonts
- Styles
- _common.scss ($font-regular definition here)
- some-folder
- styles-1.scss
- subfolder
- styles-2.scss
I can only use the above definition of $font-regular in styles-1.scss, but not in styles-2.scss, because the path is invalid
I guess I can do absolute paths but jeez
You can do the paths based off of Assets/
at least
as the CWD is always the folder above assets
well this is a package
I mean packages have absolute paths too
Packages/uitkforksp2.unity/Assets/Theme/Fonts/JetBrainsMono/JetBrainsMono-Regular SDF.asset should work
but it's ugly
lmao
Yeah, abs paths are kinda gross.
I've been working on the SCSS some more, got progress bars, radio buttons, and cleaned up the scroll bars a bit
plus Rider doesn't like these
but they do work
I prefer to keep them separated
for now I'm pretty happy with this folder structure
I might even further split controls and containers from native-controls
Fair, looks good.
I think if a theme had only a single file it would be fine, but otherwise i would def want sep folders
Wow just seeing how nice that organization looks using scss, we should've been using it earlier
I mean theoretically all this is doable with just USS
I haven't actually started converting into SCSS yet
(though I definitely will make use of this, thanks)
Are you using both the executable and importer package?
yeah
so that anyone who wants to build the project doesn't have to have Sass installed
makes sense
[Error : Unity Log] NullReferenceException while executing 'performed' callbacks of 'MapView/Focus[/Mouse/leftButton,/VirtualMouse/leftButton]'
[Error : Unity Log] NullReferenceException: Object reference not set to an instance of an object
Stack trace:
KSP.Map.Map3DManeuvers.TryGetParentItemUnderCursor[T] (T& item) (at <483cd9805b7642b5be13e081b9a5d1b4>:0)
KSP.Map.MapCore.OnFocus () (at <483cd9805b7642b5be13e081b9a5d1b4>:0)
KSP.Input.InputActionBinder.Invoke () (at <483cd9805b7642b5be13e081b9a5d1b4>:0)
KSP.Input.InputDefinition.TriggerAction (System.String id) (at <483cd9805b7642b5be13e081b9a5d1b4>:0)
KSP.Input.MapViewInputDefinition.OnFocus (UnityEngine.InputSystem.InputAction+CallbackContext context) (at <483cd9805b7642b5be13e081b9a5d1b4>:0)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at <5b4eda9332d34a6f90f7ed9a858088a9>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
[Error : Unity Log] NullReferenceException while executing 'performed' callbacks of 'MapView/Focus[/Mouse/leftButton,/VirtualMouse/leftButton]'
this is quite annoying though
it's caused by using the input locks
it seems to cause some glitches in interactions with the game's UI, too
haven't noticed anything game-breaking, but it's annoying
but it's weird because the game uses these input locks just like we do
here's the latest reference file by the way
it should have references for all the basic types of controls for all three themes
I don't intend to follow everything exactly as it is in the game (because damn, are some of the choices the game UI makes interesting)
but I feel like the general styles of the controls fit relatively well with each other for each theme
By the way, while you're working on the stylesheets, can you change the default hover color of lists?
oh yeah, for sure
just for context, the reason why we didn't use ListViews (and so we had no reason to style them) is because in 2020.3.33, their items could only have fixed height, and generally there were quite a few issues with it, with even the Unity devs recommending it just for very large uniform lists of 1000s of items
but it looks like it's much more usable now
Gotcha. Yeah, I gave up on them on the inspector, but I do like having the highlight for the game object children list
You can fake it with events, but it's not always consistent
it should be possible to just add styles with :hover to almost everything, that's what we do in the SpaceWarp modlist I'm pretty sure
actually let me check before talking lol
I've been avoiding having to bundle USS stylesheets, since it's easier for me to do stuff in raw C#, and to my knowledge you can't style psuedo states in C#
ah, yeah, gotcha
(well, you can add pseudostate styles in C#, but it will be a pain in the ass)
Really?
I'm pretty sure I saw something like that when inspecting some element styles with UE, let me check
uhh yeah it's definitely not worth it, you'd probably have to mess with the styleSheets property and manually create the structure that would be normally created when compiling USS into a bundle
Ha, thanks for checking. Pain in the ass indeed
Just create our own runtime scss parser
I mean
there is one already
(it is $70 though)
or $35 now on sale lol
and since Unity uses a fork of ExCSS (https://github.com/TylerBrinks/ExCSS), it should be possible to use that for parsing and then just reverse engineer the structure they use for their stylesheet objects
I'm already on like side project #4 right now ha
from the example it looks very similar to the USS stylesheet objects
so yeah, theoretically we could in the future add runtime USS parsing, so that USS files don't have to be bundled
but it's very low priority
I just wish I could use the unity UI Toolkit debugger in the game
Aight bet
Project #4 incoming
I havent even gotten outta bed
I think im going to use loading actions, and allow for fonts/images to be loaded using space warps asset manager
oh wait, they have the fork on GitHub https://github.com/Unity-Technologies/ExCSS
Well that makes it dead easy dont it
though it's probably not the version they're using now
since the last commit was 3 years ago
but it's a start
Ill probably go from the original version to handle my own font parsing and such
I really want a scss parser tho
oh lawd
I feel like users would like that better
I suppose extending the ExCSS parser with just minor stuff like nesting would be relatively easy
though I mean, at this point you might be better off to start from the SassyPatching project in Patch Manager
since that almost fully implements SCSS lol
Not well
It doesnt allow you to do
:parts {
> {
}
}
You have to have * on both sides of that >
Not sure if this is really a bug, but It looks like if one character is selected and you type that same character in, it won't remove the selection until you type anther character, which gives the impression that the text field isn't updating.
This is on 2.4.0 btw
interesting, that must be a UI Toolkit bug then
@stuck jasper I don't suppose you figured out that weird offset bug when unhiding another window, did you? Still running into it...
no clue about it, sorry
I tried looking into it and saw the symptoms but I have no idea what causes it
but there has to be something specific to your approach, because I haven't seen the issue in any other mod
Dang. Thanks for looking into it.
Figured it out!
Set the position of the root visual element to absolute
Maybe that should be done if the window has a drag manipulator by default?
ahh I'm stupid, I literally thought about that being a possible fix earlier
and then completely forgot
Don't know why I didn't realize sooner, ha

though it still is strange
you're creating new UIDocuments, right?
and they're basically not related in any way
so this shouldn't be happening as far as I'm concerned
As far as I can tell, they have seperate root gameobjects, which each don't have a parent
sep window ids
yeah, Cheese suggested checking the documents' parent IDs, and they were null
so they shouldn't be affecting each other's transforms
it's strange
GameObject rootGameObject = new GameObject("_Inspector");
DontDestroyOnLoad(rootGameObject);
GameObject rootGameObjectBrowser = new GameObject("_Inspector_Browser");
DontDestroyOnLoad(rootGameObjectBrowser);
WindowOptions winOptions = new WindowOptions
{
WindowId = rootGameObject.name,
Parent = rootGameObject.transform,
IsHidingEnabled = true,
DisableGameInputForTextFields = true,
MoveOptions = new MoveOptions()
{
CheckScreenBounds = false,
IsMovingEnabled = true
}
};
WindowOptions winOptionsBrowser = winOptions;
winOptionsBrowser.WindowId += "_Browser";
winOptionsBrowser.Parent = rootGameObjectBrowser.transform;
_inspectorWindow = new Inspector();
_browserWindow = new Browser(_inspectorWindow);
var v1 = Window.Create(winOptions, _inspectorWindow);
var v2 = Window.Create(winOptionsBrowser, _browserWindow);
v1.rootVisualElement.style.position = Position.Absolute;
v2.rootVisualElement.style.position = Position.Absolute;
you're basically doing the same thing that SpaceWarp does when creating its windows
and I don't think we've had to use absolute positions anywhere
oh but wait a minute, the one difference is that most other mods create the visual tree from an asset, which places it inside a TemplateContainer
could it be that the TemplateContainer is by default positioned absolutely?
Checking that right now
yep there it is
the TemplateContainer is by default absolutely positioned
so UIs loaded from UXML don't have the issue
Interesting
but also, I'm updating the API so that UIs loaded from UXML don't have the TemplateContainer as the root, instead having its first child as the root
so that it's consistent across all the ways that you can create a window
I'll add an option which wraps the UI in another root element and makes it absolute, though
so that current UIs don't have to be rebundled, only needing a change on the C# side
though I'm not sure how necessary/useful that will be when a lot of other things will be incompatible anyway
soooo, time to redo the UI reference
lmao
they fixed a lot of the issues I had with the UI
@stuck jasper
yeah I've seen this
Actually the semi-transparent background might be really cool for the small theme
also that's two new styles for switches/radios in this update

this and the cheat menu

All the styling in my code is getting a bit too much, so I'm thinking about bundling USS. How can I do that?
I would recommend using the UI template from SpaceWarp.Template to get started, it will generate a full C# solution which you don't need since you already have one, but it will also generate the Unity project for you
and you can use that to get started
it will be in src/ProjectName.Unity/ProjectName.Unity
Ah, found it on github. thanks
https://github.com/Micrologist/MicroEngineer/issues/41
@stuck jasper, I've noticed this as well. Could it be because I'm recreating windows on state changes?
I'll look into it
it really shouldn't be caused by destroying and creating the windows
as far as I can tell, that should actually make it more reliable than for example just calling SetActive(false/true)
I went through my code again, went through your code, and so far I have no clue
ah I think I found the issue
it's most likely a bug in the stock game, rather than in UITK or ME
[Error : Unity Log] NullReferenceException
Stack trace:
UnityEngine.Component.GetComponent[T] () (at <241ca07620644274b99c2f9d1288d0ab>:0)
KSP.Map.Map3DFocusItem.ToggleIconVisibility () (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.InputActionBinder.Invoke () (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.InputDefinition.TriggerAction (System.String id) (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.GlobalInputDefinition.OnToggleUIVisibility (UnityEngine.InputSystem.InputAction+CallbackContext context) (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at <eec8b0f7e605454fa749d62d287ae90f>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
[Error : Unity Log] NullReferenceException while executing 'performed' callbacks of 'Global/ToggleUIVisibility[/Keyboard/f2]'
[Error : Unity Log] NullReferenceException
Stack trace:
UnityEngine.Component.GetComponent[T] () (at <241ca07620644274b99c2f9d1288d0ab>:0)
KSP.Map.Map3DFocusItem.ToggleIconVisibility () (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.InputActionBinder.Invoke () (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.InputDefinition.TriggerAction (System.String id) (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
KSP.Input.GlobalInputDefinition.OnToggleUIVisibility (UnityEngine.InputSystem.InputAction+CallbackContext context) (at <dd6137ea2e634c0ba20d8eb5ac23d499>:0)
UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at <eec8b0f7e605454fa749d62d287ae90f>:0)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
[Error : Unity Log] NullReferenceException while executing 'performed' callbacks of 'Global/ToggleUIVisibility[/Keyboard/f2]'
thats the F2 bug that causes the orbit line issue
this exception happens when pressing F2 in the Map View, and it prevents UITK from hiding its windows
ah good to know
well rather that bug is a side effect of a deeper bug that causes it
@compact sandal so not much to do about it other than actually fixing the game's bug
which I think Cheese was able to do with a preload patcher?
It's strange that it happens only for Micro Engineer. I'm testing with both Micro Engineer and Orbital Survey windows open and it consistently happens only for ME, never for Orbital Survey. And I used almost an identical approach with Orbital Survey. I think there may be something different with ME that's causing this. I'm recreating the UI at each state change, so Flight -> Map -> Flight causes 2 refreshes. That might be messing things up. Might try to ignore state changes for Flight <-> Map to see if that fixes it.
(the reason it's like this is that earlier I had the idea of having different parameters for windows in Flight and Map states, you could have different windows shown, different positions, etc. But I abandoned the idea a while ago)
Is there a public tracker like GH Projects for UITK for KSP2? I'd like to contribute adding some more base Widgets if contributions are welcome; I think a standard Window could be helpful for example
Plus I'd really like to find a way to block scrolling (mouse wheel event) to influence Gameplay while scrolling inside a window ;_;
I don't really have anything like that, but I definitely welcome contributions
though, currently UITK is in the process of basically a complete rewrite of both the library and the themes, for the 3.0 update
Oh! Awesome ❤️
the current API has had just pretty small (and almost always just additive) updates since like version 0.3.0, which was very experimental
and since then I've mostly just been slapping on more and more code on top of that, to keep backwards compatibility, and the result after many months isn't very nice
and now after the library has actually been picked up by multiple modders, I feel like I have a pretty good idea of how to structure it better and make it more user friendly
all that said, I think right now I'd prefer to wait with contributions until after that big update
Seems like great news; I'll be happy to contribute when 3.0 is live so
awesome, thanks!
@mystic marsh About your previous message: when this will be fixed in UITK (this lib), it will be automatically fixed in every mod since the UI core is centralized thanks to @stuck jasper
About Japanese and Korean, sure; there are some Pan-CJK fonts, but I'm not an expert here
That's a really good news!
@stuck jasper https://fonts.google.com/noto/specimen/Noto+Sans+TC is Pan-CJK so could be a good candidate as a starter fallback font
take a look at this https://fonts.google.com/noto/use#faq , and in-page search for "Which Noto monospace fonts should I use?" there are multiple fonts for different languages
Seems perfect, https://fonts.google.com/noto/specimen/Noto+Sans+Mono
awesome
so basically, ideally all these
and that should hopefully cover most of our needs for CJK
for now I would just leave out the pixelated version, and just use these as the fallbacks for all fonts
Yes, I'd prefer that too
Note that for Traditional Chinese, there are two variants, HK and TC, not sure if conflicts exist
yeah, I've also noticed, but I have absolutely no clue what the differences are, to be honest
or if they can coexist
the README file seems to suggest that TC is the default Traditional Chinese variant
so I suppose we can use that one
From my search, they can not coexist and the "TC" used in Taiwan is more commonly used.
the forum editor works just fine guys
I tried to make that post three different times before clicking the Post button did anything, and when it did, it wrote out all three of them 
I am running the Chinese version of the game, so I can help you test once the update is implemented. It's even better if the forum user "lw0wl" can contribute his translation.
alright, it works fine in Unity
so I'll build a new zip of the mod and send it for testing before I release it
and just for a quick test, also added Cyrillic and Greek
those should be supported by JetBrains Mono, but I just wanted to make sure
oh but I'll probably need to add JB Mono as fallback for the two pixel fonts
great!
unrelated thought: Chinese characters can be too complicated to be pixelized, sometimes it's unreadable when the size is small.
yeah, I was kinda thinking that it might get unreadable at smaller sizes, that's why I went with just the Noto font as a fallback for all of them, instead of finding a pixel font
ahhh I'm running into an annoying issue where I have the same fallbacks set up for all fonts, but the Cyrillic and Greek characters don't work only in one case
and I have no clue why
the fallbacks display correctly in both the middle font and the bottom font, but in the selected label at the top, they don't show up
but all the fonts are set up the same way

Is it a weird switch in the doorstop config :p
what is happening 
no idea at all. Are labels any different?
nope
well
my only conclusion is that the font basically claims to have those characters, but it doesn't
since it just refuses to fall back on other fonts for them, but it does so for the Asian languages
I think I'll just try to replace it with a different font
I've had a better one (imo) for ages, in my perpetually unfinished AppBar library
so I'll just use that one instead
I feel like it more closely matches the game, anyway
seems nice!
I'll leave the old font in the mod for now, to not break mods that already use it, but I'll remove it in 3.0
Those scripts have a large amount of glyphs
yeah
just a thought, could fonts be developed into optional sub-mods in the future?
theoretically, yes
though I would have to do some runtime magic to get them to work well with the main UITK library
but it's definitely possible
at least for fallback fonts
I dont see how well this would work
Would users be expected to go and find mods because they dont have translations?
not sure how I would handle using them as the main fonts
Someone downloads science arkive for example, but doesnt have the chinese font module
How are they expected to know there is a chinese font module?
Is UITK for KSP2 supposed to detect missing glyphs and give a message to the user?
if this was done, I would be for making it so that all the languages supported by the stock game would have fonts in the main library, and then fonts for languages that are modded in (let's say something like Arabic) could be in the standalone mods, along with the game translations
We could warn them in UITK/SW, something like if (Language.Current == "Japanes" ... )
This is the main issue, since CJK are all supported in the base game
yeah, I definitely wouldn't want to take those fonts out
Arabic has many less glyphs than any of those 3 languages
but it could work for extra languages
Almost any font would be drastically smaller actually
yeah I don't really mean this as a size saving thing
more like, if someone wants to translate the game into a new language not supported by the fonts, they could add their own fonts as fallbacks
wouldn't be possible, as a fallback, to set in the TextPanelSettings the same fonts used by the game itself?
The game uses tmpro
The fonts wont have all the glyphs im pretty sure
Thats my understanding at least
yeah, the issue is that the stock game and UITK use two different systems for text
so we can't use the game font assets
that's why I haven't already done that
Ah, well, crystal clear now
Yes haha now that I think about it, it's obvious
If we could use the game fonts, we'd have made them the main fonts im pretty sure
yeaah
But the games fonts are paid and we cant really redistribute them
And we cant get them from in game
I did look into converting a TMPro font asset into a TextCore asset in C# and it looked like it would be a nightmare
it is probably possible
but a nightmare
It is my understanding that TMPro only generates glyphs for characters that are used
it's the same for TextCore
Is it really a problem to bundle the 50mb? UITK is a core library in the end
oh definitely not
I'm more annoyed about spacewarp becoming 38 mb, cuz we have to put a small exe in there
a c++ or rust exe wouldve been smaller, and have run under proton tbh
I'm using dynamic atlases, which means that only the few characters that are in my test document are actually in the assets, and the rest of glyphs are generated at runtime from the bundled ttf/otf files
but it would be a pain in the ass to have two different projects in two different dev environments
Ehh, rust wouldnt really have been
C++ with clang too, I think
I'd have to install either of these first 
Setting up MSBuild for that though 
so I declare it a pain
oh god he's here
i felt it in the force
👀

whyyyyyyyyyyy doesn't this work
Chinese font refusing to work?
yes
it's in the addressables, it's set as the fallback, and still nothing
this was supposed to be such an easy fix
and it's just one issue after the other

oh my god
mhh maybe something wrong in the mods, like TextPanelSettings not updating
?
I can debug ScienceArkive to find the TextPanelSettings and see if the fonts is there
would you mind sending me the UITK plugin?
it's not set in the text panel settings, those seem to require that the fonts be in Resources, which we can't add to the game
(If you'd like some help obviously)
each font asset has its own fallback settings instead
that way I can also differentiate between fallbacks for regular and bold fonts
yeah...

oh what the hell
the fallbacks somehow disappeared from most of the font assets??
inside the editor
Unity wtf are you doing
Classical Unity

ok what
now half of it works
is a different font used for those or something? @silk zealot
I'll double check, is it possible setting the font in the Visual Editor breaks this link with UITK?
it shouldn't
huh
I wonder if using the USS variables instead of a direct reference would fix it
but that would be weird
let me double check
I don't think it's possible because the addressable bundle is ~160kb
here's the latest build by the way
not sure what that means
probably not a different one
what I meant was more so whether directly setting the font asset reference instead of using one of the font variables could cause it
like -unity-font-definition: url('Packages/uitkforksp2.controls/Assets/Fonts/JetBrainsMono/JetBrainsMono-Bold SDF.asset') instead of -unity-font-definition: var(--font-bold)
for example
in the uxml it is -unity-font-definition: url('project://database/Packages/uitkforksp2.controls/Assets/Theme/Fonts/JetBrainsMono/JetBrainsMono-Regular%20SDF.asset?fileID=11400000&guid=f5454c9c675002c44a5a7234bd40c390&type=2#JetBrainsMono-Regular SDF');
I'll try to swap it
my guess is it would require setting the style from inside a USS file
still, this is one weird issue
that shouldn't be an issue, all of them have the fallbacks
Well, the experiment title works (it's a foldout, USS untouched)
The buttons work too
Instead the places where I set the fonts got some issues
Ah god
trying to use only USS
(Well, playing in japanese is so futuristic anyway)
Akira vibes
lol
so the issue was what I thought
by directly referencing the font asset, it actually gets copied into your bundle
gosh
it still takes the actual glyphs from the font that's inside UITK for KSP2
but it has its own asset settings
including the fallbacks
switching to the variables fixed it
another way to fix it would most likely be just updating the UITK package in Unity
after I release it
I didn't get this part, so do you mean that just removing it from inlineStyles?
because then you'll have the fallbacks defined
even in your copies
the culprit here is that I switched from asset bundles to addressables
if I were still using asset bundles, your Unity project would build both the UITK bundle, and your mod's bundle
and your bundle would only reference the assets in the UITK bundle, instead of copying them
I got rid of it exactly for the reason that I didn't like the fact that everyone's projects also automatically build the UITK bundles for no reason
But using addressables, by definition, shouldn't Unity omit these font since they are in another addressable bundle?
but it turns out it wasn't for completely no reason
well, I'm pretty sure it would, if you were also using addressables
but I don't think the two systems interact well between each other
I suppose what I could do is switch the UI template to also use addressables instead of regular bundles
at least I think that would fix the issue
but it does make the situation a bit more complex
especially for someone who comes to it with no Unity knowledge
if there is, I'm not aware of it
I think they just expect you to use one system or the other, but not a combination of both
and just to get back to this, what I did was unset the inline font asset:
and then added styles like this for all the elements with the custom font
(well I only did it for the one, but you know what I mean)
that's the best temporary fix
here you can see the variables for the various fonts
that's on me, I absolutely need to write the documentation after the rewrite
I think we should add it on the wiki
Haha sure, I could've just asked, you guys are super present
alright, so I think I can push out this UITK update then
Hahaha
Can I use the UITK variable freely or do we need an import or something like that?
Mh it seems like it is not showing in the builder
.font-pixel-label {
-unity-font-definition: url(--font-title-big);
}
how about if you add the document to a scene and run it?
oh I see the error
it's var(...) instead of url(...)
😆
Discoverables which aren't reached by the player
like Mun Monument
There is a setting to select if you want to see All of them, Only the discovered ones or to show them "Censored"
Spoiler free mode 😄
WOW! Good job guys! Thank you for the effort!
Also, someone should tell the person on the forums who is trying to add chinese to spacewarp
Yeah I will
Should UIDocument.EnableLocalization(); work on dynamic UI elements, e.g. when you instantiate dynamically an UXML and add it to parent window?
cause I'm getting this
you can call Localize on the DocumentLocalization component when you want to refresh it
but I'm not calling it anytime any UI is updated, no
Ah gotcha, thanks
ahh actually not even that will work
because it only updates the elements that are cached in the component
otherwise it would be really expensive to do a full recursive search for all elements that might need localization
Better to do it by hand so
you can either call RegisterElement to add a single element, or RegisterDocument to re-cache the whole document
but I feel like in your case, it should be enough to just call EnableLocalization after you set up everything in the window
then it should work fine
Seems working fine, thanks!
are there stiill plans to use scss?
yep, I already have that implemented in the dev (3.0) branch
and anyone else can use it right now by just installing the two Unity packages
since that's completely independent on UITK for KSP2
Ah you do have it in the dev branch
@stuck jasper in the end I got a way to make tooltips in a dedicated Window, so I think this could be a nice addition to UITK, since this way there could be only one centralized tooltip manager; plus, consistent U! I designed the tooltip to be very similar to in game ones
It's very generic so it could be enough to expose a VisualElement.AddGameTooltip extension method
https://github.com/Kerbalight/WayfarersWings/blob/main/src/WayfarersWings/UI/Components/TooltipManipulator.cs
https://github.com/Kerbalight/WayfarersWings/blob/main/src/WayfarersWings/UI/TooltipWindowController.cs
nice, thanks!
I'll definitely look at it for inspiration when I get to the UITK update
looks pretty similar to this recommended solution
I red exactly that post to implement it 😄
Plus having a central one makes for better animations
though I might try to adapt this one: https://github.com/plyoung/UIElements
I would like to integrate all of these into UITK ideally
and the tooltip here seems to additionally have support for boundary checking, so that it doesn't display off-screen, which I like
It's cool, I've seen it, but tooltips are not supported at runtime
atleast it's what written there
that is a custom implementation
I didn't dig down
"UIElements does not have tooltip support at runtime. Here's some code to show how you can get it working."
they mean, "natively they're not supported, so I made my own version"
Ahhhn
UIElements was the old name before they renamed it to UI Toolkit
indeed 😆
yep, pretty sure I can just take the best from this and from your implementation and we'll have basically perfect tooltips
For sure, but I don't care about the solutions used, just to contribute you know
Hi @munix, I’m fighting with DropdownFields right now, and I’ve discovered the popup drop-down content is shown in another rootElement, owned by Unity, so only “inherited” style sheets in the PanelSettings are applied (for example, KerbalUI is applied), but I cannot override them.
The solution would be to add my style sheet to inherited styles, but the PanelSettings is from the UITK addressable, Do you have any hint on how I could do something like that? Like, editing or cloning the PanelSettings, or duplicate it without loading all the assets
Thanks!
oh boy, here we go again

yeah, we already had this issue a few times before, and yeah, the only way to change this would be to change the main theme that's common for all mods
unless you create a custom panel
which is usually discouraged because more panels = worse performance
this is one of the main reasons why I need to make a custom dropdown element
gotcha! I thought something like that
Even if I think probably a base style for dropdowns would be adeguate
plus a wide-dropdown option or something like that to have the dropdown content expand (my problem)
is it possible to define custom controls through UXML or is it necessary to do all of them in code?
well, you can just write the UXML and then control them in your plugin
custom controls basically just encapsule the two
Have a dropdown element that can have a list of child elements rather than just text
so that they can be easily reused
I'm just lost at where to write the UXML, which file, and how to use it in other uxml templates
Btw munix, should I hold off on writing a markdown renderer until uitk for ksp2 3.0
oh well if you want to use it in multiple places, then you probably do need to make a custom control
otherwise you'd just write the UXML directly inside the UXML window where you want the dropdown
Yep, that's the reason I though about the custom controls; my doubt is that, e.g., in this unity tutorial (https://docs.unity3d.com/Manual/UIE-slide-toggle.html) they define two visual elements:
VisualElement m_Input;
VisualElement m_Knob;
However they don't ever initialize them, nor create them. How would you do that is a myster to me..
m_Input = this.Q(className: BaseField<bool>.inputUssClassName);
doesn't Q find the element?
Yes
But the custom control is created from the equivalent of a prefav
Prefab
Its instantiated from the uxml, which has the children
I'm a bit lost on where this "prefab" is placed
You have a uxml document that defines it basically, I think
basically, you put the UXML into your asset bundle, and then in the code, you load it from it
like a regular window UXML
Ok and then I'm able to put this custom control directly into my other UXMLs?
you should be able to, with the way the UI template is structured
the same C# gets compiled by both Unity for the editor, and by the main C# solution
SpaceWarp has a custom element, but it is not using the template, so the files are duplicated I'm pretty sure
oh wait actually I think it is using the UI template now
I think I did that conversion already
ok no I didn't
well, partially
but not that part

haha
I've found this
lmao
well, you can do it either way
yeah
but only in play mode, I would assume
not in the UI builder
though honestly I'm not sure
I have nearly 0 experience with custom controls
I'd like to try
actually I think it worked in the UI builder
(I hope so, since trying to run a UI project where I imported thunderkit for the addressables just crashes my unity editor)
but
to be sure
is it needed to import ThunderKit if not doing Parts (but still using addressables)
in that case it would be easy to have two projects, like XYZ.Unity and XYZ.UI or something like that
it isn't
if you don't need to use KSP2 Unity Tools
since those depend on KSP2 being imported
but I love it to build the bundles
but for just building addressables, it's not necessary
You can use custom controls inside the UI builder (if that was the question)
It's working!
Something changed in one of the recent(ish) updates. Game input isn't blocked anymore for textfields, for MicroEngineer and OrbitalSurvey. It is blocked for other mods I've tried, like Science Arkive Wayfarer's Wings and MNC. But I haven't changed anything for MicroEngineer for a while, so it must be something else that's changed.
my guess would be that it's because other mods still use the pre-2.3 API (not using WindowOptions) and that has the disabling on by default
Micro Engineer uses them, but doesn't enable the option for disabling game input on focus
if you want to use the default values and modify those, instead of making the full object from scratch, you can do this instead:
return WindowOptions.Default with
{
WindowId = windowId,
IsHidingEnabled = true,
MoveOptions = new MoveOptions
{
IsMovingEnabled = makeDraggable,
CheckScreenBounds = true
}
};
Ah, is that something new? The DisableGameInputForTextFields I mean. It's strange that I wouldn't use it in the first place
with?
Ive never seen this syntax aaa
That would be really nice to have known a while ago
honestly I don't 100% remember but I probably added it in 2.4
It works now, thanks!
I'm moving the discussion here @stuck jasper
I was thinking
is it possible someway the "default" values set in Unity for the KerbalPanelSettings, gets "applied" to the in-game UI, so the UIDocuments width/height/transform is changed, then it gets reset by the UITK Manual/Auto switch, but now it's late since dimensions are already computed?
well, switching between auto and manual requires a game restart for everything to properly apply
but then it should be working fine
mh
this channel is really cool to lear UITK !!
UI Toolkit is a Unity’s new UI creation and development tool. This tutorial introduces the UI toolkit through making a simple but working UI. For those who are still unfamiliar with it, especially UI artists in the field, it will be an opportunity to foresee the future changes in the production.
00:00 Introduction
00:22 UI Toolkit?
00:53 Setti...
awesome, thanks for sharing!
this is helping me a lot
@stuck jasper I made a PR to the unity side
AH I didn't notice, sorry
I'm trying to bring MicroEngineer to the newest template version, primary goal to finally decouple unity files from a single unity project into separate mod projects (I blame @ Lux for teaching me this 😆 ).
Anyway, I have some custom controls in the main project that I'd like to move to the unity project. Issue is that inside the controls I'm using some classes from the main project, so I need to add a reference to them. If I try to add a reference to the main project it says that it would create a circular reference (well yeah, makes sense). So how do I actually do that? I could add a reference to the compiled dll from the main project, but there must be a direct way. This is a noob question so I feel there's an obvious answer here 🙂
Well, the ideal way to do it would be not to have any logic code inside UI controls definitions
And instead passing data to them from the controller
I'll move the control initialization to the controller then
Alternatives sound too complex and not worthy
You generally dont want to reference spacewarp stuff in unity, or youll have to drag in every single spacewarp/bepinex assembly
Yeah, I've read about that now. Would have to set up nuget packages that unity doesn't like, so there are workarounds for it.
From my side, the K2D2 port will take a little bit longer than expected. I'm still in a long learning curve. Perhaps because I need for to be confident for continuing with it. I really need to master many little ui tricks I was use to have using IMGUI.
My first attemp of UI was really too complex to adapt to add simple feature. coming from Unity editor, Build UI, go back to vscode, Build and see the result on KSP2.
I need to have a better workflow and that's why I need a long preparation of my tools under Unity Editor.
I'm currently creating a set of little UI Component I used to have in previous K2D2 UI. Thiis inlcude :
- tabs with a light on it when Pilot is On
- 3 differents styles and behavior for buttons.
- new toggles and sliders with a better look
- FoldOut
and Labels, console infos and so on.
Building all this stuff takes a long time.
I'm following that examples given here : https://docs.unity3d.com/2022.3/Documentation/Manual/UIE-slide-toggle.html
I mean, you don't really have to create a custom control for just a toggle
you can just restyle the native toggle
like I did
unless you want to do something really complex
Yes of course but i've adjusted so many little things in the k2d2 ui that I want at least to have that level of quality and doing this is a good tutorial for more complex UI like the compass and so on
The tabs of example have level and 2 toggle states. many button in K2D2 ui have this kind of logic I need to reproduce
I could have a first version of K2D2 with UITK quick but it will be harder to continue on it rather than having betters bases. so just to say I take time to create this. it could be used in another projects, making it relatively generic.
I want for example to add animated controllers anywhere it is possible and interesting.