/// <summary> /// This event is fired when the 'SaveButton' is clicked. /// </summary> private void SaveButton_Click(object sender, EventArgs e) { // Capture the Game Manager from this form this.GameManager = CaptureGameManager(); // If the GameManager object exists (should always be true) if (this.HasGameManager) { // if the values needs to be saved on this computer if (gameManager.HouseRules.SaveSettingsOnThisComputer) { // The gameManager needs to be converted to a SecureUserData (ApplicationSettings) object. SecureUserData security = SecureUserDataFactory.Convert(gameManager); // If the security object exists if (NullHelper.Exists(security)) { // set the LastSavedDate security.LastSavedDate = DateTime.Now; // save the values in the settings security.Save(); } } // The user did not cancel this.UserCancelled = false; // Close this form this.Close(); } }
/// <summary> /// This event is fired when Table Options Control _ Load /// </summary> private void TableOptionsControl_Load(object sender, EventArgs e) { // Get the GameSpeed from the Security SecureUserData security = new SecureUserData(); // set the gameSpeed GameSpeedEnum gameSpeed = security.GameSpeed; // Setup the GameSpeedControl this.GameSpeedControl.SelectedIndex = FindGameSpeedIndex(gameSpeed); this.GameSpeedControl.SelectedIndexListener = this; }
/// <summary> /// The Selected has changed. /// </summary> /// <param name="control"></param> /// <param name="selectedIndex"></param> public void OnSelectedIndexChanged(LabelComboBoxControl control, int selectedIndex, object selectedItem) { // if Manuel Deal if (selectedIndex == 0) { // change out the button to blue and enable the button this.DealButton.BackgroundImage = Properties.Resources.DarkBlueButton; this.DealButton.ForeColor = Color.LemonChiffon; // Put the events back (the appearance changes if you just disable the button) this.DealButton.Click += DealButton_Click; this.DealButton.MouseEnter += Button_MouseEnter; this.DealButton.MouseLeave += Button_MouseLeave; } else { // use the dark button and disable the button this.DealButton.BackgroundImage = Properties.Resources.DarkButton; this.DealButton.ForeColor = Color.LightGray; // Remove the events (the appearance changes if you just disable the button) this.DealButton.Click -= DealButton_Click; this.DealButton.MouseEnter -= Button_MouseEnter; this.DealButton.MouseLeave -= Button_MouseLeave; } // If the GameManager object exists if ((this.HasGameManager) && (this.HasParentMainForm)) { // Set the GameSpeed this.GameManager.HouseRules.GameSpeed = ParseGameSpeed(selectedItem); // now save the value in the settings SecureUserData security = new SecureUserData(); // Set the value for DontShowChipSelectorInstructions security.GameSpeed = this.GameManager.HouseRules.GameSpeed; // Save the settings with this value not showing again security.Save(); // if we are not on ManuelDeal if (this.GameManager.HouseRules.GameSpeed != GameSpeedEnum.Manuel_Deal) { // Start Dealing this.ParentMainForm.StartDealing(); } } }
/// <summary> /// This method returns the GameManager. It first attempts to load the values from the settings /// and if not found the default GameManager.Options and GameManager.Players are created. /// </summary> private GameManager LoadGameManager() { // initial value GameManager gameManager = null; // local so the Settings file only has to be loaded once SecureUserData security = new SecureUserData(); // this is used during development so everything default is restored, this has to be taken out or commented out // security.LastSavedDate = new DateTime(1900, 1, 1); // save (this needs to be taken out or commented out also) // security.Save(); // We must load our five PlayerControls List <BlackJackPlayerControl> playerControls = GetPlayerControls(); // if the security object has a LastSavedDate we can load a GameManager from it if (security.HasLastSavedDate) { // convert the settings to a gameManager object gameManager = SecureUserDataFactory.Export(security, playerControls, this); } else { // Create a new instance of a 'GameManager' object. gameManager = new GameManager(NumericHelper.ParseInteger(Properties.Resources.TimesToShuffle, 0, -1), this); // Now we must load the Options and Players from the Settings gameManager.HouseRules = Options.CreateDefault(); // Load the players from the Settings or create them gameManager.Players = CreateDefaultPlayers(gameManager.HouseRules); } //// Create a new instance of an 'OptionsForm' object. OptionsForm optionsForm = new OptionsForm(this); // Setup the form optionsForm.Setup(gameManager); //// Show the dialog optionsForm.ShowDialog(); // if the user did not cancel if (!optionsForm.UserCancelled) { // set the return value this.GameManager = optionsForm.GameManager; } else { // if the GameManager does not exist if (!this.HasGameManager) { // Close this app Environment.Exit(0); } } // return value return(gameManager); }