#UITK for KSP 2

1 messages · Page 4 of 1

stuck jasper
#

I guess it makes sense to keep the experimental this way so that they stay last if we add new namespaces

ebon seal
#

yeah and people wont be as inclined to use them

stuck jasper
#

oh and (hopefully) last question, why are they internal?

ebon seal
#

cuz they arent suposed to be used in code

stuck jasper
#

I'm guessing the game will still be able to find them since it uses reflection

ebon seal
#

they just expose them to the UIBuilder

#

yeah

#

i think the selector is public tho? or not?

stuck jasper
#

nope, also internal

#

I should probably change that

ebon seal
#

the exposed ones should stay internal to avoid u using them since they are empty classes

#

yeah change it MisatoPray

stuck jasper
#

and probably make BaseControl abstract

#

so it can't be instantiated

ebon seal
#

i dont remember why i didnt make it abstract tbh, but sure

stuck jasper
#

alright, package seems to be working fine

stuck jasper
#

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

stuck jasper
#

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
GitHub

This package contains assets and controls for creating UIs with UITK for KSP 2. - GitHub - jan-bures/UitkForKsp2.Controls: This package contains assets and controls for creating UIs with UITK for K...

ebon seal
#

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 AsukaDead

stuck jasper
#

Having a Unity solution within another C# solution didn't seem like the best idea

ebon seal
#

oh yeah ur using an actual solution, makes sense yea

stuck jasper
#

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

ebon seal
#

oh yeah wtf that works greatly

stuck jasper
#

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

cyan terrace
#

who did stuff.

ebon seal
#

@stuck jasper is it a dependecy for uitk?

stuck jasper
cyan terrace
#

munix you fucked up, fix the package

stuck jasper
#

done, delete the uitkforksp2 folder from your Nuget cache

#

and restore again

compact sandal
#

seems that 1.3.0 isn't on CKAN yet

stuck jasper
#

no clue why that would happen, it is on SpaceDock

stuck jasper
#

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

hard onyx
stuck jasper
#

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

stuck jasper
#

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

stuck jasper
#

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

compact sandal
#

Is there a specific reason the struct is named "MoveOptions" and not "DragOptions"?

compact sandal
#

Maybe you could also add CenterByDefault to WindowOptions?

south tendon
#

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

hard onyx
#

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

stuck jasper
#

Yeah, I don't think that's limited in any way

stuck jasper
stuck jasper
#

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)

compact sandal
#

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.

compact sandal
stuck jasper
#

While what I mean by creating the window is calling Window.Create

hard onyx
#

(You should add window.Hide and window.Show extension functions to UITKForKSP2 in that case)

stuck jasper
#

Which most mods do somewhere like in OnInitialized, so as soon as the game is loaded

compact sandal
#

I don't hide the window. When it's closed, I destroy it GameObject.Destroy(document);

stuck jasper
#

It makes sense in your use case where you're updating the window every frame

compact sandal
#

DisplayStyle.None/Flex I'm using only for foldouts and some other special cases, but never to hide the entire window

stuck jasper
#

You don't want it to keep updating in the background

compact sandal
#

Exactly

stuck jasper
#

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

stuck jasper
compact sandal
#

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.

stuck jasper
#

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

compact sandal
#

Alright, got it, thanks

stuck jasper
#

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

compact sandal
#

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 🙂

stuck jasper
#

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

compact sandal
#

In the first case you're calling CenterByDefault for the first element in the root and in the second case on the root itself?

stuck jasper
#

actually it does that in Awake, which should go through before the CenterByDefault method is called

#

I'm not sure

stuck jasper
#

I'll try that

#

I'm blind

#

yeah that was the issue

compact sandal
#

nice

stuck jasper
#

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!

stuck jasper
stuck jasper
#

and now, big sigh, forum thread for this

#

though I might just wait until I have the documentation ready

hard onyx
#

Just light a fire under your ass by making the forum post like me

stuck jasper
#

lmao I guess it will be one way to motivate me

dense bison
#

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

compact sandal
# dense bison So I'm thinking about updating the template uss to make drop downs better match ...

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

dense bison
#

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.

stuck jasper
#

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

dense bison
#

Here's my attempt at making the controls a little more consistent with each other and the base game

#

Dropdown text color fixed too

hard onyx
#

Looks nice

stuck jasper
#

looks great, thanks for doing this!

