diff --git a/src/SpaceWarp.UI/Backend/UI/Appbar/AppbarBackend.cs b/src/SpaceWarp.UI/Backend/UI/Appbar/AppbarBackend.cs index 1169473..b90cc79 100644 --- a/src/SpaceWarp.UI/Backend/UI/Appbar/AppbarBackend.cs +++ b/src/SpaceWarp.UI/Backend/UI/Appbar/AppbarBackend.cs @@ -303,21 +303,28 @@ private static void SetOABTrayState(bool state) #region KSC App Bar private static GameObject _kscTray; - + // ReSharper disable once InconsistentNaming private static GameObject KSCTray { get { if (_kscTray == null) - { - return _kscTray = CreateKSCTray(); + { + return _kscTray = CreateKSCTray(); } return _kscTray; } } + private const string KscMenuPath = + "GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/KSCMenu(Clone)/Panel/Window-FacilityMenu/GRP-Body/Content/Menu"; + + private const string FlyoutName = "LaunchLocationFlyoutHeaderToggle"; + + private const string TargetName = "LaunchLocationsFlyoutTarget"; + // ReSharper disable once InconsistentNaming private static GameObject CreateKSCTray() { @@ -326,8 +333,8 @@ private static GameObject CreateKSCTray() // Find the KSC launch locations menu item; it will be used for cloning the app tray // Get the Launch Pads menu item - var kscMenu = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/KSCMenu(Clone)/LandingPanel/InteriorWindow/MenuButtons/Content/Menu"); - var launchLocationsButton = kscMenu != null ? kscMenu.GetChild("LaunchLocationFlyoutHeaderToggle") : null; + var kscMenu = GameObject.Find(KscMenuPath); + var launchLocationsButton = kscMenu != null ? kscMenu.GetChild(FlyoutName) : null; if (kscMenu == null || launchLocationsButton == null) { @@ -340,13 +347,13 @@ private static GameObject CreateKSCTray() kscAppTrayButton.name = "KSC-AppTrayButton"; // Set the button icon (use OAB app tray icon) - var image = kscAppTrayButton.GetChild("Header").GetChild("Content").GetChild("Icon Panel").GetChild("icon").GetComponent(); + var image = kscAppTrayButton.GetChild("ICO-Launchpad").GetComponent(); var tex = AssetManager.GetAsset($"{SpaceWarpPlugin.ModGuid}/images/oabTrayButton.png"); tex.filterMode = FilterMode.Point; image.sprite = Sprite.Create(tex, new Rect(0, 0, 32, 32), new Vector2(0.5f, 0.5f)); // Change the text to APPS - var title = kscAppTrayButton.GetChild("Header").GetChild("Content").GetChild("Title"); + var title = kscAppTrayButton.GetChild("TXT-Launchpad"); { // Suppress renaming of the button to Launchpad var localizer = title.GetComponent(); @@ -359,19 +366,42 @@ private static GameObject CreateKSCTray() } // Get the popup tray and rename it - var kscAppTray = kscAppTrayButton.GetChild("LaunchLocationsFlyoutTarget"); + var originalFlyout = kscMenu.GetChild(TargetName); + var originalToggle = launchLocationsButton.GetComponent(); + var kscAppTray = UnityObject.Instantiate(originalFlyout, kscMenu.transform); kscAppTray.name = "KSC-AppTray"; + // Delete existing buttons and separators in the tray for (var i = 0; i < kscAppTray.transform.childCount; i++) { var child = kscAppTray.transform.GetChild(i); - + // Destroy all objects inside the tray, but keep the arrow ("thingy") that points to the menu button - if (!child.name.ToLowerInvariant().Contains("thingy")) + if (!child.name.ToLowerInvariant().Contains("bg-panel")) UnityObject.Destroy(child.gameObject); } + var toggleFlyout = kscAppTrayButton.GetComponent(); + toggleFlyout.OnDisable(); + toggleFlyout._target = kscAppTray; + toggleFlyout._toggle = kscAppTrayButton.GetComponent(); + toggleFlyout._toggleCanvas = kscAppTray.GetComponent(); + toggleFlyout.OnEnable(); + toggleFlyout._toggleCanvas.enabled = true; + toggleFlyout._toggle.onValueChanged.AddListener(x => + { + if (!x) return; + if (!originalToggle.isOn) return; + originalToggle.Set(false); + }); + originalToggle.onValueChanged.AddListener(x => + { + if (!x) return; + if (!toggleFlyout._toggle.isOn) return; + toggleFlyout._toggle.Set(false); + }); + Logger.LogInfo("Created KSC app tray."); return kscAppTray; @@ -386,7 +416,7 @@ public static void AddKSCButton(string buttonText, Sprite buttonIcon, string but // Find the Launchpad_1 button. var kscLaunchLocationsFlyoutTarget = GameObject.Find( - "GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Main Canvas/KSCMenu(Clone)/LandingPanel/InteriorWindow/MenuButtons/Content/Menu/LaunchLocationFlyoutHeaderToggle/LaunchLocationsFlyoutTarget"); + $"{KscMenuPath}/{TargetName}"); var launchPadButton = kscLaunchLocationsFlyoutTarget != null ? kscLaunchLocationsFlyoutTarget.GetChild("Launchpad_1") : null; if (launchPadButton == null) @@ -400,7 +430,7 @@ public static void AddKSCButton(string buttonText, Sprite buttonIcon, string but modButton.name = buttonId; // Change the text - var modText = modButton.GetChild("Content").GetChild("Text (TMP)").GetComponent(); + var modText = modButton.GetChild("TXT-LocationName").GetComponent(); modText.text = buttonText; // Suppress renaming of the button @@ -411,7 +441,7 @@ public static void AddKSCButton(string buttonText, Sprite buttonIcon, string but } // Change the icon - var icon = modButton.GetChild("Icon"); + var icon = modButton.GetChild("ICO-Location"); var image = icon.GetComponent(); image.sprite = buttonIcon; diff --git a/src/SpaceWarp.UI/Modules/UI.cs b/src/SpaceWarp.UI/Modules/UI.cs index eed59bc..3b63876 100644 --- a/src/SpaceWarp.UI/Modules/UI.cs +++ b/src/SpaceWarp.UI/Modules/UI.cs @@ -1,5 +1,6 @@ using HarmonyLib; using JetBrains.Annotations; +using KSP.UI.Flight; using SpaceWarp.API.Assets; using SpaceWarp.API.Configuration; using SpaceWarp.API.UI.Appbar;