/*
  * Called once everything in scene is loaded
  */
 public void Start()
 {
     try {
         this._guiVisible = (
             null != EditorLogic.fetch &&
             (_config.allowCareerMode || !_config.allowCareerMode && HighLogic.fetch.currentGame.Mode != Game.Modes.CAREER)
             );
         EditorLockManager.resetEditorLocks();
         _editorFacility = EditorDriver.editorFacility;
     } catch (Exception e) {
         Log.ex(this, e);
     } finally {
         Log.dbgGui(this, "Start handled");
     }
 }
        /*
         * Lock editor if mouse pointer is inside window rect
         */
        private void PreventClickThrough(Rect rect)
        {
            Vector2 pointerPos = Mouse.screenPos;

            //			  if (rect.Contains(pointerPos) && !EditorLogic.softLock)
            if (rect.Contains(pointerPos))
            {
                EditorLockManager.lockEditor(Constants.settingPreventClickThroughLock);
            }
            //			  else if (!rect.Contains(pointerPos) && EditorLogic.softLock)
            else if (!rect.Contains(pointerPos))
            {
                EditorLockManager.unlockEditor(Constants.settingPreventClickThroughLock);
            }
        }
        /// <summary>
        /// Public Eventcall at the GuiDraw
        /// </summary>
        private void HandleGUI()
        {
            if (!_guiVisible)
            {
                //TODO: Play a "uh-uh" (nops) sound.
                Log.dbgGui(this, "GUI is set to invisible!");
                return;
            }

            GUI.skin = _guiskin;
            switch (this.state)
            {
            case DisplayState.none:
                EditorLockManager.unlockEditor(Constants.settingPreventClickThroughLock);
                EditorLockManager.unlockEditor(Constants.settingWeldingLock);
                break;

            case DisplayState.weldError:
                _editorErrorDial = ClickThruBlocker.GUILayoutWindow((int)this.state, _editorErrorDial, OnErrorDisplay, Constants.weldManufacturer);
                break;

            case DisplayState.weldWarning:
                _editorWarningDial = ClickThruBlocker.GUILayoutWindow((int)this.state, _editorWarningDial, OnWarningDisplay, Constants.weldManufacturer);
                break;

            case DisplayState.infoWindow:
                _editorInfoWindow = ClickThruBlocker.GUIWindow((int)this.state, _editorInfoWindow, OnInfoWindow, Constants.weldManufacturer);
                PreventClickThrough(_editorInfoWindow);
                break;

            case DisplayState.savedWindow:
                _editorSavedDial = ClickThruBlocker.GUILayoutWindow((int)this.state, _editorSavedDial, OnSavedDisplay, Constants.weldManufacturer);
                break;

            case DisplayState.overwriteDial:
                _editorOverwriteDial = ClickThruBlocker.GUILayoutWindow((int)this.state, _editorOverwriteDial, OnOverwriteDisplay, Constants.weldManufacturer);
                break;

            case DisplayState.mainWindow:
                _editorMainWindow = ClickThruBlocker.GUIWindow((int)this.state, _editorMainWindow, OnMainWindow, Constants.weldManufacturer);
                PreventClickThrough(_editorMainWindow);
                break;

            case DisplayState.partSelection:
                ScreenMessages.PostScreenMessage(Constants.guiScreenMessagePartSelection, Time.deltaTime, ScreenMessageStyle.UPPER_CENTER);
                break;
            }
        }         //private void OnDraw()
 /*
  * Free and clear the editor
  */
 private void ClearEditor()
 {
     if (_config.clearEditor)
     {
         EditorLockManager.resetEditorLocks();
         EditorPartList.Instance.Refresh();
         if (_selectedPartbranch != null)
         {
             disablePartHighlight(_selectedPartbranch);
             EditorLogic.fetch.OnSubassemblyDialogDismiss(EditorLogic.RootPart);
             Log.dbg("{0} {1} - {2}", _config.clearEditor, _selectedPartbranch, EditorLogic.SelectedPart);
             EditorLogic.DeletePart(EditorLogic.RootPart);
             _selectedPartbranch = null;
         }
     }
 }
