Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
 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);
     }
 }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        protected override bool OnTest()
        {
            Logger.Log("Running WindowSettings tests...");

            WindowSettings s1 = new(new Vector2u(400, 400), 0, true, true, 45.0f);

            if (s1.Width is not 400)
            {
                return(Logger.LogReturn("Failed: WindowSettings width did not set correctly.", false));
            }
            if (s1.Height is not 400)
            {
                return(Logger.LogReturn("Failed: WindowSettings height did not set correctly.", false));
            }
            if (s1.WindowMode is not 0)
            {
                return(Logger.LogReturn("Failed: WindowSettings fullscreen did not set correctly.", false));
            }
            if (s1.TargetFps is not 45.0f)
            {
                return(Logger.LogReturn("Failed: WindowSettings target fps did not set correctly.", false));
            }

            string         xml = $"{ Xml.Header }\r\n{ s1 }";
            WindowSettings x   = XmlLoadable.FromXml <WindowSettings>(xml);

            if (x == null)
            {
                return(Logger.LogReturn("Failed: Unable to load WindowSettings from xml.", false));
            }
            if (!x.Equals(s1))
            {
                return(Logger.LogReturn("Failed: Xml loaded WindowSettings has incorrect values.", false));
            }

            return(Logger.LogReturn("WindowSettings tests succeeded!", true));
        }
Exemplo n.º 9
0
        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);
        }