Jump to content

Trying to open the resource panel


Recommended Posts

I'm trying to get the resource panel to open automatically when entering flight scene. Seems simple enough, but without any plain English descriptions in most of the KSP API "documentation", I'm just guessing how to do it.  I'm trying to use ShowResourceList but it doesn't do anything.  I'm using Update(), which starts before the Resource app is launched, resulting in some initial Null Refs, but once it's loaded, then it does nothing AFAIK. 

using System;
using System.Threading;
using UnityEngine;
using KSP.UI.Screens; // has class ResourceDisplay

namespace Rememberer
{

    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class RememFlight : MonoBehaviour
    {
        private bool setResourcePanelNotDone = true;  
        private int iter = 0;

        public void Start()
        {
            Debug.Log("RememFlight - Start");
        }

        public void Update()
        {
            if (setResourcePanelNotDone)
            {
                iter++;
                Debug.Log("RememFlight - Update " + iter);
                ResourceDisplay.Instance.ShowResourceList(true);  //tried true and false

                if (iter > 160)
                {
                    setResourcePanelNotDone = false;
                }
            }
        }

        public void OnDisable()
        {
            Debug.Log("RememFlight - Disable");
            Debug.Log("RememFlight - Disable iter= " + iter);
            Debug.Log("RememFlight - Disable setResourcePanelNotDone= " + setResourcePanelNotDone);
        }

    }

}

Here's log:

KSP log

I could try to clear the Null Refs with a callback/ delegate but why bother if the basic function doesn't work? Unless the Null Refs are causing ShowResourceList to not work later? Doubtful. I could try looking in the AlternateResourcePanel mod but not sure what that might yield.

So... is this normal for everyone, to guess how to use the KSP API?

UPDATE:

This basically works: ResourceDisplay.Instance.appLauncherButton.SetTrue()

Edited by Krazy1
Link to comment
Share on other sites

  • 3 weeks later...
On 4/28/2021 at 10:30 PM, Krazy1 said:

So... is this normal for everyone, to guess how to use the KSP API?

Guess/experiment/examine mods that do something similar/ask here on the forum are the only ways I've found.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...