Exemple #5
0
 /*
  * Free and clear the editor
  */
 private void ClearEditor()
 {
     if (_config.clearEditor)
     {
         EditorLockManager.resetEditorLocks();
         EditorPartList.Instance.Refresh();
         if (_selectedPartbranch != null)
         {
             disablePartHighlight(_selectedPartbranch);
             EditorLogic.fetch.OnSubassemblyDialogDismiss(EditorLogic.RootPart);
             Debug.Log(string.Format("{0}{1} {2} - {3}", Constants.logPrefix, _config.clearEditor, _selectedPartbranch, EditorLogic.SelectedPart));
             EditorLogic.DeletePart(EditorLogic.RootPart);
             _selectedPartbranch = null;
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Public Eventcall at the GuiDraw
        /// </summary>
        private void OnDraw()
        {
            if (_guiVisible)
            {
                GUI.skin = _guiskin;

                switch (_state)
                {
                case DisplayState.none:
                    EditorLockManager.unlockEditor(Constants.settingPreventClickThroughLock);
                    EditorLockManager.unlockEditor(Constants.settingWeldingLock);
                    break;

                case DisplayState.weldError:
                    _editorErrorDial = GUILayout.Window((int)_state, _editorErrorDial, OnErrorDisplay, Constants.weldManufacturer);
                    break;

                case DisplayState.weldWarning:
                    _editorWarningDial = GUILayout.Window((int)_state, _editorWarningDial, OnWarningDisplay, Constants.weldManufacturer);
                    break;

                case DisplayState.infoWindow:
                    _editorInfoWindow = GUI.Window((int)_state, _editorInfoWindow, OnInfoWindow, Constants.weldManufacturer);
                    PreventClickThrough(_editorInfoWindow);
                    break;

                case DisplayState.savedWindow:
                    _editorSavedDial = GUILayout.Window((int)_state, _editorSavedDial, OnSavedDisplay, Constants.weldManufacturer);
                    break;

                case DisplayState.overwriteDial:
                    _editorOverwriteDial = GUILayout.Window((int)_state, _editorOverwriteDial, OnOverwriteDisplay, Constants.weldManufacturer);
                    break;

                case DisplayState.mainWindow:
                    _editorMainWindow = GUI.Window((int)_state, _editorMainWindow, OnMainWindow, Constants.weldManufacturer);
                    PreventClickThrough(_editorMainWindow);
                    break;

                case DisplayState.partSelection:
                    ScreenMessages.PostScreenMessage(Constants.guiScreenMessagePartSelection, Time.deltaTime, ScreenMessageStyle.UPPER_CENTER);
                    break;
                }
            }     //if (_guiVisible)
        }         //private void OnDraw()
        /*
         * Error Message
         */
        private void HandleErrorDisplay(int windowID)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label(Constants.guiDialFail);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(Constants.guiOK))
            {
                EditorLockManager.unlockEditor(Constants.settingWeldingLock);
                this.state = DisplayState.none;
            }
            GUILayout.EndVertical();

            GUI.DragWindow();
        }         //private void OnErrorDisplay()
Exemple #8
0
 /// <summary>
 /// Welds the whole active craft in the scene in case the stocktoolbar is used
 /// </summary>
 public void stockToolbarButtonUsed()
 {
     if (!EditorLockManager.isEditorLocked())
     {
         if (EditorLogic.RootPart != null)
         {
             if (_state != DisplayState.mainWindow)
             {
                 _state = DisplayState.mainWindow;
             }
             else
             {
                 closeMainwindow();
             }
         }
     }
     //_stockToolbarButton.SetFalse();
 }
 /// <summary>
 /// Welds the whole active craft in the scene in case the stocktoolbar is used
 /// </summary>
 public void HandleToolbarButtonUsed()
 {
     try
     {
         if (!EditorLockManager.isEditorLocked())
         {
             if (EditorLogic.RootPart != null)
             {
                 if (this.state != DisplayState.mainWindow)
                 {
                     this.state = DisplayState.mainWindow;
                 }
                 else
                 {
                     closeMainwindow();
                 }
             }
             else
             {
                 Log.dbgGui(this, "EditorLogic.RootPart == null!");
             }
         }
         else
         {
             Log.dbgGui(this, "EditorLockManager.isEditorLocked()!");
         }
     }
     catch (Exception e)
     {
         Log.ex(this, e);
     }
     finally
     {
         Log.dbgGui(this, "HandleToolbarButtonUsed handled.");
     }
 }
        /*
         * Main window
         */
        private void HandleMainWindow(int windowID)
        {
            GUIStyle _settingsToggleGroupStyle = new GUIStyle(GUI.skin.toggle);

            _settingsToggleGroupStyle.margin.left += 40;

            //save Window Position
            _config.MainWindowXPosition = (int)_editorMainWindow.xMin;
            _config.MainWindowYPosition = (int)_editorMainWindow.yMin;

            GUILayout.BeginVertical();
            GUILayout.EndVertical();
            GUILayout.BeginVertical();

            if (GUILayout.Button(Constants.guiSettingsGUIContent, GUILayout.MaxWidth(160)))
            {
                _mainWindowsSettingsMode = !_mainWindowsSettingsMode;
            }
            //Settings
            if (_mainWindowsSettingsMode)
            {
                _editorMainWindow.height         = Constants.guiMainWindowHSettingsExpanded;
                _settingsScrollPosition          = GUILayout.BeginScrollView(_settingsScrollPosition);
                _config.includeAllNodes          = GUILayout.Toggle(_config.includeAllNodes, Constants.guiAllNodesGUIContent);
                Welder.includeAllNodes           = _config.includeAllNodes;
                _config.dontProcessMasslessParts = GUILayout.Toggle(_config.dontProcessMasslessParts, Constants.guiDontProcessMasslessPartsGUIContent);
                Welder.dontProcessMasslessParts  = _config.dontProcessMasslessParts;
                _config.dataBaseAutoReload       = GUILayout.Toggle(_config.dataBaseAutoReload, Constants.guiDbAutoReloadGUIContent);
                _config.useNamedCfgFile          = GUILayout.Toggle(_config.useNamedCfgFile, Constants.guiUseNamedCfgFileGUIContent);
                _config.advancedDebug            = GUILayout.Toggle(_config.advancedDebug, Constants.guiAdvancedDebugGUIContent);
                _config.clearEditor        = GUILayout.Toggle(_config.clearEditor, Constants.guiClearEditorGUIContent);
                _config.fileSimplification = GUILayout.Toggle(_config.fileSimplification, Constants.guiFileSimplificationGUIContent);
                Welder.fileSimplification  = _config.fileSimplification;
                GUILayout.Space(10.0f);
                GUILayout.Label(" Vector Precision: " + _config.precisionDigits);
                _config.precisionDigits = (int)GUILayout.HorizontalSlider(_config.precisionDigits, 1, 6);
                Welder.precisionDigits  = _config.precisionDigits;
                GUILayout.Space(10.0f);
                GUILayout.Label("Strength params calculation method");
//				_config.StrengthCalcMethod = (StrengthParamsCalcMethod)GUILayout.SelectionGrid((int)_config.StrengthCalcMethod, Constants.StrengthParamsCalcMethodsGUIContent, 1, GUILayout.MaxWidth(140));
                foreach (StrengthParamsCalcMethod method in Enum.GetValues(typeof(StrengthParamsCalcMethod)))
                {
                    if (GUILayout.Toggle((_config.StrengthCalcMethod == method), Constants.StrengthParamsCalcMethodsGUIContent[(int)method], _settingsToggleGroupStyle))
                    {
                        _config.StrengthCalcMethod = method;
                        Welder.StrengthCalcMethod  = method;
                    }
                }
                GUILayout.Space(10.0f);
                GUILayout.Label("MaxTemp calculation method");
//				_config.MaxTempCalcMethod = (MaxTempCalcMethod)GUILayout.SelectionGrid((int)_config.MaxTempCalcMethod, Constants.MaxTempCalcMethodsGUIContent, 1, GUILayout.MaxWidth(140));
                foreach (MaxTempCalcMethod method in Enum.GetValues(typeof(MaxTempCalcMethod)))
                {
                    if (GUILayout.Toggle((_config.MaxTempCalcMethod == method), Constants.MaxTempCalcMethodsGUIContent[(int)method], _settingsToggleGroupStyle))
                    {
                        _config.MaxTempCalcMethod = method;
                        Welder.MaxTempCalcMethod  = method;
                    }
                }
                GUILayout.EndScrollView();

//				GUILayout.Space(10.0f);
                if (GUILayout.Button(Constants.guiSaveSettingsButtonGUIContent, GUILayout.MaxWidth(160)))
                {
                    FileManager.saveConfig(_config);
                    _config = FileManager.loadConfig();
                }
            }
            else
            {
                _editorMainWindow.height = Constants.guiMainWindowH;
                GUILayout.Space(20.0f);
            }

            //SelectPArtbranch button
            if (GUILayout.RepeatButton(Constants.guiSelectPartGUIContent, GUILayout.MaxWidth(160)))
            {
                this.state = DisplayState.partSelection;
            }

            //Weld button
            if (GUILayout.Button(Constants.guiWeldItButtonGUIContent, GUILayout.MaxWidth(160)))
            {
                FileManager.saveConfig(_config);

                if (EditorLockManager.isEditorLocked())
                {
                    if (_selectedPartbranch == null)
                    {
                        _selectedPartbranch = EditorLogic.RootPart;
                    }
                    repositionPreWeldment(_selectedPartbranch);
                    weldPart(_selectedPartbranch);
                }
            }
            if (GUILayout.Button(Constants.guiCloseGUIContent, GUILayout.MaxWidth(160)))
            {
                closeMainwindow();
            }
            //Hints area
            GUILayout.TextArea(GUI.tooltip, GUILayout.ExpandHeight(true), GUILayout.MaxHeight(100));
            GUIStyle VersionLabelGUIStyle = new GUIStyle(GUI.skin.label);

            VersionLabelGUIStyle.fontSize = 12;
            GUILayout.Label(Constants.logVersion, VersionLabelGUIStyle);
            GUILayout.EndVertical();

            GUI.DragWindow();
        }         //private void OnMainWindow()
        }         //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;
            }
        }
Exemple #12
0
 /*
  * Called once everything in scene is loaded
  */
 public void Start()
 {
     initGUI();
     EditorLockManager.resetEditorLocks();
     _editorFacility = EditorDriver.editorFacility;
 }