#UITK for KSP 2
1 messages ยท Page 5 of 1
I'll ask for help when really struggling on something.
What is mainly hard for the moment is to figure out what is the cause of the look of any control.
I'm struggling on css tricks I'm not used to.
have you seen this before? https://flexboxfroggy.com/
it's a pretty cool way to learn the flexbox layout
Yes and it helped me a lot
ah alright ๐
good stuff, you sent me once ๐
It's really good.
I've got a little question on .uss file and UIBuilder
It's quite difficult to add uss file to the UIBuilder
the
is terrible to use, it open a file seletion at the root of the project.
do you edit used .uss file list directly in the xml ?
well, I usually just have a single USS file for most things
you can have a main one, and then import other USS files into it
with @import
I've tried of course but without big sucess
I also have one .uss per mod. I add selectors and edit styles in the UI builder. Rarely when I want to copy-paste from a different project, I'll do it directly in the visual studio/code, but before that I make sure I saved everything in the project - unity doesn't like it when you edit files externally. And variables I add in VS also.
multiple .uxmls, but one .uss.
depending if you have multiple windows or components you'd like to reuse
what was the issue?
I'll try multiple .uss file too using .tss file to gather them at the very end.
but while editing them it's useful to have them in the UIBuilder
a .tss file wouldn't work well, because you would have to overwrite the theme for all mods
since a panel can only have one theme style sheet
I'll import KerbalUI as a dependencie.
that's still not great
you could define some classes that other mods also use
and then you would break their styles
you can do the same with a .uss file, no need to define a new theme
yes but a simgle .uss file is more difficult to maintains
I mean a single USS file that imports other USS files
ok.... I'll try a litlle more
it's exactly the same as a .tss file, just with a different extension
... I've created a file MyNewUI.uss
@import url("SlideToggle.cs");
@import url("MyButton.uss");
and this does not seems to import my style
that should probably be SlideToggle.uss, not SlideToggle.cs
and you can if you make it a .tss file?
to be clear I have almost no experience using the UI builder for styles, it's pretty limited when it comes to that and I prefer writing my own USS, plus I even actually use the SCSS preprocessor in UITK for KSP2 now (it's available as a Unity package):
I'll try to use it at the very end. but as .uss includes works, it make my life so simplier
๐ค I'm missing something in my uss syntax
how can I copy the base uss style used for one af the default controlers (here a slider)
copy it?
why do you want to copy it, though, when it's already there one?
the object is child of slider
and It could be simplier to affect it by name but my syntax does not work
i've tried
.k2-slider > #unity-dragger {
height: 10px;
}
this works but sure can affect other UI
#unity-dragger {
height: 10px;
color: rgb(255, 0, 0);
background-color: : rgb(255, 0, 0);
}
using > only checks direct children, which in your case are only these two, and neither of them match
you probably want .k2-slider #unity-dragger
that selects all descendants recursively
oh my fucking god I can see why you'd have issues with PM if CSS does that
lol
yeahh, this is kinda what I meant by inconsistency with (S)CSS as a source of confusion
๐
Now time for me being the ignorant one with UITK for KSP2
how the fuck do I use the font variables
thank you
Thank you
Why is close-button not being found?
because you misspelled it
Hello, I well advance on the K2D2 port ! but of course I've got a bunch of very technical questions ๐
first is about the @stuck jasper template. I've modified the .vsproj file in order to add a "close KSP" before build
And It was working fine in my old build way (using only .bat).
I call this .bat :
@REM test if KSP2_x64.exe is running
echo off
tasklist /fi "imagename eq KSP2_x64.exe" |find ":" > nul
if errorlevel 1 (
echo "Kill KSP2 !!!!"
taskkill /f /im "KSP2_x64.exe"
timeout 2
) else echo "KSP2 Not running"
and it's working fine but the "timeout 2" is skipped and the build continue without waiting for a proper time.
The build then fail because KSP2 is runnign and dll could not be replaced.
It's for sure the way dotnet is running build commands and to speed up time out are ignored
perhaps there is a way to add the pause directly in the pre-build step
i've added the command in the Directory.Build.targets file
<!-- Close game Before Deploy -->
<Message Text="Closing kerbal" Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun"/>
<Exec Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun"
Command="$(PowerShellExecutable) -Command "& {Push-Location '$(SolutionDir)/scripts'; close_ksp2.bat; Pop-Location}""/>
the trouble is not "that annoying", if I build another time averything workd fine
sorry, no clue about that one, never tried to pause/timeout within a MSBuild target
right, I'll try to find it out
thanks
annnnnd of course it was easy to find
it's in fact working if I add a new target to the file
<Target Name="BeforeBuild">
<!-- Close game Before Deploy -->
<Message Text="Closing kerbal" Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun"/>
<Exec Condition="$(ConfigurationName) == Deploy Or $(ConfigurationName) == DeployAndRun" Command="$(PowerShellExecutable) -Command "& {Push-Location '$(SolutionDir)/scripts'; close_ksp2.bat; Pop-Location}""/>
</Target>
it was that easy.
And then come my second question, more about uitk
I come often in a situation where one of my panels is hidden and I can't figure why.
I use to change the Display style of the VisualElement.
I'd like to debug to understand what's going on and I can get any VisualElement Style value
Perhaps I'm missing something but I can See in my debugger the current element style.
I could only trace it with debug.logs
I usually use Reflektor or Unity Explorer for this type of debugging
the panel could theoretically be offscreen, or have its visibility (not display) set to hidden, or something else like that
but it's hard to guess without debugging
it seems so cool and useful, thanks
Hello, I've got again many small issues I don't know how to fix.
first are UI Fields
I'm sure there is a simple way to block Key binding with the game.
@stuck jasper made an api for this iirc
the Window class also automatically does it for all elements extending/including TextField https://github.com/UitkForKsp2/UitkForKsp2/blob/b62ba3319deabec16bdadfbd3ab759a0dab1bda8/src/UitkForKsp2/API/Window.cs#L101
thanks, i've not found the DisableGameInputForTextFields option
hummm it was on....
I'll add to IntergerField and FloatField too
I've got a new question @stuck jasper :
I've created a modified version of the DragManipulator
because I'need to ignore many visualElement in the OnPointerDown function
private void OnPointerDown(PointerDownEvent evt)
{
if (!(evt.target is VisualElement))
return;
VisualElement target = evt.target as VisualElement;
if (!IsEnabled) return;
if (checkTarget<IntegerField>(target)) return;
if (checkTarget<FloatField>(target)) return;
if (checkTarget<TextField>(target)) return;
if (checkTarget<K2Toggle>(target)) return;
if (checkTarget<K2Compass>(target)) return;
// _mode = target.pickingMode;
// target.pickingMode = PickingMode.Ignore;
IsDragging = true;
_offset = evt.localPosition;
_target.CapturePointer(evt.pointerId);
}
do you think there could be another way to do it ?
If I use the default DragManipulator, my Sliders, compass and other field starts a drag.
I can't really think of anything better right now
right and it will be enough then
I've moved the manipulator code from UnityUI code to main mod code and I can then use the UitkForKsp2 package
I've added a way to check window limit in my own class using UitkForKsp2.Configuration class
you can do that in the Unity project, too
I see I didn't add a UitkForKsp2 Nuget reference by default, but you can add it
to the *.Unity.csproj file
it will work in Unity, since the Unity project is using the UITK for KSP2 package
great, I didn't know where to add this
and it's working fine in KSP but not in the UnityEditor.
Perhaps I need to add a the utik as a package ?
what exactly doesn't work?
but I can't import UITK code like the Configuration
it causes errors in Unity?
yes I'm currently trying to show it
I just include it like this
in the project that UnityEditor Builds it does not seem to be in the imported packages
and the Editor does not find it too
It is not a blocking trouble, cause I can add it to my main cs project and It's working fine then
ahh nevermind, yeah, the package only contains the code that is needed in editor (custom controls mostly)
I had to check since I didn't really remember
I don't need that, it could be fine in a future version if you have time to.
But it would be the final key to have my full ui set in a separate repo that can be used for other projects
it would be very impractical to transfer all the code to work in Unity, since it has other dependencies like KSP2 and BepInEx
yes and that's the very point I was struggling with
so it have to be kept like that.
the best thing to do is to ideally completely separate the view (UITK) layer from the rest of the application, and use public methods to set the data from your controller class
good point. I can have a base class without the need to fit in the screen
and an overloaded one that can add this feature
but inside the mod code
or, possibly an easier way, the class can have a delegate field fitToScreen that will accept a Func/Action object, and if that field is not null, it will call that function
and then in your controller, you can just assign the correct function to the field
that's the way I have imagined that just a delegate function. it so much simplier.
thanks again. you've got always elegant and pragmatic solutions
Maybe we could create a base uss for all plugins ?
I will probably end up copying @shut beacon PlanFlight uss but if there is a better source...
I will create my own uss classes and use them afterwards but my classes will be very generic.
From what I understand, there are 4 base colors
=> black background by default
=> grey background for all buttons
=> blue borders for popup and buttons
=> green text and border for activated buttons / important text
That's what the Kerbal UI is
Flight Plan, Maneuver Node Controller and K2-D2 are outliers in this sense, almost all other mods have UI based on the KerbalUI theme (which itself is based on the game's UI)
in K2-D2 I've added many new controls i'll present it when the mod is ready
Ah, ok. I will launch the game to check. I never analysed the style of the various UI elements.
It's not ready yet , But it will be soon
But indeed Flight Plan has its own theme. Well, I have less work to do. Great. ๐
by the way, this is what you need to do to see the correct UI styles in Unity
Ah, that's definitely useful. ๐
definitvely ๐
Slightly different from definitely, definitively conveys that something is clear and unambiguous but in a conclusive, final way.
https://www.dictionary.com/e/definitely-vs-definitively/
I am improving my english at the same time. ๐
I didn't know the difference. I'm improving my english too there
does anyone knows how to change the drodown menu uss
It's quite hard to find what .class names needs to be overloaded
it won't show up in the UI Builder
to see how it really looks, you need to play it in a scene
here you can see the setup and the difference
as for changing the styles of the dropdown list itself, it's a bit tricky, since to change them, you would need to either modify the existing KerbalPanelSettings and that would change the style for all mods, or create your own custom panel settings with its own theme files and all that
the ideal solution would be to create our custom implementation of dropdowns (which I am planning to do for the big UITK for KSP2 update, I just really don't have the time to do it in the near future)
because the native dropdowns are done really stupidly
Oh ok, quite a big job. i've already remade Slider, Progress bar , toggle and many others
I'll perhaps add it to a future job
it will be enough for now
I'll rewrite a better dropbox after
for the moment i'd need infos on how the autobuild in github works... It launch a compilation when I push on any branch ?
yes
the sln file looks alright
no clue why this would happen
and I see it's been like that since you started the rewrite
I buid perfectly on local so that's not a big deal
mmmmh Odd . I'm looking for RepeatButton
it's not in the editor UI I don't think
you need to write it manually in the UXML file
I've see in use in MNC and. I can't find the standard button in the UIBuilder
ok.... and there are others controls that are not in the Builder ?
a lot of them, probably
all of them that are in the UnityEngine.UIElements namespace, not the ones in UnityEditor.UIElements (those only work for creating Unity Editor UIs)
Ok .... how do you get a list of them ?
Oh the list is huge in fact. there where gradiant et curve .... damnit I've made them by myself
I've never seen this list. I should have before
those are only in the UnityEditor namespace so you can't use them anyway
ok, so it's not loosing time to have remade some. And it was the funiest part of the code
it helped me a lot for making the compass
That it the K2D2 is released with UITK !
Thanks a lot @stuck jasper for the precious help.
I'd like then to release the K2UI package
it's the full set of controllers that I have used and I think it's full detached from the K2D2 code
how do you think we should process ?
you can do the same thing as UITK for KSP2 or LFO, simply by having the package as a separate repository that is included in the main repo as a submodule
I've also some changes made in the UITK template project like the auto close KSP
could I send a Pull Request ?
https://github.com/UitkForKsp2/UitkForKsp2/tree/main/src/UitkForKsp2.Controls/UitkForKsp2Unity/Packages
you can see the folder structure where the package has to be located
Unity UI Toolkit library for KSP 2. Contribute to UitkForKsp2/UitkForKsp2 development by creating an account on GitHub.
and then the structure of the package itself
the most important thing is that it needs the package.json metadata file
sure!
I'll try to. I'll first create my repo for K2UI
I've not used git sub modules, it seems to be simple link to other repos. very simple.
yep, that's basically the whole concept
yeah I quite like the Git docs
for the moment I just use it as a subModule
not like a Unity package
I'll try to import it in a new test Mod created with your template
then to make that transition, all you'd need to do would just be to move the folder from Assets/Runtime into Packages and add the package.json file
and it should be all done
what is the advantage to be seen as a package ? the code is kind of read only ?
well the advantage is that users don't have to manually download it, they can just open the Unity package manager and install it from the GitHub URL
and then just update with a button click anytime
oh but also, considering how your project is currently structured, you will need to add the new path to the csproj
I've just built it and it's fine. with the current Path
K2UI Submodule is inside the Runtime folder
But I'll change all this when testing it in a new project
yes, what I said applied to my other message that I was replying to
after moving the stuff to Packages
great
I've tried yesterday to adapt the K2UI to a package and
it's was a complete failure.
I'm not sure why yet and I'll try agin this evening restarting from scratch
Unity...
Unity chose to use npm
I'm not sure creating a package worth it. As a simple sub module in the Runtime folder it is easy to use :
- you've got direct access to the code and can easily debug in it. and modify the code if needed. just need to fork the repo.
- you don't have to add a new folder in the csproj to include the new code.
why would you need to add a new folder to include the code?
you won't be compiling the code from the package into your mod's DLLs
or wait, do you mean that you won't be providing it as a runtime library on CKAN?
I feel like having every modder compile their own version of it is not a good thing
it will just lead to unnecessary duplication in the game
well I've planned to provide it in ckan as a dependency. for the moment the package could be used a simple set of Unity toolkit controls. It is not linked to Ksp.
then from my experience it would be simplier for any develloper that want to use it to just add it to it's mod.
but I know it would lead to code duplication but as it's only simples UI controls, I think it will be simplier to integrate in new mods.
the simple subModules mechanism will avoid duplication.
I mean, you do you, but I feel like making it a Unity package will make things much easier for everyone
you literally just have to import it in Unity and that's it
ah no I just realized that you're right about needing to add the path to your .csproj file if you want to programmatically access the classes outside of UXML files (or a Nuget package, but yeah, it does complicate stuff)
sorry
don't be sorry, it can be a good idea but i will cost more work from my side and as i'm not really aware on how to perform it I find it quite hard to do it.
the simple sub module creates for me a situation where I find it easy to edit it in 2 different projects.
I've created a separate project just to test the UI Controls.
if you do in the future want to separate it, you can look at how UITK for KSP2 does it, it has a submodule (UitkForKsp2.Unity) which is a Unity package, and it also automatically builds a Nuget package which includes the Unity project
I did have a look and, tried to do the same but the Unity package refused to add my "embed" source and I didn't understood why
I think the issue was mostly just the package ID
yes perhaps. I'll try again later. The package structure have to be with the Assets and Runtime folders ? or is it completly free ?
I don't think any of it is necessary, but it's a good convention: https://docs.unity3d.com/Manual/cus-layout.html
great i'll try to fit to that.
I'm trying to fix many little bugs i've got with my K2UI
I've got missing fonts or images and I can't figure out where they are located
in my xml ? in the .uss
quite hard to say. the logs does not point out where it could be
and often I've got
errors like that and I suspect it to reset The UIBuilder state. I'd like to fix it but without a clue on where to find the VisualElement that have and "invalid property"
huh I can't say I remember seeing that one before
not quite easy to find out.
I've tried to remove all ?fileID and the warning is still there
sometime I've got a warning coming from UITK itself
oh the cache invalidation one you can totally ignore
it happens because the font assets have dynamic atlases, and those usually get updated whenever you edit some static text in your UI
ok so no trouble about that, as I'm trying to remove all warning from K2UI
i've got also a warning in the UIBuilder
yeah the UI Builder support for variables is not great
I've noticed it's quite buggy
I prefer to just write the USS by hand because of many small details that the builder gets wrong
Yes but it can be tricky for asset like fonts and images...
yeah, that's where I like to use variables
like:
:root {
--font-regular: url('Fonts/JetBrainsMono/JetBrainsMono-Regular SDF.asset');
}
.some-selector {
-unity-font-definition: var(--font-regular);
}
so I can move the files around and just change the path in one place
I've used them too
taking the MNC as a good example
When opening the uss file in a ui builder it will add references
to tehm automatically
?fileID=11400000&guid=1aa6f9b14a5b16b4
glad I did that rewrite then ๐
It has been a greaaaat help
does it do that even when you don't use the project:// schema?
hummm no it could be the trick to avoid that
i'll try to replace using always relatives pathes
well If I change any setting in the UIBuilder It dully rebuild the whole line
so it loose the advantage of editing in the UIBuilder
but I understand why you prefer editing by hand
but it need a quite accurate knowledge about css/uss
ah that's annoying
the USS support is one thing I really wish they would improve in the builder
but since it's now part of the Unity core, they can't just update the package
ah yes and as Unity version is fixed by KSP 2 we're stuck to this version.
perhaps using a different version of Unity would fit
building the assets bundle and UI controls
they're usually backwards compatible, but not forward
(so 2020.3 bundles worked fine on 2022.3, but not the other way around)
plus I don't think that the 2023 version has a much better UI Builder so it doesn't really matter anyway
at least we're not stuck with the preview UITK package for Unity 2020.3, that was a nightmare, what we currently have is amazing in comparison
Oh my god ๐
Is there a way to react to change of a TextField ? ๐ค I didn't find any method.
event listeners are added with element.RegisterCallback<EventType>(callback);
events reference is here: https://docs.unity3d.com/Manual/UIE-Events-Reference.html
specifically you want ChangeEvent
