Skip to content

Commit a668cb8

Browse files
authored
Merge pull request #10 from Safarte/ns-resource-ui-not-resizing-when-loading-save
Use PersistentSubscribe for the NS Resource UI refresh handle
2 parents d75e1a3 + 2db14d9 commit a668cb8

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/CommunityResources/CommunityResourceUnitsPlugin.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BepInEx;
2+
using BepInEx.Logging;
23
using HarmonyLib;
34
using JetBrains.Annotations;
45
using KSP.Game;
@@ -23,6 +24,7 @@ public class CommunityResourceUnitsPlugin : BaseSpaceWarpPlugin
2324

2425
// Singleton instance of the plugin class
2526
public static CommunityResourceUnitsPlugin Instance { get; set; }
27+
public new static ManualLogSource Logger { get; set; }
2628

2729
private void Awake()
2830
{
@@ -36,6 +38,7 @@ private void Awake()
3638
public override void OnInitialized()
3739
{
3840
base.OnInitialized();
41+
Logger = base.Logger;
3942

4043
GameManager.Instance.Assets.LoadByLabel<TextAsset>("resource_units", RegisterUnits, delegate (IList<TextAsset> assetLocations)
4144
{

src/CommunityResources/NonStageableResourcesUIController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class NonStageableResourcesUIController : KerbalMonoBehaviour
1717

1818
private void Start()
1919
{
20-
Game.Messages.Subscribe<VesselChangedMessage>(OnVesselChanged);
20+
Game.Messages.PersistentSubscribe<VesselChangedMessage>(OnVesselChanged);
2121
}
2222

2323
private void OnDestroy()
@@ -61,6 +61,8 @@ private void UpdateNonStageableResourcesUI()
6161
// Get number of non-stageable resources in the active vessel
6262
int nsResourcesCount = GetNonStageableResourcesCount(_activeVessel);
6363

64+
CommunityResourceUnitsPlugin.Logger.LogInfo($"Updating the Non-Stageable Resource UI. Found {nsResourcesCount} Resources to display.");
65+
6466
// Find the non-stageable resources window game object
6567
_nsResourcesUI = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Scaled Main Canvas/FlightHudRoot(Clone)/NonStageableResources(Clone)/KSP2UIWindow/Root/UIPanel");
6668

0 commit comments

Comments
 (0)