From 23622feb6d3129fe3c4424107d1544908623724c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Tue, 23 Jan 2024 00:51:49 +0100 Subject: [PATCH 1/3] Chinese (simplified) translations --- README.md | 2 +- plugin_template/localizations/warp_to_orbital_point.csv | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4a074ba..6cc92fa 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,4 @@ All life hacks can be toggled on or off in `Main menu` -> `Settings` -> `Mods` - take effect after the game is restarted. Life hacks are enabled by default unless otherwise noted. ## Contributing If you'd like to contribute to this project, please take a look at -[our wiki](https://github.com/KSP2Community/KerbalLifeHacks/wiki/Adding-your-hack). +[our wiki](https://github.com/KSP2Community/KerbalLifeHacks/wiki/Adding-your-hack). \ No newline at end of file diff --git a/plugin_template/localizations/warp_to_orbital_point.csv b/plugin_template/localizations/warp_to_orbital_point.csv index 4613188..12a26d7 100644 --- a/plugin_template/localizations/warp_to_orbital_point.csv +++ b/plugin_template/localizations/warp_to_orbital_point.csv @@ -1,4 +1,4 @@ -Key,Type,Desc,English -KerbalLifeHacks/Map/WarpToAp,text,,Warp to Apoapsis -KerbalLifeHacks/Map/WarpToPe,text,,Warp to Periapsis -KerbalLifeHacks/Map/WarpToSOI,text,,Warp to SOI Change \ No newline at end of file +Key,Type,Desc,English,Chinese (Simplified) +KerbalLifeHacks/Map/WarpToAp,text,,Warp to Apoapsis,时间加速至远点 +KerbalLifeHacks/Map/WarpToPe,text,,Warp to Periapsis,时间加速至近点 +KerbalLifeHacks/Map/WarpToSOI,text,,Warp to SOI Change,时间加速至引力作用范围变化 \ No newline at end of file From c779371c4990864e2f64530962df802dd28b6ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Wed, 24 Jan 2024 01:43:41 +0100 Subject: [PATCH 2/3] Fix IVAPortraitsToggler button not always appearing --- .../Hacks/IVAPortraitsToggler/AppBarButton.cs | 29 +++++++++----- .../IVAPortraitsToggler.cs | 39 ++++++++++++++----- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs b/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs index 7a80014..822ecfd 100644 --- a/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs +++ b/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs @@ -11,6 +11,7 @@ namespace KerbalLifeHacks.Hacks.IVAPortraitsToggler; internal class AppBarButton { private readonly UIValue_WriteBool_Toggle _buttonState; + private readonly GameObject _button; public AppBarButton( string buttonTooltip, @@ -35,35 +36,35 @@ public AppBarButton( // Clone 'NonStageable-Resources' button - var barButton = UnityObject.Instantiate(nonStageableResources, list.transform); + _button = UnityObject.Instantiate(nonStageableResources, list.transform); if (siblingIndex >= 0 && siblingIndex < list.transform.childCount - 1) { - barButton.transform.SetSiblingIndex(siblingIndex); + _button.transform.SetSiblingIndex(siblingIndex); } - barButton.name = buttonId; + _button.name = buttonId; // Change the tooltip - barButton.GetComponent()._tooltipTitleKey = buttonTooltip; + _button.GetComponent()._tooltipTitleKey = buttonTooltip; // Change the icon var sprite = Appbar.GetAppBarIconFromTexture(buttonIcon); - var icon = barButton.GetChild("Content").GetChild("GRP-icon"); + var icon = _button.GetChild("Content").GetChild("GRP-icon"); var image = icon.GetChild("ICO-asset").GetComponent(); image.sprite = sprite; // Add our function call to the toggle - var toggle = barButton.GetComponent(); + var toggle = _button.GetComponent(); toggle.onValueChanged.AddListener(state => function(state)); - toggle.onValueChanged.AddListener(SetButtonState); + toggle.onValueChanged.AddListener(SetState); // Set the initial state of the button - _buttonState = barButton.GetComponent(); + _buttonState = _button.GetComponent(); _buttonState.valueKey = $"Is{buttonId}Visible"; _buttonState.BindValue(new Property(false)); } - public void SetButtonState(bool state) + public void SetState(bool state) { if (_buttonState == null) { @@ -72,4 +73,14 @@ public void SetButtonState(bool state) _buttonState.SetValue(state); } + + public void SetActive(bool isActive = true) + { + if (_button == null) + { + return; + } + + _button.SetActive(isActive); + } } \ No newline at end of file diff --git a/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/IVAPortraitsToggler.cs b/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/IVAPortraitsToggler.cs index 533dc15..d42f8c8 100644 --- a/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/IVAPortraitsToggler.cs +++ b/src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/IVAPortraitsToggler.cs @@ -1,6 +1,9 @@ -using KSP.Game; +using System.Collections; +using KSP.Game; using KSP.Messages; +using KSP.Sim.impl; using SpaceWarp.API.Assets; +using SpaceWarp.API.Game; using UnityEngine; namespace KerbalLifeHacks.Hacks.IVAPortraitsToggler; @@ -11,7 +14,7 @@ public class IVAPortraitsToggler : BaseHack private AppBarButton _buttonBar; // ReSharper disable once InconsistentNaming, IdentifierTypo - private Canvas _ivaportraits_canvas; + private GameObject _ivaportraits; public override void OnInitialized() { @@ -21,19 +24,20 @@ public override void OnInitialized() private void OnFlightViewEnteredMessage(MessageCenterMessage msg) { - if (_ivaportraits_canvas == null) + if (_ivaportraits == null) { var instruments = GameManager.Instance.Game.UI.FlightHud._instruments; // ReSharper disable once StringLiteralTypo instruments.TryGetValue("group_ivaportraits", out var ivaPortraits); if (ivaPortraits != null) { - _ivaportraits_canvas = ivaPortraits._parentCanvas; + _ivaportraits = ivaPortraits._parentCanvas.gameObject; } } if (_buttonBar != null) { + _buttonBar.SetActive(); return; } @@ -41,9 +45,19 @@ private void OnFlightViewEnteredMessage(MessageCenterMessage msg) "IVA Portraits", "BTN-IVA-Portraits", AssetManager.GetAsset($"KerbalLifeHacks/images/IVAPortraitsToggler-icon.png"), - ToggleIVAPortraitsCanvas, + SetIVAPortraitsState, 0 ); + _buttonBar.SetActive(); + + try + { + StartCoroutine(HandleVessel(Vehicle.ActiveSimVessel.GetControlOwner().GlobalId)); + } + catch + { + // ignored + } } private void OnVesselChangedMessage(MessageCenterMessage msg) @@ -54,16 +68,23 @@ private void OnVesselChangedMessage(MessageCenterMessage msg) } var vesselGuid = vessel.GetControlOwner().GlobalId; + StartCoroutine(HandleVessel(vesselGuid)); + } + + private IEnumerator HandleVessel(IGGuid vesselGuid) + { + yield return new WaitForUpdate(); + var allKerbalsInSimObject = GameManager.Instance.Game.KerbalManager._kerbalRosterManager ?.GetAllKerbalsInSimObject(vesselGuid); var state = allKerbalsInSimObject?.Count > 0; - ToggleIVAPortraitsCanvas(state); - _buttonBar.SetButtonState(state); + SetIVAPortraitsState(state); + _buttonBar.SetState(state); } - public void ToggleIVAPortraitsCanvas(bool state) + public void SetIVAPortraitsState(bool state) { - _ivaportraits_canvas.enabled = state; + _ivaportraits.SetActive(state); } } \ No newline at end of file From de7d2fb03b673268726963bc3f6cba360be8eb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Wed, 24 Jan 2024 01:44:16 +0100 Subject: [PATCH 3/3] Version 1.2.1 --- plugin_template/swinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_template/swinfo.json b/plugin_template/swinfo.json index 0bc15df..8ca451c 100644 --- a/plugin_template/swinfo.json +++ b/plugin_template/swinfo.json @@ -5,7 +5,7 @@ "name": "Kerbal Life Hacks", "description": "A counterpart to Community Fixes which contains quality of life improvements and tuning tweaks.", "source": "https://github.com/KSP2Community/KerbalLifeHacks", - "version": "1.2.0", + "version": "1.2.1", "version_check": "https://raw.githubusercontent.com/KSP2Community/KerbalLifeHacks/main/plugin_template/swinfo.json", "ksp2_version": { "min": "0.2.0",