#UITK for KSP 2

1 messages · Page 2 of 1

stuck jasper
#

yeah I guess everyone will have to if they want CKAN manual install autodetection

#

should update the template docs to mention that

stuck jasper
#

there you go @cyan terrace

cyan terrace
#

yay

#

amazing

cyan terrace
#

I dont see it

stuck jasper
#

do you have your CKAN set up to download the newest mod lists on every launch?

cyan terrace
#

yes

stuck jasper
#

weird

cyan terrace
#

restarted it a few times

stuck jasper
#

it showed up for me instantly after the PR was merged

cyan terrace
stuck jasper
#

strange

cyan terrace
#

just reinstalled everything (KSP2 & Ckan) and now it shows

#

working now

cyan terrace
#

@stuck jasper

stuck jasper
#

are you using the UITK nuget package?

cyan terrace
#

no im using the dlls

stuck jasper
#

could you try with the package please?

#

I know it's working for me for SpaceWarp and my testing mod

#

but I'd like some more data anyway

cyan terrace
#

not really since I keep everything in a central location to save space.

#

unless I can configure nuget to use 1 location for all the mods

stuck jasper
#

I mean

#

that's literally what it's for

#

you have 1 folder with all cached packages

#

C:/Users/<username>/.nuget/packages

cyan terrace
#

can you send me the xml config for it

stuck jasper
#
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <LangVersion>latest</LangVersion>
        <ImplicitUsings>true</ImplicitUsings>
        <AssemblyName>com.github.jan-bures.UitkTestMod</AssemblyName>
        <Product>UITK Test Mod</Product>
        <Version>0.1.1</Version>
        <RestoreAdditionalProjectSources>
            https://api.nuget.org/v3/index.json;
            https://nuget.spacewarp.org/v3/index.json
        </RestoreAdditionalProjectSources>
        <RootNamespace>UitkTestMod</RootNamespace>
        <ModId Condition="'$(ModId)'==''">uitk_test_mod</ModId>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="Assembly-CSharp">
            <HintPath>..\external_dlls\Assembly-CSharp.dll</HintPath>
            <Publicize>true</Publicize>
            <Private>false</Private>
        </Reference>
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
        <PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.0" PrivateAssets="all" />
        <PackageReference Include="BepInEx.Core" Version="5.*" />
        <PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
        <PackageReference Include="HarmonyX" Version="2.10.1" />
        <PackageReference Include="SpaceWarp" Version="1.1.1" />
        <PackageReference Include="UnityEngine.Modules" Version="2020.3.33" />
        <PackageReference Include="UnityEngine.UITK" Version="2020.3.33" />
        <PackageReference Include="Ksp2Uitk" Version="0.3.0" />
    </ItemGroup>
    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
        <Exec Command="rm -rf &quot;$(ProjectDir)..\$(ConfigurationName)&quot;&#xA;echo d | xcopy /y /s &quot;$(ProjectDir)..\$(ModId)\&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\&quot;&#xA;echo f | xcopy /y &quot;$(TargetPath)&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\$(ModId).dll&quot;&#xA;if $(ConfigurationName) == Debug echo f | xcopy /y &quot;$(TargetDir)$(TargetName).pdb&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\$(ModId).pdb&quot;&#xA;xcopy /y &quot;$(ProjectDir)..\LICENSE&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\&quot;&#xA;echo f | xcopy /y &quot;$(ProjectDir)..\README.md&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\README.txt&quot;" />
    </Target>
</Project>

this is the .csproj for my testing mod

#

you need at least the <RestoreAdditionalProjectSources> element and the <PackageReference>s

#

I like this way more than .dlls since I only need to copy the game's DLL this way and everything else is handled and versioned using Nuget

ebon seal
#

@stuck jasper is there an Unity.Addressables package?

stuck jasper
#

there isn't, neither on BepInEx nor on SpaceWarp nuget servers, but I can definitely add it for you

cyan terrace
#

that fixed it, but that still does not answer why the DLLs was not working.

stuck jasper
#

no idea, I was using the DLLs for a long time and never had that issue

ebon seal
#

would be good for any mod that loads files by themselves through addressables

stuck jasper
#

I assume S.T.A.G.E was also using the DLLs fine?

ebon seal
#

not that adding the .dll is hard, not at all i was just wondering just realized, wrong chat, sorry

cyan terrace
stuck jasper
#

interesting, the UnityEngine files themselves haven't changed at all

cyan terrace
#

hmmm

#

yes its only when using the KSP2UITK stuff the Unity stuff works

stuck jasper
#

I mean the only difference in the library's files compared to the ones inside the game's folder is that the library DLLs are publicized

#

but that should just mean you have access to more stuff

#

not less

stuck jasper
# cyan terrace

though the Window.CreateFromElement method won't work if you reference the old ksp2_uitk.dll

#

since the API changed slightly in 0.3

cyan terrace
#

yes as I said its using the one from ckan

stuck jasper
#

both the UnityEngine dlls and the ksp2_uitk one?

cyan terrace
#

yes

stuck jasper
#

weird

#

the exact same thing is in the nuget package

cyan terrace
#

double check

stuck jasper
#

alright, did a fresh download from both Nuget and CKAN and comparing the individual files

#

the ksp2_uitk dll is exactly the same

#

and the lib/UnityEngine.xxx.dll files are the same except for the access modifiers

#

which is what I already said about the publicizer stuff

#

I mean I assume so since that was the first one that included the Element and Window classes API

#

and if that's the case, then I can confirm the lib/UnityEngine.xxxxx.dll files are exactly the same there as in the 0.3 release on GitHub/SpaceDock/CKAN

cyan terrace
stuck jasper
#

yeah then I have no idea where the issue is

cyan terrace
#

its odd. I copied them from the mods folder to my central source again and same issue

stuck jasper
#

I was using the <PackageReference Include="UnityEngine.Modules" Version="2020.3.33" IncludeAssets="compile"/> nuget package from the BepInEx nuget feed

#

and it was interfering with local .dll references for the UITK dlls

#

but having either both as dlls or both as packages works fine

#

I assume you just had copies of all the game's DLLs in your central source and then copied over the UITK ones and replaced the game ones with them?

#

since in that case the issue is not that

stuck jasper
#

yeah, then I really have no idea

cyan terrace
#

im using the nuget now but still

#

going to quickly swap countdown to uitk and see if the dlls are going to be any issue when running the game

stuck jasper
#

sure

#

I was having some issues with correctly getting font assets to load when they're in one bundle and they're referenced inside another bundle's .uss file but I think I solved that, all my tests worked

#

and you're not using bundles and .uss styles anyway so it shouldn't affect you at all

cyan terrace
#

not yet anyway. until I can find a way to do bundles without opening unity

hard onyx
#

I doubt that thats easy
You'd have to learn meta files and all that as well

stuck jasper
#

well, that's probably a very long way off, we'd have to write a full custom parser for UXML and USS, since Unity compiles those in the Editor and puts the compiled versions into the bundles

cyan terrace
stuck jasper
#

making the bundle itself is the easy part here

stuck jasper
#

but not the parsing/compilation

stuck jasper
#

they did say that they'd like to add support for UXML/USS loading at runtime, but they have no specific plans for it yet, and it will likely be only supported in games using Unity versions starting from the version in which they implement it (if they do at all), not 2020.3.33 which KSP 2 uses

cyan terrace
#

UITK = less code

#

your drag script is a bit funky

stuck jasper
#

I think I just directly copied over the one you sent me?

cyan terrace
#

its jumping all over the place

stuck jasper
#

oh yeah I noticed that too in my testing mod, it seems to work just fine when using it with Window.CreateFromUxml(...) using a .uxml loaded from a bundle

#

but when using Window.CreateFromElement, it was acting weird and jumpy

cyan terrace
#

I will swap to my one then

stuck jasper
#

are there any differences at all?

#

if so, I will just update it

cyan terrace
#

I apply it to each window that requires it like this

stuck jasper
#

and the window is the return value of Window.CreateFromElement(...)?

cyan terrace
#

no

#

thats from VisualElement stageInfoWindow = Element.Root();

stuck jasper
#