dense bison
#

By the way, whats the reason for the seperate KerbalUI and UitkForKsp2 uss themes?

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

oh, that's weird, what was it?

dense bison
#
.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

stuck jasper
#

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

dense bison
stuck jasper
#

will do when I get the chance, thanks

dense bison
#

Multiple themes sounds cool, btw

stuck jasper
cyan terrace
#

omg why

stuck jasper
#

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

stuck jasper
cyan terrace
#

wait thats in the games ui

stuck jasper
#

yes

cyan terrace
#

@trail stag please fix. I cannot unsee.

stuck jasper
hard onyx
#

Eww

stuck jasper
#

another fun one right in the same window is the save button

#

this is the active (currently clicking on it) state

#

lmao

cyan terrace
#

thats not good.

hard onyx
#

Thats ... very slughtly off center isnt it or are my eyes playing tricks

stuck jasper
#

not sure, but the disappearing text feels like the bigger problem here lmao

hard onyx
#

I knew it

stuck jasper
#

lol

cyan terrace
#

I think they should push 0.2.0.0 back a bit for this

stuck jasper
hard onyx
#

We should file a bug report

cyan terrace
#

heres the fixed save button

stuck jasper
#

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

hard onyx
stuck jasper
#

and it's something that's been annoying me since 0.1.0

cyan terrace
hard onyx
#

Ill be honest that doesnt look much better

#

The line being skewed i hate

cyan terrace
hard onyx
#

Move the x right a bit

stuck jasper
#

I feel like the line should end before the x

#

yeah

#

that too

cyan terrace
stuck jasper
cyan terrace
#

added some line ends

hard onyx
#

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

cyan terrace
#

its the same

stuck jasper
#

these are all buttons accessible in the VAB

cyan terrace
#

wait you mean 1 sec

stuck jasper
#

and there are many more outside of it

cyan terrace
stuck jasper
#

yeah that looks good

cyan terrace
hard onyx
#

(My last suggestion would be make the x bigger maybe

stuck jasper
cyan terrace
stuck jasper
#

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

hard onyx
# cyan terrace

Looks nice, just needs a higher res x, which i wont have you do

stuck jasper
#

but it's also doable in uGUI

#

even if it's slightly more difficult

cyan terrace
hard onyx
#

Ooo

stuck jasper
#

@ Dakota forget what I said about hiring us for modding, just hire me for UI smh

hard onyx
stuck jasper
#

yeah but I don't see that happening

#

they'd have to start UI from scratch

hard onyx
#

plus we could use their themes and such if they did

cyan terrace
#

maybe I should just go for one of the design roles.

stuck jasper
#

including the supporting systems, not just the UI itself

stuck jasper
#

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)

compact sandal
dense bison
#

I can't remember, does the text box also turn green when you select it? That was the thing that bugged me the most

stuck jasper
#

yeah

#

that's from the game

dense bison
#

Eww lol

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

yeah, it will be awesome to have that

stuck jasper
#

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

stuck jasper
#

(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 couldyounot

#

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

dense bison
#

Sounds great! Better to get radical changes out of the way while the modding community is relatively small anyways IMO

dense bison
#

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.

compact sandal
#

Can you create a new "KerbalUI2" theme and leave "KerbalUI" as is? I'm not keen on updating all my mods tbh

stuck jasper
#

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?

hard onyx
#

Uhhh theres got to be a better way than multiple panel settings

stuck jasper
#

well, yeah, the alternative I suggested

hard onyx
#

Yeah but in general

stuck jasper
#

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

hard onyx
#

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

stuck jasper
#

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

hard onyx
#

It doesnt sound like overkill to me tbh but I getcha I suppose

stuck jasper
#

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

hard onyx
#

Is there not a stylesheet property on the VisualDocument?

stuck jasper
#

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

hard onyx
#

Also, this may have been the cause of the reflektor offsetting issue

stuck jasper
#

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

hard onyx
#

Ahh

#

Was just a theory

compact sandal
stuck jasper
#

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

compact sandal
#

That'd be sweet

stuck jasper
#

I'll probably do that, then

stuck jasper
#

@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

dense bison
#

Thanks! Ah that's too bad. I was hoping to avoid custom controls

dense bison
#

Fixed the foldout. Are you aware of any other classes that have the toggle?

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

I was guessing because of this page in the docs

dense bison
#

Right, you have to use code to make that though, it doesn't come like that

stuck jasper
#

yeah, that's what I meant by saying it has to be generated dynamically

dense bison
#

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;
}
stuck jasper
#

