Esempio n. 1
0
        public MenuWindow(Core core, SettingsContainer settingsContainer, Dictionary <string, FontContainer> fonts)
        {
            this.core          = core;
            _settingsContainer = settingsContainer;
            _CoreSettings      = settingsContainer.CoreSettings;
            Fonts       = fonts;
            themeEditor = new ThemeEditor(_CoreSettings);

            /*Input.RegisterKey(Keys.F12);
             * Input.ReleaseKey += (sender, keys) =>
             * {
             *  if (keys== SettingsCoreSettings.MainMenuKeyToggle.Value)
             *  {
             *      Enable = !Enable;
             *  }
             * };*/

            CoreSettingsDrawers = new List <ISettingsHolder>();

            SettingsParser.Parse(_CoreSettings, CoreSettingsDrawers);
            Selected = CoreSettings;

            CoreSettings = () =>
            {
                foreach (var drawer in CoreSettingsDrawers)
                {
                    drawer.Draw();
                }
            };

            _index   = -1;
            Selected = CoreSettings;

            Core.DebugInformations.CollectionChanged += OnDebugInformationsOnCollectionChanged;
            debugInformation = new DebugInformation("DebugWindow", false);
            OpenWindow       = Windows.MainDebugs;
            WindowsName      = Enum.GetValues(typeof(Windows));

            OnWindowChange += () =>
            {
                MoreInformation = null;
                selectedName    = "";
            };

            Input.RegisterKey(_CoreSettings.MainMenuKeyToggle);
            _CoreSettings.MainMenuKeyToggle.OnValueChanged += () => { Input.RegisterKey(_CoreSettings.MainMenuKeyToggle); };

            _CoreSettings.Enable.OnValueChanged += (sender, b) =>
            {
                if (!_CoreSettings.Enable)
                {
                    try
                    {
                        _settingsContainer.SaveCoreSettings();

                        foreach (var plugin in core.pluginManager.Plugins)
                        {
                            try
                            {
                                _settingsContainer.SaveSettings(plugin.Plugin);
                            }
                            catch (Exception e)
                            {
                                DebugWindow.LogError($"SaveSettings for plugin error: {e}");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        DebugWindow.LogError($"SaveSettings error: {e}");
                    }
                }
            };
        }
Esempio n. 2
0
        public MenuWindow(Core core, SettingsContainer settingsContainer, Dictionary <string, FontContainer> fonts, ref VersionChecker versionChecker)
        {
            this.Core          = core;
            _settingsContainer = settingsContainer;
            CoreSettings       = settingsContainer.CoreSettings;
            Fonts = fonts;
            CoreSettingsDrawers = new List <ISettingsHolder>();
            SettingsParser.Parse(CoreSettings, CoreSettingsDrawers);

            PluginsUpdateSettings        = settingsContainer.PluginsUpdateSettings;
            PluginsUpdateSettingsDrawers = new List <ISettingsHolder>();
            SettingsParser.Parse(PluginsUpdateSettings, PluginsUpdateSettingsDrawers);

            VersionChecker = versionChecker;

            Selected = CoreSettingsAction;

            CoreSettingsAction = () =>
            {
                foreach (var drawer in CoreSettingsDrawers)
                {
                    drawer.Draw();
                }
            };

            _index   = -1;
            Selected = CoreSettingsAction;

            Core.DebugInformations.CollectionChanged += OnDebugInformationsOnCollectionChanged;
            debugInformation = new DebugInformation("DebugWindow", false);
            OpenWindow       = Windows.MainDebugs;
            WindowsName      = Enum.GetValues(typeof(Windows));

            OnWindowChange += () =>
            {
                MoreInformation = null;
                selectedName    = "";
            };

            Input.RegisterKey(CoreSettings.MainMenuKeyToggle);
            CoreSettings.MainMenuKeyToggle.OnValueChanged += () => { Input.RegisterKey(CoreSettings.MainMenuKeyToggle); };

            CoreSettings.Enable.OnValueChanged += (sender, b) =>
            {
                if (!CoreSettings.Enable)
                {
                    try
                    {
                        _settingsContainer.SaveCoreSettings();
                        try
                        {
                            _settingsContainer.SavePluginAutoUpdateSettings();
                        }
                        catch (Exception e)
                        {
                            DebugWindow.LogError($"SaveSettings for PluginAutoUpdate error: {e}");
                        }
                        foreach (var plugin in core.pluginManager.Plugins)
                        {
                            try
                            {
                                _settingsContainer.SaveSettings(plugin.Plugin);
                            }
                            catch (Exception e)
                            {
                                DebugWindow.LogError($"SaveSettings for plugin error: {e}");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        DebugWindow.LogError($"SaveSettings error: {e}");
                    }
                }
            };
        }