/// <summary> /// Creates a new hotkeyset with input from the user and a random ID /// Imports a config file to go with the hotkeyset /// </summary> private void AddHotkeySetAndConfig() { if (IsTibiaRunning()) // If tibia is running { // Shows an error message MessageBox.Show("You cannot add new hotkeysets while tibia is running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (hksManager.IsListFull()) // If the list is full { // Shows an error message MessageBox.Show(String.Format("The maximum number of sets ({0}) have been reached.", hksManager.HotkeySetsLimit), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // If the list is not full { hksForm = new HotkeySetForm(hksManager.NewIDGenerator()); // New instance of the hotkeysetform with a new id in the constructor param hksForm.Text = "Add new config"; // Change the title of the instance if (hksForm.ShowDialog() == DialogResult.OK) // Shows form and if the dialogresult is OK (the user ends the form by pressing "Add") { xmlHandler.XMLAddSet(hksForm.HotkeySetData); // Gets the newly made set from the form and creates an xml element from it // Gets the newly made set's filepath and id and runs the method to import the file to the hotkeysets folder cfgHandler.ImportConfig(hksForm.HotkeySetFile, hksForm.HotkeySetData.ID); } } } }
/// <summary> /// Changes the values (info & character class) of a hotkeyset /// Imports a new config to replace the old if selected /// The ID never changes with this method /// </summary> private void ChangeHotkeySetValuesAndConfig() { if (IsTibiaRunning()) // If tibia is running { // Shows an error message MessageBox.Show("You cannot add edit hotkeysets while tibia is running.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // If tibia is not running { if (dgwHotkeySetList.Rows.Count == 0) // If the datagridview is empty { MessageBox.Show("The list is empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // If the datagridview has content and thereby have a selected row { int selectedID = (int)dgwHotkeySetList.CurrentRow.Cells[0].Value; // Gets the id of the selected row and parses it as an int HotkeySet loadSet; // Creates a HotkeySet object from what's selected in the list xmlHandler.XMLReadSet(selectedID, out loadSet); hksForm = new HotkeySetForm(selectedID); // New instance of the hotkeysetform hksForm.HotkeySetData = loadSet; // Sets the data of the form the ones we loaded hksForm.LoadChangeMode(); // Actually outputs those in the form if (hksForm.ShowDialog() == DialogResult.OK) // If the form was exited by pressing the change button { // Runs the hotkeyset manager's changeset method with a new HotkeySet as param // The new HotkeySet is made by the old ID, and the new vocation and info xmlHandler.XMLChangeSet(hksForm.HotkeySetData); // Imports the specified config to overwrite the old one // If the old and new filepath is the same, does nothing cfgHandler.ImportConfig(hksForm.HotkeySetFile, hksForm.HotkeySetData.ID); } } } }