ahh, the arrows are in resources, of course

dense bison
#

Yeah, took me a bit to figure that one out

stuck jasper
#

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)

dense bison
#

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

dense bison
#

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

stuck jasper
#

then it's most likely due to scaling

dense bison
#

Oof. KSP2 scaling strikes again lol

stuck jasper
#

looks ok at 1080p

stuck jasper
dense bison
#

1440p

stuck jasper
#

yeaah

#

that's the issue with trying to display 1.3333px wide borders and paddings

#

lmao

dense bison
#

makes sense

stuck jasper
#

this is how Unity renders it at 1440p for me

#

not much better

dense bison
#

Oh yeah, you're right

stuck jasper
#

only looks good in 4K

dense bison
#

Let me see if maybe I can fix that

#

Yeah, 4K is double pixel scale, so it should be fine

stuck jasper
#

yeah

dense bison
#

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

stuck jasper
#

yep, already did that

dense bison
#

Sweet

stuck jasper
#

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

#

😆

dense bison
stuck jasper
#

ah, then I see we had a similar idea lol

#

you have top: -4px; and I "fixed" it with margin-top: -5px;

dense bison
#

Ah, yeah I was trying to make the arrow appear to pivot around the center

stuck jasper
#

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)

dense bison
#

Yeah css can get ugly real fast

stuck jasper
#

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

dense bison
#

Crazy idea, but maybe we could generate uss from a template?

stuck jasper
#

hmmm

#

hmmmmmmm

#

I'm willing to give this a try

dense bison
#

Interesting, nice that there's a package for it

stuck jasper
#

yeah, I like the idea a lot

#

I'll head to bed now but I'll definitely take a look at it tomorrow

dense bison
#

💤

stuck jasper
#

thanks for all the help by the way!

dense bison
#

NP. It's something I'm interested in, so I def want to help if I can.

stuck jasper
dense bison
#

Oh cool!

stuck jasper
#

might have to add some sort of an indicator to make it obvious

dense bison
#

Oh, forgot that SCSS has variables. Nice.

stuck jasper
#

yeah, though I've been using the native CSS/USS ones with no issues

dense bison
#

Ah, I forgot that default css has that, ha

stuck jasper
#

for example

#

I definitely want to use them more often, for stuff like common colors, etc.

#

the stylesheet is a hot mess right now

dense bison
#

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

stuck jasper
#

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

dense bison
#

Hey, refactoring is FUN

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

Damn, I can hear people outside my apartment leaving for work

#

That's how I know it's really time for bed lmao

dense bison
#

Oof, you're in europe right? I'm on night shift, so my schedule is already all f'd up

stuck jasper
#

Haha yeah, almost 6am

dense bison
#

Just woke up a few hours ago

stuck jasper
#

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

hard onyx
#

Imagine patch manager without the nested selectors

stuck jasper
#

Oh god

hard onyx
#

I dont think it would actually work as you need the variables from outer selectors

dense bison
#

Feel free to steal anything from here if you want

hard onyx
#

Thats much nicer lol

hard onyx
#

having variables like that is like please

dense bison
#

By the way from my testing it seems that the SCSS addon doesn't like // comments inside block comments

hard onyx
#

Just always use /* comments */ tbh

stuck jasper
#

this hybrid of USS and SCSS should be called SUSS

dense bison
#

Nice

stuck jasper
#

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

hard onyx
#

You can do the paths based off of Assets/

#

at least

#

as the CWD is always the folder above assets

stuck jasper
#

well this is a package

hard onyx
#

Wait nvm then

#

yeah, absolute paths not gonna work then

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

but they do work

dense bison
#

Does each theme need it's own folder?

#

Oh, never mind saw the root folder

stuck jasper
#

for now I'm pretty happy with this folder structure

#

I might even further split controls and containers from native-controls

dense bison
#

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

stuck jasper
#

just to have everything nicely organized, instead of having comments for it

#

lmao

hard onyx
#

Wow just seeing how nice that organization looks using scss, we should've been using it earlier

stuck jasper
#

I haven't actually started converting into SCSS yet

stuck jasper
dense bison
#

NP

#

Trying out a little tweak with the dropdowns