oh

#

that should be the same way that I do it then

#
Element.Root(isDraggable: true);

// where the Root method is:
public static UnityEngine.UIElements.VisualElement Root(
    string name = null,
    string classes = null,
    IEnumerable<UnityEngine.UIElements.VisualElement> children = null,
    bool isDraggable = true)
{
    UnityEngine.UIElements.VisualElement ele = Element.VisualElement(name, classes, children);
    ele.AddToClassList("root");
    if (isDraggable)
        ele.AddManipulator(new DragManipulator());
    return ele;
}
#

it just adds the manipulator before the root element is returned, not after

#

shouldn't change anything

cyan terrace
#

this is very much a "works on my machine" situation.

stuck jasper
#

yeah lmao

cyan terrace
#

my code works fine but when I use your one it breaks, even tho its the same

stuck jasper
#

how the fuck

#

let me quickly test the way you do it lmao

#

and you can see the SpaceWarp mod list which is loaded from a bundle works just fine

hard onyx
#

I see progress on the mod list :3

stuck jasper
#

not really, I haven't done any new work since this progress update: #🔴space-warp message

#

I'm a bit stuck on that

#

namely we ideally first need to make the click through blocker (I do have 3 different ideas of how to make it, but no specific implementations yet)

#

the click event issue shouldn't be too difficult to solve but I haven't been able to do it so far

#

and as for the colors, I'm still waiting for the dev responses and hoping we get something helpful for that

cyan terrace
#

Are you applying the manipulator anywhere else?

#

yes you must be

stuck jasper
#

Jesus Christ on a stick

cyan terrace
#

I set it to false and removed my one

stuck jasper
#

of course I am

#

I'm so dumb lmao

cyan terrace
#

yes

stuck jasper
#

I apply it both in Element.Root and Window.CreateFromElement

#

ffs

#

well, 0.3.1 coming in a few minutes

#

lol

#

thanks for helping debug that btw

#

I kinda just forgot about the issue until now

#

love having a personal beta tester lmao

cyan terrace
#

smh. tbh you should just let the modder add it them self rather than it be a default true

stuck jasper
#

I guess at the very least I can make the default false

#

so that the API doesn't change in a patch version

cyan terrace
#

that would be good

stuck jasper
#

well, actually since I'm already making an update, I'll also rename the .dll files to fit with the CKAN naming scheme

cyan terrace
#

oh shit

#

everythings going to break

stuck jasper
#

aka BepInEx/plugins/ksp2_uitk/ksp2_uitk.dll to BepInEx/plugins/UITKForKSP2/UITKForKSP2.dll

#

I'd rather do it sooner than later

#

before more people start using it

cyan terrace
#

good

hard onyx
#

Ckan aint gonna like that

#

But yeah good

cyan terrace
#

they recommended it

stuck jasper
#

will it remove the files that it had installed in a previous version of the mod?

hard onyx
#

More like its gonna just cause an inflation issue (i think thats the term)

cyan terrace
#

who knows, ckan runs on dark magic ¯_(ツ)_/¯

stuck jasper
#

I'll just ask HebaruSan in the comments on the PR where we discussed this earlier today

cyan terrace
#

let me know when you update the nuget so I can continue with this update

stuck jasper
#

will do, I'll just wait for the answer and then do it asap

#

well actually for the Nuget package itself I don't even need to wait

#

so I'll do that right now

cyan terrace
#

thanks

#

can you also send the replacement dll

stuck jasper
#

sure

cyan terrace
#

I will continue in a few hrs.

stuck jasper
#

nice, it should all work fine when I just rename it

stuck jasper
cyan terrace
#

@stuck jasper the error still happens

