Nehemia Engineering Orbital Science

Nehemia Engineering Orbital Science

13.5k Downloads

KEMINI - resetting an experiment does not allow re-run

mwerle opened this issue ยท 3 comments

commented

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.

commented

Just found this which could be interesting:

commented

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);
        }
commented

Fixed by disabling the Reset button instead of allowing reset.