// Constructors #region Constructors /// <summary> /// Default constructor /// </summary> public SMRandomGeneratorForm() { // Create the visual components this.InitializeComponent(); // Ajusts the size of the window in case of a low resolution screen this.SetWindowSize(); // Max value alowed for a seed this.SeedNumericSelection.Maximum = int.MaxValue; // Try to load the last section parameters RandomizerParameters rdparameters = null; try { rdparameters = new RandomizerParameters(Core.StandAlone); } catch (Exception ex) { this.PrintUserMessage(Properties.Resources.LoadingSettingsErrorMessage, UserMessageType.Warning); this.PrintUserMessage(Properties.Resources.LoadingDefaultMessage, UserMessageType.Information); ex.Log(); rdparameters = new RandomizerParameters(); } // Populates the difficulty option combobox this.PopulateRandomizerParameters(rdparameters); // Check for exception log files this.CheckExceptionLogFiles(); // Display the application version this.Text += " - " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
/// <summary> /// Populates the difficulty option combobox /// </summary> /// <param name="lastselected">Last item selected</param> private void PopulateRandomizerParameters(RandomizerParameters rdparameters) { // Set previously used parameters this.FileSelectTextBox.Text = rdparameters.SourceFilePath; this.SeedRadioButton.Checked = rdparameters.UserInputSeed; this.RandomSeedRadioButton.Checked = !rdparameters.UserInputSeed; this.SeedNumericSelection.Value = rdparameters.Seed; this.RandomSeedNumericSelection.Value = rdparameters.RandomSeedCount; this.SpoilerCheckBox.Checked = rdparameters.SaveSpoilers; this.UseEmulatorCheckBox.Checked = rdparameters.StartEmulator; this.EmulatorSourceTextBox.Text = rdparameters.EmulatorExecutablePath; // Populates the difficulty combobox options List <DifficultyOption> options = new List <DifficultyOption>(); foreach (Types.Difficulty difficulty in this._SupportedDifficulties) { options.Add(new DifficultyOption(difficulty)); } options.Sort(); this.DifficultyComboBox.Items.AddRange(options.ToArray()); // Pre-select the option from the user registry this.DifficultyComboBox.SelectedIndex = (int)rdparameters.Difficulty; }
/// <summary> /// When the form is closed /// </summary> private void SMRandomGeneratorForm_FormClosed(object sender, FormClosedEventArgs e) { try { // Save parameters RandomizerParameters rdparameters = this.GetRandomizerParameters(); rdparameters.SaveParameters(Core.StandAlone); } // If there is an error while saving the parameters, just log it and ignore it catch (Exception ex) { ex.Log(); } }
/// <summary> /// Return the current randomization parameters /// </summary> private RandomizerParameters GetRandomizerParameters() { // Get the randomization parameters RandomizerParameters rdparameters = new RandomizerParameters() { UserInputSeed = this.SeedRadioButton.Checked, SourceFilePath = this.FileSelectTextBox.Text, Seed = (int)this.SeedNumericSelection.Value, SaveSpoilers = this.SpoilerCheckBox.Checked, RandomSeedCount = (int)this.RandomSeedNumericSelection.Value, Difficulty = (this.DifficultyComboBox.SelectedItem as DifficultyOption).Difficulty, StartEmulator = this.UseEmulatorCheckBox.Checked, EmulatorExecutablePath = this.EmulatorSourceTextBox.Text }; return(rdparameters); }
/// <summary> /// Click on the "Randomize!" button to start a randomziation process /// </summary> private void RandomizeButton_Click(object sender, EventArgs e) { try { // Check if the filepath is valid if (string.IsNullOrWhiteSpace(this.FileSelectTextBox.Text) || !File.Exists(this.FileSelectTextBox.Text)) { // If it is invalid, change the color of the text box to show the problem this.FileSelectTextBox.BackColor = Color.Salmon; this.PrintUserMessage(Properties.Resources.FilePathWarning, UserMessageType.Warning); this.PrintUserMessage("", UserMessageType.Warning); return; } // Check if the emulator is valid if (this.UseEmulatorCheckBox.Checked && (string.IsNullOrWhiteSpace(this.EmulatorSourceTextBox.Text) || !File.Exists(this.EmulatorSourceTextBox.Text))) { // If it is invalid, change the color of the text box to show the problem this.EmulatorSourceTextBox.BackColor = Color.Salmon; this.PrintUserMessage(Properties.Resources.EmulatorFilePathWarning, UserMessageType.Warning); this.PrintUserMessage("", UserMessageType.Warning); return; } // Get the randomization parameters RandomizerParameters rdparameters = this.GetRandomizerParameters(); // Disable user input components this.UserInputLock(); // Starts the randomization process this.RandomizerThread.RunWorkerAsync(rdparameters); } catch (Exception ex) { ex.LogAndDisplayMessage(); // Unlock the user interface this.UserInputUnlock(); } }