コード例 #1
0
        private void button_apply_Click(object sender, EventArgs e)
        {
            try
            {
                // Make a backup of the selected character file
                if (!Util.BackupFile(Customization.SelectedCharacter.File))
                {
                    MessageBox.Show("Error while backing up character file.", "ERROR", MessageBoxButtons.OK);
                    return;
                }

                // Write customization, if fail restore backup
                if (Customization.WriteCustomization())
                {
                    MessageBox.Show("Customization applied.", "INFO", MessageBoxButtons.OK);
                    _Populate();
                }
                else
                {
                    MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "ERROR", MessageBoxButtons.OK);
                    Util.RestoreFile();
                    return;
                }
            }
            catch
            {
                MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "FATAL ERROR", MessageBoxButtons.OK);
                Util.RestoreFile();
            }
        }
コード例 #2
0
        private void button_Apply_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(comboBox_Characters.SelectedItem.ToString()) ||
                String.IsNullOrEmpty(comboBox_Beard.SelectedItem.ToString()) ||
                String.IsNullOrEmpty(comboBox_Hair.SelectedItem.ToString()) ||
                String.IsNullOrEmpty(comboBox_HairColor.SelectedItem.ToString()))
            {
                MessageBox.Show("Beard, hair and color must be chosen.", "WARNING", MessageBoxButtons.OK);

                return;
            }

            try
            {
                if (Customization.WriteCustomization(textBox_Name.Text, comboBox_Beard.SelectedItem.ToString(), comboBox_Hair.SelectedItem.ToString(), comboBox_HairColor.SelectedItem.ToString(), checkBox_ChangeName))
                {
                    MessageBox.Show("Customization applied.", "INFO", MessageBoxButtons.OK);
                    Application.Exit();
                }
            }
            catch
            {
                MessageBox.Show("There was an error while applying the new customization. Character data will be restored.", "ERROR", MessageBoxButtons.OK);
                Util.RestoreFile(Customization.last_backup);
            }
        }
コード例 #3
0
        private void button_Apply_Click(object sender, EventArgs e)
        {
            // Check GUI elements content
            if (String.IsNullOrEmpty(comboBox_Beard.SelectedItem.ToString()) || String.IsNullOrEmpty(textBox_Name.Text) ||
                String.IsNullOrEmpty(comboBox_Hair.SelectedItem.ToString()) || String.IsNullOrEmpty(comboBox_Gender.SelectedItem.ToString()))
            {
                MessageBox.Show("Please fill in every field under Character customization.", "ERROR", MessageBoxButtons.OK);
                return;
            }

            // Check name length
            if (!(textBox_Name.Text.Length >= 3 && textBox_Name.Text.Length <= 15))
            {
                MessageBox.Show("Name must be between 3 and 15 characters.", "ERROR", MessageBoxButtons.OK);
                return;
            }

            try
            {
                // Ask to continue and write customization
                DialogResult continue_with_write = MessageBox.Show("The following customization will be applied:\n\t- Name: " +
                                                                   textBox_Name.Text + "\n\t- Beard: " +
                                                                   comboBox_Beard.SelectedItem.ToString() + ".\n\t- Hair: " +
                                                                   comboBox_Hair.SelectedItem.ToString() + ".\n\t- Gender: " +
                                                                   comboBox_Gender.SelectedItem.ToString() + ".\n\n Do you want to continue?",
                                                                   "WARNING", MessageBoxButtons.YesNo);
                if (continue_with_write == DialogResult.No)
                {
                    return;
                }

                // Make a backup of the selected character file
                if (!Util.BackupFile(Customization.SelectedCharacter.File))
                {
                    MessageBox.Show("Error while backing up character file.", "ERROR", MessageBoxButtons.OK);
                    return;
                }

                // Apply changes from the form into CurrentCharacter
                Customization.SelectedCharacter.Data.Name      = textBox_Name.Text;
                Customization.SelectedCharacter.Data.Hair      = ValheimEngine.HairsInternal[Array.IndexOf(ValheimEngine.HairsUI, comboBox_Hair.SelectedItem)];
                Customization.SelectedCharacter.Data.Beard     = ValheimEngine.BeardsInternal[Array.IndexOf(ValheimEngine.BeardsUI, comboBox_Beard.SelectedItem)];
                Customization.SelectedCharacter.Data.Gender    = Customization.GenderUItoInternal(comboBox_Gender.SelectedItem.ToString());
                Customization.SelectedCharacter.Data.HairColor = Util.ColorToVec3(textBox_HairColor.BackColor);
                Customization.SelectedCharacter.Data.SkinColor = Util.ColorToVec3(textBox_SkinTone.BackColor);

                // Write customization, if fail restore backup
                if (Customization.WriteCustomization())
                {
                    MessageBox.Show("Customization applied.", "INFO", MessageBoxButtons.OK);
                    _Refresh();
                }
                else
                {
                    MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "ERROR", MessageBoxButtons.OK);
                    Util.RestoreFile();
                    return;
                }
            }
            catch
            {
                MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "FATAL ERROR", MessageBoxButtons.OK);
                Util.RestoreFile();
            }
        }
