}         //private void OnDraw()

        private void weldPart(Part partToWeld)
        {
            //Lock editor
            EditorLockManager.lockEditor(Constants.settingWeldingLock);

            //process the welding
#if (DEBUG)
            Debug.ClearDeveloperConsole();

            Log.info("{0}", Constants.logVersion);
            Log.info("{0}", Constants.logStartWeld);
#endif
            bool warning = false;
            _welder = new Welder();
            _welder.init();

            partToWeld.transform.eulerAngles = Vector3.zero;
            WeldingReturn ret = 0;

            if (!WeldingHelpers.DoesTextContainRegex(partToWeld.name, "strutConnector"))
            {
                ret = _welder.weldThisPart(partToWeld);
            }

            if (ret < 0)
            {
                Log.dbg("{0}", Constants.logEndWeld);
                this.state = DisplayState.weldError;
                return;
            }
            else
            {
                warning = warning || (0 < ret);
            }

            Part[] children = partToWeld.FindChildParts <Part>(true);

            if (children != null)
            {
                foreach (Part child in children)
                {
                    if (!WeldingHelpers.DoesTextContainRegex(child.name, "strutConnector"))
                    {
                        ret = _welder.weldThisPart(child);
                    }

                    if (ret < 0)
                    {
                        Log.dbg("{0}", Constants.logEndWeld);
                        this.state = DisplayState.weldError;
                        return;
                    }
                    else
                    {
                        warning = warning || (0 < ret);
                    }
                }
            }
            _welder.processNewCoM();

            _welder.prepDecals(_welder.moduleList);
            if (_welder.isMeshSwitchRequired)
            {
                _welder.prepareWeldedMeshSwitchModule(_welder.moduleList);
            }

            _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _guiStyle, _techDropdown);

            if (_welder.vesselTypeList.Count > 0)
            {
                _vesselTypeDropdown = WeldingHelpers.initVesselTypeDropDown(_welder.vesselTypeList, _guiStyle, _vesselTypeDropdown);
            }

            _scrollMod = Vector2.zero;
            _scrollRes = Vector2.zero;

            Log.dbg("| {0} Parts welded", _welder.NbParts);

            if (warning)
            {
                Log.dbg(Constants.logEndWeld);
                this.state = DisplayState.weldWarning;
            }
            else
            {
                Log.dbg("welder.Category: {0}", (int)_welder.Category);
                _catDropdown.SelectedItemIndex = (int)_welder.Category;
                this.state = DisplayState.infoWindow;
            }
        }
        } //private void OnDraw()

        /*
         * Editor Button Draw
         */
        private void OnWeldButton()
        {
            //Making sure the editor is not on softlock or no parts are selected
            if (EditorLogic.softLock || null == EditorLogic.SelectedPart)
            {
                GUI.Box(_editorButton, Constants.guiWeldLabel);
            }
            else
            {
                if (GUI.Button(_editorButton, Constants.guiWeldLabel))
                {
                    //Lock editor
                    EditorLogic.fetch.Lock(true, true, true, "UBILOCK9213");

                    //process the welding
#if (DEBUG)
                    Debug.ClearDeveloperConsole();
#endif
                    Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logVersion));
                    Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logStartWeld));
                    Part selectedPart = EditorLogic.fetch.PartSelected;
                    bool warning      = false;
                    _welder = new Welder();

                    WeldingReturn ret = _welder.weldThisPart(selectedPart);
                    if (0 > ret)
                    {
                        Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
                        _state = DisplayState.weldError;
                        return;
                    }
                    else
                    {
                        warning = warning || (0 < ret);
                    }

                    Part[] children = selectedPart.FindChildParts <Part>(true);
                    if (null != children)
                    {
                        foreach (Part child in children)
                        {
                            ret = _welder.weldThisPart(child);
                            if (0 > ret)
                            {
                                Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
                                _state = DisplayState.weldError;
                                return;
                            }
                            else
                            {
                                warning = warning || (0 < ret);
                            }
                        }
                    }
                    _welder.processNewCoM();
                    _scrollMod = Vector2.zero;
                    _scrollRes = Vector2.zero;
                    Debug.Log(string.Format("{0} {1}{2}", Constants.logPrefix, _welder.NbParts, Constants.logEndWeld));
                    Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
                    if (warning)
                    {
                        _state = DisplayState.weldWarning;
                    }
                    else
                    {
                        _catDropdown.SelectedItemIndex = (int)_welder.Category;
                        _state = DisplayState.infoWindow;
                    }
                } // if (GUI.Button(_editorButton, Constants.guiWeldLabel))
            }     // elsef if (EditorLogic.softLock || null == EditorLogic.SelectedPart)
        }         //private void OnWeldButton()
Esempio n. 3
0
        }         //private void OnDraw()

        private void weldPart(Part partToWeld)
        {
            //Lock editor
            EditorLogic.fetch.Lock(true, true, true, Constants.settingWeldingLock);

            //process the welding
#if (DEBUG)
            Debug.ClearDeveloperConsole();

            Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logVersion));
            Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logStartWeld));
#endif
            bool warning = false;
            _welder = new Welder();

            partToWeld.transform.eulerAngles = Vector3.up;
            WeldingReturn ret = _welder.weldThisPart(partToWeld);

            if (ret < 0)
            {
#if (DEBUG)
                Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
#endif
                _state = DisplayState.weldError;
                return;
            }
            else
            {
                warning = warning || (0 < ret);
            }

            Part[] children = partToWeld.FindChildParts <Part>(true);

            if (children != null)
            {
                foreach (Part child in children)
                {
                    ret = _welder.weldThisPart(child);

                    if (ret < 0)
                    {
#if (DEBUG)
                        Debug.Log(string.Format("{0}{1}", Constants.logPrefix, Constants.logEndWeld));
#endif
                        _state = DisplayState.weldError;
                        return;
                    }
                    else
                    {
                        warning = warning || (0 < ret);
                    }
                }
            }
            _welder.processNewCoM();

            _techDropdown = WeldingHelpers.initTechDropDown(_welder.techList, _catListStyle, _techDropdown);

            _scrollMod = Vector2.zero;
            _scrollRes = Vector2.zero;
#if (DEBUG)
            Debug.Log(string.Format("{0} {1} | {2} Parts welded", Constants.logPrefix, Constants.logEndWeld, _welder.NbParts));
#endif
            if (warning)
            {
                Debug.Log(string.Format("{0} {1} | Warning", Constants.logPrefix, Constants.logEndWeld));
                _state = DisplayState.weldWarning;
            }
            else
            {
                _catDropdown.SelectedItemIndex = (int)_welder.Category;
                _state = DisplayState.infoWindow;
            }
        }