Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-bures committed Dec 10, 2023
2 parents 2841309 + b4ef930 commit 970e4ba
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 101 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.UitkForKsp2/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

<PropertyGroup Label="Build and namespace configuration">
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
<BuildFolder>$(SolutionDir)build/bin</BuildFolder>
<BaseOutputPath>$(SolutionDir)build/bin/$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(SolutionDir)build/obj/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<PluginBinPath>$(SolutionDir)build/bin/plugin</PluginBinPath>
<PatcherBinPath>$(SolutionDir)build/bin/patcher</PatcherBinPath>
<BaseOutputPath>$(PluginBinPath)/$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$(SolutionDir)build/obj/plugin/$(MSBuildProjectName)</BaseIntermediateOutputPath>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<NoWarn>$(NoWarn);CS0436;NU5125</NoWarn>
Expand All @@ -31,33 +32,29 @@
</RestoreAdditionalProjectSources>
</PropertyGroup>

<PropertyGroup>
<Version Condition="'$(Version)'==''">2.1.1</Version>
</PropertyGroup>

<ItemGroup Label="Dependencies for build targets">
<PackageReference Include="JsonPeek" Version="1.2.0" PrivateAssets="all"/>
</ItemGroup>

<!-- Define the main target -->
<Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" AfterTargets="MinVer">
<Target Label="Reading properties from swinfo.json" Name="ReadPropertiesFromJson" BeforeTargets="PreBuildEvent;AddGeneratedFile">
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$">
<Output TaskParameter="Result" ItemName="Swinfo"/>
</JsonPeek>
<JsonPeek ContentPath="$(SolutionDir)/plugin_template/swinfo.json" Query="$.dependencies">
<Output TaskParameter="Result" ItemName="Dependencies"/>
</JsonPeek>

<!-- Extract properties from the JSON -->
<PropertyGroup>
<ModId>@(Swinfo -> '%(mod_id)')</ModId>
<PackageVersion>@(Swinfo -> '%(version)')</PackageVersion>
<Version>@(Swinfo -> '%(version)')</Version>
<Version Condition="$(Version.Contains('-'))">$(Version.Substring(0, $(Version.IndexOf('-'))))</Version>
<Product>@(Swinfo -> '%(name)')</Product>
<Authors>@(Swinfo -> '%(author)')</Authors>
<Description>@(Swinfo -> '%(description)')</Description>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>@(Swinfo -> '%(source)')</RepositoryUrl>
<BepInExPluginGuid>$(ModId)</BepInExPluginGuid>
<BepInExPluginName>$(Product)</BepInExPluginName>
<BepInExPluginVersion>$(Version)</BepInExPluginVersion>
</PropertyGroup>
</Target>
</Project>
11 changes: 0 additions & 11 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions Package.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<licenseUrl>https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/LICENSE</licenseUrl>
<description>$description$</description>
<tags>ksp ksp2 mod library</tags>
<projectUrl>$repositoryUrl$</projectUrl>
<repository type="$repositoryType$" url="$repositoryUrl$" />
<readme>README.md</readme>
<dependencies>
<group targetFramework=".NETStandard2.1" />
</dependencies>
</metadata>
<files>
<file src="README.md" target="" />
<file src="LICENSE" target="LICENSE" />
<file src="temp_nuget\*.dll" target="lib/netstandard2.1/" />
<file src="temp_nuget\*.xml" target="lib/netstandard2.1/" />
</files>
</package>
2 changes: 1 addition & 1 deletion plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 0 additions & 22 deletions src/UitkForKsp2.Controls/UitkForKsp2.Controls.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<!-- NuGet package configuration -->
<PropertyGroup>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup Label="NuGet package configuration">
<PackageId Label="ID of your NuGet package">$(MSBuildProjectName)</PackageId>
<PackageLicenseUrl Label="URL to the license of your mod">https://raw.githubusercontent.com/jan-bures/UitkForKsp2/main/LICENSE</PackageLicenseUrl>
<PackageOutputPath Label="Path to the NuGet package output">$(SolutionDir)/nuget</PackageOutputPath>
<PackageProjectUrl Label="Optional URL to your project's website (e.g. forum post)">https://github.com/jan-bures/UitkForKsp2</PackageProjectUrl>
<PackageReadmeFile Label="Filename of your README file">README.md</PackageReadmeFile>
<PackageTags Label="Optional tags of your NuGet package">ksp2;mod;library</PackageTags>
</PropertyGroup>
<Target Name="IncludeAllFilesInTargetDir" AfterTargets="Build">
<ItemGroup>
<None Label="Path to LICENSE file" Include="$(SolutionDir)LICENSE" Pack="true" PackagePath="/"/>
<None Label="Path to README file" Include="$(SolutionDir)/README.md" Pack="true" PackagePath="/"/>
<None Label="Path to the target build" Include="$(BaseOutputPath)/$(ConfigurationName)/$(TargetFramework)/**" Pack="true" PackagePath="/lib/$(TargetFramework)"/>
</ItemGroup>
</Target>

<!-- Package references -->
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="all"/>
Expand Down
16 changes: 13 additions & 3 deletions src/UitkForKsp2/API/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

namespace UitkForKsp2.API;

/// <summary>
/// Contains extension methods for UI Toolkit documents and elements.
/// </summary>
/// <summary
[PublicAPI]
public static class Extensions
{
Expand Down Expand Up @@ -72,6 +70,18 @@ public static class Extensions
return element;
}

/// <summary>
/// Enables the F2 hiding functionality for a visual element.
/// </summary>
/// <param name="element">The visual element to enable hiding for.</param>
/// <typeparam name="T">The type of the visual element.</typeparam>
/// <returns>The visual element with the hiding functionality enabled.</returns>
public static T EnableHiding<T>(this T element) where T : VisualElement
{
element.AddManipulator(new HideManipulator());
return element;
}

/// <summary>
/// Automatically localize elements in a document. Only elements with a string property "text" whose value is a
/// localization key starting with '#' will be localized.
Expand Down
52 changes: 52 additions & 0 deletions src/UitkForKsp2/API/HideManipulator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using KSP.Game;
using KSP.Input;
using UnityEngine;
using UnityEngine.UIElements;

namespace UitkForKsp2.API;

/// <summary>
/// Allows hiding a VisualElement with the F2 key.
/// </summary>
public class HideManipulator : IManipulator
{
private bool _isHidden;
private DisplayStyle _originalDisplayStyle;

private VisualElement _target;

/// <summary>
/// The target element that will be hidden.
/// </summary>
public VisualElement target
{
get => _target;
set
{
var game = GameManager.Instance.Game;
if (game.InputManager.TryGetInputDefinition<GlobalInputDefinition>(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;
}
}
}

0 comments on commit 970e4ba

Please sign in to comment.