Beispiel #1
0
        private void Awake()
        {
            if (instance != null)
            {
                Destroy(gameObject);
            }

            DontDestroyOnLoad(gameObject);

            instance = this;

            fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName).Replace("\\", "/");
            GameEvents.OnGameSettingsApplied.Add(SettingsApplied);

            if (Load())
            {
                ManeuverController.maneuverLog("Settings file loaded", logLevels.log);
            }
            else
            {
                if (Save())
                {
                    ManeuverController.maneuverLog("New Settings file generated at:\n{0}", logLevels.log, fullPath);
                }
            }
        }
Beispiel #2
0
        public bool Load()
        {
            bool b = false;

            try
            {
                if (File.Exists(fullPath))
                {
                    ConfigNode node      = ConfigNode.Load(fullPath);
                    ConfigNode unwrapped = node.GetNode(GetType().Name);
                    ConfigNode.LoadObjectFromConfig(this, unwrapped);
                    b = true;
                }
                else
                {
                    ManeuverController.maneuverLog("Settings file could not be found [{0}]", logLevels.log, fullPath);
                    b = false;
                }
            }
            catch (Exception e)
            {
                ManeuverController.maneuverLog("Error while loading settings file from [{0}]\n{1}", logLevels.log, fullPath, e);
                b = false;
            }

            return(b);
        }
Beispiel #3
0
        private ConfigNode AsConfigNode()
        {
            try
            {
                ConfigNode node = new ConfigNode(GetType().Name);

                node = ConfigNode.CreateConfigFromObject(this, node);
                return(node);
            }
            catch (Exception e)
            {
                ManeuverController.maneuverLog("Failed to generate settings file node...\n{0}", logLevels.log, e);
                return(new ConfigNode(GetType().Name));
            }
        }
Beispiel #4
0
        public bool Save()
        {
            bool b = false;

            try
            {
                ConfigNode node    = AsConfigNode();
                ConfigNode wrapper = new ConfigNode(GetType().Name);
                wrapper.AddNode(node);
                wrapper.Save(fullPath);
                b = true;
            }
            catch (Exception e)
            {
                ManeuverController.maneuverLog("Error while saving settings file at [{0}]\n{1}", logLevels.log, fullPath, e);
                b = false;
            }

            return(b);
        }
Beispiel #5
0
        public void SettingsApplied()
        {
            if (HighLogic.CurrentGame != null)
            {
                settings = HighLogic.CurrentGame.Parameters.CustomParams <ManeuverGameParams>();
            }

            if (settings == null)
            {
                return;
            }

            if (settings.useAsDefault)
            {
                useManeuverTab      = settings.useManeuverSnapTab;
                dynamicScaling      = settings.dynamicScaling;
                baseScale           = settings.baseScale;
                maxScale            = settings.maxScale;
                forceOpen           = settings.forceOpen;
                selectionTolerance  = settings.selectionTolerance;
                alignToOrbit        = settings.alignToOrbit;
                accuracy            = settings.accuracy;
                replaceGizmoButtons = settings.replaceGizmoButtons;
                rightClickClose     = settings.rightClickClose;
                stickyOpenFlight    = settings.stickyOpenFlight;
                showWindowLines     = settings.showWindowLines;
                rememberManualInput = settings.rememberManualInput;
                showManeuverCycle   = settings.showManeuverCycle;
                focusOnNextManeuver = settings.focusOnNextManeuver;
                useKeyboard         = settings.useKeyboard;

                if (Save())
                {
                    ManeuverController.maneuverLog("Settings file saved", logLevels.log);
                }
            }
        }