System.TypeLoadException: Could not load type of field 'ShadowUtilityLIB.UI.Manager:<Windows>k__BackingField' (1) due to: Could not resolve type with token 0100002b (from typeref, class/assembly UnityEngine.UIElements.UIDocument, UnityEngine.UIElementsModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:UnityEngine.UIElementsModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:UnityEngine.UIElements.UIDocument member:(null) signature:<none>
  at SpaceWarp.Patching.LoadingActions.InitializeModAction.DoAction (System.Action resolve, System.Action`1[T] reject) [0x00000] in <903e43f16c5745be9d0911dfe1510a8f>:0 
stuck jasper
#

with the nuget package?

cyan terrace
#

yes this is from the BepInEx log

stuck jasper
#

i thought the error happened at compile time before, not at runtime?

#

did you delete the old Ksp2Uitk folders in the game and install the new ones?

stuck jasper
#

including in the patchers folder

cyan terrace
#

I have now

ebon seal
#

could it be that Shadow lib is getting loaded before UITK?

#

also isnt this the same isse that the guy was having earlier with referencing other assemblies?

stuck jasper
#

does it?

cyan terrace
stuck jasper
#

good

stuck jasper
#

to make sure UITK loads before the lib does

cyan terrace
#

it never uses any of the mod

stuck jasper
cyan terrace
#

because the mods that use shadow lib use the namespace ShadowUtilityLIB.UI stuff that uses using UnityEngine.UIElements;

stuck jasper
#

I'm talking about the library defining a dependency on the UITK mod

cyan terrace
#

thats all after every mod is loaded

#

UITK is required as it adds UnityEngine.UIElements;

stuck jasper
#

yes, and a situation can happen where ShadowUtilityLIB starts getting loaded by BepInEx before UITK does

#

which would result into an error

#

that's why the dependency definition is important

cyan terrace
#

that wont error as the UI stuff only is used after loading is done

ebon seal
stuck jasper
#

we literally had that same lengthy conversation yesterday with schlosrat and his soft dependency

cyan terrace
#

hey @stuck jasper, everything works. conversion went good.

ebon seal
#

🙏

cyan terrace
cyan terrace
#

Few questions.

  1. I set the background color to transparent, how do I change them other colors. such as hover, I dont see them in the style list.
  2. how do I fix the manipulator, the component was added after.
#

@stuck jasper ^

stuck jasper
#

good question, I haven't used the C# approach to building UI at all so I have no idea how styling works there, need to go research online

cyan terrace
#

ok will take another crack at it tomorrow then.

stuck jasper
#

from all the mentions of this I could find, it seems you have to use events

#

which sucks

cyan terrace
#

what the fuck, all I want to do is set the color to none

#

also that goes to a china site, an I blocked all of china rip

stuck jasper
#

oh yeah lmao

#

they have a separate Chinese site because of some local laws or whatever

#

and it often pops up in Google searches before the global one

cyan terrace
#

not sure if thats even what I need. I dont see it interacting with the hover color value

stuck jasper
#

there's no hover color value

cyan terrace
#

I cant access :hover it seems

stuck jasper
#

they just update the regular color style on hover

#

and then set it back when the pointer is not on the element

cyan terrace
#

looks like im going to have to add some custom reflections to shadowlib

stuck jasper
#
myElement.RegisterCallback<PointerEnterEvent>(evt =>
{
    (evt.currentTarget as VisualElement).style.backgroundColor = Color.clear;
});
myElement.RegisterCallback<PointerLeaveEvent>(evt =>
{
    (evt.currentTarget as VisualElement).style.backgroundColor = //original color;
});
#

that should be what you need

cyan terrace
#

or that

stuck jasper
#

that's literally what I just wrote

cyan terrace
stuck jasper
#

just using Mouse instead of Pointer

#

it's the same thing

cyan terrace
#

no the one I sent edits the :hover

stuck jasper
#

where?

#

I see this

cyan terrace
#

this one

#

I linked directly to it.

stuck jasper
#

try to open the link

#

it throws me to the post I screenshot

cyan terrace
#

It sends me to that text

#

are you using chrome or firefox

#

will test that stuff tomorrow

stuck jasper
#

oh lol

#

I just finished reading the code

#

it does in fact not edit any styles

#

nor does it allow you to

#

it just adds a custom way for setting the :hover state on an element

#

but you still don't have any way to style it

cyan terrace
#

Noooooooooooooooooooooooooooo

stuck jasper
#

the pseudoclasses just don't have their own styles

#

it's done dynamically

#

like in the code I wrote

#

it's just abstracted away nicely in USS

#

I can add an API for setting pseudoclass styles, but it will just use events in the background anyway

cyan terrace
#

so I looked deeper into it and TextField has an embedded textInput so doing this fixed it

stuck jasper
#

alright, good to know!

cyan terrace
#

you dont need the event stuff

#

just this by its self works

textField.textInput.style.backgroundColor = new StyleColor(new Color32(0, 0, 0, 0));
#

Still need to try and fix the drag manipulator issue

cyan terrace
#

Making a new drag manipulator with a definable deadzone.

stuck jasper
#

it's weird that it happens in the first place though

#

shouldn't the call to target.CapturePointer(evt.pointerId) make it so that the cursor "can't" leave the element?

cyan terrace
#

yes

cyan terrace
#

well the deadzone works

#
using UnityEngine;
using UnityEngine.UIElements;
using Logger = ShadowUtilityLIB.logging.Logger;

namespace Notebook.UI
{
    public class DragManipulator: IManipulator
    {
        private Logger logger = new Logger(NotebookMod.ModName, NotebookMod.ModVersion);
        public VisualElement _target;
        public Vector3 offset;
        public PickingMode Mode;
        public bool Dragging = false;
        public Vector2[] deadzone = new Vector2[0];
        public VisualElement target
        {
            get => _target;
            set
            {
                _target = value;

                _target.RegisterCallback<PointerDownEvent>(DragBegin);
                _target.RegisterCallback<PointerUpEvent>(DragEnd);
                _target.RegisterCallback<PointerMoveEvent>(PointerMove);
            }
        }

        public void DragBegin(PointerDownEvent evt)
        {
            if (evt.localPosition.x >= deadzone[0].x && evt.localPosition.x <= deadzone[1].x && evt.localPosition.y >= deadzone[0].y && evt.localPosition.y <= deadzone[1].y)
            {
                logger.Debug($"drag is in deadzone");
            }
            else
            {
                Mode = target.pickingMode;
                target.pickingMode = PickingMode.Ignore;
                offset = evt.localPosition;
                Dragging = true;
                target.CapturePointer(evt.pointerId);
            }
            
        }

        public void DragEnd(IPointerEvent evt)
        {
            target.ReleasePointer(evt.pointerId);
            Dragging = false;
            target.pickingMode = Mode;
        }
        public void PointerMove(PointerMoveEvent evt)
        {
            if (Dragging)
            {
                Vector3 delta = evt.localPosition - (Vector3)offset;
                target.transform.position += delta;
            }
        }
    }
}

if you want to make a deadzoneable one heres the code.

#

to apply it all you do is this.

cyan terrace
#

Currently trying to get a way to find the current XY position of a component so I can make dynamic deadzones

#

so far not had good luck

stuck jasper
#

I'll try to look into it once I get to a PC

cyan terrace
#

the only thing that outputs a position is yourVisualElement.worldBound and thats the world position, useless for doing stuff with child elements where you need the local. local gives you 0

ebon seal
#

how do i do this? i want to change the TextInput Text size

#

like not the font size, the width of the item

stuck jasper
#

you need to write some USS for it

ebon seal
#

oh ok, wtf why would it be locked under a new template?

stuck jasper
#

what do you mean?

#

this is like HTML and CSS

#

you have one file for markup and one for stylesheets

ebon seal
#

Oh yeah i thought u was saying i have to modify th stylesheet for that

stuck jasper
#

you can look at Theme/KerbalUI.uss at how I use the styles

#

basically let's say I want to edit the styles of the tracker part of a scrollbar inside a scroll view

#

this is the full hierarchy where #modlist-scrollview is my ScrollView element

#

so I would do something like this:

#modlist-scrollview .unity-scroller .unity-base-slider__tracker {
    /* my styles */
}
#

and you can find those class names in the inspector when you click on the individual elements in the hierarchy

#

it's not the most intuitive thing but basically I just go for the simplest possible selector with enough specificity to override the defaults lmao

ebon seal
#

so i want to add a field on TemplateContainer to control the label font size

stuck jasper
#

oh btw to get the full KSP window look, your root VisualElement needs to have the .root class

ebon seal
#

how tf do i do it? The whole thing is a template

#

Oh ok i wondered why it wasnt working lmao

stuck jasper
#

yeah, sorry, I haven't really bothered making a documentation yet because I expect a lot will still change

#

it's kinda all hanging on whether the devs respond to my question or not

#

so I've been waiting for that

ebon seal
#

oh lmao yeah i imagine

#

tho is there any way to add that on UITK?

#

ie a foldout template has the "Text" and "Value"

stuck jasper
#

I'm not sure I totally understand

#

I mean I kinda know what you're asking but I don't really get the use case

#

would you maybe mind hopping into vc for a sec?

ebon seal
#

i cant rn i'll go grocery shopping in a bit lmao

stuck jasper
#

np

#

just thought it'd go faster than typing 😄

ebon seal
#

its mostly IE if i want to make the label bigger and the inputs label (XYZ) smaller to add more contrast between then

#

then i just set LabelFontSize to 20 and InputLabelFontSize to 10

#

since labels aren't really automatically (else i could use just a 100% on Size.Height)

stuck jasper
#

why not just give them classes and set those values in the USS?

ebon seal
#

that might work lmao yeah, thx!

stuck jasper
#
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <Style src="ModListItem.uss" />
    <ui:VisualElement class="mod-item">
        <ui:Label class="mod-item-label" />
        <ui:Toggle class="toggle mod-toggle" />
    </ui:VisualElement>
</ui:UXML>

for example this is the full UXML for an item in the mod list

#

I dynamically instantiate this for each item in the list and assign the correct values to the label and toggle

#

and the ModListItem.uss file has all the styles based on the mod-item, mod-item-label and mod-toggle classes

#

basically with UITK you have to think like a web designer

ebon seal
#

im guessing you cant retroport features right?

#

it seems like theres already an editor for Animation Curves

#

i wanted to use that

#

or atleast an API that will make it easier to add an Animation Curve editor

#

tho this is fan, and it will look prettttyyyyyy

#

basically, Label will be partName, then you select a mesh on that partName (only will be listed the ones with the LFO module)

#

on select you get the infos, and each will have its way of editing (or not)

#

from top to bottom

  • Information - for info like State, Seed, etc
  • Button - to trigger something
  • Vector2
  • Vector3
  • Color - will open a color selecting GUI with swatches and Hex, RGB or HSV inputs (this might take a while to add, so i'll just start with the Hex)
  • Toggle
  • Animation Curve - Will open an animation curve editor where u can add Keyframes and adjust its time and value
  • Texture Selector - Will open a texture selector window with texture's previews and maybe a search function
  • Slider - for things like opacity and to test different Thrust and Atm
stuck jasper
ebon seal
#

oh :/ i guess i'll have to make one myself

cyan terrace
#

yep

stuck jasper
#

tbh I have a hard time understanding the whole nature of Unity packages

#

it doesn't make much sense to me

#

they act as if they're completely decoupled optional features which you can install into any version of Unity Editor, and to some degree they are

ebon seal
#

yeah thats how i see them

stuck jasper
#

they have their separate versioning scheme, you can use the same version of a package across different Unity versions

#

but then the majority of the features in the package actually depend on the actual version of Unity

#

like wtf

#

choose one or the other, not both

ebon seal
#

heh maybe they just coudlnt bother with going to older versions to do the needed changed for it to work

#

probably that only happens to deprecated versions at the time that they develop it?

#

ie they developed Vector API when 2019 was already deprecated

stuck jasper
#

yes, but it doesn't even work with 2021 which is in long term support

#

so they only add package features to the newest upcoming versions of Unity as far as I understand it

#

I just don't understand why they don't either a) make the package features completely independent of specific Unity versions (the package as a whole could still only be supported in specific versions, but not this bullshit where package version 19.1 works on 6 Unity versions but feature X only in 2021+ and feature Y only in 2022.1+, etc) or just b) make the packages completely dependent on the Unity version and don't do a separate versioning scheme and selective feature support

#

it's just dumb and not transparent at all

ebon seal
#

maybe if they just hmm

#

work with the oldest LTS maybe???

#

cuz im pretty sure that if they do that, any LTS or normal version after that will also work with the package

stuck jasper
#

they added the Vector API to 2022 when it was still in beta and 2021 was the actual latest released version

ebon seal
#

1 use for the thing i mentioned earlier

#

i want to change the FieldName to Throttle but i dont want to remove the instance reference

#

so that i can change then instance and it will update all changes except the FieldName content

#

no way to do this?

stuck jasper
#

wait what?

#

I really don't understand again, sorry

ebon seal
#

its ok lmao

#

ok so

#

i have the template for the sliders, as you can see i have 2 there, the 1st one is an instance of a template

#

i wonder if there's a way to add a "variable" to the template that i can change only for this instance

cyan terrace
#

Bindings is what you want.

ebon seal
#

But i want that here on the unity editor

#

not at runtime

ebon seal
#

yeah seems to be that? probably let me test

stuck jasper
#

you can make a custom element if you want custom fields in the editor

ebon seal
#

this will take some work since i have to build the UIs in code but it will be worth it i think

ebon seal
#

@stuck jasper so... toggles

#

are they not setup like KSP2 where its the big grey/green button?

#

as you can see this is the toggle default component with the theme

stuck jasper
#

the current UI is based on the action group manager

#

you need the toggle class on it

#

it was because other parts of the UI use toggles in the background, such as the foldout

#

and this was the easiest way to separate the two

ebon seal
#

hmm okok

#

thx :D

stuck jasper
#

I mean ngl it still kinda looks like shit, but very accurate to how it's in the game lmao

ebon seal
#

yeah i find it way too bright lmao

stuck jasper
#

tell them game devs to improve their UI

#

I just copied theirs

ebon seal
#

can i target another c# version PLEASE

#

im on assembly-csharp so idk if i can

#

but god those features are being missed rn

#

how tf do i do it?

stuck jasper
ebon seal
#

this project was created on unity

#

so no csproj afaik

stuck jasper
#

oh yeah I don't think Unity supports higher language level features sadly

#

yeah, C# 9 support came with 2021.2

ebon seal
#

i cant stress how much i like UITK

#

this looks so good and with so little effort

#

also will be pretty easy to implement

ebon seal
#

i lvoe experimental version of UITK

#

i add item to foldout, foldout doesnt update the size

stuck jasper
#

that's weird, haven't encountered that yet

ebon seal
#

might have to do with me settings a background texture via code

#

but i want to add texture previews so i need to do that

#

the texture is has its size, but the unity-content doesnt update

stuck jasper
#

you need the element that uses the texture as a background to have the height set

ebon seal
#

texture sizecontent size

#

it has!

#

i do element.StretchToParentWidth()
and then element.style.height = element.resolvedStyle.width * widthToHeightRatio

#

thus width being auto but height being set

#
            float widthToHeightRatio = texture.height / texture.width;
            AddToClassList(ussClassName);
            textureContainer = new VisualElement()
            {
                name = "lfo-texture",
            };
            //textureContainer.style.backgroundImage = new StyleBackground(ColorField.GenerateColorGradient(Color.red));
            textureContainer.style.backgroundImage = new StyleBackground(ColorField.GetHueGradient());
            textureContainer.AddToClassList(ussTextureContainerClassName);

            textureFoldout = new Foldout()
            {
                name = "LFO-textureFoldout"
            };
            textureFoldout.Add(textureContainer);
            textureFoldout.AddToClassList(ussFoldoutClassName);
            textureFoldout.RegisterCallback<GeometryChangedEvent>
                (
                evt =>
                {
                    textureContainer.StretchToParentWidth();
                    textureContainer.style.height = textureContainer.resolvedStyle.width * widthToHeightRatio;
                }
                );

            ValueContent.hierarchy.Add(textureFoldout);
#

it has to be set via that callback else it wont update since the widht and height is only calculated on the 1st frame and not in the initializer

#

already tried textureFoldout.MarkAsDirty() and no luck

ebon seal
#

coming back here for some better segregation of the content

#

if you add this to "Packages/com.unity.ui/Shaders/UIE-Runtime.cginc"

#

and package it it should work

#

if it doesnt then i'll write the ^2.3 thing

#

but this should be the "right" way to do things

#

actually let me clone your repo

#

great package manager is doing its thing....... it doenst load so i cant install uitk

stuck jasper
#

lol

ebon seal
#

can you build with that @stuck jasper ?

stuck jasper
#

Unity do be like that

#

yeah let me try

ebon seal
#

removed one last if else (that shouldnt be called but just in case)

stuck jasper
#

doesn't seem like anything has changed

ebon seal
#

fuck

#

aight i'll do the testing on my computer now

#

btw whats the version of spacewar that has that ui?

stuck jasper
#

1.2

#

it's all finished other than the Colors patch thingy

#

I can send you a build if you don't want to compile it yourself rn

ebon seal
#

no its ok it builds pretty quickly

#

thx tho!

stuck jasper
#

btw the way I approach the injection of the shader is just adding the default shader and the updated cginc file into my Assets folder in the SpaceWarpUI project, changing the #include path inside the shader to match the updated cginc file, then I just assign the shader to the kerbalui asset bundle, and then in the UitkForKsp2 project I load the kerbalui bundle and load the PanelSettings from it as usual, and then I also load the updated shader from it, assign it to PanelSettings.m_RuntimeShader, and register it to be used with the patched Shader.Find() method to be returned when Hidden/UIE-Runtime is requested

#

if you see any mistakes in that approach, feel free to correct me, but I'm pretty sure it works, because when I accidentally was assigning null to the PanelSettings and Shader.Find, I kept getting a spam of errors and no UI showed up, so I'd say that I'm putting it in the right places

ebon seal
#

its wierd because it should have worked... i'll try to remove all color from the shader

ebon seal
#

hmmmmmmmmmm

#

did everything except for this

stuck jasper
#

well that's weird, and you have the UI Toolkit package installed?

ebon seal
#

yup

#

i mean it installed automatically

stuck jasper
#

oh yeah duh, I have it in manifest.json

ebon seal
#

i'll try a reinstall maybe? idk

stuck jasper
#

you can try

#

but in the worst case scenario, just delete the .cs files

#

they're just for in-editor testing

ebon seal
#

oh ok yeah cuz the used ones are on spacewarp

stuck jasper
#

yeah

ebon seal
#

u use Thunderkit to build the asset bundles right?

#

forget just saw the "build asset bundles" on the context

stuck jasper
#

yeah

#

it's just the default script from Unity docs

#

though I have absolutely 0 idea why this isn't something that's built-in

ebon seal
#

no change, im guessing its not this shader

stuck jasper
#

hm

#

in the cginc file there's this #include "UnityCG.cginc"

#

maybe something in there?

#

or would that not matter with the test you did?

ebon seal
#

it wouldnt

#

the Runtime is suposedly the last one being called before showing the pixel

#

i wonder if UE shows the material used on uitk?

stuck jasper
#

so how the hell does one figure out which shaders are being used to render something munley

#

also why does it need this shader to exist?

ebon seal
#

well can be a shader stack

#

and if you remove one of them it goes to shit

stuck jasper
#

because something in UITK calls Shader.Find("Hidden/UIE-Runtime") multiple times

ebon seal
#

can very well be a "back bone" for it

stuck jasper
#

hm

ebon seal
#

actually from what i see

stuck jasper
#

this is fun

ebon seal
#

this is mostly a "is it text or not" shader

#

UIE_FRAG_T color = (isText && _FontTexSDFScale > 0.0f) ? texColor : texColor * IN.color;

#

this is what the cginc returns on the frag (basically the Main() of hlsl)

stuck jasper
#

it still doesn't make sense why your changes wouldn't show up at all

#

if this indeed gets used somewhere

#

then something should be affected, right?

ebon seal
#

depends a lot where this is used, they can be simply checking if the pixel in x,y has color or not, my changes only multiply the colors so that wouldnt affect it

#

(im trying now the all black pixels)

#

got too ambitious and tried first the ^2.3

stuck jasper
#

hehe

ebon seal
#

no change as well... Also actually runtime.cginc uses a custom class UIE_FRAG_T

#

so this is most deffinetly being used by another shader

#

welp let the fun begin

#

try to get what shader it is

#

but first let me push Colors update

#

btw can you send me the source for the shaders?

stuck jasper
#

which ones?

ebon seal
#

the repo, but u can also send all that you suspect are being used by UITK

stuck jasper
#

if you have the UITK package installed, they're in <Project>/Library/PackageCache/[email protected]/Shaders

#

there are no shaders committed in the repo, they come with the package

ebon seal
#

oh ok yeah

#

thx :D

#

what about the cgincs?

stuck jasper
#

also there

ebon seal
#

im blind

#

i hate the who .meta thing

#

that unity does

stuck jasper
#

lmao

ebon seal
#

because it clutters the folders so much

stuck jasper
#

you can also just browse them from inside Unity, that's at least a bit clearer

ebon seal
#

oh wtf yeah much better thx!

#

i wonder if theres a debugger for shaders...

#

there probably is but i doubt i would even know how ot work with it either way

stuck jasper
#

so just to make sure, I downloaded the source code for UITK and checked all usages of Shader.Find(...) and the only ones I can see are the ones in that folder

#

specifically these

#

though that doesn't necessarily mean it doesn't use other ones

ebon seal
#

yeah exactly

#

i'll check UnityCG now

#

this might be dumb but could the .dll also contain the cginc?

stuck jasper
#

nah

#

it's not .NET code

ebon seal
#

cuz its so wierd independently of what i do to the cginc nothing changes

#

lol

#

im guessing it auto imports, but removed the cginc from the assetbundle and it still works

stuck jasper
#

like in Asset Studio or something?

ebon seal
#

this way

stuck jasper
#

oh yeah the fact that the shader imports it means that the code in the cginc file is compiled into the resulting shader file I'm pretty sure

#

you can't even put it into a bundle separately

ebon seal
#

yeah makes sense

stuck jasper
#

if you wanted to test what happens if you leave it out, just comment out the #import lines

ebon seal
#

yeah it gives errors

stuck jasper
#

by the way how are you testing replacing the original shader with the modified one?

#

do you just replace the file in the PackageCache folder before building the bundle?

ebon seal
#

nono, i set it as the kerbalui asset bundle, change the #include and build the bundle

#

then replace the bundle with the on on uitk for ksp2

stuck jasper
#

that won't do anything

ebon seal
#

well that explains a lot

stuck jasper
#

since the original shader will still be included and used

ebon seal
#

do i need to replace the one on packagecache?

stuck jasper
#

yeah that's probably the easiest way to get around it

ebon seal
#

well that also explains

#

cuz i just tried to change the cginc in the package cache

#

and it was "re-downloaded" when i built the bundle

stuck jasper
#

those two added lines you can see is how I deal with it

#

in the testing build of UitkForKsp2

ebon seal
#

ohhh okok

#

yeah makes sense ur not using that on the released build xD

stuck jasper
#

yeah 😀

#

I can send you this version

ebon seal
#

do you have it on the repo?

stuck jasper
#

nope

#

it's just for local testing for now

ebon seal
#

oh xD i mean i already cloned the repo is it only that?

stuck jasper
#

yeah pretty much

ebon seal
#

if so i can just copy and paste

#

then just send me those 2 lines :D

stuck jasper
#
var runtimeShader = bundle.LoadAsset<Shader>("assets/theme/uie-runtime-custom.shader");
PanelSettings.m_RuntimeShader = runtimeShader;
#

ofc, substitute the name for your own filename

ebon seal
#

yeah, and all in lower i imagine

stuck jasper
#

yep

#

I mean I can't say I'm 100% convinced this works, but maybe like 80%? lmao

ebon seal
#

PROGRESS!!!

#

i think i can fix it now

stuck jasper
#

nice

ebon seal
#

@stuck jasper

#

is this what you wanted?

stuck jasper
#

fucking legend

ebon seal
#

if not i can just discard it

#

:D

cyan terrace
#

wow you fixed it

ebon seal
#

yeah unity (or maybe the game) seems to be setting the shader has a Linear space

#

instead of Gamma

#

i just forced gamma

stuck jasper
#

oh wow this isn't even the ^2.3 hack?

#

even cooler

ebon seal
#

nop

#

actually im sorry

#

color = UIE_V2F_COLOR_T(uie_gamma_to_linear(v.color.rgb), v.color.a);

#

the game seems to use linear

#

so i had to force it from gamma to linear

stuck jasper
#

interesting

ebon seal
#

theres some advantages on using linear on UI

stuck jasper
#

is this something that could possibly be done without modifying the shader manually?

#

like from the SpaceWarpUI Unity project settings or something?

ebon seal
#

maybe?

#

i would have to look into it cuz you'd need to define symbols inside cginc

#
    #ifdef UNITY_COLORSPACE_GAMMA
        #define UIE_COLORSPACE_GAMMA 1
    #else
        #define UIE_COLORSPACE_GAMMA 0
    #endif // UNITY_COLORSPACE_GAMMA
#endif // UIE_COLORSPACE_GAMMA```
#

basically set this to 0

#

let me check

stuck jasper
#

like there's this for example

ebon seal
#

oh

stuck jasper
#

but I don't know if that setting is taken into account when building bundles, or if it's just for the actual build of the game

ebon seal
#

well let me try

#

it might not be since this seems to be uitk specific

stuck jasper
#

but it did do this to my UI lmao

ebon seal
#

that

#

actually

#

might fix it lmao

#

let me build it like that w/o changes a sec

stuck jasper
#

I swear to god, if this turns out to be all I've had to do

#

spent like 2 months researching this issue on and off lmao

#

but I think that just setting this won't fix anything

ebon seal
#

blame it on the KSP2 devs for using linear space for the ui lmao

stuck jasper
#

it just gives me an accurate visualization of how it will look in the actual game

ebon seal
#

it might since it makes sense for bundles to take the player settings into account

stuck jasper
#

and I think we'll still need the shader update

stuck jasper
ebon seal
#

most games do render ui and the game separately to allow for things like what KSP2 does
gamma for the game and linear for the UI
so maybe?

#

yup

stuck jasper
#

hm, alright, didn't know about that

ebon seal
#

i think that all that you had to to muñix

stuck jasper
ebon seal
#

gotta double check if my changes to the cginc are not being loaded

#

deleted all uitk folders and pasted the ones on the latest version, then replaced the bundle lets see

stuck jasper
#

yeah it works

#

you were right

ebon seal
#

lmao

#

im glad we fixed this

stuck jasper
#

I just deleted all my "-custom" files, and the extra loading code in UitkForKsp2

#

just built the asset bundle exactly like it was with just that setting changed

ebon seal
#

btw @cyan terrace you might want to redo the colors for your mods for next update

#

yup xD

stuck jasper
#

I EVEN KNEW THAT SETTING EXISTED FOR MONTHS

#

how did I never actually try to change it

ebon seal
#

u never tried? xD

cyan terrace
ebon seal
#

its always the most basic settings lmao

cyan terrace
#

too many mods

ebon seal
#

suffering from success

stuck jasper
#

isn't it just used in 2 right now?

cyan terrace
#

no lol

ebon seal
#

i thought it was only cheats menu and notebook too

stuck jasper
#

the fact that this was the whole fcking fix

cyan terrace
#

what uses uitk atm
released:
cheats menu
notebook
countdown

unreleased:
Shadow multiplayer
S.T.A.G.E
KSP stat

ebon seal
#

lmao

ebon seal
#

tho idk if who's making the ui needs to update it as well

#

in the proj

#

probably not since the spacewarp ui probably is on gamma

stuck jasper
#

I mean I'm the only one making a UITK UI in Unity I'm pretty sure

#

Shadow just uses my C# API which uses the PanelSettings from the kerbalui bundle

#

and for others I'd recommend downloading the SpaceWarpUI project as a basis and going from there, anyway

#

since they need to get many of the files and change settings to match it

ebon seal
#

yeah its way easier also

stuck jasper
#

actually I want to include a barebones Unity project as part of a UITK template in SpaceWarp.Template

ebon seal
#

i do have one made on Unity but since it has custom elements idk if it will load properly

stuck jasper
#

now that UITK is finally ready for a 1.0 release

ebon seal
#

you should, and include Unity Tools with it

stuck jasper
#

thank you so much once again

ebon seal
#

np :D im glad it worked

stuck jasper
#

I'd probably leave that for a separate part mod template

cyan terrace
#

welp now my dev queue looks like this
KSP stat
countdown
notebook
Shadow Utility Lib
cheats menu
Shadow mods site
Shadow multiplayer

ebon seal
#

oh yeah if youre making a separate one yeah

ebon seal
cyan terrace
#

how do I clone my self?

ebon seal
#

Instantiate()

stuck jasper
#

once I get to it I'll probably have to bother you again for a bit of advice

#

since I haven't actually done anything with part modding myself

ebon seal
cyan terrace
stuck jasper
#

isn't it fun taking on an excessive number of projects

#

lmao

ebon seal
#

i gotta update to windows 11 just for this

cyan terrace
stuck jasper
#

one thing I'd still like to figure out before I'm completely happy with UitkForKsp2 is providing custom elements for external mods

#

but I suspect that will be nowhere near this easy and might involve some heavy Harmony patching

#

to make the VisualTreeAsset be able to see the controls' types when they're loaded into the game

ebon seal
#

oh they're currently not working yeah

#

fuck my TUX's rewrite to UITK heavly depends on them

stuck jasper
#

it seems like they only work when the assembly you include them in is built in the same Unity project as the asset bundles that contain the UXML

#

at least that's my current assumption

ebon seal
#

thats easy to do no?

#

use the unityproj as your .netproj

stuck jasper
#

well in my case it meant I had to have a reference to the game's DLL in my Unity project, which in turn meant dependency hell where I spent like 2 hours trying to get the project to build

#

and even then it didn't work in the end lmao

#

also tried with ThunderKit but encountered some other issues there, can't remember what exactly it was right now

ebon seal
#

heh, either way that can be left for later i think since most people wont use them

stuck jasper
#

the one thing I really want them for is localization

#

so that instead of <ui:Label text="my text"/> you can use something like <KerbalUI.Controls.IntlLabel text="SpaceWarp/ModList/Title"/> and it will automatically localize it

#

I do have an interim solution but that's kinda ugly

ebon seal
#

yeah that be pretty cool

#

i imagine its reflection hell

stuck jasper
#

I mean it could be worse

ebon seal
#

heh i mean it works

#

it depends on how much it gets called but i'd guess not that mcuh

stuck jasper
#

basically it recursively goes through all elements in a UIDocument once, and if the element has a text property and its value starts with #, I save the element and the associated localization key, and then update the text value with the actual translation

#

and it only needs to be re-run whenever the language of the game changes

#

or you can trigger a change manually when you want to update some element's text

ebon seal
#

yeah it works, but it would be better with custom elements yeah

#

iirc it complains about not finding the class

stuck jasper
#

yep

ebon seal
#

so maybe its an issue like what schlosrat was having?

#

probably with reflection and fully qualified assembly names (of the classes) it should work

stuck jasper
#

#🔴space-warp message

#

the thing is, I can't seem to find any notion of the assembly names actually being used

#

when you open the UXML asset in Asset Studio, it just has some property like
class: "KerbalUI.Controls.IntlLabel"

#

and nowhere in the file is there any reference to an assembly

ebon seal
#

maybe thats the problem

#

its expecting the class to be in the assembly-csharp

#

so it doesnt need a reference

stuck jasper
#

but then if it used reflection to find the class, it would find it that way

ebon seal
#

just with that?

#

thats wierd

stuck jasper
#

maybe?

#

actually I'm not sure anymore lmao

ebon seal
#

actually it isn't, because you can get classes that are loaded like that

#

even if from different assemblies

#

the thing is, probably, uitk is using the assembly when getting the class to avoid conflicts

stuck jasper
#

yeah it's basically what I meant by the Harmony patching

#

finding the place where it's actually trying to instantiate the classes and patching it

ebon seal
#

well it would be just 1 patch (maybe)

#

let me see if i can find it

stuck jasper
#

hopefully lmao

ebon seal
#

Not sure which platform you are building for, but you may need add to add the [Preserve] attribute to your AbilityUIElement class if your are building for IL2CPP. UI Toolkit uses reflection to discover types used by UXML.

stuck jasper
#

not IL2CPP

#

KSP 2 is Mono

#

well at least it wasn't too hard to find the relevant code

ebon seal
#

lol didnt even think to look for that

#

tell me u have an uxml factory there

stuck jasper
#

I do

ebon seal
#

oh ok lmao

#

maybe a transpiller?

stuck jasper
#

most of the code is just copied over from the Unity docs examples

#

so I'm pretty sure I have all I need for it to work

#

I'll look into it in a bit, now I need to release UitkForKsp2 1.0 with the new bundle so that we can release SW 1.2 with it as a dependency

ebon seal
#

also maybe include it in the zip

#

for github and spacedock

stuck jasper
#

wdym?

#

I mean that's what I mean by "release it"

#

since there are no other changes other than that one bundle

ebon seal
#

oh ok io thought u were only gonna release the mod and then put on the description

stuck jasper
#

nope the release always contains the kerbalui bundle

#

I just don't include it in the source code in the repo

#

because the source for it is available in the git submodule in the repo

#

though wait a sec

#

I should migrate UitkForKsp2 to the new 1.2 template if I'm going to be releasing 1.0

#

no better time for it

ebon seal
#

true, i think you should

ebon seal
#

@stuck jasper can we debug this with DnSpy?

#

by this i mean UITK

stuck jasper
#

yeah, should be able to

ebon seal
#

thats funny

#

its ending here
if (!(CS$<>8__locals1.asset.fullTypeName == "UXML"))

#

and entering this if

#

the one i just sent is the decompiled version of this
else if (asset.fullTypeName == UxmlRootElementFactory.k_ElementName)
Which when decompiled turns into the inverse for some reason(probably optimizations?)

stuck jasper
#

why is UxmlRootElementFactory.k_ElementName "UXML"?

ebon seal
#

i think its a constant? let me check

#

exactly
internal const string k_ElementName = "UXML";

stuck jasper
#

then what's happening inside it?

ebon seal
#

what im guessing is that the fullTypeName is not being loaded because the Class is not being loaded

#

similar to what happened to my custom classes on switcharo

#

but i might be wrong tho i'll keep investigating

stuck jasper
#

if you mean the property fullTypeName, that's definitely loaded

ebon seal
#

yeah but not properly it seems, it should be as "UXML"

stuck jasper
#

why??

ebon seal
#
                else if (asset.fullTypeName == UxmlRootElementFactory.k_ElementName)
                {
                    // Support UXML without namespace for backward compatibility.
                    VisualElementFactoryRegistry.TryGetValue(typeof(UxmlRootElementFactory).Namespace + "." + asset.fullTypeName, out factoryList);
                }
                else
                {
                    return CreateError();
                }
#

it needs to enter that if

stuck jasper
#

well what's the actual "if"

#

before the "else if"?

ebon seal
#

oh thats to check if its a unity class let me get it

#
                if (asset.fullTypeName.StartsWith("UnityEngine.Experimental.UIElements.") || asset.fullTypeName.StartsWith("UnityEditor.Experimental.UIElements."))
                {
                    string experimentalTypeName = asset.fullTypeName.Replace(".Experimental.UIElements", ".UIElements");
                    if (!VisualElementFactoryRegistry.TryGetValue(experimentalTypeName, out factoryList))
                    {
                        return CreateError();
                    }
                }
                else if (asset.fullTypeName == "UnityEditor.UIElements.ProgressBar")
                {
                    string runtimeTypeName = asset.fullTypeName.Replace("UnityEditor", "UnityEngine");
                    if (!VisualElementFactoryRegistry.TryGetValue(runtimeTypeName, out factoryList))
                    {
                        return CreateError();
                    }
                }
                else if (asset.fullTypeName == UxmlRootElementFactory.k_ElementName)
                {
                    // Support UXML without namespace for backward compatibility.
                    VisualElementFactoryRegistry.TryGetValue(typeof(UxmlRootElementFactory).Namespace + "." + asset.fullTypeName, out factoryList);
                }
                else
                {
                    return CreateError();
                }
stuck jasper
#

what the fuck is it doing

ebon seal
#

as you can see, at least from my prespective thats only checking to see if thats an unity class

#

then it check if its a progress bar

stuck jasper
#

the fullTypeName is for example KerbalUI.Controls.IntlLabel

ebon seal
#

then it checks if its a custom class

stuck jasper
#

why should it ever be equal to "UXML"?

ebon seal
#

hmm

#

that makes me wonder

#

are consts overrideable?

#

no right?

stuck jasper
#

no

ebon seal
#

i agree with you it makes no sense

stuck jasper
#

they don't really exist in compiled files, they're replaced by their values in the places where they're used

ebon seal
#

im guessing that

#

in a regular enviroment, all custom elements get converted into UnityEngine.Experimental.UIElements

#

since Custom Elements were an experimental feature back in the day

stuck jasper
#

might be a good idea to actually build an empty Unity game with UITK and a custom element, and debug it from there

#

to see what's different

ebon seal
#

cuz this makes no sense
typeof(UxmlRootElementFactory).Namespace + "." + asset.fullTypeName

#

yeah i dont have one i was hoping u still had yours 😅

#

i do have a couple but i dont have a UITK project ready to instantiate them

stuck jasper
#

I mean you can just do that with the SpaceWarpUI repo

#

just add a custom element class and build the game

ebon seal
#

oh it still has the custom ones?

#

oh ok yeah

#

ok let me try it

stuck jasper
ebon seal
#

i'll just straight up copy it

#

the example

ebon seal
#

i was busy with some other things but back at this

#

the wierdest part about this is that
VisualElementFactoryRegistry.TryGetValue(typeof(UxmlRootElementFactory).Namespace + "." + CS$<>8__locals1.asset.fullTypeName, out list);

#

is ALWAYS going to search for the same thing

#

its always going to search for UnityEngine.UIElements.UXML

#

which seems kinda dumb if you ask me

stuck jasper
#

yeah that doesn't make any sense

ebon seal
#

WELL ACTUALLY it makes sense since you're providing it with the visual tree asset

#

basically what ur saying is
"look for a UXML on the VisualElementFactoryRegistry of this visual tree asset"

#

UXML being the root visual element of any UITK element

#

but the custom elements seem to be passing their type as the root

stuck jasper
#

it even goes against their own naming conventions

#

UXML vs UxmlFactory

#

for example

ebon seal
#

well true...

#

i'm gonna see what that dictionary has in their values/keys

#

if it does have the class name i'll transpile it

#

to bypass that if else

#

that is if unity doesnt do this......

stuck jasper
ebon seal
#

interesting

stuck jasper
#

it seems to me that we could easily fix this with a postfix of VisualElementFactoryRegistry.RegisterEngineFactories()

ebon seal
#
        internal static void RegisterUserFactories()
        {
            HashSet<string> hashSet = new HashSet<string>(ScriptingRuntime.GetAllUserAssemblies());
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (hashSet.Contains(assembly.GetName().Name + ".dll") && !(assembly.GetName().Name == "UnityEngine.UIElementsModule"))
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (typeof(IUxmlFactory).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract && !type.IsGenericType)
                        {
                            VisualElementFactoryRegistry.RegisterFactory((IUxmlFactory)Activator.CreateInstance(type));
                        }
                    }
                }
            }
        }
