private void comboBox_Characters_SelectedIndexChanged(object sender, EventArgs e) { if (Customization.FirstRun || String.IsNullOrEmpty(comboBox_Characters.SelectedItem.ToString())) { return; } try { // Initialize Customization.Initialize(comboBox_Characters.SelectedItem.ToString()); // Add world select gui comboBoxWorld.DataSource = Util.GetCharacterWorlds(Customization.SelectedCharacter); comboBoxWorld.SelectedIndex = 0; // Put appearance in gui textBox_Name.Text = Customization.SelectedCharacter.Data.Name; textBoxX.Text = Customization.SelectedCharacter.Data.WorldsData[long.Parse(comboBoxWorld.SelectedItem.ToString())].LogoutPoint.X.ToString(); textBoxY.Text = Customization.SelectedCharacter.Data.WorldsData[long.Parse(comboBoxWorld.SelectedItem.ToString())].LogoutPoint.Y.ToString(); textBoxZ.Text = Customization.SelectedCharacter.Data.WorldsData[long.Parse(comboBoxWorld.SelectedItem.ToString())].LogoutPoint.Z.ToString(); comboBox_Beard.SelectedIndex = comboBox_Beard.FindStringExact(ValheimEngine.BeardsUI[Util.FindInArrayString(ValheimEngine.BeardsInternal, Customization.SelectedCharacter.Data.Beard)]); comboBox_Hair.SelectedIndex = comboBox_Hair.FindStringExact(ValheimEngine.HairsUI[Util.FindInArrayString(ValheimEngine.HairsInternal, Customization.SelectedCharacter.Data.Hair)]); comboBox_Gender.SelectedIndex = comboBox_Gender.FindStringExact(Customization.GenderInternaltoUI(Customization.SelectedCharacter.Data.Gender)); textBox_HairColor.BackColor = Util.Vec3ToColor(Customization.SelectedCharacter.Data.HairColor); textBox_SkinTone.BackColor = Util.Vec3ToColor(Customization.SelectedCharacter.Data.SkinColor); // Enable gui elements textBox_Name.Enabled = true; comboBoxWorld.Enabled = true; textBoxX.Enabled = true; textBoxY.Enabled = true; textBoxZ.Enabled = true; comboBox_Beard.Enabled = true; comboBox_Hair.Enabled = true; comboBox_Gender.Enabled = true; button_SkinTone.Enabled = true; button_HairColor.Enabled = true; textBox_HairColor.Enabled = true; textBox_SkinTone.Enabled = true; button_Apply.Enabled = true; } catch { MessageBox.Show("There was an error while trying to get character data.", "ERROR", MessageBoxButtons.OK); } }
private void _Populate() { // Get characters try { Customization.GetCharacters(); } catch { MessageBox.Show("There was an error while scanning for characters.", "ERROR", MessageBoxButtons.OK); } // Populate forms with data comboBox_Characters.DataSource = Util.GetCharactersNames(Customization.FoundCharacters); comboBox_Characters.SelectedIndex = -1; comboBox_Beard.DataSource = ValheimEngine.BeardsUI; comboBox_Hair.DataSource = ValheimEngine.HairsUI; comboBox_Gender.DataSource = ValheimEngine.Genders; }
private void _Populate() { // Get characters try { Customization.GetCharacters(); } catch { MessageBox.Show("There was an error while scanning for characters.", "ERROR", MessageBoxButtons.OK); } // Populate forms with data comboBox_Characters.DataSource = Customization.Characters; comboBox_Characters.SelectedIndex = -1; comboBox_Beard.DataSource = Customization.Beards_UI; comboBox_Hair.DataSource = Customization.Hairs_UI; comboBox_HairColor.DataSource = Customization.Hair_Colors; }
private void comboBox_Characters_SelectedIndexChanged(object sender, EventArgs e) { if (Customization.FirstRun) { return; } try { // Initialize Customization.Initialize(comboBox_Characters.SelectedItem.ToString()); // Check character appearance if (Customization.CheckCustomization()) { // Read character appearance (beard, hair and color) Customization.ReadCustomization(); // Put appearance in gui comboBox_Beard.SelectedIndex = comboBox_Beard.FindStringExact(Customization.SelectedCharacterBeard); comboBox_Hair.SelectedIndex = comboBox_Hair.FindStringExact(Customization.SelectedCharacterHair); // Enable gui elements comboBox_Beard.Enabled = true; comboBox_Hair.Enabled = true; comboBox_HairColor.Enabled = true; button_Apply.Enabled = true; } else { return; } } catch { MessageBox.Show("There was an error while trying to get character data.", "ERROR", MessageBoxButtons.OK); } }
private void comboBox_Characters_SelectedIndexChanged(object sender, EventArgs e) { if (Customization.FirstRun) { return; } try { // Save character name and file for future operations Customization.Initialize(comboBox_Characters.SelectedItem.ToString()); // Read current character data String name = Customization.ReadCharacterName(); if (String.IsNullOrEmpty(name)) { MessageBox.Show("Pattern not found. Character can not be customized.", "ERROR", MessageBoxButtons.OK); button_RepairCharacter.Enabled = true; return; } String beard = Customization.ReadCharacterBeard(); String hair = Customization.ReadCharacterHair(); if (String.IsNullOrEmpty(hair) && String.IsNullOrEmpty(beard)) { MessageBox.Show("Please use the \"Repair character\" button.", "ERROR", MessageBoxButtons.OK); button_RepairCharacter.Enabled = true; return; } String color = Customization.ReadCharacterColor(); if (String.IsNullOrEmpty(color)) { MessageBox.Show("Pattern not found. Character can not be customized.", "ERROR", MessageBoxButtons.OK); return; } button_RepairCharacter.Enabled = false; if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(beard) || String.IsNullOrEmpty(hair)) { textBox_Name.Enabled = false; comboBox_Beard.Enabled = false; comboBox_Hair.Enabled = false; comboBox_HairColor.Enabled = false; button_Apply.Enabled = false; return; } textBox_Name.Text = name; comboBox_Beard.SelectedIndex = comboBox_Beard.FindStringExact(beard); comboBox_Hair.SelectedIndex = comboBox_Hair.FindStringExact(hair); comboBox_HairColor.SelectedIndex = comboBox_HairColor.FindStringExact(color); //textBox_Name.Enabled = true; comboBox_Beard.Enabled = true; comboBox_Hair.Enabled = true; comboBox_HairColor.Enabled = true; button_Apply.Enabled = true; } catch { MessageBox.Show("There was an error while trying to get character data.", "ERROR", MessageBoxButtons.OK); } }
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(); } }
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(); } }