Esempio n. 1
0
        private static void UninitializePart(Part part)
        {
            KJRAnalyzerJoint module = part.GetComponent <KJRAnalyzerJoint>();

            if (module != null)
            {
                Destroy(module);
            }
        }
        IEnumerator RunVesselJointUpdateFunctionDelayed(Vessel v)
        {
            yield return(new WaitForFixedUpdate());

            updatingVessels.Remove(v);

            RunVesselJointUpdateFunction(v);

#if IncludeAnalyzer
            KJRAnalyzerJoint.RunVesselJointUpdateFunction(v);

            KJRAnalyzer.WasModified(v);
#endif
        }
Esempio n. 3
0
        private static void InitializePart(Part part)
        {
            if (part.parent == null)
            {
                return;
            }

            KJRAnalyzerJoint module = part.GetComponent <KJRAnalyzerJoint>();

            if (!module || (module.relVessel != part.vessel))
            {
                if (!module)
                {
                    module = part.gameObject.AddComponent <KJRAnalyzerJoint>();
                }

                module.relVessel = part.vessel;

                module.relPos = Quaternion.Inverse(part.orgRot) * (part.parent.orgPos - part.orgPos);
                module.relRot = Quaternion.Inverse(part.parent.orgRot) * part.orgRot;
            }
        }
        private void InitSettingsWindow(bool startSolid = true)
        {
            _settingsWindow = GameObject.Instantiate(UIAssetsLoader.settingsWindowPrefab);
            _settingsWindow.transform.SetParent(UIMasterController.Instance.appCanvas.transform, false);
            _settingsWindow.GetChild("WindowTitle").AddComponent <PanelDragger>();
            _settingsWindowFader = _settingsWindow.AddComponent <CanvasGroupFader>();

            // start invisible to be toggled later
            //		if(!startSolid)
            //			_settingsWindow.GetComponent<CanvasGroup>().alpha = 0f;

            _settingsWindow.GetComponent <CanvasGroup>().alpha = 0f;

            if (_settingsWindowPosition == Vector3.zero)
            {
                _settingsWindowPosition = _settingsWindow.transform.position;                 // get the default position from the prefab
            }
            else
            {
                _settingsWindow.transform.position = ClampWindowPosition(_settingsWindowPosition);
            }

            /*
             *      var settingsButton = _settingsWindow.GetChild("WindowTitle").GetChild("LeftWindowButton");
             *      if(settingsButton != null)
             *      {
             *              settingsButton.GetComponent<Button>().onClick.AddListener(ToggleSettingsWindow);
             *              var t = settingsButton.AddComponent<BasicTooltip>();
             *              t.tooltipText = "Show/hide UI settings";
             *      }
             */
            var closeButton = _settingsWindow.GetChild("WindowTitle").GetChild("RightWindowButton");

            if (closeButton != null)
            {
                closeButton.GetComponent <Button>().onClick.AddListener(OnHideCallback);
                var t = closeButton.AddComponent <BasicTooltip>();
                t.tooltipText = "Close window";
            }

            var content = _settingsWindow.GetChild("WindowContent");

            var OptShowKSPJoints = AddNewOption(content, "ShowKSPJoints");

            OptShowKSPJoints.isOn = ShowKSPJoints;

            //		var Opt1ToggleTooltip = Opt1Toggle.gameObject.AddComponent<BasicTooltip>();
            //		Opt1ToggleTooltip.tooltipText = "Option1";

            var OptReinforceExistingJoints = AddNewOption(content, "Reinforce Existing Joints");

            OptReinforceExistingJoints.isOn = ReinforceExistingJoints;

            var OptBuildAdditionalJointToParent = AddNewOption(content, "Build Additional Joints To Parent");

            OptBuildAdditionalJointToParent.isOn = BuildAdditionalJointToParent;

            var OptShowAdditionalJointToParent = AddNewOption(content, "Show Additional Joints To Parent");

            OptShowAdditionalJointToParent.isOn = ShowAdditionalJointToParent;

            var OptBuildMultiPartJointTreeChildren = AddNewOption(content, "Build MultiPartJointTreeChildren");

            OptBuildMultiPartJointTreeChildren.isOn = BuildMultiPartJointTreeChildren;

            var OptShowMultiPartJointTreeChildren = AddNewOption(content, "Show MultiPartJointTreeChildren");

            OptShowMultiPartJointTreeChildren.isOn = ShowMultiPartJointTreeChildren;

            var OptBuildMultiPartJointTreeChildrenRoot = AddNewOption(content, "Build MultiPartJointTreeChildrenRoot");

            OptBuildMultiPartJointTreeChildrenRoot.isOn = BuildMultiPartJointTreeChildrenRoot;

            var OptShowMultiPartJointTreeChildrenRoot = AddNewOption(content, "Show MultiPartJointTreeChildrenRoot");

            OptShowMultiPartJointTreeChildrenRoot.isOn = ShowMultiPartJointTreeChildrenRoot;

            var OptAutoStrutDisplay = AddNewOption(content, "Show AutoStruts");

            OptAutoStrutDisplay.isOn = PhysicsGlobals.AutoStrutDisplay;

            var OptShowInstability = AddNewOption(content, "Show Instability");

            OptShowInstability.isOn = ShowInstability;

            var footerButtons = _settingsWindow.GetChild("WindowFooter").GetChild("WindowFooterButtonsHLG");

            var cancelButton = footerButtons.GetChild("CancelButton").GetComponent <Button>();

            cancelButton.onClick.AddListener(() =>
            {
                OptShowKSPJoints.isOn                       = ShowKSPJoints;
                OptReinforceExistingJoints.isOn             = ReinforceExistingJoints;
                OptBuildAdditionalJointToParent.isOn        = BuildAdditionalJointToParent;
                OptShowAdditionalJointToParent.isOn         = ShowAdditionalJointToParent;
                OptBuildMultiPartJointTreeChildren.isOn     = BuildMultiPartJointTreeChildren;
                OptShowMultiPartJointTreeChildren.isOn      = ShowMultiPartJointTreeChildren;
                OptBuildMultiPartJointTreeChildrenRoot.isOn = BuildMultiPartJointTreeChildrenRoot;
                OptShowMultiPartJointTreeChildrenRoot.isOn  = ShowMultiPartJointTreeChildrenRoot;
                OptAutoStrutDisplay.isOn                    = PhysicsGlobals.AutoStrutDisplay;
                OptShowInstability.isOn                     = ShowInstability;
            });

            var defaultButton = footerButtons.GetChild("DefaultButton").GetComponent <Button>();

            defaultButton.onClick.AddListener(() =>
            {
                bool bCycle = false, bCycle2 = false;

                OptShowKSPJoints.isOn = ShowKSPJoints = false;

                if (!ReinforceExistingJoints)
                {
                    bCycle = true;
                }
                OptReinforceExistingJoints.isOn = ReinforceExistingJoints = true;

                if (!BuildAdditionalJointToParent)
                {
                    bCycle = true;
                }
                OptBuildAdditionalJointToParent.isOn = BuildAdditionalJointToParent = true;

                OptShowAdditionalJointToParent.isOn = ShowAdditionalJointToParent = false;

                if (!BuildMultiPartJointTreeChildren)
                {
                    bCycle = true;
                }
                OptBuildMultiPartJointTreeChildren.isOn = BuildMultiPartJointTreeChildren = true;

                OptShowMultiPartJointTreeChildren.isOn = ShowMultiPartJointTreeChildren = false;

                if (!BuildMultiPartJointTreeChildrenRoot)
                {
                    bCycle = true;
                }
                OptBuildMultiPartJointTreeChildrenRoot.isOn = BuildMultiPartJointTreeChildrenRoot = true;

                OptShowMultiPartJointTreeChildrenRoot.isOn = ShowMultiPartJointTreeChildrenRoot = false;

                OptAutoStrutDisplay.isOn = PhysicsGlobals.AutoStrutDisplay = false;

                if (ShowInstability)
                {
                    bCycle2 = true;
                }
                OptShowInstability.isOn = ShowInstability = false;

                KJRAnalyzer.Show = ShowKSPJoints | ShowAdditionalJointToParent | ShowMultiPartJointTreeChildren | ShowMultiPartJointTreeChildrenRoot;

                if (HighLogic.LoadedSceneIsFlight)
                {
                    if (bCycle)
                    {
                        KJRManager.Instance.OnVesselWasModified(FlightGlobals.ActiveVessel);
                    }
                    else if (bCycle2)
                    {
                        KJRAnalyzerJoint.RunVesselJointUpdateFunction(FlightGlobals.ActiveVessel);
                    }
                }
            });

            var applyButton = footerButtons.GetChild("ApplyButton").GetComponent <Button>();

            applyButton.onClick.AddListener(() =>
            {
                bool bCycle = false, bCycle2 = false;

                ShowKSPJoints = OptShowKSPJoints.isOn;

                if (ReinforceExistingJoints != OptReinforceExistingJoints.isOn)
                {
                    bCycle = true;
                    ReinforceExistingJoints = OptReinforceExistingJoints.isOn;
                }

                if (BuildAdditionalJointToParent != OptBuildAdditionalJointToParent.isOn)
                {
                    bCycle = true;
                    BuildAdditionalJointToParent = OptBuildAdditionalJointToParent.isOn;
                }

                ShowAdditionalJointToParent = OptShowAdditionalJointToParent.isOn;

                if (BuildMultiPartJointTreeChildren != OptBuildMultiPartJointTreeChildren.isOn)
                {
                    bCycle = true;
                    BuildMultiPartJointTreeChildren = OptBuildMultiPartJointTreeChildren.isOn;
                }

                ShowMultiPartJointTreeChildren = OptShowMultiPartJointTreeChildren.isOn;

                if (BuildMultiPartJointTreeChildrenRoot != OptBuildMultiPartJointTreeChildrenRoot.isOn)
                {
                    bCycle = true;
                    BuildMultiPartJointTreeChildrenRoot = OptBuildMultiPartJointTreeChildrenRoot.isOn;
                }

                ShowMultiPartJointTreeChildrenRoot = OptShowMultiPartJointTreeChildrenRoot.isOn;

                PhysicsGlobals.AutoStrutDisplay = OptAutoStrutDisplay.isOn;

                if (ShowInstability != OptShowInstability.isOn)
                {
                    bCycle2         = true;
                    ShowInstability = OptShowInstability.isOn;
                }

                KJRAnalyzer.Show = ShowKSPJoints | ShowAdditionalJointToParent | ShowMultiPartJointTreeChildren | ShowMultiPartJointTreeChildrenRoot;

                if (HighLogic.LoadedSceneIsFlight)
                {
                    if (bCycle)
                    {
                        KJRManager.Instance.OnVesselWasModified(FlightGlobals.ActiveVessel);
                    }
                    else if (bCycle2)
                    {
                        KJRAnalyzerJoint.RunVesselJointUpdateFunction(FlightGlobals.ActiveVessel);
                    }
                }
            });
        }