hard onyx
#

Are you using both the executable and importer package?

stuck jasper
#

yeah

#

so that anyone who wants to build the project doesn't have to have Sass installed

hard onyx
#

makes sense

stuck jasper
#
[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

dense bison
#

By the way, while you're working on the stylesheets, can you change the default hover color of lists?

stuck jasper
#

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

dense bison
#

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

stuck jasper
#

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

dense bison
#

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#

stuck jasper
#

ah, yeah, gotcha

#

(well, you can add pseudostate styles in C#, but it will be a pain in the ass)

dense bison
#

Really?

stuck jasper
#

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

dense bison
#

Ha, thanks for checking. Pain in the ass indeed

hard onyx
#

Just create our own runtime scss parser

stuck jasper
#

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

dense bison
#

I'm already on like side project #4 right now ha

stuck jasper
#

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

dense bison
#

I just wish I could use the unity UI Toolkit debugger in the game

stuck jasper
#

oh no, now Cheese is going to make this before 0.2.0 drops

hard onyx
#

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

stuck jasper
hard onyx
#

Well that makes it dead easy dont it

stuck jasper
#

though it's probably not the version they're using now

#

since the last commit was 3 years ago

#

but it's a start

hard onyx
#

Ill probably go from the original version to handle my own font parsing and such

#

I really want a scss parser tho

stuck jasper
#

oh lawd

hard onyx
#

I feel like users would like that better

stuck jasper
#

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

hard onyx
#

Not well
It doesnt allow you to do

:parts {
    > {
    }
}

You have to have * on both sides of that >

dense bison
#

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

stuck jasper
#

interesting, that must be a UI Toolkit bug then

dense bison
#

@stuck jasper I don't suppose you figured out that weird offset bug when unhiding another window, did you? Still running into it...

stuck jasper
#

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

dense bison
#

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?

stuck jasper
#

ahh I'm stupid, I literally thought about that being a possible fix earlier

#

and then completely forgot

dense bison
#

Don't know why I didn't realize sooner, ha

stuck jasper
#

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

dense bison
#

As far as I can tell, they have seperate root gameobjects, which each don't have a parent

#

sep window ids

stuck jasper
#

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

dense bison
#
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;
stuck jasper
#

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

dense bison
#

Interesting

stuck jasper
#

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

stuck jasper
#

soooo, time to redo the UI reference

#

lmao

#

they fixed a lot of the issues I had with the UI

hard onyx
#

@stuck jasper

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

hard onyx
#

FUCKING ALT F8 DOESN'T WORK FOR ME

#

It brings up nvidia

#

fucking hell

stuck jasper
dense bison
#

All the styling in my code is getting a bit too much, so I'm thinking about bundling USS. How can I do that?

stuck jasper
#

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

dense bison
#

Ah, found it on github. thanks

compact sandal
stuck jasper
#

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]'
hard onyx
#

thats the F2 bug that causes the orbit line issue

stuck jasper
#

this exception happens when pressing F2 in the Map View, and it prevents UITK from hiding its windows

stuck jasper
hard onyx
#

well rather that bug is a side effect of a deeper bug that causes it

stuck jasper
#

@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?

compact sandal
#

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)

silk zealot
#

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 ;_;

stuck jasper
#

though, currently UITK is in the process of basically a complete rewrite of both the library and the themes, for the 3.0 update

silk zealot
#

Oh! Awesome ❤️

stuck jasper
#

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

silk zealot
#

Seems like great news; I'll be happy to contribute when 3.0 is live so

stuck jasper
#

awesome, thanks!

silk zealot
#

@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

silk zealot
mystic marsh
#

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

Google Fonts

Noto is a collection of high-quality fonts in more than 1,000 languages and over 150 writing systems.

silk zealot
stuck jasper
#

awesome

#

so basically, ideally all these

#

and that should hopefully cover most of our needs for CJK

silk zealot
#

Hm the version I download as a "global" ttf

stuck jasper
#

the version you linked only seems to support Latin, Cyrillic and Greek alphabets

silk zealot
#

Ah! My bad

#

Perfect so

stuck jasper
#

for now I would just leave out the pixelated version, and just use these as the fallbacks for all fonts

silk zealot
#

Yes, I'd prefer that too

mystic marsh
#

Note that for Traditional Chinese, there are two variants, HK and TC, not sure if conflicts exist

