Esempio n. 1
0
    public static CheckersSettings DeserializeSettingsFile(string path)
    {
        var fileName = path + "settings.xml";

        UnityEngine.Debug.Log(fileName);
        CheckersSettings tmp = new CheckersSettings();

        try
        {
            if (File.Exists(fileName))
            {
                using (var r = new StreamReader(fileName, false))
                {
                    XmlSerializer deserializer = new XmlSerializer(typeof(CheckersSettings));
                    tmp = (CheckersSettings)deserializer.Deserialize(r);
                    return(tmp);
                }
            }
            else
            {
                //if the file doesnt exist, create a new object, save it, then reload it
                CheckersSettings newObj = new CheckersSettings();
                SerializeSettingsFile(path, newObj);
                DeserializeSettingsFile(path);
            }
            return(tmp);
        }
        catch (Exception e)
        {
            Trace.WriteLine(e);
            return(tmp);
        }
    }
Esempio n. 2
0
 void Start()
 {
     Debug.Log(Application.dataPath);
     //on start load the settings file
     settings       = CheckersSettings.DeserializeSettingsFile(Application.dataPath + "/");
     boardGenerator = BoardGenerator.instance;
     if (boardGenerator != null)
     {
         GenerateBoard();
     }
 }
Esempio n. 3
0
 public bool SaveChanges()
 {
     try
     {
         CheckersSettings.SerializeSettingsFile(Application.dataPath + "/", settings);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 4
0
    public static void SerializeSettingsFile(string path, CheckersSettings settings)
    {
        var fileName = path + "settings.xml";

        UnityEngine.Debug.Log(fileName);
        //load settings.xml or create a new file
        try
        {
            using (var s = new StreamWriter(fileName, false))
            {
                XmlSerializer serailizer = new XmlSerializer(typeof(CheckersSettings));
                serailizer.Serialize(s, settings);
            }
        }
        catch (Exception e)
        {
            Trace.WriteLine(e);
        }
    }
        /// <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;
        }
 /// <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();
 }
Esempio n. 7
0
 /// <summary>
 /// Handles the Click event of the menuViewPreferences 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 menuViewPreferences_Click(object sender, System.EventArgs e)
 {
     PreferencesDialog form = new PreferencesDialog();
     form.Settings = settings;
     if(form.ShowDialog(this) == DialogResult.Cancel)
         return;
     settings = form.Settings;
     UpdateBoard();
 }
Esempio n. 8
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();
 }