#

well that wouldnt work

#

you need to patch the if else

stuck jasper
#

you wouldn't

#

because the top if wouldn't be false

ebon seal
#

well yeah

#

tbf its mostly my preference to not use the engine's path

stuck jasper
#

(this I mean: if (!VisualElementFactoryRegistry.TryGetValue(asset.fullTypeName, out factoryList)))

ebon seal
#

and instead use the path that is supsed to

#

but it would work yeah

stuck jasper
#

I mean not the if that is highlighted but the one above

#

that doesn't have anything to do with the engine paths

ebon seal
#

oh yeah i mean yeah

#

if its entering that if it means that it doesnt have the class somehow

#

i totally overlooked that

stuck jasper
#

sorry lmao that was a really dumb screenshot

ebon seal
#

np xD i mean yeah either the class is not present or the name is different

#

only if unity collaborated with me :)

#

speaking of that i think it just did lol

stuck jasper
#

and speaking of RegisterUserFactories, we know where the issue is now

#

HashSet<string> userAssemblies = new HashSet<string>(ScriptingRuntime.GetAllUserAssemblies());

ebon seal
#

Scripting runtime?

#

lmao

stuck jasper
#

I'm pretty sure this filters out all our assemblies

#

and only uses the game ones

ebon seal
#

want me to write and transpiller for that?

