/// <summary> /// Disposes of all game content, ready to be destroyed. /// </summary> public void Dispose() { Running = false; OnDispose(); if (SaveInputSettings) { if (!Input.Manager.SaveToFile()) { Logger.Log("Unable to save input settings to file.", LogType.Error); } } if (SaveWindowSettings) { if (!XmlLoadable.ToFile(Settings, SettingsPath, true)) { Logger.Log("Unable to save window settings to file.", LogType.Error); } } if (Manager is not null) { Manager.Dispose(); Manager = null; } if (Window is not null) { Window.Dispose(); Window = null; } GC.SuppressFinalize(this); }
private void CancelClicked(object sender, EventArgs e) { if (!m_theme.Equals(Program.Theme)) { DialogResult result = MessageBox.Show(this, "Would you like to save your changes?", "Save Changes?", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { if (!XmlLoadable.ToFile(m_theme, FilePaths.Theme, true)) { MessageBox.Show(this, "Failed saving theme settings.", "Error", MessageBoxButtons.OK); } } else if (result == DialogResult.No) { if (!XmlLoadable.ToFile(m_theme, FilePaths.Theme, true)) { MessageBox.Show(this, "Failed saving theme settings.", "Error", MessageBoxButtons.OK); } } else if (result == DialogResult.Cancel) { return; } } Close(); }
/// <summary> /// Saves the global theme. /// </summary> /// <returns> /// True if the theme file was saved successfully, otherwise false. /// </returns> public static bool SaveTheme() { if (!XmlLoadable.ToFile(Theme, FilePaths.Theme, true)) { return(Logger.LogReturn("Failed saving theme settings to file \"" + FilePaths.Theme + "\".", false, LogType.Error)); } return(true); }
private void SaveClicked(object sender, EventArgs e) { if (!XmlLoadable.ToFile(m_theme, FilePaths.Theme, true)) { MessageBox.Show(this, "Failed saving theme settings.", "Error", MessageBoxButtons.OK); } if (!Program.Theme.LoadFromFile(FilePaths.Theme)) { MessageBox.Show(this, "Failed applying theme settings.", "Error", MessageBoxButtons.OK); } }
/// <summary> /// Saves settings for the current target folder. /// </summary> /// <returns> /// True if the settings file was saved successfully, otherwise false. /// </returns> public static bool SaveSettings() { if (TargetFolder == null) { return(false); } string setfile = Path.Combine(TargetFolder, FilePaths.Settings); if (!XmlLoadable.ToFile(FolderSettings, setfile, true)) { return(Logger.LogReturn("Failed saving settings to file.", false, LogType.Error)); } return(true); }
/// <summary> /// Changes the current window settings, optionally restarting the game for the changes to /// take effect. Has no effect if <see cref="SaveWindowSettings"/> is false. /// </summary> /// <remarks> /// Changes will not be loaded on restart if <see cref="LoadWindowSettings"/> is false. /// Changes will not be saved if <see cref="SaveWindowSettings"/> is false as thus will /// not be applied unless <see cref="LoadWindowSettings"/> is also false. /// </remarks> /// <param name="settings"> /// Window settings. /// </param> /// <param name="restart"> /// If game should close and restart to apply new changes. /// </param> /// <returns> /// True if settings were valid and were assigned and written to file, otherwise false. /// </returns> public bool ChangeSettings(WindowSettings settings, bool restart = false) { if (settings is null || !settings.IsValid) { return(false); } Settings = settings; if (SaveWindowSettings && !XmlLoadable.ToFile(Settings, SettingsPath, true)) { return(Logger.LogReturn("Unable to save newly set window settings to file.", false, LogType.Error)); } if (restart) { RunAgain = true; Exit(); } return(true); }
private void SaveClicked(object sender, EventArgs e) { if (!Directory.Exists(Program.TargetFolder)) { return; } try { string setfile = Path.Combine(Program.TargetFolder, FilePaths.Settings); if (!XmlLoadable.ToFile(m_settings, setfile, true)) { using (ErrorForm ef = new ErrorForm("Unable to save settings to file: \"" + setfile + "\".")) ef.ShowDialog(this); } } catch (Exception ex) { using (ErrorForm ef = new ErrorForm("Unable to save settings to file: " + ex.Message + ".")) ef.ShowDialog(this); } }
private bool Initialise() { // Load input settings. if (LoadInputSettings) { if (!Input.Manager.LoadFromFile()) { if (!MapDefaultActions()) { return(Logger.LogReturn("Failed assigning default input actions.", false, LogType.Error)); } if (!Input.Manager.SaveToFile()) { Logger.Log("Failed saving default inputs. Any modifications to the assigned inputs will not be saved.", LogType.Warning); } } } else if (!MapDefaultActions()) { return(Logger.LogReturn("Failed assigning default input actions.", false, LogType.Error)); } if (Settings is null) { Settings = new WindowSettings(); } // Load/Save WindowSettings. if (LoadWindowSettings) { if (File.Exists(SettingsPath)) { Settings = XmlLoadable.FromFile <WindowSettings>(SettingsPath); if (Settings is null) { ExitCode = ExitCode.InitFail; return(Logger.LogReturn("Failed loading window settings from file although it exists.", false, LogType.Error)); } } } Settings.MakeValid(); if (SaveWindowSettings) { if (!XmlLoadable.ToFile(Settings, SettingsPath, true)) { ExitCode = ExitCode.InitFail; return(Logger.LogReturn("Failed saving window settings to file.", false, LogType.Error)); } } // Set up window. if (Window is not null) { Window.Dispose(); } Styles wm = Settings.WindowMode is WindowMode.Bordered ? Styles.Titlebar : (Settings.WindowMode is WindowMode.Fullscreen ? Styles.Fullscreen : Styles.None); if (wm is Styles.Titlebar) { if (Settings.Close) { wm |= Styles.Close; } if (Settings.Resizable) { wm |= Styles.Resize; } } Window = new RenderWindow(new VideoMode(Settings.Width, Settings.Height), GameTitle, wm); if (Window is null || !Window.IsOpen) { ExitCode = ExitCode.InitFail; return(Logger.LogReturn("Failed creating render window.", false, LogType.Error)); } Window.Closed += OnClose; Manager = new StateManager(this); if (!OnInit()) { ExitCode = ExitCode.OnInitFail; return(false); } return(true); }