Skip to content
cfloutier edited this page Apr 29, 2024 · 16 revisions

This set of controls is used by the K2D2 Kerbal Space Program 2 mod

image

The repo contains all the code needed to build your own mod using the UI Controls found in K2D2

You can find an exemple of use of each the controls in this repo : https://github.com/cfloutier/test_k2ui I use it to test the UI behavior before using it in KSP 2

Installation

test K2UI controls

  1. : create the mod with the @munix template builder : https://github.com/SpaceWarpDev/SpaceWarp.Template

Follow the Readme.md instructions. It worked like a charm for me

  1. : add K2UI as a sub module in the src/yourMod.Unity/yourMod.Unity/Assets/Runtime folder
  2. : the K2UI needs Newtonsoft.Json, it is included in Kerbal Main Game But should be added in your Unity Project

edit : src/test_k2ui.Unity/test_k2ui.Unity/Packages/manifest.json

and add the line in the modules definition

    "com.unity.nuget.newtonsoft-json": "2.0.0"

Then Open the Unity Project : src/yourMod.Unity/yourMod.Unity

Open the packageManager. Add the git package : https://github.com/JamesNK/Newtonsoft.Json.git

using it as a package

This repo can not yet be used as a Unity package or a dependendency Mod in SpaceDock.

Dor the moment I just add it as a sub module in my projects. But this can change if I find a better way to deal with dependencies.

You can directly use as git subModule like described upper, or fork it to adjust it to your uses. It can be a good starting point for a bigger set of tools.

And Pull Request would be fully appreciated. Thanks in advance.

UI Builder

All controls are fully editable in the UI Builder.

Creates a new Visual Tree Asset

image

Controls

Uss

please use the KerbalUI Theme

And include the K2UI.uss file in your xml tree definition.

This uss defines global variables and includes all others uss that is used by all controls. Complex controls could have it's own uss file ex : K2Toggle.uss or K2Compas.uss

to edit those file I adds them to the UIBuilder. But only the main K2UI.uss is needed for your own UI file.

KTools

Ktool are a set of classes used by the Controls

  • Settings : a set of class used to bind values with controls and save it to local disc as player preferences.
  • ColorTools : A set of tools for colors
    • Convert colors from and to htlml codes. with parseColor and formatColorHtml
    • Create gradients and color colections with getRandomColorArray and getRainbowColorArray
    • use Hue Saturation Value space to and adjust colors with FromHSV, ToHSV and changeColorHSV
  • Extensions : A set of Function that extends standard cs primitives
  • ReflexionTool : tools to call reflexion. It is used to call private and protected functions and to access properties. Useful to call 'forbidden' interanl fucntion from the main game (Ksp2 main engine)
  • StrTools a set of tools used to convert to string different kind to values : like Duration, Distances and Vectors

Clone this wiki locally