#

just tell me what i should put there xD

stuck jasper
#

well, we could probably just postfix ScriptingRuntime.GetAllUserAssemblies()

#

and add UitkForKsp2.dll to the list set

ebon seal
#

well yeah

#

huh maybe we need more than just UITKforKSP2

#

i mean each custom element will be in its own .dll

stuck jasper
#

we could put in all the BepInEx plugins' assemblies

ebon seal
#

that'd be better imo

#

else i kinda couldnt use it xD

#

and any other modder

stuck jasper
ebon seal
#

Sorry i mean each mod will have its own .dll with custom elements inside

stuck jasper
#

oh ok

ebon seal
#

not 1 dll per element

#

how do we get all BepInEx's assemblies?

#

(without iterating through every folder)

stuck jasper
#

Chainloader.Plugins.Select(plugin => plugin.GetType().Assembly).ToList();

ebon seal
#

on it

#

i'll pr the change in a bit

#

good eye on that RuntimeFactories thing btw

#
public static class RegisterBepInExFactoriesPatch
{
    [HarmonyPostfix]
    [HarmonyPatch(typeof(VisualElementFactoryRegistry), nameof(VisualElementFactoryRegistry.RegisterUserFactories))]
    public static void RegisterBepInExFactories(ref string[] __result)
    {
        __result = __result.AddRangeToArray(Chainloader.Plugins.Select(plugin => plugin.GetType().Assembly.FullName).ToArray());
    }
}
#