stuck jasper
#

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

mystic marsh
#

From my search, they can not coexist and the "TC" used in Taiwan is more commonly used.

stuck jasper
#

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 lifesupport

silk zealot
#

Hahaha

#

awesome

mystic marsh
#

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.

stuck jasper
#

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

mystic marsh
#

great!

#

unrelated thought: Chinese characters can be too complicated to be pixelized, sometimes it's unreadable when the size is small.

stuck jasper
#

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

hard onyx
#

Is it a weird switch in the doorstop config :p

stuck jasper
#

what is happening lifesupport

mystic marsh
#

no idea at all. Are labels any different?

stuck jasper
#

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

silk zealot
#

seems nice!

stuck jasper
#

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

stuck jasper
#

oof

#

from 1 MB to 50 MB

#

with those new fonts

#

a loooot of characters in them

hard onyx
#

Those scripts have a large amount of glyphs

stuck jasper
#

yeah

mystic marsh
#

just a thought, could fonts be developed into optional sub-mods in the future?

stuck jasper
#

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

hard onyx
stuck jasper
#

not sure how I would handle using them as the main fonts

hard onyx
#

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?

stuck jasper
#

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

silk zealot
#

We could warn them in UITK/SW, something like if (Language.Current == "Japanes" ... )

silk zealot
stuck jasper
#

yeah, I definitely wouldn't want to take those fonts out

hard onyx
#

Arabic has many less glyphs than any of those 3 languages

stuck jasper
#

but it could work for extra languages

hard onyx
#

Almost any font would be drastically smaller actually

stuck jasper
#

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

silk zealot
#

wouldn't be possible, as a fallback, to set in the TextPanelSettings the same fonts used by the game itself?

hard onyx
#

The game uses tmpro
The fonts wont have all the glyphs im pretty sure

#

Thats my understanding at least

stuck jasper
#

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

silk zealot
#

Ah, well, crystal clear now

silk zealot
hard onyx
#

If we could use the game fonts, we'd have made them the main fonts im pretty sure

stuck jasper
#

yeaah

hard onyx
#

But the games fonts are paid and we cant really redistribute them

#

And we cant get them from in game

stuck jasper
#

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

hard onyx
#

It is my understanding that TMPro only generates glyphs for characters that are used

stuck jasper
#

it's the same for TextCore

silk zealot
#

Is it really a problem to bundle the 50mb? UITK is a core library in the end

hard onyx
#

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

stuck jasper
# stuck jasper it's the same for TextCore

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

stuck jasper
hard onyx
#

C++ with clang too, I think

stuck jasper
#

I'd have to install either of these first munley

hard onyx
#

Setting up MSBuild for that though lifesupport

stuck jasper
#

so I declare it a pain

hard onyx
#

Hell zig would work too, but its not 1.0

#

Anyways #🔴space-warp

chilly thorn
#

zig?

#

i heard zig

stuck jasper
#

oh god he's here

chilly thorn
#

i felt it in the force

stuck jasper
#

hide yo kids hide yo wives

#

the Ziggler is here

chilly thorn
#

👀

stuck jasper
stuck jasper
#

whyyyyyyyyyyy doesn't this work

silk zealot
#

Chinese font refusing to work?

stuck jasper
#

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

silk zealot
#

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?

stuck jasper
#

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

silk zealot
#

