mwerle / OrbitalMaterialScience

KSP mod that adds new ways to get science from space stations.
GNU General Public License v3.0
5 stars 4 forks source link

KEMINI - resetting an experiment does not allow re-run #8

Closed mwerle closed 5 years ago

mwerle commented 8 years ago

Actual: If an experiment is reset, it disappears. Expect: experiment to be available for a re-run after reset.

TODO: Work out how to capture "reset" button click in KSP and hook logic onto that.

mwerle commented 6 years ago

Just found this which could be interesting:

mwerle commented 5 years ago

And just worked this out (Found some code giving me the start here). Now we can disable the "Reset" button. Presumably we can also hook into the onButtonPressed event and do other stuff.

(Hooking into onButton: replace the event with our own callback, and then optionally call the original one)

        private bool isExperimentsResultDialogOpen = false;
        public override void OnUpdate()
        {
            base.OnUpdate();
            // check experiments result dialog has closed on this frame
            if (isExperimentsResultDialogOpen && ExperimentsResultDialog.Instance == null)
            {
                // Do stuff if it closed
            }
            if (ExperimentsResultDialog.Instance != null)
            {
                // check experiments result dialog has opened on this frame
                if (isExperimentsResultDialogOpen == false)
                {
                    // Do stuff if it just opened

                    ExperimentsResultDialog erd = ExperimentsResultDialog.Instance;
                    // TODO: Hook into callbacks?
                    // TODO: Ensure current page is for KEES!
                    if (erd.currentPage.pageData.subjectID.Contains("NE_KEES"))
                    {
                        UnityEngine.UI.Button[] buttons = erd.GetComponentsInChildren<UnityEngine.UI.Button>();
                        foreach (UnityEngine.UI.Button b in buttons)
                        {
                            // Disable the Reset and Lab buttons
                            if (b.name == "ButtonReset" || b.name == "ButtonLab")
                            {
                                b.interactable = false;
                            }
                        }

                        // This doesn't seem to do anything
                        //erd.currentPage.showReset = false;
                    }
                }
            }

            // update experiments result dialog open state
            isExperimentsResultDialogOpen = (ExperimentsResultDialog.Instance != null);
        }
mwerle commented 5 years ago

Fixed by disabling the Reset button instead of allowing reset.