smth like this i guess

#

it wants this format

    "mscorlib",
    "System",
    "System.Core",
    "System.Security.Cryptography.Algorithms",
    "System.Net.Http",
    "System.Data",
    "System.Runtime.Serialization",
    "System.Xml.Linq",
    "System.Numerics",
    "System.Xml",
    "System.Configuration",
    "ExCSS.Unity",
    "Unity.Cecil",
    "Unity.CompilationPipeline.Common",
stuck jasper
#

it has to be on ScriptingRuntime.GetAllUserAssemblies()

ebon seal
#

yeah thx lmao

stuck jasper
#

Chainloader.Plugins.SelectMany(plugin => plugin.GetType().Assembly.GetFiles()) .Select(file => Path.GetFileNameWithoutExtension(file.Name));

#

is probably what you want

ebon seal
#

huh

#

fullname returns the .dlk with it

#

didnt know about that

#

actually

#

idk if its the namespace name

#

or the actual .dll file name

stuck jasper
#

yeah it gives you the namespace, not the filename

#

which is why I went the route of ...Assembly.GetFiles()...

#

(that was before I changed Path.GetFileName to Path.GetFileNameWithoutExtension)

ebon seal
#

yeah makes sense

#

i'll try with the SpaceWarp.dll on the unity proj