(If you'd like some help obviously)

stuck jasper
#

each font asset has its own fallback settings instead

#

that way I can also differentiate between fallbacks for regular and bold fonts

silk zealot
#

Seems good

#

.. well, if it does work

stuck jasper
#

yeah...

#

oh what the hell

#

the fallbacks somehow disappeared from most of the font assets??

#

inside the editor

#

Unity wtf are you doing

silk zealot
#

Classical Unity

stuck jasper
#

ok what

#

now half of it works

#

is a different font used for those or something? @silk zealot

silk zealot
#

I'll double check, is it possible setting the font in the Visual Editor breaks this link with UITK?

stuck jasper
#

it shouldn't

silk zealot
stuck jasper
#

huh

#

I wonder if using the USS variables instead of a direct reference would fix it

#

but that would be weird

silk zealot
#

let me double check

#

I don't think it's possible because the addressable bundle is ~160kb

stuck jasper
stuck jasper
silk zealot
#

If it's using a different font, it should be bundled here right?

stuck jasper
#

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

silk zealot
#

ahn

#

so strange

stuck jasper
#

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

silk zealot
#

in the uxml it is -unity-font-definition: url(&apos;project://database/Packages/uitkforksp2.controls/Assets/Theme/Fonts/JetBrainsMono/JetBrainsMono-Regular%20SDF.asset?fileID=11400000&amp;guid=f5454c9c675002c44a5a7234bd40c390&amp;type=2#JetBrainsMono-Regular SDF&apos;);

stuck jasper
#

hm

#

not sure if USS variables can be used directly in UXML

silk zealot
#

I'll try to swap it

stuck jasper
#

my guess is it would require setting the style from inside a USS file

#

still, this is one weird issue

silk zealot
#

I'm using the JetBrains Regular font

#

just to double check

stuck jasper
#

that shouldn't be an issue, all of them have the fallbacks

silk zealot
#

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

stuck jasper
#

lol

silk zealot
#

this sounds not goot

stuck jasper
#

so the issue was what I thought

silk zealot
#

(or is it normal?)

#

What!

stuck jasper
#

by directly referencing the font asset, it actually gets copied into your bundle

silk zealot
#

gosh

stuck jasper
#

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

silk zealot
stuck jasper
#

even in your copies

silk zealot
#

Sure

#

But I'd like to avoid the copies if possible

stuck jasper
#

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

silk zealot
#

But using addressables, by definition, shouldn't Unity omit these font since they are in another addressable bundle?

stuck jasper
#

but it turns out it wasn't for completely no reason

stuck jasper
#

but I don't think the two systems interact well between each other

silk zealot
#

Ahhn, but I'm using just regular bundles

#

(Just to talk again about the Unity mess)

stuck jasper
#

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

silk zealot
#

Mh yes this is my doubt too

#

Was wondering if there is some settings to avoid this

stuck jasper
#

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

stuck jasper
#

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

silk zealot
#

I should admit I used the selector

#

just because I didn't find this

stuck jasper
#

that's on me, I absolutely need to write the documentation after the rewrite

silk zealot
#

I think we should add it on the wiki

stuck jasper
#

there's just always something else more pressing to do first

silk zealot
#

Haha sure, I could've just asked, you guys are super present

stuck jasper
#

alright, so I think I can push out this UITK update then

silk zealot
#

let me just double check all the UI

#

2 minutes

#

if you don't mind

stuck jasper
#

oh sure

#

(damn you if you manage to find a different bug though 😠 )

silk zealot
#

Hahaha

#

Can I use the UITK variable freely or do we need an import or something like that?

stuck jasper
#

yeah, you can just use it wherever

#

since it's defined in the main theme

silk zealot
#

Mh it seems like it is not showing in the builder

#
.font-pixel-label {
    -unity-font-definition: url(--font-title-big);
}
stuck jasper
#

how about if you add the document to a scene and run it?

#

oh I see the error

#

it's var(...) instead of url(...)

silk zealot
#

Oh, lol

#

I could atleast read the error message

stuck jasper
#

😆

silk zealot
#

perfect

#

beautiful!

hard onyx
#

Awesome!

#

What are the ???

silk zealot
#

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 😄

mystic marsh
hard onyx
#

Also, someone should tell the person on the forums who is trying to add chinese to spacewarp

stuck jasper
#

Yeah I will

silk zealot
#

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

stuck jasper
#

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

silk zealot
#

Ah gotcha, thanks

stuck jasper
#

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

silk zealot
#

Better to do it by hand so

stuck jasper
#

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

silk zealot
#

Seems working fine, thanks!

hard onyx
#

are there stiill plans to use scss?

stuck jasper
#

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

hard onyx
#

Ah you do have it in the dev branch

silk zealot
#

@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

stuck jasper
#

nice, thanks!

#

I'll definitely look at it for inspiration when I get to the UITK update

#

looks pretty similar to this recommended solution

silk zealot
#

I red exactly that post to implement it 😄

#

Plus having a central one makes for better animations

stuck jasper
#

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

silk zealot
#

It's cool, I've seen it, but tooltips are not supported at runtime

#

atleast it's what written there

stuck jasper
#

that is a custom implementation

silk zealot
#

I didn't dig down

stuck jasper
#

"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"

silk zealot
#

Ahhhn

stuck jasper
#

it's quite similar to your implementation, too

#

just a bit more robust

silk zealot
#

I thought he/she was referring to the library as UIElements

#

lol

stuck jasper
#

UIElements was the old name before they renamed it to UI Toolkit

silk zealot
#

I didn't remember

#

too many changes in U world..

stuck jasper
#

indeed 😆

silk zealot
#

Anyway it's perfect

#

love the popup

stuck jasper
#

yep, pretty sure I can just take the best from this and from your implementation and we'll have basically perfect tooltips

silk zealot
#

For sure, but I don't care about the solutions used, just to contribute you know

silk zealot
#

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!

stuck jasper
#

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

silk zealot
#

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?

stuck jasper
#

well, you can just write the UXML and then control them in your plugin

#

custom controls basically just encapsule the two

hard onyx
#

Have a dropdown element that can have a list of child elements rather than just text

stuck jasper
#

so that they can be easily reused

silk zealot
hard onyx
#

Btw munix, should I hold off on writing a markdown renderer until uitk for ksp2 3.0

stuck jasper
#

otherwise you'd just write the UXML directly inside the UXML window where you want the dropdown

silk zealot
#

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..

hard onyx
#

m_Input = this.Q(className: BaseField<bool>.inputUssClassName);

silk zealot
#

doesn't Q find the element?

hard onyx
#

Yes

#

But the custom control is created from the equivalent of a prefav

#

Prefab

#

Its instantiated from the uxml, which has the children

silk zealot
#

I'm a bit lost on where this "prefab" is placed

hard onyx
#

You have a uxml document that defines it basically, I think

stuck jasper
#

basically, you put the UXML into your asset bundle, and then in the code, you load it from it

#

like a regular window UXML

silk zealot
#

Ok and then I'm able to put this custom control directly into my other UXMLs?

stuck jasper
#

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

silk zealot
#

yep

#

and the worst question: is there any example about this that you know 😄 ?

stuck jasper
#

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

silk zealot
#

haha

silk zealot
#

I've found this

stuck jasper
#

lmao

silk zealot
#

hahahah

#

nice 😄

stuck jasper
#

yeah seems like Lux just creates the UXML programmatically

#

so no .uxml file

silk zealot
#

so the VisualElement should be built programmatically

#

ok, not a problem

stuck jasper
#

well, you can do it either way

silk zealot
#

since you can just put it into the UXML

#

and preview it

stuck jasper
#

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

silk zealot
stuck jasper
#

actually I think it worked in the UI builder

silk zealot
#

(I hope so, since trying to run a UI project where I imported thunderkit for the addressables just crashes my unity editor)

stuck jasper
#

ahh yeah

#

that's the biggest issue with ThunderKit

silk zealot
#

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

stuck jasper
#

it isn't

#

if you don't need to use KSP2 Unity Tools

#

since those depend on KSP2 being imported

silk zealot
stuck jasper
#

but for just building addressables, it's not necessary

stuck jasper
#

it is convenient

compact sandal
#

You can use custom controls inside the UI builder (if that was the question)

silk zealot
#

It's working!

compact sandal
#

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.

stuck jasper
#

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
    }
};
compact sandal
#

Ah, is that something new? The DisableGameInputForTextFields I mean. It's strange that I wouldn't use it in the first place

hard onyx
stuck jasper
#

yes it's really nice

#

you can use it to copy structs with some modified values

hard onyx
#

That would be really nice to have known a while ago

stuck jasper
compact sandal
#

It works now, thanks!

silk zealot
#

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?

stuck jasper
#

well, switching between auto and manual requires a game restart for everything to properly apply

#

but then it should be working fine

silk zealot
#

mh

shut beacon
#

this channel is really cool to lear UITK !!

stuck jasper
#

awesome, thanks for sharing!

shut beacon
#

this is helping me a lot

hard onyx
#

@stuck jasper I made a PR to the unity side

stuck jasper
#

yup, I already merged it

#

thanks

hard onyx
#

AH I didn't notice, sorry

compact sandal
#

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 🙂

stuck jasper
#

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

compact sandal
#

I'll move the control initialization to the controller then

#

Alternatives sound too complex and not worthy

hard onyx
#

You generally dont want to reference spacewarp stuff in unity, or youll have to drag in every single spacewarp/bepinex assembly

compact sandal
#

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.

shut beacon
#

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.

stuck jasper
#

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

shut beacon
#

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.