From 16cbac3bc2a99ad8e025039b99e9c2e467912ba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Mon, 10 Apr 2023 17:58:52 +0200 Subject: [PATCH 01/35] Corrected the name of the folder `localization` to `localizations` in README --- .github/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/README.md b/.github/README.md index fa1fc00a..7d132769 100644 --- a/.github/README.md +++ b/.github/README.md @@ -50,7 +50,7 @@ KSP2_Root_Folder/ │ │ │ │ │ ├── *.bundle │ │ │ │ ├── images/ │ │ │ │ │ ├── * -│ │ │ ├── localization/ +│ │ │ ├── localizations/ │ │ │ │ ├── *.csv │ │ │ ├── addressables/ │ │ │ │ ├── catalog.json From 1c704bbd818fb47cdcae147ab4737bf2ab6e1a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Mon, 10 Apr 2023 18:24:24 +0200 Subject: [PATCH 02/35] Added .gitattributes --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..a3ce42f3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# Auto detect text files and perform LF normalization +* text=auto + +*.cs text diff=csharp +*.csx text diff=csharp +*.sln text eol=crlf +*.csproj text eol=crlf + +*.csv text eol=lf From 3cedd038a2ef29d87dcdb0318450f6fb9e031d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Sat, 15 Apr 2023 17:48:17 +0200 Subject: [PATCH 03/35] Mod list rewrite first iteration --- Directory.Build.props | 2 +- NuGet.config | 1 + SpaceWarp/SpaceWarp.csproj | 6 +- SpaceWarp/SpaceWarpManager.cs | 12 +- SpaceWarp/SpaceWarpPlugin.cs | 35 +- SpaceWarp/UI/ModList/ModListController.cs | 404 +++++++++++++ SpaceWarp/UI/ModList/ModListItemController.cs | 57 ++ SpaceWarp/UI/ModListUI.cs | 534 ------------------ .../assets/bundles/modlist.bundle | Bin 0 -> 4797 bytes 9 files changed, 496 insertions(+), 555 deletions(-) create mode 100644 SpaceWarp/UI/ModList/ModListController.cs create mode 100644 SpaceWarp/UI/ModList/ModListItemController.cs delete mode 100644 SpaceWarp/UI/ModListUI.cs create mode 100644 SpaceWarpBuildTemplate/assets/bundles/modlist.bundle diff --git a/Directory.Build.props b/Directory.Build.props index 81ae7375..dd8d84ce 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.1.3 + 1.2.0 net472 11 true diff --git a/NuGet.config b/NuGet.config index fffd9183..df370a2a 100644 --- a/NuGet.config +++ b/NuGet.config @@ -2,5 +2,6 @@ + diff --git a/SpaceWarp/SpaceWarp.csproj b/SpaceWarp/SpaceWarp.csproj index 43a887b4..4b615a2c 100644 --- a/SpaceWarp/SpaceWarp.csproj +++ b/SpaceWarp/SpaceWarp.csproj @@ -15,13 +15,15 @@ + - + + - + diff --git a/SpaceWarp/SpaceWarpManager.cs b/SpaceWarp/SpaceWarpManager.cs index 983c23b2..afea06d3 100644 --- a/SpaceWarp/SpaceWarpManager.cs +++ b/SpaceWarp/SpaceWarpManager.cs @@ -5,7 +5,6 @@ using BepInEx; using BepInEx.Bootstrap; using BepInEx.Logging; -using I2.Loc; using SpaceWarpPatcher; using Newtonsoft.Json; using SpaceWarp.API.Assets; @@ -14,7 +13,7 @@ using SpaceWarp.API.Mods.JSON; using SpaceWarp.API.UI.Appbar; using SpaceWarp.Backend.UI.Appbar; -using SpaceWarp.UI; +using SpaceWarp.UI.ModList; using UnityEngine; namespace SpaceWarp; @@ -41,7 +40,7 @@ internal static class SpaceWarpManager private static GUISkin _skin; - public static ModListUI ModListUI { get; internal set; } + public static ModListController ModListController { get; internal set; } public static GUISkin Skin { @@ -144,7 +143,7 @@ internal static void GetSpaceWarpPlugins() public static void Initialize(SpaceWarpPlugin spaceWarpPlugin) { - Logger = spaceWarpPlugin.Logger; + Logger = SpaceWarpPlugin.Logger; SpaceWarpFolder = Path.GetDirectoryName(spaceWarpPlugin.Info.Location); @@ -213,12 +212,11 @@ internal static void CheckKspVersions() { var tex = new Texture2D(2, 2, TextureFormat.ARGB32, false) { - filterMode = FilterMode.Point + filterMode = FilterMode.Point }; var fileData = File.ReadAllBytes(filename); tex.LoadImage(fileData); // Will automatically resize - List<(string name, UnityObject asset)> assets = new(); - assets.Add(($"images/{internalPath}",tex)); + List<(string name, UnityObject asset)> assets = new() { ($"images/{internalPath}",tex) }; return assets; } diff --git a/SpaceWarp/SpaceWarpPlugin.cs b/SpaceWarp/SpaceWarpPlugin.cs index 61c8e8a7..a4a56ebd 100644 --- a/SpaceWarp/SpaceWarpPlugin.cs +++ b/SpaceWarp/SpaceWarpPlugin.cs @@ -9,7 +9,9 @@ using BepInEx.Logging; using HarmonyLib; using KSP.Messages; +using Ksp2Uitk.API; using Newtonsoft.Json; +using SpaceWarp.API.Assets; using SpaceWarp.API.Game.Messages; using SpaceWarp.API.Mods; using SpaceWarp.API.Mods.JSON; @@ -17,8 +19,10 @@ using SpaceWarp.API.Versions; using SpaceWarp.UI; using SpaceWarp.UI.Debug; +using SpaceWarp.UI.ModList; using UnityEngine; using UnityEngine.Networking; +using UnityEngine.UIElements; namespace SpaceWarp; @@ -44,7 +48,12 @@ public sealed class SpaceWarpPlugin : BaseSpaceWarpPlugin internal ConfigEntry ConfigWarningColor; private string _kspVersion; - internal new ManualLogSource Logger => base.Logger; + internal new static ManualLogSource Logger; + + public SpaceWarpPlugin() + { + Logger = base.Logger; + } public void Awake() { @@ -78,9 +87,9 @@ public void Awake() BepInEx.Logging.Logger.Listeners.Add(new SpaceWarpConsoleLogListener(this)); Harmony.CreateAndPatchAll(typeof(SpaceWarpPlugin).Assembly, ModGuid); - + SpaceWarpManager.InitializeSpaceWarpsLoadingActions(); - + SpaceWarpManager.Initialize(this); } @@ -93,7 +102,6 @@ public override void OnInitialized() Game.Messages.Subscribe(typeof(GameStateLeftMessage), StateChanges.OnGameStateLeft, false, true); Game.Messages.Subscribe(typeof(GameStateChangedMessage), StateChanges.OnGameStateChanged, false, true); - InitializeUI(); if (_configFirstLaunch.Value) { _configFirstLaunch.Value = false; @@ -113,6 +121,8 @@ public override void OnInitialized() } SpaceWarpManager.CheckKspVersions(); + + InitializeUI(); } public void ClearVersions() @@ -200,13 +210,13 @@ private void InitializeUI() SpaceWarpManager.ConfigurationManager = (ConfigurationManager.ConfigurationManager)Chainloader .PluginInfos[ConfigurationManager.ConfigurationManager.GUID].Instance; - GameObject modUIObject = new("Space Warp Mod UI"); - modUIObject.Persist(); - - modUIObject.transform.SetParent(transform); - SpaceWarpManager.ModListUI = modUIObject.AddComponent(); - modUIObject.SetActive(true); + var modListUxml = AssetManager.GetAsset($"spacewarp/modlist/modlist.uxml"); + var modList = Window.CreateFromUxml(modListUxml, "Space Warp Mod List", transform); + var modListObject = modList.gameObject; + modListObject.Persist(); + SpaceWarpManager.ModListController = modListObject.AddComponent(); + modList.rootVisualElement.style.display = DisplayStyle.None; GameObject consoleUIObject = new("Space Warp Console"); consoleUIObject.Persist(); @@ -214,6 +224,9 @@ private void InitializeUI() consoleUIObject.AddComponent(); consoleUIObject.SetActive(true); - MainMenu.RegisterLocalizedMenuButton("SpaceWarp/Mods", SpaceWarpManager.ModListUI.ToggleVisible); + MainMenu.RegisterLocalizedMenuButton( + "SpaceWarp/Mods", + () => SpaceWarpManager.ModListController.GetComponent().rootVisualElement.style.display = DisplayStyle.Flex + ); } } \ No newline at end of file diff --git a/SpaceWarp/UI/ModList/ModListController.cs b/SpaceWarp/UI/ModList/ModListController.cs new file mode 100644 index 00000000..ec843dfe --- /dev/null +++ b/SpaceWarp/UI/ModList/ModListController.cs @@ -0,0 +1,404 @@ +using System; +using System.Collections.Generic; +using System.IO; +using BepInEx; +using SpaceWarp.API.Assets; +using SpaceWarp.API.Mods.JSON; +using SpaceWarpPatcher; +using UnityEngine; +using UnityEngine.UIElements; + +namespace SpaceWarp.UI.ModList; + +public class ModListController : MonoBehaviour +{ + private VisualTreeAsset _listEntryTemplate; + private VisualTreeAsset _dependencyTemplate; + + // Mod list UI element references + private Button _enableAllButton; + private Button _disableAllButton; + private Button _revertChangesButton; + private Label _changesLabel; + private const string ChangesLabelText = "Changes detected: {0}. Please restart the game."; + + private Foldout _spaceWarpModFoldout; + private VisualElement _spaceWarpModList; + private Foldout _otherModFoldout; + private VisualElement _otherInfoModList; + private VisualElement _otherModList; + private Foldout _disabledModFoldout; + private VisualElement _disabledInfoModList; + private VisualElement _disabledModList; + + // Details UI element references + private Label _detailsNameLabel; + private Label _detailsIdLabel; + private Label _detailsAuthorLabel; + private Label _detailsVersionLabel; + private Label _detailsSourceLabel; + private Label _detailsDescriptionLabel; + private Label _detailsKspVersionLabel; + private VisualElement _detailsContainer; + private Foldout _detailsDependenciesFoldout; + private VisualElement _detailsDependenciesList; + + // State + private readonly List _modItemElements = new(); + + private Dictionary _toggles; + private Dictionary _initialToggles; + + private static readonly IReadOnlyList NoToggleGuids = new List + { + SpaceWarpPlugin.ModGuid, + ConfigurationManager.ConfigurationManager.GUID + }; + + private bool _isLoaded; + + private void OnEnable() + { + if (_isLoaded) + { + return; + } + + InitializeElements(); + FillModLists(); + SetupToggles(); + _isLoaded = true; + } + + private void InitializeElements() + { + _listEntryTemplate = AssetManager.GetAsset($"spacewarp/modlist/modlistitem.uxml"); + _dependencyTemplate = AssetManager.GetAsset($"spacewarp/modlist/modlistdetailsitem.uxml"); + + var root = GetComponent().rootVisualElement; + + // Register a callback for the back button + root.Q