stuck jasper
#

hopefully this is what we need

ebon seal
#

to see if i can load the visual element from a dll instead of an cs file inside unity

#

seems like it

stuck jasper
#

how are you dealing with the dependencies?

ebon seal
#
        [MethodImpl(MethodImplOptions.InternalCall)]
        public static extern string[] GetAllUserAssemblies();
ebon seal
#

we should have a lib on SpaceWarp or smth like that to deal with dependencies

stuck jasper
#

yeah I just mean that for me a Unity project with SpaceWarp.dll won't compile unless I carefully cherrypick most of the KSP 2 folder of dependencies

ebon seal
#

oh no yeah i mean

#

i was able to put SORRY's dll on my unity proj

#

with some configs on the .dll importing

#

let me see if ican do the same a sec

stuck jasper
#

interesting

ebon seal
#

and i think that it would be the same for SpaceWarp since SORRY depends on SpaceWarp

#

so the dependencies should be the same if not more

stuck jasper
#

I would use ThunderKit but it doesn't allow you to play a scene

#

which sucks if you're working on UI

ebon seal
#

you can test UITK w/o hitting play tho

#

not the custom elements but if you set up the custom elements right you can set their values inside the UI Builder

stuck jasper
#

well, not fully, for example the SpaceWarp mod list is mostly empty and items are dynamically added in the C# scripts

