diff --git a/.idea/.idea.UitkForKsp2/.idea/vcs.xml b/.idea/.idea.UitkForKsp2/.idea/vcs.xml
index 35eb1dd..b3d2d9f 100644
--- a/.idea/.idea.UitkForKsp2/.idea/vcs.xml
+++ b/.idea/.idea.UitkForKsp2/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/Directory.Build.props b/Directory.Build.props
index 0001fcb..ba32962 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -15,9 +15,10 @@
$(MSBuildThisFileDirectory)
- $(SolutionDir)build/bin
- $(SolutionDir)build/bin/$(MSBuildProjectName)
- $(SolutionDir)build/obj/$(MSBuildProjectName)
+ $(SolutionDir)build/bin/plugin
+ $(SolutionDir)build/bin/patcher
+ $(PluginBinPath)/$(MSBuildProjectName)
+ $(SolutionDir)build/obj/plugin/$(MSBuildProjectName)
$(MSBuildProjectName)
$(AssemblyName)
$(NoWarn);CS0436;NU5125
@@ -31,33 +32,29 @@
-
- 2.1.1
-
-
-
+
-
-
-
@(Swinfo -> '%(mod_id)')
- @(Swinfo -> '%(version)')
@(Swinfo -> '%(version)')
+ $(Version.Substring(0, $(Version.IndexOf('-'))))
@(Swinfo -> '%(name)')
@(Swinfo -> '%(author)')
@(Swinfo -> '%(description)')
git
@(Swinfo -> '%(source)')
+ $(ModId)
+ $(Product)
+ $(Version)
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 1be1f19..6f879e1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,14 +1,3 @@
-Unity plugins are licensed under under the Unity Companion License for
-Unity-dependent projects--see [Unity Companion
-License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
-
-Unless expressly provided otherwise, the Software under this license is made
-available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED. Please review the license for details on these and other terms and
-conditions.
-
-UITK for KSP 2 is licensed under the MIT License reproduced below:
-
Copyright (c) 2023 Jan Bureš (munix)
Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/Package.nuspec b/Package.nuspec
new file mode 100644
index 0000000..f1f70ee
--- /dev/null
+++ b/Package.nuspec
@@ -0,0 +1,24 @@
+
+
+
+ $id$
+ $version$
+ $authors$
+ false
+ https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/LICENSE
+ $description$
+ ksp ksp2 mod library
+ $repositoryUrl$
+
+ README.md
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/plugin_template/swinfo.json b/plugin_template/swinfo.json
index 8636c13..358969d 100644
--- a/plugin_template/swinfo.json
+++ b/plugin_template/swinfo.json
@@ -5,7 +5,7 @@
"name": "UITK for KSP 2",
"description": "Unity UI Toolkit support for KSP 2 and an accompanying API.",
"source": "https://github.com/jan-bures/UitkForKsp2",
- "version": "2.1.1",
+ "version": "2.2.0",
"version_check": "https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.1.5",
diff --git a/src/UitkForKsp2.Controls/UitkForKsp2.Controls.csproj b/src/UitkForKsp2.Controls/UitkForKsp2.Controls.csproj
index a25d5c8..ed63338 100644
--- a/src/UitkForKsp2.Controls/UitkForKsp2.Controls.csproj
+++ b/src/UitkForKsp2.Controls/UitkForKsp2.Controls.csproj
@@ -1,27 +1,5 @@
-
-
- true
- true
- false
-
-
- $(MSBuildProjectName)
- https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/LICENSE
- $(SolutionDir)/nuget
- https://github.com/jan-bures/UitkForKsp2
- README.md
- ksp2;mod;library
-
-
-
-
-
-
-
-
-
diff --git a/src/UitkForKsp2/API/Extensions.cs b/src/UitkForKsp2/API/Extensions.cs
index 6cdec7b..644b183 100644
--- a/src/UitkForKsp2/API/Extensions.cs
+++ b/src/UitkForKsp2/API/Extensions.cs
@@ -5,9 +5,7 @@
namespace UitkForKsp2.API;
-///
-/// Contains extension methods for UI Toolkit documents and elements.
-///
+///
+ /// Enables the F2 hiding functionality for a visual element.
+ ///
+ /// The visual element to enable hiding for.
+ /// The type of the visual element.
+ /// The visual element with the hiding functionality enabled.
+ public static T EnableHiding(this T element) where T : VisualElement
+ {
+ element.AddManipulator(new HideManipulator());
+ return element;
+ }
+
///
/// Automatically localize elements in a document. Only elements with a string property "text" whose value is a
/// localization key starting with '#' will be localized.
diff --git a/src/UitkForKsp2/API/HideManipulator.cs b/src/UitkForKsp2/API/HideManipulator.cs
new file mode 100644
index 0000000..f20ca8b
--- /dev/null
+++ b/src/UitkForKsp2/API/HideManipulator.cs
@@ -0,0 +1,52 @@
+using KSP.Game;
+using KSP.Input;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+namespace UitkForKsp2.API;
+
+///
+/// Allows hiding a VisualElement with the F2 key.
+///
+public class HideManipulator : IManipulator
+{
+ private bool _isHidden;
+ private DisplayStyle _originalDisplayStyle;
+
+ private VisualElement _target;
+
+ ///
+ /// The target element that will be hidden.
+ ///
+ public VisualElement target
+ {
+ get => _target;
+ set
+ {
+ var game = GameManager.Instance.Game;
+ if (game.InputManager.TryGetInputDefinition(out var definition))
+ {
+ Debug.Log("HideManipulator: Binding ToggleHidden to GlobalInputDefinition");
+ definition.BindAction(game.Input.Global.ToggleUIVisibility.name, ToggleHidden);
+ }
+ _target = value;
+ }
+ }
+
+ private void ToggleHidden()
+ {
+ if (_isHidden)
+ {
+ Debug.Log("HideManipulator: Unhiding.");
+ _isHidden = false;
+ _target.style.display = _originalDisplayStyle;
+ }
+ else
+ {
+ Debug.Log("HideManipulator: Hiding.");
+ _isHidden = true;
+ _originalDisplayStyle = _target.style.display.value;
+ _target.style.display = DisplayStyle.None;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UitkForKsp2/API/Window.cs b/src/UitkForKsp2/API/Window.cs
index 730b75d..6f1bf89 100644
--- a/src/UitkForKsp2/API/Window.cs
+++ b/src/UitkForKsp2/API/Window.cs
@@ -15,17 +15,20 @@ public static class Window
/// Creates an empty UIDocument with a pre-styled root element.
///
/// Pre-styled root element of the UIDocument.
+ /// Should window hiding with F2 be enabled?
/// Unique ID for the game object. Autogenerated if null.
/// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
/// Can the window be moved by dragging?
/// New empty UIDocument.
public static UIDocument Create(
out VisualElement root,
+ bool enableHiding,
string windowId = null,
Transform parent = null,
bool makeDraggable = false
)
{
+ Debug.Log("Window.Create: Creating window with hiding: " + enableHiding);
var document = CreateInternal(windowId, parent);
root = Element.Root();
@@ -34,6 +37,11 @@ public static class Window
root.MakeDraggable();
}
+ if (enableHiding)
+ {
+ root.EnableHiding();
+ }
+
document.m_RootVisualElement = root;
document.AddRootVisualElementToTree();
@@ -41,30 +49,61 @@ public static class Window
return document;
}
+
+ ///
+ /// Creates an empty UIDocument with a pre-styled root element.
+ ///
+ /// Pre-styled root element of the UIDocument.
+ /// Unique ID for the game object. Autogenerated if null.
+ /// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
+ /// Can the window be moved by dragging?
+ /// New empty UIDocument.
+ public static UIDocument Create(
+ out VisualElement root,
+ string windowId = null,
+ Transform parent = null,
+ bool makeDraggable = false
+ )
+ {
+ return Create(out root, true, windowId, parent, makeDraggable);
+ }
///
/// Creates a new UIDocument from a UXML asset.
///
/// UXML asset containing the UI.
+ /// Should window hiding with F2 be enabled?
/// Unique ID for the game object. Autogenerated if null.
/// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
/// Can the window be moved by dragging?
/// UIDocument with the UI defined in UXML.
public static UIDocument CreateFromUxml(
VisualTreeAsset uxml,
+ bool enableHiding,
string windowId = null,
Transform parent = null,
bool makeDraggable = false
)
{
+ Debug.Log("Window.Create: Creating window with hiding: " + enableHiding);
var document = CreateInternal(windowId, parent);
document.sourceAsset = uxml;
document.RecreateUI();
- if (makeDraggable && document.rootVisualElement.hierarchy.childCount > 0)
+ if (document.rootVisualElement.hierarchy.childCount > 0)
{
- document.rootVisualElement.hierarchy.ElementAt(0).MakeDraggable();
+ var rootElement = document.rootVisualElement.hierarchy.ElementAt(0);
+
+ if (makeDraggable)
+ {
+ rootElement.MakeDraggable();
+ }
+
+ if (enableHiding)
+ {
+ rootElement.EnableHiding();
+ }
}
document.PostInitialize();
@@ -72,21 +111,42 @@ public static class Window
return document;
}
+ ///
+ /// Creates a new UIDocument from a UXML asset.
+ ///
+ /// UXML asset containing the UI.
+ /// Unique ID for the game object. Autogenerated if null.
+ /// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
+ /// Can the window be moved by dragging?
+ /// UIDocument with the UI defined in UXML.
+ public static UIDocument CreateFromUxml(
+ VisualTreeAsset uxml,
+ string windowId = null,
+ Transform parent = null,
+ bool makeDraggable = false
+ )
+ {
+ return CreateFromUxml(uxml, true, windowId, parent, makeDraggable);
+ }
+
///
/// Creates a new UIDocument from an existing root VisualElement. Doesn't include default root style.
///
/// Root element of the UIDocument.
+ /// Should window hiding with F2 be enabled?
/// Unique ID for the game object. Autogenerated if null.
/// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
/// Can the window be moved by dragging?
/// New UIDocument with the element parameter as root.
public static UIDocument CreateFromElement(
VisualElement element,
+ bool enableHiding,
string windowId = null,
Transform parent = null,
bool makeDraggable = false
)
{
+ Debug.Log("Window.Create: Creating window with hiding: " + enableHiding);
var document = CreateInternal(windowId, parent);
if (makeDraggable)
@@ -94,6 +154,11 @@ public static class Window
element.MakeDraggable();
}
+ if (enableHiding)
+ {
+ element.EnableHiding();
+ }
+
document.m_RootVisualElement = element;
document.AddRootVisualElementToTree();
@@ -102,6 +167,24 @@ public static class Window
return document;
}
+ ///
+ /// Creates a new UIDocument from an existing root VisualElement. Doesn't include default root style.
+ ///
+ /// Root element of the UIDocument.
+ /// Unique ID for the game object. Autogenerated if null.
+ /// Parent game object transform. Uses "UI Manager(Clone)/Main Canvas" if null.
+ /// Can the window be moved by dragging?
+ /// New UIDocument with the element parameter as root.
+ public static UIDocument CreateFromElement(
+ VisualElement element,
+ string windowId = null,
+ Transform parent = null,
+ bool makeDraggable = false
+ )
+ {
+ return CreateFromElement(element, true, windowId, parent, makeDraggable);
+ }
+
private static UIDocument CreateInternal(string windowId = null, Transform parent = null)
{
var gameObject = new GameObject(windowId ?? $"ui-{Guid.NewGuid()}");
diff --git a/src/UitkForKsp2/Directory.Build.targets b/src/UitkForKsp2/Directory.Build.targets
index 7a3eb0e..f4f7aeb 100644
--- a/src/UitkForKsp2/Directory.Build.targets
+++ b/src/UitkForKsp2/Directory.Build.targets
@@ -1,66 +1,91 @@
-
-
-
+
-
+
+
+
+
+
-
-
-
+
+
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+ DestinationFolder="$(KSP2DIR)/BepInEx/%(RecursiveDir)"/>
+
-
+
-
\ No newline at end of file
+
diff --git a/src/UitkForKsp2/UitkForKsp2.csproj b/src/UitkForKsp2/UitkForKsp2.csproj
index cd42c4a..ed5a12c 100644
--- a/src/UitkForKsp2/UitkForKsp2.csproj
+++ b/src/UitkForKsp2/UitkForKsp2.csproj
@@ -1,26 +1,5 @@
-
-
- true
- true
-
-
- $(MSBuildProjectName)
- https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/LICENSE
- $(SolutionDir)/nuget
- https://github.com/jan-bures/UitkForKsp2
- README.md
- ksp2;mod;library
-
-
-
-
-
-
-
-
-