Exemple #1
0
        public static CheckersSettings FromFile(string fileName)
        {
            CheckersSettings settings = null;

            if (File.Exists(fileName))
            {
                FileStream fs = File.OpenRead(fileName);
                try
                {
                    settings = (CheckersSettings)(new SoapFormatter()).Deserialize(fs);
                }
                catch (SerializationException e)
                {
                    MessageBox.Show("Could not load settings:\n" + e.Message + "\n\nUsing default settings.", "Checkers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                fs.Close();
            }
            if ((settings != null) && ((settings.sounds == null) || (settings.sounds.Length != (new CheckersSettings()).sounds.Length)))
            {
                MessageBox.Show("Settings are corrupt.\n\nUsing default settings.", "Checkers", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                settings = null;
            }
            if (settings == null)
            {
                settings = new CheckersSettings();
                settings.Save();
            }
            return(settings);
        }
Exemple #2
0
 /// <summary>
 /// Handles the Click event of the btnDefault control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void btnDefault_Click(object sender, System.EventArgs e)
 {
     if (MessageBox.Show(this, "All settings will be lost. Reset to default settings?", "Checkers", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
     {
         return;
     }
     settings = new CheckersSettings();
     ShowSettings();
 }
Exemple #3
0
 /// <summary>
 /// Handles the Load event of the frmMain control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void frmMain_Load(object sender, System.EventArgs e)
 {
     // Hack: Get actual minimal size
     ClientSize  = new Size(CheckersUI.Width + 8, CheckersUI.Height + 8);
     MinimumSize = Size;
     // Set initial size
     Size = new Size(MinimumSize.Width + 130, MinimumSize.Height);
     // Load settings
     settings = CheckersSettings.Load();
     UpdateBoard();
 }
Exemple #4
0
        /// <summary>
        /// Called when the dialog is shown.
        /// </summary>
        public new DialogResult OnShowDialog(IWin32Window owner)
        {
            if (settings == null)
            {
                settings = new CheckersSettings();
            }

            // Show settings
            ShowSettings();

            // Show dialog
            DialogResult result = base.ShowDialog(owner);

            // Set properties
            if (result != DialogResult.Cancel)
            {
                settings = new CheckersSettings();
                // General settings
                settings.HighlightSelection     = chkHighlightSelection.Checked;
                settings.HighlightPossibleMoves = chkHighlightPossibleMoves.Checked;
                settings.ShowJumpMessage        = chkShowJumpMessage.Checked;
                settings.ShowTextFeedback       = chkShowTextFeedback.Checked;
                // Net settings
                settings.FlashWindowOnGameEvents = chkFlashWindowOnGameEvents.Checked;
                settings.FlashWindowOnTurn       = chkFlashWindowOnTurn.Checked;
                settings.FlashWindowOnMessage    = chkFlashWindowOnMessage.Checked;
                settings.ShowNetPanelOnMessage   = chkShowNetPanelOnMessage.Checked;
                // Board appearance
                settings.BackColor      = picBackColor.BackColor;
                settings.BoardBackColor = picBoardBackColor.BackColor;
                settings.BoardForeColor = picBoardForeColor.BackColor;
                settings.BoardGridColor = picBoardGridColor.BackColor;
                // Sounds
                settings.sounds     = sounds;
                settings.MuteSounds = chkMuteSounds.Checked;
                // Save the settings
                settings.Save();
            }
            return(result);
        }