示例#1
0
        void InitConfig()
        {
            try {
                //get location and version info of the plugin
                Assembly execAssembly = Assembly.GetExecutingAssembly();
                pluginVersion    = execAssembly.GetName().Version;
                _pluginDirectory = Path.GetDirectoryName(execAssembly.Location);

                //dll's path + filename for the config file
                _configFilePath = Path.Combine(_pluginDirectory, ConfigFileName);

                //check if the config file is there and create if its missing
                if (ConfigManager.FileExists(_configFilePath))
                {
                    cfg = ConfigManager.LoadConfig(_configFilePath);

                    if (cfg == null)
                    {
                        //failed to load config, create new
                        cfg = ConfigManager.CreateDefaultConfig(_configFilePath, pluginVersion.ToString());
                    }
                    else
                    {
                        //check config file version
                        Version fileVersion = new Version();

                        if (cfg.FileVersion != null)
                        {
                            Log.Debug("Config v" + cfg.FileVersion + " Mod v" + pluginVersion.ToString());

                            try {
                                fileVersion = new Version(cfg.FileVersion);
                            } catch (Exception ex) {
                                Log.Error("Error parsing version from config file: " + ex.Message);
                            }
                        }

                                                #if DEBUG
                        //for debug, replace if version isn't exactly the same
                        bool versionMismatch = (cfg.FileVersion == null || fileVersion != pluginVersion);
                                                #else
                        //replace if x.x doesn't match
                        bool versionMismatch = (cfg.FileVersion == null || fileVersion.Major < pluginVersion.Major || (fileVersion.Major == pluginVersion.Major && fileVersion.Minor < pluginVersion.Minor));
                                                #endif

                        if (versionMismatch)
                        {
                            Log.Info("Config file version mismatch, replacing with new defaults");
                            cfg = ConfigManager.CreateDefaultConfig(_configFilePath, pluginVersion.ToString());
                        }
                        else
                        {
                            Log.Debug("Config file is current");
                        }
                    }
                }
                else
                {
                    cfg = ConfigManager.CreateDefaultConfig(_configFilePath, pluginVersion.ToString());
                    Log.Info("No existing config found, created new default config");
                }

                Log.Debug("Initializing version " + pluginVersion.ToString());
            } catch (Exception ex) {
                Log.Debug("FATAL ERROR - Unable to initialize: " + ex.Message);
                //_abort = true;
                return;
            }
        }
示例#2
0
 public void SettingsWindowClosed()
 {
     Log.Debug("Settings window closed, reloading config");
     cfg = ConfigManager.LoadConfig(_configFilePath);
     Hide();
 }
示例#3
0
        void WindowContent(int windowID)
        {
            toolbarInt = GUILayout.Toolbar(toolbarInt, _toolbarStrings);

            GUILayout.BeginVertical("box");

            #region Settings
            if (toolbarInt == 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Version: " + _version.ToString());
                GUILayout.EndHorizontal();

#if DEBUG
                GUILayout.Label("Debug Build");
                GUILayout.Label("_lastKeyPressed: " + _lastKeyPressed.ToString());
#endif

                GUILayout.BeginHorizontal();
                GUILayout.Label("Message delay:", settingsLabelLayout);
                if (GUILayout.Button("-"))
                {
                    _config.OnScreenMessageTime -= 0.5f;
                }
                GUILayout.Label(_config.OnScreenMessageTime.ToString(), "TextField");
                if (GUILayout.Button("+"))
                {
                    _config.OnScreenMessageTime += 0.5f;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max symmetry:", settingsLabelLayout);
                if (GUILayout.Button("-"))
                {
                    _config.MaxSymmetry--;
                }
                GUILayout.Label(_config.MaxSymmetry.ToString(), "TextField");
                if (GUILayout.Button("+"))
                {
                    _config.MaxSymmetry++;
                }
                GUILayout.EndHorizontal();

                if (keyMapToUpdate == string.Empty)
                {
                    GUILayout.Label("Click button and press key to change");
                }
                else
                {
                    GUILayout.Label("Waiting for key");
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label("Surface attachment:", settingsLabelLayout);
                if (keyMapToUpdate == "am" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.AttachmentMode = _lastKeyPressed;
                    keyMapToUpdate = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.AttachmentMode.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "am";
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Vertical snap:", settingsLabelLayout);
                if (keyMapToUpdate == "vs" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.VerticalSnap = _lastKeyPressed;
                    keyMapToUpdate = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.VerticalSnap.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "vs";
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Horizontal snap:", settingsLabelLayout);
                if (keyMapToUpdate == "hs" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.HorizontalSnap = _lastKeyPressed;
                    keyMapToUpdate = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.HorizontalSnap.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "hs";
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Strut/fuel align:", settingsLabelLayout);
                if (keyMapToUpdate == "cpa" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.CompoundPartAlign = _lastKeyPressed;
                    keyMapToUpdate = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.CompoundPartAlign.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "cpa";
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Reset camera:", settingsLabelLayout);
                if (keyMapToUpdate == "rc" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.ResetCamera = _lastKeyPressed;
                    keyMapToUpdate             = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.ResetCamera.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "rc";
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Zoom Selected:", settingsLabelLayout);
                if (keyMapToUpdate == "zs" && _lastKeyPressed != KeyCode.None)
                {
                    _config.KeyMap.ZoomSelected = _lastKeyPressed;
                    keyMapToUpdate = string.Empty;
                }
                if (GUILayout.Button(_config.KeyMap.ZoomSelected.ToString()))
                {
                    _lastKeyPressed = KeyCode.None;
                    keyMapToUpdate  = "zs";
                }
                GUILayout.EndHorizontal();
            }
            #endregion

            #region angle snap values settings
            if (toolbarInt == 1)
            {
                try {
                    lock (anglesLock) {
                        foreach (float a in _config.AngleSnapValues)
                        {
                            if (a != 0.0f)
                            {
                                GUILayout.BeginHorizontal();
                                GUILayout.Label(a.ToString(), settingsLabelLayout);
                                if (GUILayout.Button("Remove"))
                                {
                                    _config.AngleSnapValues.Remove(a);
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Add angle: ");
                    newAngleString = GUILayout.TextField(newAngleString);
                    if (GUILayout.Button("Add"))
                    {
                        float newAngle = 0.0f;

                        if (!string.IsNullOrEmpty(newAngleString) && float.TryParse(newAngleString, out newAngle))
                        {
                            lock (anglesLock) {
                                if (newAngle > 0.0f && newAngle <= 90.0f && _config.AngleSnapValues.IndexOf(newAngle) == -1)
                                {
                                    _config.AngleSnapValues.Add(newAngle);
                                    _config.AngleSnapValues.Sort();
                                }
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                                #if DEBUG
                catch (Exception ex) {
                    //potential for some intermittent locking/threading issues here
                    //Debug only to avoid log spam
                    Log.Error("Error updating AngleSnapValues: " + ex.Message);
                }
                                #else
                catch (Exception) {
                    //just ignore the error and continue since it's non-critical
                }
                                #endif
            }

            #endregion

            GUILayout.EndVertical();             //end main content

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Close"))
            {
                //reload config to reset any unsaved changes?
                //_config = ConfigManager.LoadConfig (_configFilePath);
                CloseWindow();
            }

            if (GUILayout.Button("Defaults"))
            {
                _config = ConfigManager.CreateDefaultConfig(_configFilePath, _version);;
            }

            if (GUILayout.Button("Save"))
            {
                ConfigManager.SaveConfig(_config, _configFilePath);
                CloseWindow();
            }
            GUILayout.EndHorizontal();

            GUI.DragWindow();
        }