#

you can't preview that in UI Builder

#

only in play mode

ebon seal
#

im pretty sure ThunderKit was suposed to allow for play mode

#

huh

stuck jasper
#

it just crashes Unity for me

ebon seal
#

@stoic bane wasnt it?

stuck jasper
#

even with just empty ThunderKit and KSP 2 imported

stoic bane
#

Its theoretically possible in the right circumstances

#

But ksp2 doesn't meet those circumstances

stuck jasper
#

yeah, sadly

stoic bane
#

I was able to do itnwith ror2, but I had to reimplement stuff still

#

But it was possible because ror2 has 100% of its assets in Addressables

stuck jasper
#

I really like the idea of developing mods in Unity, but when you combine the fact that I can't preview UI in play mode, and Unity doesn't support modern versions of C#, just makes it not worth it for me

ebon seal
#

tho its a bit wierd since we dont really have any KSP2 functionality on unity do we?

stoic bane
stuck jasper
#

I just have separate Unity projects for UI bundles and then C#-only projects for the mod code

ebon seal
#

but i think you can also populate it with the UXMLFactory

stoic bane
#

Make design time data fakes

ebon seal
#

yeah i think you can do that

stuck jasper
#

but it makes the whole developing pipeline much more complicated

ebon seal
#

also why not try a [RunInEditMode]?

stuck jasper
#

either I can have fake data in the list and see it in the UI Builder preview, or I can have it be done dynamically like in the real use case and I can just change some values and immediately build my bundles

#

I mean I already made a whole mock SpaceWarp.dll which contains fake data for the mod list monobehaviors

#

so I can easily preview the list functionality in play mode

ebon seal
#

i mean i think that as long as you keep the same assembly name you can use both the mock and the SpaceWarp's class no?

stuck jasper
#

and still keep the actual UXML assets exactly as they're used in the game

ebon seal
ebon seal
#

since it loads through the name

#

so if you make SpaceWarpMock to be SpaceWarp (this being the assembly name)

#

UITK wouldnt know the difference between the mock and the original

stuck jasper
#

oh yeah that's how it works

#

I'm using the same assembly name and namespaces and everything

ebon seal
#

oh great then that should work yeah

#

then i think theres no need for thunder kit

#

tho its a bit more work to keep both custom controls the same

#

both the mock and the code's custom control

#

maybe add a convention to keep a modId.UITK.dll?

#

and custom load it?

#

tbh thats even worse lmao

stuck jasper
#

but then it won't show up in Chainloader.Plugins

ebon seal
#

oh true

#

and also you'd need to still sync it with the project's class

stuck jasper
#

btw have you tested this? iirc, you can't just patch a native method easily

#

(the PR i mean)

ebon seal
#

...

#

brb

#

lmao

#

im doing like 3 projects at the same time

stuck jasper
#

afaik, it basically completely replaces the method and the original won't run

ebon seal
#

if so i'll transpile the UITK's RegisterUserFactories

#

to after getting all assemblies, add the BepInEx's also

stuck jasper
#

I'm almost done with it, no worries

#
[HarmonyPatch]
public static class CustomElementsPatch
{
#pragma warning disable CS0618
    [HarmonyPatch(typeof(VisualElementFactoryRegistry), nameof(VisualElementFactoryRegistry.RegisterUserFactories))]
    [HarmonyPostfix]
    public static void VisualElementFactoryRegistry_RegisterUserFactories()
    {
        Chainloader.Plugins
            .SelectMany(plugin => plugin.GetType().Assembly.GetTypes())
            .Where(type => typeof(IUxmlFactory).IsAssignableFrom(type)
                           && !type.IsInterface
                           && !type.IsAbstract
                           && !type.IsGenericType)
            .ToList()
            .ForEach(type =>
            {
                var factory = (IUxmlFactory)Activator.CreateInstance(type);
                VisualElementFactoryRegistry.RegisterFactory(factory);
            });
    }
#pragma warning restore CS0618
}
#

does that look ok to you?

ebon seal
#

it does but let me double check with the og code

#
        internal static void RegisterUserFactories()
        {
            HashSet<string> hashSet = new HashSet<string>(ScriptingRuntime.GetAllUserAssemblies());
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (hashSet.Contains(assembly.GetName().Name + ".dll") && !(assembly.GetName().Name == "UnityEngine.UIElementsModule"))
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (typeof(IUxmlFactory).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract && !type.IsGenericType)
                        {
                            VisualElementFactoryRegistry.RegisterFactory((IUxmlFactory)Activator.CreateInstance(type));
                        }
                    }
                }
            }
        }
#

pasting here for eassier comparison

stuck jasper
#

is that decompiled?

ebon seal
#

nop

#

source

#

BUT

stuck jasper
#

oh, I was just wondering because it's different from my source, lmao

ebon seal
#

i think this is old source

#

theres 2 uitk repos

stuck jasper
#

one is very outdated and one is much newer than our version

#

from what I've seen

#

lmao

ebon seal
#

and this

#

yeah but tbf we need to look at the outdated one

#

since were on a old version

ebon seal
stuck jasper
#

the exact code that our version is using is in SpaceWarpUI/Library/PackageCache/[email protected]/Core

ebon seal
#

thats the source u have?

stuck jasper
#
internal static void RegisterUserFactories()
{
    // In the Player, we filter assemblies to only introspect types of user assemblies
    // which will exclude Unity builtin assemblies (i.e. runtime modules).
#if !UNITY_EDITOR
    HashSet<string> userAssemblies = new HashSet<string>(ScriptingRuntime.GetAllUserAssemblies());
    var assemblies = AppDomain.CurrentDomain.GetAssemblies();
    foreach (Assembly assembly in assemblies)
    {
        if (!(userAssemblies.Contains(assembly.GetName().Name + ".dll"))
            // Exclude core UIElements factories which are registered manually
            || assembly.GetName().Name == "UnityEngine.UIElementsModule")
            continue;

        var types = assembly.GetTypes();
        foreach (Type type in types)
        {
            if (!typeof(IUxmlFactory).IsAssignableFrom(type)
                || type.IsInterface
                || type.IsAbstract
                || type.IsGenericType)
                continue;

            var factory = (IUxmlFactory)Activator.CreateInstance(type);
            RegisterFactory(factory);
        }
    }
#endif
}
#

yep

#

all the packages' sources are in PackageCache

#

lmao

ebon seal
#

i'll delete my pr 🥲

#

xD

stuck jasper
#

😅

#

I still very much appreciate all the assistance and having someone to bounce ideas off of each other

ebon seal
#

xD thats what im here for

#

u already help me a lot with my mods so just giving back MisatoPray

#

i think thats all for UITK then

#

now its just a matter of adding custom controls that people can use like the intlabel

stuck jasper
#

well, for me the biggest thing for now is the game fonts

ebon seal
#

lets make someone pay for them Evilll

stuck jasper
#

I can get the TMP_FontAsset for them, but UITK doesn't use TMP

#

but since TextCore is basically a direct descendant of TMP, I think it should be possible to "convert" it

#

aka just copy all the relevant properties into an instance of TextCore FontAsset

ebon seal
#

i think if we dig into the TMP_Font conversion we can reverse engineer it

#

since on unity you can convert fonts from .font to TMP_Font

#

line 1733
private void UpgradeFontAsset()

stuck jasper
#

lmao I see it's the same thing I was suggesting