Exemplo n.º 1
0
        /// <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);
                    }
                }
            }
        }