コード例 #4
0
        private void button_Apply_Click(object sender, EventArgs e)
        {
            // Check GUI elements content
            if (String.IsNullOrEmpty(comboBox_Characters.SelectedItem.ToString()) || String.IsNullOrEmpty(comboBox_Beard.SelectedItem.ToString()) ||
                String.IsNullOrEmpty(comboBox_Hair.SelectedItem.ToString()) || String.IsNullOrEmpty(comboBox_HairColor.SelectedItem.ToString()))
            {
                MessageBox.Show("At least character, beard, hair and color must be chosen.", "ERROR", MessageBoxButtons.OK);
                return;
            }

            // Check name if enabled
            if (checkBox_ChangeName.Checked && String.IsNullOrEmpty(textBox_Name.Text) && !Customization.isCorrectName(textBox_Name.Text))
            {
                MessageBox.Show("Name must contain ONLY letters (A-Z) and stay between 3 and 15 characters long.", "ERROR", MessageBoxButtons.OK);
                return;
            }

            try
            {
                // WRITE CUSTOMIZATION WITHOUT NAME
                if (!checkBox_ChangeName.Checked || String.IsNullOrEmpty(textBox_Name.Text))
                {
                    // Ask to continue
                    DialogResult continue_with_write = MessageBox.Show("The following customization will be applied:\n\t- Beard: " +
                                                                       comboBox_Beard.SelectedItem.ToString() + ".\n\t- Hair: " +
                                                                       comboBox_Hair.SelectedItem.ToString() + ".\n\t- Hair color: " +
                                                                       comboBox_HairColor.SelectedItem.ToString() + ".\n\n Do you want to continue?",
                                                                       "WARNING", MessageBoxButtons.YesNo);
                    if (continue_with_write == DialogResult.No)
                    {
                        return;
                    }

                    // Make a backup of the selected character file
                    if (!Util.BackupFile(Customization.SelectedCharacterFile))
                    {
                        MessageBox.Show("Error while backing up character file.", "ERROR", MessageBoxButtons.OK);
                        return;
                    }

                    // Write customization, if fail restore backup
                    if (Customization.WriteCustomization(comboBox_Beard.SelectedItem.ToString(), comboBox_Hair.SelectedItem.ToString(),
                                                         comboBox_HairColor.SelectedItem.ToString()))
                    {
                        MessageBox.Show("Customization applied.", "INFO", MessageBoxButtons.OK);
                        _Refresh();
                    }
                    else
                    {
                        MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "ERROR", MessageBoxButtons.OK);
                        Util.RestoreFile();
                        return;
                    }
                }
                // WRITE CUSTOMIZATION WITH NAME
                else
                {
                    // Ask to continue
                    DialogResult continue_with_write = MessageBox.Show("The following customization will be applied:\n\t- Name: " +
                                                                       textBox_Name.Text + "\n\t- Beard: " +
                                                                       comboBox_Beard.SelectedItem.ToString() + ".\n\t- Hair: " +
                                                                       comboBox_Hair.SelectedItem.ToString() + ".\n\t- Hair color: " +
                                                                       comboBox_HairColor.SelectedItem.ToString() + ".\n\n Do you want to continue?",
                                                                       "WARNING", MessageBoxButtons.YesNo);
                    if (continue_with_write == DialogResult.No)
                    {
                        return;
                    }

                    // Make a backup of the selected character file
                    if (!Util.BackupFile(Customization.SelectedCharacterFile))
                    {
                        MessageBox.Show("Error while backing up character file.", "ERROR", MessageBoxButtons.OK);
                        return;
                    }

                    // Write customization, if fail restore backup
                    if (Customization.WriteCustomization(comboBox_Beard.SelectedItem.ToString(), comboBox_Hair.SelectedItem.ToString(),
                                                         comboBox_HairColor.SelectedItem.ToString(), textBox_Name.Text))
                    {
                        MessageBox.Show("Customization applied.", "INFO", MessageBoxButtons.OK);
                        _Refresh();
                    }
                    else
                    {
                        MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "ERROR", MessageBoxButtons.OK);
                        Util.RestoreFile();
                        return;
                    }
                }
            }
            catch
            {
                MessageBox.Show("There was an error while applying the new customization. Last backup will be restored.", "FATAL ERROR", MessageBoxButtons.OK);
                Util.RestoreFile();
            }
        }